File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717#define HOMA_PERF_H
1818
1919#include < Homa/Perf.h>
20+ #include < PerfUtils/Cycles.h>
2021
2122#include < atomic>
2223
@@ -225,6 +226,34 @@ struct ThreadCounters : public Counters {
225226 */
226227extern thread_local ThreadCounters counters;
227228
229+ /* *
230+ * Provides a convenient way to measure multiple consecutive cycle time
231+ * intervals.
232+ */
233+ class Timer {
234+ public:
235+ /* *
236+ * Construct a new uninitialized Timer.
237+ */
238+ Timer ()
239+ : split_tsc(0 )
240+ {}
241+
242+ /* *
243+ * Return the number of cycles since the last time split was called.
244+ */
245+ inline uint64_t split ()
246+ {
247+ uint64_t prev_tsc = split_tsc;
248+ split_tsc = PerfUtils::Cycles::rdtsc ();
249+ return split_tsc - prev_tsc;
250+ }
251+
252+ private:
253+ // / Cycle time that split was last called.
254+ uint64_t split_tsc;
255+ };
256+
228257} // namespace Perf
229258} // namespace Homa
230259
Original file line number Diff line number Diff line change @@ -93,13 +93,16 @@ TransportImpl::poll()
9393void
9494TransportImpl::processPackets ()
9595{
96- uint64_t start_tsc = PerfUtils::Cycles::rdtsc ();
97- bool idle = true ;
96+ // Keep track of time spent doing active processing versus idle.
97+ Perf::Timer activityTimer;
98+ activityTimer.split ();
99+ uint64_t activeTime = 0 ;
100+ uint64_t idleTime = 0 ;
101+
98102 const int MAX_BURST = 32 ;
99103 Driver::Packet* packets[MAX_BURST];
100104 int numPackets = driver->receivePackets (MAX_BURST, packets);
101105 for (int i = 0 ; i < numPackets; ++i) {
102- idle = false ;
103106 Driver::Packet* packet = packets[i];
104107 assert (packet->length >=
105108 Util::downCast<int >(sizeof (Protocol::Packet::CommonHeader)));
@@ -140,13 +143,12 @@ TransportImpl::processPackets()
140143 sender->handleErrorPacket (packet, driver);
141144 break ;
142145 }
146+ activeTime += activityTimer.split ();
143147 }
144- uint64_t elapsed_cycles = PerfUtils::Cycles::rdtsc () - start_tsc;
145- if (!idle) {
146- Perf::counters.active_cycles .add (elapsed_cycles);
147- } else {
148- Perf::counters.idle_cycles .add (elapsed_cycles);
149- }
148+ idleTime += activityTimer.split ();
149+
150+ Perf::counters.active_cycles .add (activeTime);
151+ Perf::counters.idle_cycles .add (idleTime);
150152}
151153
152154} // namespace Core
You can’t perform that action at this time.
0 commit comments