MCPcopy Create free account
hub / github.com/F-Stack/f-stack / calc_latency

Function calc_latency

dpdk/examples/rxtx_callbacks/main.c:71–110  ·  view source on GitHub ↗

Callback is added to the TX port. 8< */

Source from the content-addressed store, hash-verified

69
70/* Callback is added to the TX port. 8< */
71static uint16_t
72calc_latency(uint16_t port, uint16_t qidx __rte_unused,
73 struct rte_mbuf **pkts, uint16_t nb_pkts, void *_ __rte_unused)
74{
75 uint64_t cycles = 0;
76 uint64_t queue_ticks = 0;
77 uint64_t now = rte_rdtsc();
78 uint64_t ticks;
79 unsigned i;
80
81 if (hw_timestamping)
82 rte_eth_read_clock(port, &ticks);
83
84 for (i = 0; i < nb_pkts; i++) {
85 cycles += now - *tsc_field(pkts[i]);
86 if (hw_timestamping)
87 queue_ticks += ticks - *hwts_field(pkts[i]);
88 }
89
90 latency_numbers.total_cycles += cycles;
91 if (hw_timestamping)
92 latency_numbers.total_queue_cycles += (queue_ticks
93 * ticks_per_cycle_mult) >> TICKS_PER_CYCLE_SHIFT;
94
95 latency_numbers.total_pkts += nb_pkts;
96
97 if (latency_numbers.total_pkts > (100 * 1000 * 1000ULL)) {
98 printf("Latency = %"PRIu64" cycles\n",
99 latency_numbers.total_cycles / latency_numbers.total_pkts);
100 if (hw_timestamping) {
101 printf("Latency from HW = %"PRIu64" cycles\n",
102 latency_numbers.total_queue_cycles
103 / latency_numbers.total_pkts);
104 }
105 latency_numbers.total_cycles = 0;
106 latency_numbers.total_queue_cycles = 0;
107 latency_numbers.total_pkts = 0;
108 }
109 return nb_pkts;
110}
111/* >8 End of callback addition. */
112
113/*

Callers

nothing calls this directly

Calls 5

rte_eth_read_clockFunction · 0.85
tsc_fieldFunction · 0.85
hwts_fieldFunction · 0.85
rte_rdtscFunction · 0.50
printfFunction · 0.50

Tested by

no test coverage detected