[14/15] examples/rxtx_callbacks: switch to dynamic mbuf field

Message ID 20201026052105.1561859-15-thomas@monjalon.net (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series remove mbuf userdata |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Thomas Monjalon Oct. 26, 2020, 5:21 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.

Note: RTE_MBUF_DYNFIELD_TIMESTAMP_NAME is an existing mbuf field name.

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

Comments

David Marchand Oct. 26, 2020, 10:43 a.m. UTC | #1
On Mon, Oct 26, 2020 at 6:21 AM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> 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.

I am a bit lost.
How is this going to work as the mbuf timestamp field is used in this
example too?
  
Thomas Monjalon Oct. 26, 2020, 2:33 p.m. UTC | #2
26/10/2020 11:43, David Marchand:
> On Mon, Oct 26, 2020 at 6:21 AM Thomas Monjalon <thomas@monjalon.net> wrote:
> >
> > 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.
> 
> I am a bit lost.
> How is this going to work as the mbuf timestamp field is used in this
> example too?

Oh, you're right!
I will change the naming scheme to a custom "TSC" field.
  
Stephen Hemminger Oct. 26, 2020, 2:53 p.m. UTC | #3
On Mon, 26 Oct 2020 15:33:14 +0100
Thomas Monjalon <thomas@monjalon.net> wrote:

> 26/10/2020 11:43, David Marchand:
> > On Mon, Oct 26, 2020 at 6:21 AM Thomas Monjalon <thomas@monjalon.net> wrote:  
> > >
> > > 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.  
> > 
> > I am a bit lost.
> > How is this going to work as the mbuf timestamp field is used in this
> > example too?  
> 
> Oh, you're right!
> I will change the naming scheme to a custom "TSC" field.
> 
> 

Since timestamp is still there why doesn't the example just use that?
  
Thomas Monjalon Oct. 26, 2020, 4:32 p.m. UTC | #4
26/10/2020 15:53, Stephen Hemminger:
> On Mon, 26 Oct 2020 15:33:14 +0100
> Thomas Monjalon <thomas@monjalon.net> wrote:
> 
> > 26/10/2020 11:43, David Marchand:
> > > On Mon, Oct 26, 2020 at 6:21 AM Thomas Monjalon <thomas@monjalon.net> wrote:  
> > > >
> > > > 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.  
> > > 
> > > I am a bit lost.
> > > How is this going to work as the mbuf timestamp field is used in this
> > > example too?  
> > 
> > Oh, you're right!
> > I will change the naming scheme to a custom "TSC" field.
> 
> Since timestamp is still there why doesn't the example just use that?

This is what I did, but it's wrong because it is a different timestamp.
The example is doing a comparison of timestamps (AFAIU).
  

Patch

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(&timestamp_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)