[dpdk-dev] [PATCH v4 03/16] latency: switch Rx timestamp to dynamic mbuf field

Thomas Monjalon thomas at monjalon.net
Tue Nov 3 13:21:52 CET 2020


The mbuf timestamp is moved to a dynamic field
in order to allow removal of the deprecated static field.
The related mbuf flag is also replaced with the dynamic one.

Signed-off-by: Thomas Monjalon <thomas at monjalon.net>
Acked-by: David Marchand <david.marchand at redhat.com>
---
 lib/librte_latencystats/rte_latencystats.c | 30 ++++++++++++++++++----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/lib/librte_latencystats/rte_latencystats.c b/lib/librte_latencystats/rte_latencystats.c
index ba2fff3bcb..ab8db7a139 100644
--- a/lib/librte_latencystats/rte_latencystats.c
+++ b/lib/librte_latencystats/rte_latencystats.c
@@ -9,6 +9,7 @@
 
 #include <rte_string_fns.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_log.h>
 #include <rte_cycles.h>
 #include <rte_ethdev.h>
@@ -31,6 +32,16 @@ latencystat_cycles_per_ns(void)
 /* Macros for printing using RTE_LOG */
 #define RTE_LOGTYPE_LATENCY_STATS RTE_LOGTYPE_USER1
 
+static uint64_t timestamp_dynflag;
+static int timestamp_dynfield_offset = -1;
+
+static inline rte_mbuf_timestamp_t *
+timestamp_dynfield(struct rte_mbuf *mbuf)
+{
+	return RTE_MBUF_DYNFIELD(mbuf,
+			timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
+}
+
 static const char *MZ_RTE_LATENCY_STATS = "rte_latencystats";
 static int latency_stats_index;
 static uint64_t samp_intvl;
@@ -128,10 +139,10 @@ add_time_stamps(uint16_t pid __rte_unused,
 		diff_tsc = now - prev_tsc;
 		timer_tsc += diff_tsc;
 
-		if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) == 0
+		if ((pkts[i]->ol_flags & timestamp_dynflag) == 0
 				&& (timer_tsc >= samp_intvl)) {
-			pkts[i]->timestamp = now;
-			pkts[i]->ol_flags |= PKT_RX_TIMESTAMP;
+			*timestamp_dynfield(pkts[i]) = now;
+			pkts[i]->ol_flags |= timestamp_dynflag;
 			timer_tsc = 0;
 		}
 		prev_tsc = now;
@@ -161,8 +172,8 @@ calc_latency(uint16_t pid __rte_unused,
 
 	now = rte_rdtsc();
 	for (i = 0; i < nb_pkts; i++) {
-		if (pkts[i]->ol_flags & PKT_RX_TIMESTAMP)
-			latency[cnt++] = now - pkts[i]->timestamp;
+		if (pkts[i]->ol_flags & timestamp_dynflag)
+			latency[cnt++] = now - *timestamp_dynfield(pkts[i]);
 	}
 
 	rte_spinlock_lock(&glob_stats->lock);
@@ -241,6 +252,15 @@ rte_latencystats_init(uint64_t app_samp_intvl,
 		return -1;
 	}
 
+	/* Register mbuf field and flag for Rx timestamp */
+	ret = rte_mbuf_dyn_rx_timestamp_register(&timestamp_dynfield_offset,
+			&timestamp_dynflag);
+	if (ret != 0) {
+		RTE_LOG(ERR, LATENCY_STATS,
+			"Cannot register mbuf field/flag for timestamp\n");
+		return -rte_errno;
+	}
+
 	/** Register Rx/Tx callbacks */
 	RTE_ETH_FOREACH_DEV(pid) {
 		struct rte_eth_dev_info dev_info;
-- 
2.28.0



More information about the dev mailing list