[13/15] examples/rxtx_callbacks: switch timestamp to dynamic field
diff mbox series

Message ID 20201029092751.3837177-14-thomas@monjalon.net
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series
  • remove mbuf timestamp
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Thomas Monjalon Oct. 29, 2020, 9:27 a.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>
---
 examples/rxtx_callbacks/main.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Andrew Rybchenko Oct. 29, 2020, 10:21 a.m. UTC | #1
On 10/29/20 12:27 PM, Thomas Monjalon wrote:
> 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>
> ---
>  examples/rxtx_callbacks/main.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/examples/rxtx_callbacks/main.c b/examples/rxtx_callbacks/main.c
> index b9a98ceddc..4798e0962c 100644
> --- a/examples/rxtx_callbacks/main.c
> +++ b/examples/rxtx_callbacks/main.c
> @@ -19,6 +19,10 @@
>  #define MBUF_CACHE_SIZE 250
>  #define BURST_SIZE 32
>  
> +static int hwts_dynfield_offset = -1;
> +#define HWTS_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
> +		hwts_dynfield_offset, rte_mbuf_timestamp_t *))
> +

Why is approach here differs? Macro vs inline function.
Thomas Monjalon Oct. 29, 2020, 10:44 a.m. UTC | #2
29/10/2020 11:21, Andrew Rybchenko:
> On 10/29/20 12:27 PM, Thomas Monjalon wrote:
> > 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>
> > ---
> >  examples/rxtx_callbacks/main.c | 12 +++++++++++-
> >  1 file changed, 11 insertions(+), 1 deletion(-)
> > 
> > diff --git a/examples/rxtx_callbacks/main.c b/examples/rxtx_callbacks/main.c
> > index b9a98ceddc..4798e0962c 100644
> > --- a/examples/rxtx_callbacks/main.c
> > +++ b/examples/rxtx_callbacks/main.c
> > @@ -19,6 +19,10 @@
> >  #define MBUF_CACHE_SIZE 250
> >  #define BURST_SIZE 32
> >  
> > +static int hwts_dynfield_offset = -1;
> > +#define HWTS_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
> > +		hwts_dynfield_offset, rte_mbuf_timestamp_t *))
> > +
> 
> Why is approach here differs? Macro vs inline function.

Because it is a self-contained file,
and there is already a macro for another field.

If you really want a function, I could it for both fields.

Patch
diff mbox series

diff --git a/examples/rxtx_callbacks/main.c b/examples/rxtx_callbacks/main.c
index b9a98ceddc..4798e0962c 100644
--- a/examples/rxtx_callbacks/main.c
+++ b/examples/rxtx_callbacks/main.c
@@ -19,6 +19,10 @@ 
 #define MBUF_CACHE_SIZE 250
 #define BURST_SIZE 32
 
+static int hwts_dynfield_offset = -1;
+#define HWTS_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		hwts_dynfield_offset, rte_mbuf_timestamp_t *))
+
 typedef uint64_t tsc_t;
 static int tsc_dynfield_offset = -1;
 #define TSC_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
@@ -73,7 +77,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;
@@ -137,6 +141,12 @@  port_init(uint16_t port, struct rte_mempool *mbuf_pool)
 			return -1;
 		}
 		port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_TIMESTAMP;
+		hwts_dynfield_offset = rte_mbuf_dynfield_lookup(
+				RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL);
+		if (hwts_dynfield_offset < 0) {
+			printf("ERROR: Failed to lookup timestamp field\n");
+			return -rte_errno;
+		}
 	}
 
 	retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);