[PATCH v3 2/2] latencystats: optimize locking on transmit
Stephen Hemminger
stephen at networkplumber.org
Tue Jun 17 17:00:17 CEST 2025
If transmit callback is called, and there are no packets
in the burst with timestamp set, then the expensive operations
of locking and accessing TSC can be skipped.
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
lib/latencystats/rte_latencystats.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/lib/latencystats/rte_latencystats.c b/lib/latencystats/rte_latencystats.c
index 72a58d78d1..f61d5a273f 100644
--- a/lib/latencystats/rte_latencystats.c
+++ b/lib/latencystats/rte_latencystats.c
@@ -194,10 +194,17 @@ calc_latency(uint16_t pid __rte_unused,
{
unsigned int i;
uint64_t now, latency;
+ uint64_t ts_flags = 0;
static uint64_t prev_latency;
- now = rte_rdtsc();
+ for (i = 0; i < nb_pkts; i++)
+ ts_flags |= (pkts[i]->ol_flags & timestamp_dynflag);
+
+ /* no samples in this burst, skip locking */
+ if (likely(ts_flags == 0))
+ return nb_pkts;
+ now = rte_rdtsc();
rte_spinlock_lock(&glob_stats->lock);
for (i = 0; i < nb_pkts; i++) {
if (!(pkts[i]->ol_flags & timestamp_dynflag))
--
2.47.2
More information about the dev
mailing list