[v4,14/15] examples/rxtx_callbacks: switch to dynamic mbuf field
diff mbox series

Message ID 20201028102640.3191964-15-thomas@monjalon.net
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series
  • remove mbuf userdata
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Thomas Monjalon Oct. 28, 2020, 10:26 a.m. UTC
The example used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 doc/guides/sample_app_ug/rxtx_callbacks.rst |  4 ++--
 examples/rxtx_callbacks/main.c              | 20 ++++++++++++++++++--
 2 files changed, 20 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/doc/guides/sample_app_ug/rxtx_callbacks.rst b/doc/guides/sample_app_ug/rxtx_callbacks.rst
index 62d1f39d7e..56c4293a1a 100644
--- a/doc/guides/sample_app_ug/rxtx_callbacks.rst
+++ b/doc/guides/sample_app_ug/rxtx_callbacks.rst
@@ -152,7 +152,7 @@  all packets received:
         uint64_t now = rte_rdtsc();
 
         for (i = 0; i < nb_pkts; i++)
-            pkts[i]->udata64 = now;
+            TSC_FIELD(pkts[i]) = now;
 
         return nb_pkts;
     }
@@ -179,7 +179,7 @@  packets prior to transmission:
         unsigned i;
 
         for (i = 0; i < nb_pkts; i++)
-            cycles += now - pkts[i]->udata64;
+            cycles += now - TSC_FIELD(pkts[i]);
 
         latency_numbers.total_cycles += cycles;
         latency_numbers.total_pkts   += nb_pkts;
diff --git a/examples/rxtx_callbacks/main.c b/examples/rxtx_callbacks/main.c
index 6fe39546dd..b9a98ceddc 100644
--- a/examples/rxtx_callbacks/main.c
+++ b/examples/rxtx_callbacks/main.c
@@ -10,6 +10,7 @@ 
 #include <rte_cycles.h>
 #include <rte_lcore.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 #define RX_RING_SIZE 1024
 #define TX_RING_SIZE 1024
@@ -18,6 +19,11 @@ 
 #define MBUF_CACHE_SIZE 250
 #define BURST_SIZE 32
 
+typedef uint64_t tsc_t;
+static int tsc_dynfield_offset = -1;
+#define TSC_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		tsc_dynfield_offset, tsc_t *))
+
 static const char usage[] =
 	"%s EAL_ARGS -- [-t]\n";
 
@@ -47,7 +53,7 @@  add_timestamps(uint16_t port __rte_unused, uint16_t qidx __rte_unused,
 	uint64_t now = rte_rdtsc();
 
 	for (i = 0; i < nb_pkts; i++)
-		pkts[i]->udata64 = now;
+		TSC_FIELD(pkts[i]) = now;
 	return nb_pkts;
 }
 
@@ -65,7 +71,7 @@  calc_latency(uint16_t port, uint16_t qidx __rte_unused,
 		rte_eth_read_clock(port, &ticks);
 
 	for (i = 0; i < nb_pkts; i++) {
-		cycles += now - pkts[i]->udata64;
+		cycles += now - TSC_FIELD(pkts[i]);
 		if (hw_timestamping)
 			queue_ticks += ticks - pkts[i]->timestamp;
 	}
@@ -261,6 +267,11 @@  main(int argc, char *argv[])
 	};
 	int opt, option_index;
 
+	static const struct rte_mbuf_dynfield tsc_dynfield_desc = {
+		.name = "example_bbdev_dynfield_tsc",
+		.size = sizeof(tsc_t),
+		.align = __alignof__(tsc_t),
+	};
 
 	/* init EAL */
 	int ret = rte_eal_init(argc, argv);
@@ -292,6 +303,11 @@  main(int argc, char *argv[])
 	if (mbuf_pool == NULL)
 		rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n");
 
+	tsc_dynfield_offset =
+		rte_mbuf_dynfield_register(&tsc_dynfield_desc);
+	if (tsc_dynfield_offset < 0)
+		rte_exit(EXIT_FAILURE, "Cannot register mbuf field\n");
+
 	/* initialize all ports */
 	RTE_ETH_FOREACH_DEV(portid)
 		if (port_init(portid, mbuf_pool) != 0)