The example used the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.
Note: RTE_MBUF_DYNFIELD_TIMESTAMP_NAME is an existing mbuf field name. Signed-off-by: Thomas Monjalon <tho...@monjalon.net> --- doc/guides/sample_app_ug/rxtx_callbacks.rst | 4 ++-- examples/rxtx_callbacks/main.c | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/doc/guides/sample_app_ug/rxtx_callbacks.rst b/doc/guides/sample_app_ug/rxtx_callbacks.rst index 62d1f39d7e..8c3b49ae62 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; + TIMESTAMP_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 - TIMESTAMP_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..8f9852bf6f 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,10 @@ #define MBUF_CACHE_SIZE 250 #define BURST_SIZE 32 +static int timestamp_dynfield_offset; +#define TIMESTAMP_FIELD(mbuf) \ + (*RTE_MBUF_DYNFIELD(mbuf, timestamp_dynfield_offset, uint64_t *)) + static const char usage[] = "%s EAL_ARGS -- [-t]\n"; @@ -47,7 +52,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; + TIMESTAMP_FIELD(pkts[i]) = now; return nb_pkts; } @@ -65,7 +70,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 - TIMESTAMP_FIELD(pkts[i]); if (hw_timestamping) queue_ticks += ticks - pkts[i]->timestamp; } @@ -261,6 +266,11 @@ main(int argc, char *argv[]) }; int opt, option_index; + static const struct rte_mbuf_dynfield timestamp_dynfield_desc = { + .name = RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, + .size = sizeof(uint64_t), + .align = __alignof__(uint64_t), + }; /* init EAL */ int ret = rte_eal_init(argc, argv); @@ -292,6 +302,11 @@ main(int argc, char *argv[]) if (mbuf_pool == NULL) rte_exit(EXIT_FAILURE, "Cannot create mbuf pool\n"); + timestamp_dynfield_offset = + rte_mbuf_dynfield_register(×tamp_dynfield_desc); + if (timestamp_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) -- 2.28.0