diff mbox series

[v4,12/16] examples/rxtx_callbacks: switch timestamp to dynamic field

Message ID 20201103122205.183472-13-thomas@monjalon.net (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series remove mbuf timestamp | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Thomas Monjalon Nov. 3, 2020, 12:22 p.m. UTC
The mbuf timestamp is moved to a dynamic field
in order to allow removal of the deprecated static field.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: David Marchand <david.marchand@redhat.com>
---
 examples/rxtx_callbacks/main.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/examples/rxtx_callbacks/main.c b/examples/rxtx_callbacks/main.c
index 1a8e7d47d9..35c6c39807 100644
--- a/examples/rxtx_callbacks/main.c
+++ b/examples/rxtx_callbacks/main.c
@@ -19,6 +19,15 @@ 
 #define MBUF_CACHE_SIZE 250
 #define BURST_SIZE 32
 
+static int hwts_dynfield_offset = -1;
+
+static inline rte_mbuf_timestamp_t *
+hwts_field(struct rte_mbuf *mbuf)
+{
+	return RTE_MBUF_DYNFIELD(mbuf,
+			hwts_dynfield_offset, rte_mbuf_timestamp_t *);
+}
+
 typedef uint64_t tsc_t;
 static int tsc_dynfield_offset = -1;
 
@@ -77,7 +86,7 @@  calc_latency(uint16_t port, uint16_t qidx __rte_unused,
 	for (i = 0; i < nb_pkts; i++) {
 		cycles += now - *tsc_field(pkts[i]);
 		if (hw_timestamping)
-			queue_ticks += ticks - pkts[i]->timestamp;
+			queue_ticks += ticks - *hwts_field(pkts[i]);
 	}
 
 	latency_numbers.total_cycles += cycles;
@@ -141,6 +150,11 @@  port_init(uint16_t port, struct rte_mempool *mbuf_pool)
 			return -1;
 		}
 		port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
+		rte_mbuf_dyn_rx_timestamp_register(&hwts_dynfield_offset, NULL);
+		if (hwts_dynfield_offset < 0) {
+			printf("ERROR: Failed to register timestamp field\n");
+			return -rte_errno;
+		}
 	}
 
 	retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);