Skip to contentSkip to conversation

remove mbuf userdata

PATCH Superseded Thomas Monjalon 17 participants 178 messages Oct 26, 2020 – Nov 2, 2020 Page 1 of 2

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover remove mbuf userdata

The mbuf field userdata (aliased as udata64)
was announced to be removed for two reasons:
- applications, libraries and drivers used the same field for different purposes, with a risk of usage conflict.
- this field always used 8 bytes even if unneeded

Some dynamic fields are created when needed to replace the big static userdata field.
As a consequence, 8 bytes can be re-allocated to dynamic fields.

This mbuf layout change is important to allow adding more features (consuming more dynamic fields) during the next year.

Thomas Monjalon (15):
examples: enclose DPDK includes with angle brackets
kni: move header file from EAL
mbuf: fix typo in dynamic field convention note
node: switch IPv4 metadata to dynamic mbuf field
security: switch metadata to dynamic mbuf field event/sw: switch test counter to dynamic mbuf field net/ark: ignore user data
net/bnxt: switch CFA code to dynamic mbuf field net/vmxnet3: switch MSS hint to dynamic mbuf field test/distributor: switch sequence to dynamic mbuf field test/graph: switch user data to dynamic mbuf field app/eventdev: switch flow ID to dynamic mbuf field examples/bbdev: switch to dynamic mbuf field examples/rxtx_callbacks: switch to dynamic mbuf field
mbuf: remove userdata field

 app/test-eventdev/test_order_atq.c            |  4 +-
 app/test-eventdev/test_order_common.c         | 16 +++-
 app/test-eventdev/test_order_common.h         |  5 +
 app/test-eventdev/test_order_queue.c          |  4 +-
 app/test/test_distributor.c                   | 27 +++++-
 app/test/test_graph.c                         | 93 +++++++++++--------
 doc/guides/prog_guide/rte_security.rst        |  9 +-
 doc/guides/rel_notes/deprecation.rst          |  1 -
 doc/guides/rel_notes/release_20_11.rst        |  3 +
 doc/guides/sample_app_ug/rxtx_callbacks.rst   |  4 +-
 drivers/crypto/octeontx2/otx2_cryptodev_sec.c |  5 +-
 drivers/event/sw/sw_evdev_selftest.c          | 22 ++++-
 drivers/net/ark/ark_ddm.h                     |  2 +-
 drivers/net/ark/ark_ethdev_rx.c               |  1 -
 drivers/net/ark/ark_ethdev_tx.c               |  1 -
 drivers/net/ark/ark_udm.h                     |  2 +-
 drivers/net/bnxt/bnxt_ethdev.c                | 19 ++++
 drivers/net/bnxt/bnxt_rxr.c                   |  5 +-
 drivers/net/bnxt/bnxt_rxr.h                   |  2 +
 drivers/net/bnxt/rte_pmd_bnxt.h               |  3 +
 drivers/net/ixgbe/ixgbe_ipsec.c               |  5 +-
 drivers/net/ixgbe/ixgbe_rxtx.c                |  6 +-
 drivers/net/octeontx2/otx2_ethdev.h           |  1 +
 drivers/net/octeontx2/otx2_ethdev_sec.c       |  5 +-
 drivers/net/octeontx2/otx2_ethdev_sec_tx.h    |  2 +-
 drivers/net/octeontx2/otx2_rx.h               |  2 +-
 drivers/net/vmxnet3/vmxnet3_ethdev.c          | 15 +++
 drivers/net/vmxnet3/vmxnet3_ethdev.h          |  2 +
 drivers/net/vmxnet3/vmxnet3_rxtx.c            | 10 +-
 examples/bbdev_app/main.c                     | 67 ++++++++-----
 examples/bond/main.c                          | 11 +--
 examples/ipsec-secgw/ipsec-secgw.c            | 15 ++-
 examples/ipsec-secgw/ipsec.h                  |  3 +
 examples/ipsec-secgw/ipsec_worker.c           | 13 ++-
 examples/rxtx_callbacks/main.c                | 19 +++-
 examples/tep_termination/vxlan_setup.c        |  2 +-
 kernel/linux/kni/meson.build                  |  2 +-
 lib/librte_eal/linux/include/meson.build      |  1 -
 lib/librte_kni/meson.build                    |  2 +-
 .../include => librte_kni}/rte_kni_common.h   |  3 +-
 lib/librte_mbuf/rte_mbuf_core.h               |  8 +-
 lib/librte_mbuf/rte_mbuf_dyn.h                |  2 +-
 lib/librte_node/ip4_lookup.c                  |  7 ++
 lib/librte_node/ip4_rewrite.c                 | 10 ++
 lib/librte_node/node_private.h                | 12 ++-
 lib/librte_security/rte_security.c            | 10 ++
 lib/librte_security/rte_security.h            |  5 +
 lib/librte_security/rte_security_driver.h     | 20 ++++
 lib/librte_security/version.map               |  2 +
 49 files changed, 357 insertions(+), 133 deletions(-)
 rename lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h (97%)
Signature · 1 line
2.28.0
#1 lore raw

PATCH 1/15 examples: enclose DPDK includes with angle brackets

In examples, DPDK header files are external,
so they must be enclosed with angle brackets, not quotes.

---
 examples/bbdev_app/main.c              | 30 +++++++++++++-------------
 examples/bond/main.c                   | 11 ++++------
 examples/tep_termination/vxlan_setup.c |  2 +-
 3 files changed, 20 insertions(+), 23 deletions(-)
examples/bbdev_app/main.c +15 -15
index 43fe631760..e512c807cd 100644
@@ -18,21 +18,21 @@
 #include <getopt.h>
 #include <signal.h>
 
-#include "rte_atomic.h"
-#include "rte_common.h"
-#include "rte_eal.h"
-#include "rte_cycles.h"
-#include "rte_ether.h"
-#include "rte_ethdev.h"
-#include "rte_ip.h"
-#include "rte_lcore.h"
-#include "rte_malloc.h"
-#include "rte_mbuf.h"
-#include "rte_memory.h"
-#include "rte_mempool.h"
-#include "rte_log.h"
-#include "rte_bbdev.h"
-#include "rte_bbdev_op.h"
+#include <rte_atomic.h>
+#include <rte_common.h>
+#include <rte_eal.h>
+#include <rte_cycles.h>
+#include <rte_ether.h>
+#include <rte_ethdev.h>
+#include <rte_ip.h>
+#include <rte_lcore.h>
+#include <rte_malloc.h>
+#include <rte_mbuf.h>
+#include <rte_memory.h>
+#include <rte_mempool.h>
+#include <rte_log.h>
+#include <rte_bbdev.h>
+#include <rte_bbdev_op.h>
 
 /* LLR values - negative value for '1' bit */
 #define LLR_1_BIT 0x81
examples/bond/main.c +4 -7
index 398553b785..81a6fa976b 100644
@@ -41,6 +41,10 @@
 #include <rte_tcp.h>
 #include <rte_arp.h>
 #include <rte_spinlock.h>
+#include <rte_devargs.h>
+#include <rte_byteorder.h>
+#include <rte_cpuflags.h>
+#include <rte_eth_bond.h>
 
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
@@ -53,13 +57,6 @@
 
 #include "main.h"
 
-#include <rte_devargs.h>
-
-
-#include "rte_byteorder.h"
-#include "rte_cpuflags.h"
-#include "rte_eth_bond.h"
-
 #define RTE_LOGTYPE_DCB RTE_LOGTYPE_USER1
 
 #define NB_MBUF   (1024*8)
examples/tep_termination/vxlan_setup.c +1 -1
index 4b44ccc143..0bcd870b4a 100644
@@ -18,9 +18,9 @@
 #include <rte_ip.h>
 #include <rte_udp.h>
 #include <rte_tcp.h>
+#include <rte_vhost.h>
 
 #include "main.h"
-#include "rte_vhost.h"
 #include "vxlan.h"
 #include "vxlan_setup.h"
 
Signature · 1 line
2.28.0
Acked-by on v1 1/15
#3 lore raw

Re: [dpdk-dev] [PATCH 01/15] examples: enclose DPDK includes with angle brackets

In reply to Thomas Monjalon
Quoted 9 lines · Thomas Monjalon

In examples, DPDK header files are external,
so they must be enclosed with angle brackets, not quotes.

---
 examples/bbdev_app/main.c              | 30 +++++++++++++-------------
 examples/bond/main.c                   | 11 ++++------
 examples/tep_termination/vxlan_setup.c |  2 +-
 3 files changed, 20 insertions(+), 23 deletions(-)
#4 lore raw

PATCH 2/15 kni: move header file from EAL

In reply to Thomas Monjalon

Since the kernel module is not part of EAL anymore, there is no need to have the common KNI header file in EAL. The file rte_kni_common.h is moved to librte_kni.

---
 kernel/linux/kni/meson.build                                  | 2 +-
 lib/librte_eal/linux/include/meson.build                      | 1 -
 lib/librte_kni/meson.build                                    | 2 +-
 lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h | 0
 4 files changed, 2 insertions(+), 3 deletions(-)
 rename lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h (100%)
kernel/linux/kni/meson.build +1 -1
index d696347f22..07e0c9dae7 100644
@@ -18,7 +18,7 @@ custom_target('rte_kni',
 		'src=' + meson.current_source_dir(),
 		'MODULE_CFLAGS=-include ' + meson.source_root() + '/config/rte_config.h' +
 		' -I' + meson.source_root() + '/lib/librte_eal/include' +
-		' -I' + meson.source_root() + '/lib/librte_eal/linux/include' +
+		' -I' + meson.source_root() + '/lib/librte_kni' +
 		' -I' + meson.build_root() +
 		' -I' + meson.current_source_dir(),
 		'modules'],
lib/librte_eal/linux/include/meson.build +0 -1
index 1241894b3c..7d18dd52f1 100644
@@ -4,6 +4,5 @@
 includes += include_directories('.')
 
 headers += files(
-        'rte_kni_common.h',
         'rte_os.h',
 )
lib/librte_kni/meson.build +1 -1
index 963eae6fe0..ad598bb3d0 100644
@@ -6,5 +6,5 @@ if not is_linux or not dpdk_conf.get('RTE_ARCH_64')
 	reason = 'only supported on 64-bit linux'
 endif
 sources = files('rte_kni.c')
-headers = files('rte_kni.h')
+headers = files('rte_kni.h', 'rte_kni_common.h')
 deps += ['ethdev', 'pci']
lib/librte_kni/rte_kni_common.h renamed from lib/librte_eal/linux/include/rte_kni_common.h +0 -0
similarity index 100%
rename from lib/librte_eal/linux/include/rte_kni_common.h
rename to lib/librte_kni/rte_kni_common.h
Signature · 1 line
2.28.0
Acked-by on v1 2/15
#6 lore raw

Re: [dpdk-dev] [PATCH 02/15] kni: move header file from EAL

In reply to Thomas Monjalon
Quoted 4 lines · Thomas Monjalon

Since the kernel module is not part of EAL anymore, there is no need to have the common KNI header file in EAL. The file rte_kni_common.h is moved to librte_kni.

Quoted 9 lines
---
 kernel/linux/kni/meson.build                                  | 2 +-
 lib/librte_eal/linux/include/meson.build                      | 1 -
 lib/librte_kni/meson.build                                    | 2 +-
 lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h | 0
 4 files changed, 2 insertions(+), 3 deletions(-)
 rename lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h (100%)
#7 lore raw

PATCH 3/15 mbuf: fix typo in dynamic field convention note

In reply to Thomas Monjalon

Replace "in a in PMD" with "in a PMD".

Fixes 4958ca3a443a ("mbuf: support dynamic fields and flags")
---
 lib/librte_mbuf/rte_mbuf_dyn.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_mbuf/rte_mbuf_dyn.h +1 -1
index 8407230ecf..0ebac88b83 100644
@@ -62,7 +62,7 @@
  * conventions than function names in dpdk:
  * - "rte_mbuf_dynfield_<name>" if defined in mbuf library
  * - "rte_<libname>_dynfield_<name>" if defined in another library
- * - "rte_net_<pmd>_dynfield_<name>" if defined in a in PMD
+ * - "rte_net_<pmd>_dynfield_<name>" if defined in a PMD
  * - any name that does not start with "rte_" in an application
  */
 
Signature · 1 line
2.28.0
#9 lore raw

PATCH 4/15 node: switch IPv4 metadata to dynamic mbuf field

In reply to Thomas Monjalon

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 lib/librte_node/ip4_lookup.c   |  7 +++++++
 lib/librte_node/ip4_rewrite.c  | 10 ++++++++++
 lib/librte_node/node_private.h | 12 ++++++++++--
 3 files changed, 27 insertions(+), 2 deletions(-)
lib/librte_node/ip4_lookup.c +7 -0
index 8835aab9dd..2cc91c0c67 100644
@@ -21,6 +21,8 @@
 
 #include "node_private.h"
 
+int node_mbuf_priv1_dynfield_offset;
+
 #define IPV4_L3FWD_LPM_MAX_RULES 1024
 #define IPV4_L3FWD_LPM_NUMBER_TBL8S (1 << 8)
 
@@ -178,6 +180,11 @@ ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node)
 	RTE_SET_USED(node);
 
 	if (!init_once) {
+		node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+				&node_mbuf_priv1_dynfield_desc);
+		if (node_mbuf_priv1_dynfield_offset < 0)
+			return -1;
+
 		/* Setup LPM tables for all sockets */
 		RTE_LCORE_FOREACH(lcore_id)
 		{
lib/librte_node/ip4_rewrite.c +10 -0
index bb7f671b5c..2ffb3f4340 100644
@@ -248,9 +248,19 @@ ip4_rewrite_node_process(struct rte_graph *graph, struct rte_node *node,
 static int
 ip4_rewrite_node_init(const struct rte_graph *graph, struct rte_node *node)
 {
+	static bool init_once;
 
 	RTE_SET_USED(graph);
 	RTE_SET_USED(node);
+
+	if (!init_once) {
+		node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+				&node_mbuf_priv1_dynfield_desc);
+		if (node_mbuf_priv1_dynfield_offset < 0)
+			return -1;
+		init_once = true;
+	}
+
 	node_dbg("ip4_rewrite", "Initialized ip4_rewrite node initialized");
 
 	return 0;
lib/librte_node/node_private.h +10 -2
index ab7941c12b..bafea3704d 100644
@@ -8,6 +8,7 @@
 #include <rte_common.h>
 #include <rte_log.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 extern int rte_node_logtype;
 #define NODE_LOG(level, node_name, ...)                                        \
@@ -21,7 +22,6 @@ extern int rte_node_logtype;
 #define node_dbg(node_name, ...) NODE_LOG(DEBUG, node_name, __VA_ARGS__)
 
 /**
- *
  * Node mbuf private data to store next hop, ttl and checksum.
  */
 struct node_mbuf_priv1 {
@@ -37,6 +37,13 @@ struct node_mbuf_priv1 {
 	};
 };
 
+static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = {
+	.name = "rte_node_dynfield_priv1",
+	.size = sizeof(uint64_t),
+	.align = __alignof__(uint64_t),
+};
+extern int node_mbuf_priv1_dynfield_offset;
+
 /**
  * Node mbuf private area 2.
  */
@@ -60,7 +67,8 @@ struct node_mbuf_priv2 {
 static __rte_always_inline struct node_mbuf_priv1 *
 node_mbuf_priv1(struct rte_mbuf *m)
 {
-	return (struct node_mbuf_priv1 *)&m->udata64;
+	return RTE_MBUF_DYNFIELD(m,
+		node_mbuf_priv1_dynfield_offset, struct node_mbuf_priv1 *);
 }
 
 /**
Signature · 1 line
2.28.0
#10 lore raw

Re: [dpdk-dev] [PATCH 04/15] node: switch IPv4 metadata to dynamic mbuf field

Quoted 25 lines · Thomas Monjalon

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 lib/librte_node/ip4_lookup.c   |  7 +++++++
 lib/librte_node/ip4_rewrite.c  | 10 ++++++++++
 lib/librte_node/node_private.h | 12 ++++++++++--
 3 files changed, 27 insertions(+), 2 deletions(-)
lib/librte_node/ip4_lookup.c +2 -0
index 8835aab9dd..2cc91c0c67 100644
@@ -21,6 +21,8 @@
 
 #include "node_private.h"
 
+int node_mbuf_priv1_dynfield_offset;
+
 #define IPV4_L3FWD_LPM_MAX_RULES 1024
 #define IPV4_L3FWD_LPM_NUMBER_TBL8S (1 << 8)
 

lib/librte_node/ip4_lookup.c ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node) · line 186

Quoted 7 lines
lib/librte_node/ip4_lookup.c +4 -0
@@ -178,6 +180,11 @@ ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node)
        RTE_SET_USED(node);
 
        if (!init_once) {
+               node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+                               &node_mbuf_priv1_dynfield_desc);
+               if (node_mbuf_priv1_dynfield_offset < 0)
+                       return -1;

How about return -rte_errno like what is done in setup_lpm()?

Quoted 4 lines
lib/librte_node/ip4_lookup.c +1 -0
+
                /* Setup LPM tables for all sockets */
                RTE_LCORE_FOREACH(lcore_id)
                {

[snip]

Quoted 21 lines
lib/librte_node/node_private.h +1 -1
index ab7941c12b..bafea3704d 100644
@@ -8,6 +8,7 @@
 #include <rte_common.h>
 #include <rte_log.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 extern int rte_node_logtype;
 #define NODE_LOG(level, node_name, ...)                                        \
@@ -21,7 +22,6 @@ extern int rte_node_logtype;
 #define node_dbg(node_name, ...) NODE_LOG(DEBUG, node_name, __VA_ARGS__)
 
 /**
- *
  * Node mbuf private data to store next hop, ttl and checksum.
  */
 struct node_mbuf_priv1 {

lib/librte_node/node_private.h struct node_mbuf_priv1 { · line 43

Quoted 7 lines
lib/librte_node/node_private.h +4 -0
@@ -37,6 +37,13 @@ struct node_mbuf_priv1 {
        };
 };
 
+static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = {
+       .name = "rte_node_dynfield_priv1",
+       .size = sizeof(uint64_t),
+       .align = __alignof__(uint64_t),

s/uint64_t/struct node_mbuf_priv1/g ?

Quoted 6 lines
lib/librte_node/node_private.h +3 -0
+};
+extern int node_mbuf_priv1_dynfield_offset;
+
 /**
  * Node mbuf private area 2.
  */
Signature · 1 line
David Marchand
#11 lore raw

Re: [dpdk-dev] [PATCH 04/15] node: switch IPv4 metadata to dynamic mbuf field

26/10/2020 11:40, David Marchand:

Quoted 7 lines · Thomas Monjalon

lib/librte_node/ip4_lookup.c ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node) · line 186

Quoted 4 lines
lib/librte_node/ip4_lookup.c +4 -0
+               node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+                               &node_mbuf_priv1_dynfield_desc);
+               if (node_mbuf_priv1_dynfield_offset < 0)
+                       return -1;

How about return -rte_errno like what is done in setup_lpm()?

Yes, looks better

[...]

Quoted 6 lines

lib/librte_node/node_private.h struct node_mbuf_priv1 { · line 43

Quoted 4 lines
lib/librte_node/node_private.h +4 -0
+static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = {
+       .name = "rte_node_dynfield_priv1",
+       .size = sizeof(uint64_t),
+       .align = __alignof__(uint64_t),

s/uint64_t/struct node_mbuf_priv1/g ?

Yes will do

#12 lore raw

Re: [dpdk-dev] [PATCH 04/15] node: switch IPv4 metadata to dynamic mbuf field

Quoted 12 lines · Thomas Monjalon

26/10/2020 11:40, David Marchand:

Quoted 7 lines · Thomas Monjalon

lib/librte_node/ip4_lookup.c ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node) · line 186

Quoted 4 lines
lib/librte_node/ip4_lookup.c +4 -0
+               node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+                               &node_mbuf_priv1_dynfield_desc);
+               if (node_mbuf_priv1_dynfield_offset < 0)
+                       return -1;

How about return -rte_errno like what is done in setup_lpm()?

Yes, looks better

[...]

Quoted 9 lines
Quoted 6 lines

lib/librte_node/node_private.h struct node_mbuf_priv1 { · line 43

Quoted 4 lines
lib/librte_node/node_private.h +4 -0
+static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = {
+       .name = "rte_node_dynfield_priv1",
+       .size = sizeof(uint64_t),
+       .align = __alignof__(uint64_t),

s/uint64_t/struct node_mbuf_priv1/g ?

Yes will do

Just to be sure - "struct node_mbuf_priv1 *"

#13 lore raw

Re: [dpdk-dev] [PATCH 04/15] node: switch IPv4 metadata to dynamic mbuf field

26/10/2020 15:34, Andrew Rybchenko:

Quoted 18 lines · Thomas Monjalon
Quoted 17 lines

26/10/2020 11:40, David Marchand:

Quoted 7 lines · Thomas Monjalon

lib/librte_node/ip4_lookup.c ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node) · line 186

Quoted 4 lines
lib/librte_node/ip4_lookup.c +4 -0
+               node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+                               &node_mbuf_priv1_dynfield_desc);
+               if (node_mbuf_priv1_dynfield_offset < 0)
+                       return -1;

How about return -rte_errno like what is done in setup_lpm()?

Yes, looks better

[...]

Quoted 5 lines
Quoted 4 lines
lib/librte_node/node_private.h +4 -0
+static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = {
+       .name = "rte_node_dynfield_priv1",
+       .size = sizeof(uint64_t),
+       .align = __alignof__(uint64_t),
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

s/uint64_t/struct node_mbuf_priv1/g ?

Yes will do

Just to be sure - "struct node_mbuf_priv1 *"

Yes, pointer to node_mbuf_priv1.

#14 lore raw

PATCH 5/15 security: switch metadata to dynamic mbuf field

In reply to Thomas Monjalon

The device-specific metadata was stored in the deprecated field udata64. It is moved to a dynamic mbuf field in order to allow removal of udata64.

---
 doc/guides/prog_guide/rte_security.rst        |  9 +++++----
 drivers/crypto/octeontx2/otx2_cryptodev_sec.c |  5 ++++-
 drivers/net/ixgbe/ixgbe_ipsec.c               |  5 ++++-
 drivers/net/ixgbe/ixgbe_rxtx.c                |  6 ++++--
 drivers/net/octeontx2/otx2_ethdev.h           |  1 +
 drivers/net/octeontx2/otx2_ethdev_sec.c       |  5 ++++-
 drivers/net/octeontx2/otx2_ethdev_sec_tx.h    |  2 +-
 drivers/net/octeontx2/otx2_rx.h               |  2 +-
 examples/ipsec-secgw/ipsec-secgw.c            | 15 +++++++++-----
 examples/ipsec-secgw/ipsec.h                  |  3 +++
 examples/ipsec-secgw/ipsec_worker.c           | 13 ++++++++----
 lib/librte_security/rte_security.c            | 10 ++++++++++
 lib/librte_security/rte_security.h            |  5 +++++
 lib/librte_security/rte_security_driver.h     | 20 +++++++++++++++++++
 lib/librte_security/version.map               |  2 ++
 15 files changed, 83 insertions(+), 20 deletions(-)
doc/guides/prog_guide/rte_security.rst +5 -4
index c64aef3de9..f72bc8a78f 100644
@@ -125,8 +125,9 @@ ESP/AH headers will be removed from the packet and the received packet
 will contains the decrypted packet only. The driver Rx path checks the
 descriptors and based on the crypto status sets additional flags in
 ``rte_mbuf.ol_flags`` field. The driver would also set device-specific
-metadata in ``rte_mbuf.udata64`` field. This will allow the application
-to identify the security processing done on the packet.
+metadata in ``RTE_SECURITY_DYNFIELD_NAME`` field.
+This will allow the application to identify the security processing
+done on the packet.
 
 .. note::
 
@@ -568,8 +569,8 @@ security session which processed the packet.
 
 .. note::
 
-    In case of inline processed packets, ``rte_mbuf.udata64`` field would be
-    used by the driver to relay information on the security processing
+    In case of inline processed packets, ``RTE_SECURITY_DYNFIELD_NAME`` field
+    would be used by the driver to relay information on the security processing
     associated with the packet. In ingress, the driver would set this in Rx
     path while in egress, ``rte_security_set_pkt_metadata()`` would perform a
     similar operation. The application is expected not to modify the field
drivers/crypto/octeontx2/otx2_cryptodev_sec.c +4 -1
index b80ec7bff2..2e5e73143b 100644
@@ -455,6 +455,9 @@ otx2_crypto_sec_session_create(void *device,
 	if (conf->action_type != RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL)
 		return -ENOTSUP;
 
+	if (rte_security_dynfield_register() < 0)
+		return -rte_errno;
+
 	if (rte_mempool_get(mempool, (void **)&priv)) {
 		otx2_err("Could not allocate security session private data");
 		return -ENOMEM;
@@ -514,7 +517,7 @@ otx2_crypto_sec_set_pkt_mdata(void *device __rte_unused,
 			      struct rte_mbuf *m, void *params __rte_unused)
 {
 	/* Set security session as the pkt metadata */
-	m->udata64 = (uint64_t)session;
+	*rte_security_dynfield(m) = (RTE_SECURITY_DYNFIELD_TYPE)session;
 
 	return 0;
 }
drivers/net/ixgbe/ixgbe_ipsec.c +4 -1
index 48f5082d49..0232db20ed 100644
@@ -484,7 +484,8 @@ ixgbe_crypto_update_mb(void *device __rte_unused,
 			get_sec_session_private_data(session);
 	if (ic_session->op == IXGBE_OP_AUTHENTICATED_ENCRYPTION) {
 		union ixgbe_crypto_tx_desc_md *mdata =
-			(union ixgbe_crypto_tx_desc_md *)&m->udata64;
+			(union ixgbe_crypto_tx_desc_md *)
+			rte_security_dynfield(m);
 		mdata->enc = 1;
 		mdata->sa_idx = ic_session->sa_index;
 		mdata->pad_len = ixgbe_crypto_compute_pad_len(m);
@@ -751,5 +752,7 @@ ixgbe_ipsec_ctx_create(struct rte_eth_dev *dev)
 			return -ENOMEM;
 		}
 	}
+	if (rte_security_dynfield_register() < 0)
+		return -rte_errno;
 	return 0;
 }
drivers/net/ixgbe/ixgbe_rxtx.c +4 -2
index 5f19972031..5e7ea001f3 100644
@@ -34,6 +34,7 @@
 #include <rte_mbuf.h>
 #include <rte_ether.h>
 #include <rte_ethdev_driver.h>
+#include <rte_security_driver.h>
 #include <rte_prefetch.h>
 #include <rte_udp.h>
 #include <rte_tcp.h>
@@ -694,7 +695,7 @@ ixgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 			if (use_ipsec) {
 				union ixgbe_crypto_tx_desc_md *ipsec_mdata =
 					(union ixgbe_crypto_tx_desc_md *)
-							&tx_pkt->udata64;
+					rte_security_dynfield(tx_pkt);
 				tx_offload.sa_idx = ipsec_mdata->sa_idx;
 				tx_offload.sec_pad_len = ipsec_mdata->pad_len;
 			}
@@ -859,7 +860,8 @@ ixgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 				}
 
 				ixgbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req,
-					tx_offload, &tx_pkt->udata64);
+					tx_offload,
+					rte_security_dynfield(tx_pkt));
 
 				txe->last_id = tx_last;
 				tx_id = txe->next_id;
drivers/net/octeontx2/otx2_ethdev.h +1 -0
index b20f399a15..3b9871f4dc 100644
@@ -13,6 +13,7 @@
 #include <rte_kvargs.h>
 #include <rte_mbuf.h>
 #include <rte_mempool.h>
+#include <rte_security_driver.h>
 #include <rte_string_fns.h>
 #include <rte_time.h>
 
drivers/net/octeontx2/otx2_ethdev_sec.c +4 -1
index 4e0dd4e49e..78c5bbeb99 100644
@@ -684,7 +684,7 @@ otx2_eth_sec_set_pkt_mdata(void *device __rte_unused,
 			    struct rte_mbuf *m, void *params __rte_unused)
 {
 	/* Set security session as the pkt metadata */
-	m->udata64 = (uint64_t)session;
+	*rte_security_dynfield(m) = (RTE_SECURITY_DYNFIELD_TYPE)session;
 
 	return 0;
 }
@@ -831,6 +831,9 @@ otx2_eth_sec_init(struct rte_eth_dev *eth_dev)
 	    !(dev->rx_offloads & DEV_RX_OFFLOAD_SECURITY))
 		return 0;
 
+	if (rte_security_dynfield_register() < 0)
+		return -rte_errno;
+
 	nb_sa = dev->ipsec_in_max_spi;
 	mz_sz = nb_sa * sa_width;
 	in_sa_mz_name_get(name, RTE_MEMZONE_NAMESIZE, port);
drivers/net/octeontx2/otx2_ethdev_sec_tx.h +1 -1
index 5bf8c19995..284bcd5367 100644
@@ -55,7 +55,7 @@ otx2_sec_event_tx(struct otx2_ssogws *ws, struct rte_event *ev,
 		struct nix_iova_s nix_iova;
 	} *sd;
 
-	priv = get_sec_session_private_data((void *)(m->udata64));
+	priv = get_sec_session_private_data((void *)(*rte_security_dynfield(m)));
 	sess = &priv->ipsec.ip;
 	sa = &sess->out_sa;
 
drivers/net/octeontx2/otx2_rx.h +1 -1
index f29a0542f9..61a5c436dd 100644
@@ -241,7 +241,7 @@ nix_rx_sec_mbuf_update(const struct nix_cqe_hdr_s *cq, struct rte_mbuf *m,
 	spi = cq->tag & 0xFFFFF;
 
 	sa = nix_rx_sec_sa_get(lookup_mem, spi, m->port);
-	m->udata64 = (uint64_t)sa->userdata;
+	*rte_security_dynfield(m) = sa->udata64;
 
 	data = rte_pktmbuf_mtod(m, char *);
 
examples/ipsec-secgw/ipsec-secgw.c +10 -5
index 2219148285..b68d1212ba 100644
@@ -165,6 +165,8 @@ static uint32_t nb_lcores;
 static uint32_t single_sa;
 static uint32_t nb_bufs_in_pool;
 
+int security_dynfield_offset;
+
 /*
  * RX/TX HW offload capabilities to enable/use on ethernet ports.
  * By default all capabilities are enabled.
@@ -426,7 +428,8 @@ prepare_one_packet(struct rte_mbuf *pkt, struct ipsec_traffic *t)
 	 * with the security session.
 	 */
 
-	if (pkt->ol_flags & PKT_RX_SEC_OFFLOAD) {
+	if (pkt->ol_flags & PKT_RX_SEC_OFFLOAD &&
+			security_dynfield_offset >= 0) {
 		struct ipsec_sa *sa;
 		struct ipsec_mbuf_metadata *priv;
 		struct rte_security_ctx *ctx = (struct rte_security_ctx *)
@@ -436,10 +439,9 @@ prepare_one_packet(struct rte_mbuf *pkt, struct ipsec_traffic *t)
 		/* Retrieve the userdata registered. Here, the userdata
 		 * registered is the SA pointer.
 		 */
-
-		sa = (struct ipsec_sa *)
-				rte_security_get_userdata(ctx, pkt->udata64);
-
+		sa = (struct ipsec_sa *) rte_security_get_userdata(ctx,
+			*RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset,
+				RTE_SECURITY_DYNFIELD_TYPE *));
 		if (sa == NULL) {
 			/* userdata could not be retrieved */
 			return;
@@ -2898,6 +2900,9 @@ main(int32_t argc, char **argv)
 	}
 	printf("Number of mbufs in packet pool %d\n", nb_bufs_in_pool);
 
+	security_dynfield_offset =
+		rte_mbuf_dynfield_lookup(RTE_SECURITY_DYNFIELD_NAME, NULL);
+
 	RTE_ETH_FOREACH_DEV(portid) {
 		if ((enabled_port_mask & (1 << portid)) == 0)
 			continue;
examples/ipsec-secgw/ipsec.h +3 -0
index 7031e28c46..49cd6ce923 100644
@@ -8,6 +8,7 @@
 #include <stdint.h>
 
 #include <rte_byteorder.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_crypto.h>
 #include <rte_security.h>
 #include <rte_flow.h>
@@ -67,6 +68,8 @@ struct ip_addr {
 
 #define MAX_KEY_SIZE		36
 
+extern int security_dynfield_offset;
+
 /*
  * application wide SA parameters
  */
examples/ipsec-secgw/ipsec_worker.c +9 -4
index b6c851f257..72f698893d 100644
@@ -208,7 +208,8 @@ process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt,
 					"Inbound security offload failed\n");
 				goto drop_pkt_and_exit;
 			}
-			sa = pkt->userdata;
+			sa = RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset,
+					struct ipsec_sa *);
 		}
 
 		/* Check if we have a match */
@@ -226,7 +227,8 @@ process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt,
 					"Inbound security offload failed\n");
 				goto drop_pkt_and_exit;
 			}
-			sa = pkt->userdata;
+			sa = RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset,
+					struct ipsec_sa *);
 		}
 
 		/* Check if we have a match */
@@ -357,7 +359,8 @@ process_ipsec_ev_outbound(struct ipsec_ctx *ctx, struct route_table *rt,
 	}
 
 	if (sess->security.ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
-		pkt->userdata = sess->security.ses;
+		*RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset,
+			struct rte_security_session **) = sess->security.ses;
 
 	/* Mark the packet for Tx security offload */
 	pkt->ol_flags |= PKT_TX_SEC_OFFLOAD;
@@ -465,7 +468,9 @@ ipsec_wrkr_non_burst_int_port_drv_mode(struct eh_event_link_info *links,
 			}
 
 			/* Save security session */
-			pkt->userdata = sess_tbl[port_id];
+			*RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset,
+					struct rte_security_session **) =
+				sess_tbl[port_id];
 
 			/* Mark the packet for Tx security offload */
 			pkt->ol_flags |= PKT_TX_SEC_OFFLOAD;
lib/librte_security/rte_security.c +10 -0
index ee4666026a..9b5f9b72aa 100644
@@ -23,6 +23,16 @@
 	RTE_PTR_OR_ERR_RET(p1->p2->p3, last_retval);			\
 } while (0)
 
+int rte_security_dynfield_offset;
+
+int
+rte_security_dynfield_register(void)
+{
+	rte_security_dynfield_offset =
+		rte_mbuf_dynfield_register(&rte_security_dynfield_desc);
+	return rte_security_dynfield_offset;
+}
+
 struct rte_security_session *
 rte_security_session_create(struct rte_security_ctx *instance,
 			    struct rte_security_session_conf *conf,
lib/librte_security/rte_security.h +5 -0
index 271531af12..c3647151e5 100644
@@ -451,6 +451,11 @@ int
 rte_security_session_destroy(struct rte_security_ctx *instance,
 			     struct rte_security_session *sess);
 
+/** Device-specific metadata field name (for mbuf dynfield lookup) */
+#define RTE_SECURITY_DYNFIELD_NAME "rte_security_dynfield_metadata"
+/** Device-specific metadata field type */
+#define RTE_SECURITY_DYNFIELD_TYPE uint64_t
+
 /**
  *  Updates the buffer with device-specific defined metadata
  *
lib/librte_security/rte_security_driver.h +20 -0
index 1b561f8528..ba9691b4a0 100644
@@ -17,6 +17,8 @@
 extern "C" {
 #endif
 
+#include <rte_mbuf_dyn.h>
+
 #include "rte_security.h"
 
 /**
@@ -89,6 +91,24 @@ typedef int (*security_session_stats_get_t)(void *device,
 		struct rte_security_session *sess,
 		struct rte_security_stats *stats);
 
+/* Dynamic mbuf field for device-specific metadata */
+static const struct rte_mbuf_dynfield rte_security_dynfield_desc = {
+	.name = RTE_SECURITY_DYNFIELD_NAME,
+	.size = sizeof(RTE_SECURITY_DYNFIELD_TYPE),
+	.align = __alignof__(RTE_SECURITY_DYNFIELD_TYPE),
+};
+extern int rte_security_dynfield_offset;
+
+__rte_experimental
+int rte_security_dynfield_register(void);
+
+static inline RTE_SECURITY_DYNFIELD_TYPE *
+rte_security_dynfield(struct rte_mbuf *mbuf)
+{
+	return RTE_MBUF_DYNFIELD(mbuf,
+	rte_security_dynfield_offset, RTE_SECURITY_DYNFIELD_TYPE *);
+}
+
 /**
  * Update the mbuf with provided metadata.
  *
lib/librte_security/version.map +2 -0
index d84eec0a88..22775558c8 100644
@@ -15,6 +15,8 @@ DPDK_21 {
 EXPERIMENTAL {
 	global:
 
+	rte_security_dynfield_offset;
+	rte_security_dynfield_register;
 	rte_security_get_userdata;
 	rte_security_session_stats_get;
 	rte_security_session_update;
Signature · 1 line
2.28.0
#15 lore raw

Re: [dpdk-dev] [PATCH 05/15] security: switch metadata to dynamic mbuf field

Quoted 14 lines · Thomas Monjalon
lib/librte_security/rte_security_driver.h +2 -0
index 1b561f8528..ba9691b4a0 100644
@@ -17,6 +17,8 @@
 extern "C" {
 #endif
 
+#include <rte_mbuf_dyn.h>
+
 #include "rte_security.h"
 
 /**

lib/librte_security/rte_security_driver.h typedef int (*security_session_stats_get_t)(void *device, · line 99

Quoted 9 lines
lib/librte_security/rte_security_driver.h +6 -0
@@ -89,6 +91,24 @@ typedef int (*security_session_stats_get_t)(void *device,
                struct rte_security_session *sess,
                struct rte_security_stats *stats);
 
+/* Dynamic mbuf field for device-specific metadata */
+static const struct rte_mbuf_dynfield rte_security_dynfield_desc = {
+       .name = RTE_SECURITY_DYNFIELD_NAME,
+       .size = sizeof(RTE_SECURITY_DYNFIELD_TYPE),
+       .align = __alignof__(RTE_SECURITY_DYNFIELD_TYPE),
+};

Should be in rte_security.c?

Quoted 12 lines
lib/librte_security/rte_security_driver.h +12 -0
+extern int rte_security_dynfield_offset;
+
+__rte_experimental
+int rte_security_dynfield_register(void);
+
+static inline RTE_SECURITY_DYNFIELD_TYPE *
+rte_security_dynfield(struct rte_mbuf *mbuf)
+{
+       return RTE_MBUF_DYNFIELD(mbuf,
+       rte_security_dynfield_offset, RTE_SECURITY_DYNFIELD_TYPE *);
+}
+
Signature · 1 line
David Marchand
#16 lore raw

Re: [dpdk-dev] [PATCH 05/15] security: switch metadata to dynamic mbuf field

26/10/2020 11:41, David Marchand:

Quoted 9 lines · Thomas Monjalon

lib/librte_security/rte_security_driver.h typedef int (*security_session_stats_get_t)(void *device, · line 99

Quoted 6 lines
lib/librte_security/rte_security_driver.h +6 -0
+/* Dynamic mbuf field for device-specific metadata */
+static const struct rte_mbuf_dynfield rte_security_dynfield_desc = {
+       .name = RTE_SECURITY_DYNFIELD_NAME,
+       .size = sizeof(RTE_SECURITY_DYNFIELD_TYPE),
+       .align = __alignof__(RTE_SECURITY_DYNFIELD_TYPE),
+};

Should be in rte_security.c?

Yes,
and the inline function below can be a simple macro.

Quoted 11 lines
Quoted 11 lines
lib/librte_security/rte_security_driver.h +11 -0
+extern int rte_security_dynfield_offset;
+
+__rte_experimental
+int rte_security_dynfield_register(void);
+
+static inline RTE_SECURITY_DYNFIELD_TYPE *
+rte_security_dynfield(struct rte_mbuf *mbuf)
+{
+       return RTE_MBUF_DYNFIELD(mbuf,
+       rte_security_dynfield_offset, RTE_SECURITY_DYNFIELD_TYPE *);
+}
#17 lore raw

Re: [dpdk-dev] [PATCH 05/15] security: switch metadata to dynamic mbuf field

In reply to David Marchand
Quoted 31 lines

Review

Quoted 1 line · Thomas Monjalon
(quoted diff) +0 -0

b/lib/librte_security/rte_security_driver.h

lib/librte_security/rte_security_driver.h typedef int (*security_session_stats_get_t)(void

Quoted 13 lines

index 1b561f8528..ba9691b4a0 100644

lib/librte_security/rte_security_driver.h +2 -0
@@ -17,6 +17,8 @@
 extern "C" {
 #endif
 
+#include <rte_mbuf_dyn.h>
+
 #include "rte_security.h"
 
 /**
@@ -89,6 +91,24 @@ typedef int (*security_session_stats_get_t)(void

*device,

lib/librte_security/rte_security_driver.h typedef int (*security_session_stats_get_t)(void *device, · line 99

Quoted 9 lines
lib/librte_security/rte_security_driver.h +6 -0
                struct rte_security_session *sess,
                struct rte_security_stats *stats);
 
+/* Dynamic mbuf field for device-specific metadata */
+static const struct rte_mbuf_dynfield rte_security_dynfield_desc = {
+       .name = RTE_SECURITY_DYNFIELD_NAME,
+       .size = sizeof(RTE_SECURITY_DYNFIELD_TYPE),
+       .align = __alignof__(RTE_SECURITY_DYNFIELD_TYPE),
+};

Should be in rte_security.c?

Quoted 11 lines

lib/librte_security/rte_security_driver.h typedef int (*security_session_stats_get_t)(void *device, · line 110

Quoted 11 lines
lib/librte_security/rte_security_driver.h +11 -0
+extern int rte_security_dynfield_offset;
+
+__rte_experimental
+int rte_security_dynfield_register(void);
+
+static inline RTE_SECURITY_DYNFIELD_TYPE *
+rte_security_dynfield(struct rte_mbuf *mbuf)
+{
+       return RTE_MBUF_DYNFIELD(mbuf,
+       rte_security_dynfield_offset, RTE_SECURITY_DYNFIELD_TYPE *);
+}

code indentation -
Atleast one more tab before rte_security_dynfield_offset, RTE_SECURITY_DYNFIELD_TYPE *).

#18 lore raw

Re: [dpdk-dev] [PATCH 05/15] security: switch metadata to dynamic mbuf field

In reply to Thomas Monjalon
Quoted 4 lines · Thomas Monjalon

The device-specific metadata was stored in the deprecated field udata64. It is moved to a dynamic mbuf field in order to allow removal of udata64.

[snip]

drivers/net/ixgbe/ixgbe_ipsec.c ixgbe_crypto_update_mb(void *device __rte_unused, · line 488

Quoted 11 lines
drivers/net/ixgbe/ixgbe_ipsec.c +2 -1
index 48f5082d49..0232db20ed 100644
@@ -484,7 +484,8 @@ ixgbe_crypto_update_mb(void *device __rte_unused,
 			get_sec_session_private_data(session);
 	if (ic_session->op == IXGBE_OP_AUTHENTICATED_ENCRYPTION) {
 		union ixgbe_crypto_tx_desc_md *mdata =
-			(union ixgbe_crypto_tx_desc_md *)&m->udata64;
+			(union ixgbe_crypto_tx_desc_md *)
+			rte_security_dynfield(m);

IMHO alignment looks a bit confusing here, may be add one more TAB?

Quoted 11 lines
drivers/net/ixgbe/ixgbe_ipsec.c +2 -0
 		mdata->enc = 1;
 		mdata->sa_idx = ic_session->sa_index;
 		mdata->pad_len = ixgbe_crypto_compute_pad_len(m);
@@ -751,5 +752,7 @@ ixgbe_ipsec_ctx_create(struct rte_eth_dev *dev)
 			return -ENOMEM;
 		}
 	}
+	if (rte_security_dynfield_register() < 0)
+		return -rte_errno;
 	return 0;
 }

[snip]

examples/ipsec-secgw/ipsec_worker.c process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt, · line 212

Quoted 11 lines
examples/ipsec-secgw/ipsec_worker.c +2 -1
index b6c851f257..72f698893d 100644
@@ -208,7 +208,8 @@ process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt,
 					"Inbound security offload failed\n");
 				goto drop_pkt_and_exit;
 			}
-			sa = pkt->userdata;
+			sa = RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset,
+					struct ipsec_sa *);

I think it should be de-reference above, i.e.
sa = (struct ipsec_sa *)*RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset, RTE_SECURITY_DYNFIELD_TYPE *);
or just
sa = *RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset, struct ipsec_sa **);

and why not rte_security_dynfield()?

It all looks very fragile. May be at least add
RTE_BUILD_BUG_ON(sizeof(RTE_SECURITY_DYNFIELD_TYPE) ==

                    sizeof(ipsec_sa *));

and similar checks when an application or a library does lookup for a dynamic field.

In general since lookup should not happen on data path, may be lookup should return size of the field which must be checked by the caller for consistency.

examples/ipsec-secgw/ipsec_worker.c process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt, · line 231

Quoted 10 lines
examples/ipsec-secgw/ipsec_worker.c +2 -1
 		}
 
 		/* Check if we have a match */
@@ -226,7 +227,8 @@ process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt,
 					"Inbound security offload failed\n");
 				goto drop_pkt_and_exit;
 			}
-			sa = pkt->userdata;
+			sa = RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset,
+					struct ipsec_sa *);

same

examples/ipsec-secgw/ipsec_worker.c process_ipsec_ev_outbound(struct ipsec_ctx *ctx, struct route_table *rt, · line 363

Quoted 10 lines
examples/ipsec-secgw/ipsec_worker.c +2 -1
 		}
 
 		/* Check if we have a match */
@@ -357,7 +359,8 @@ process_ipsec_ev_outbound(struct ipsec_ctx *ctx, struct route_table *rt,
 	}
 
 	if (sess->security.ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
-		pkt->userdata = sess->security.ses;
+		*RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset,
+			struct rte_security_session **) = sess->security.ses;

rte_security_dynfield() ?

Is it really different types of value in one example application? It looks like it should be different dynamic fields. Otherwise, I don't understand how to work with it.

In fact may be above is out of scope of the patch series...

examples/ipsec-secgw/ipsec_worker.c ipsec_wrkr_non_burst_int_port_drv_mode(struct eh_event_link_info *links, · line 473

Quoted 11 lines
examples/ipsec-secgw/ipsec_worker.c +3 -1
 	/* Mark the packet for Tx security offload */
 	pkt->ol_flags |= PKT_TX_SEC_OFFLOAD;
@@ -465,7 +468,9 @@ ipsec_wrkr_non_burst_int_port_drv_mode(struct eh_event_link_info *links,
 			}
 
 			/* Save security session */
-			pkt->userdata = sess_tbl[port_id];
+			*RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset,
+					struct rte_security_session **) =
+				sess_tbl[port_id];

rte_security_dynfield() ?

Quoted 3 lines
examples/ipsec-secgw/ipsec_worker.c +0 -0
 			/* Mark the packet for Tx security offload */
 			pkt->ol_flags |= PKT_TX_SEC_OFFLOAD;

[snip]

#19 lore raw

Re: [dpdk-dev] [PATCH 05/15] security: switch metadata to dynamic mbuf field

26/10/2020 16:06, Andrew Rybchenko:

Quoted 9 lines · Thomas Monjalon

drivers/net/ixgbe/ixgbe_ipsec.c ixgbe_crypto_update_mb(void *device __rte_unused, · line 488

Quoted 5 lines
drivers/net/ixgbe/ixgbe_ipsec.c +2 -1
-			(union ixgbe_crypto_tx_desc_md *)&m->udata64;
+			(union ixgbe_crypto_tx_desc_md *)
+			rte_security_dynfield(m);

IMHO alignment looks a bit confusing here, may be add one more TAB?

OK, no opinion

Quoted 10 lines

[snip]

drivers/net/ixgbe/ixgbe_ipsec.c

Quoted 3 lines
drivers/net/ixgbe/ixgbe_ipsec.c +2 -1
-			sa = pkt->userdata;
+			sa = RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset,
+					struct ipsec_sa *);

I think it should be de-reference above, i.e.
sa = (struct ipsec_sa *)*RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset, RTE_SECURITY_DYNFIELD_TYPE *);
or just
sa = *RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset, struct ipsec_sa **);

You're right something is wrong.
I should add a dereference.

Quoted 1 line

and why not rte_security_dynfield()?

Because I need good reviews from you and David :) Will fix one and the other occurences.
I've prepared a v2 using a macro, but I think I will follow your suggestion of having static inline functions.

Quoted 5 lines

It all looks very fragile. May be at least add
RTE_BUILD_BUG_ON(sizeof(RTE_SECURITY_DYNFIELD_TYPE) ==

                    sizeof(ipsec_sa *));

and similar checks when an application or a library does lookup for a dynamic field.

You mean adding this after the lookup in the app?

Quoted 3 lines

In general since lookup should not happen on data path, may be lookup should return size of the field which must be checked by the caller for consistency.

It does. I can add a check.

Quoted 4 lines

Is it really different types of value in one example application? It looks like it should be different dynamic fields. Otherwise, I don't understand how to work with it.

Yes, udata64 was a trash bin used to store different kind of data, even inside librte_security.

Quoted 1 line

In fact may be above is out of scope of the patch series...

Yes, I think moving to a dedicated field is a first step. Second step (not by me) will be to split in different fields.

#20 lore raw

Re: [dpdk-dev] [PATCH 05/15] security: switch metadata to dynamic mbuf field

26/10/2020 17:49, Thomas Monjalon:

Quoted 13 lines

26/10/2020 16:06, Andrew Rybchenko:

Quoted 11 lines · Thomas Monjalon

[snip]

examples/ipsec-secgw/ipsec_worker.c process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt, · line 212

Quoted 3 lines
examples/ipsec-secgw/ipsec_worker.c +2 -1
-			sa = pkt->userdata;
+			sa = RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset,
+					struct ipsec_sa *);

I think it should be de-reference above, i.e.
sa = (struct ipsec_sa *)*RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset, RTE_SECURITY_DYNFIELD_TYPE *);
or just
sa = *RTE_MBUF_DYNFIELD(pkt, security_dynfield_offset, struct ipsec_sa **);

Quoted 6 lines

You're right something is wrong.
I should add a dereference.

Quoted 1 line

and why not rte_security_dynfield()?

Because I need good reviews from you and David :)

The initial idea was to have a field lookup in the app, and to not rely on what drivers have registered. After more thoughts, the lookup can be replaced with a check rte_security_dynfield_is_registered(),
so rte_security_dynfield() can be used.

Quoted 11 lines

Will fix one and the other occurences.
I've prepared a v2 using a macro, but I think I will follow your suggestion of having static inline functions.

Quoted 5 lines

It all looks very fragile. May be at least add
RTE_BUILD_BUG_ON(sizeof(RTE_SECURITY_DYNFIELD_TYPE) ==

                    sizeof(ipsec_sa *));

and similar checks when an application or a library does lookup for a dynamic field.

You mean adding this after the lookup in the app?

I will remove the lookup, it is less fragile.

#21 lore raw

PATCH 6/15 event/sw: switch test counter to dynamic mbuf field

In reply to Thomas Monjalon

The test worker_loopback used the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 drivers/event/sw/sw_evdev_selftest.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
drivers/event/sw/sw_evdev_selftest.c +19 -3
index 5c7e527917..754504c421 100644
@@ -40,6 +40,10 @@ struct test {
 	uint32_t service_id;
 };
 
+static int counter_dynfield_offset;
+#define COUNTER_FIELD(mbuf) \
+	(*RTE_MBUF_DYNFIELD(mbuf, counter_dynfield_offset, uint8_t *))
+
 static struct rte_event release_ev;
 
 static inline struct rte_mbuf *
@@ -2987,8 +2991,8 @@ worker_loopback_worker_fn(void *arg)
 			}
 
 			ev[i].queue_id = 0;
-			ev[i].mbuf->udata64++;
-			if (ev[i].mbuf->udata64 != 16) {
+			COUNTER_FIELD(ev[i].mbuf)++;
+			if (COUNTER_FIELD(ev[i].mbuf) != 16) {
 				ev[i].op = RTE_EVENT_OP_FORWARD;
 				enqd = rte_event_enqueue_burst(evdev, port,
 						&ev[i], 1);
@@ -3028,7 +3032,7 @@ worker_loopback_producer_fn(void *arg)
 			m = rte_pktmbuf_alloc(t->mbuf_pool);
 		} while (m == NULL);
 
-		m->udata64 = 0;
+		COUNTER_FIELD(m) = 0;
 
 		struct rte_event ev = {
 				.op = RTE_EVENT_OP_NEW,
@@ -3061,6 +3065,18 @@ worker_loopback(struct test *t, uint8_t disable_implicit_release)
 	int err;
 	int w_lcore, p_lcore;
 
+	static const struct rte_mbuf_dynfield counter_dynfield_desc = {
+		.name = "rte_event_sw_dynfield_selftest_counter",
+		.size = sizeof(uint8_t),
+		.align = __alignof__(uint8_t),
+	};
+	counter_dynfield_offset =
+		rte_mbuf_dynfield_register(&counter_dynfield_desc);
+	if (counter_dynfield_offset < 0) {
+		printf("Error registering mbuf field\n");
+		return -1;
+	}
+
 	if (init(t, 8, 2) < 0 ||
 			create_atomic_qids(t, 8) < 0) {
 		printf("%d: Error initializing device\n", __LINE__);
Signature · 1 line
2.28.0
#23 lore raw

PATCH 7/15 net/ark: ignore user data

In reply to Thomas Monjalon

The second field of metadata is reserved for user data which is a deprecated mbuf field.
The usage of mbuf udata64 is removed
and the corresponding ark metadata field is annotated as ignored.

---
 drivers/net/ark/ark_ddm.h       | 2 +-
 drivers/net/ark/ark_ethdev_rx.c | 1 -
 drivers/net/ark/ark_ethdev_tx.c | 1 -
 drivers/net/ark/ark_udm.h       | 2 +-
 4 files changed, 2 insertions(+), 4 deletions(-)
drivers/net/ark/ark_ddm.h +1 -1
index 5456b4b5cc..99eded8524 100644
@@ -19,7 +19,7 @@
 /* struct defining Tx meta data --  fixed in FPGA -- 16 bytes */
 struct ark_tx_meta {
 	uint64_t physaddr;
-	uint32_t user1;
+	uint32_t user1;		/* ignored */
 	uint16_t data_len;		/* of this MBUF */
 #define   ARK_DDM_EOP   0x01
 #define   ARK_DDM_SOP   0x02
drivers/net/ark/ark_ethdev_rx.c +0 -1
index 2f8d05099c..5ead67e6b8 100644
@@ -272,7 +272,6 @@ eth_ark_recv_pkts(void *rx_queue,
 		mbuf->pkt_len = meta->pkt_len;
 		mbuf->data_len = meta->pkt_len;
 		mbuf->timestamp = meta->timestamp;
-		mbuf->udata64 = meta->user_data;
 
 		if (ARK_DEBUG_CORE) {	/* debug sanity checks */
 			if ((meta->pkt_len > (1024 * 16)) ||
drivers/net/ark/ark_ethdev_tx.c +0 -1
index a0e35af880..8a0a9381f7 100644
@@ -70,7 +70,6 @@ eth_ark_tx_meta_from_mbuf(struct ark_tx_meta *meta,
 			  uint8_t flags)
 {
 	meta->physaddr = rte_mbuf_data_iova(mbuf);
-	meta->user1 = (uint32_t)mbuf->udata64;
 	meta->data_len = rte_pktmbuf_data_len(mbuf);
 	meta->flags = flags;
 }
drivers/net/ark/ark_udm.h +1 -1
index 5846c825b8..ba436ee25b 100644
@@ -18,7 +18,7 @@
 /* Meta data structure apssed from FPGA, must match layout in FPGA */
 struct ark_rx_meta {
 	uint64_t timestamp;
-	uint64_t user_data;
+	uint64_t user_data; /* ignored */
 	uint8_t port;
 	uint8_t dst_queue;
 	uint16_t pkt_len;
Signature · 1 line
2.28.0
#24 lore raw

PATCH 8/15 net/bnxt: switch CFA code to dynamic mbuf field

In reply to Thomas Monjalon

The CFA code from mark was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 drivers/net/bnxt/bnxt_ethdev.c  | 19 +++++++++++++++++++
 drivers/net/bnxt/bnxt_rxr.c     |  5 ++++-
 drivers/net/bnxt/bnxt_rxr.h     |  2 ++
 drivers/net/bnxt/rte_pmd_bnxt.h |  3 +++
 4 files changed, 28 insertions(+), 1 deletion(-)
drivers/net/bnxt/bnxt_ethdev.c +19 -0
index 1c7d1b758d..e12de94f04 100644
@@ -31,6 +31,7 @@
 #include "bnxt_nvm_defs.h"
 #include "bnxt_tf_common.h"
 #include "ulp_flow_db.h"
+#include "rte_pmd_bnxt.h"
 
 #define DRV_MODULE_NAME		"bnxt"
 static const char bnxt_version[] =
@@ -163,6 +164,8 @@ static const char *const bnxt_dev_args[] = {
  */
 #define BNXT_DEVARG_REP_FC_F2R_INVALID(rep_fc_f2r)	((rep_fc_f2r) > 1)
 
+int bnxt_cfa_code_dynfield_offset;
+
 /*
  * max_num_kflows must be >= 32
  * and must be a power-of-2 supported value
@@ -6021,6 +6024,22 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev, void *params __rte_unused)
 	    pci_dev->id.device_id == BROADCOM_DEV_ID_58802_VF)
 		bp->flags |= BNXT_FLAG_STINGRAY;
 
+	if (BNXT_TRUFLOW_EN(bp)) {
+		/* extra mbuf field is required to store CFA code from mark */
+		static const struct rte_mbuf_dynfield bnxt_cfa_code_dynfield_desc = {
+			.name = RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME,
+			.size = sizeof(uint32_t),
+			.align = __alignof__(uint32_t),
+		};
+		bnxt_cfa_code_dynfield_offset =
+			rte_mbuf_dynfield_register(&bnxt_cfa_code_dynfield_desc);
+		if (bnxt_cfa_code_dynfield_offset < 0) {
+			PMD_DRV_LOG(ERR,
+			    "Failed to register mbuf field for TruFlow mark\n");
+			return -1;
+		}
+	}
+
 	rc = bnxt_init_board(eth_dev);
 	if (rc) {
 		PMD_DRV_LOG(ERR,
drivers/net/bnxt/bnxt_rxr.c +4 -1
index 039217fa60..e913745e91 100644
@@ -28,6 +28,8 @@
  * RX Ring handling
  */
 
+int cfa_code_dynfield_offset;
+
 static inline struct rte_mbuf *__bnxt_alloc_rx_data(struct rte_mempool *mb)
 {
 	struct rte_mbuf *data;
@@ -606,7 +608,8 @@ bnxt_ulp_set_mark_in_mbuf(struct bnxt *bp, struct rx_pkt_cmpl_hi *rxcmp1,
 			return mark_id;
 		/* Got the mark, write it to the mbuf and return */
 		mbuf->hash.fdir.hi = mark_id;
-		mbuf->udata64 = (cfa_code & 0xffffffffull) << 32;
+		*RTE_MBUF_DYNFIELD(mbuf, bnxt_cfa_code_dynfield_offset,
+			uint32_t *) = cfa_code & 0xffffffffull;
 		mbuf->hash.fdir.id = rxcmp1->cfa_code;
 		mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
 		return mark_id;
drivers/net/bnxt/bnxt_rxr.h +2 -0
index b874e54a8c..324d5dad50 100644
@@ -95,6 +95,8 @@ void bnxt_set_mark_in_mbuf(struct bnxt *bp,
 			   struct rx_pkt_cmpl_hi *rxcmp1,
 			   struct rte_mbuf *mbuf);
 
+extern int bnxt_cfa_code_dynfield_offset;
+
 #define BNXT_RX_META_CFA_CODE_SHIFT		19
 #define BNXT_CFA_CODE_META_SHIFT		16
 #define BNXT_RX_META_CFA_CODE_INT_ACT_REC_BIT	0x8000000
drivers/net/bnxt/rte_pmd_bnxt.h +3 -0
index 81d0d0e032..8d3303bb0f 100644
@@ -9,6 +9,9 @@
 #include <rte_ethdev.h>
 #include <rte_ether.h>
 
+/* mbuf dynfield where CFA code is stored */
+#define RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME "rte_net_bnxt_dynfield_cfa_code"
+
 /*
  * Response sent back to the caller after callback
  */
Signature · 1 line
2.28.0
#25 lore raw

Re: [dpdk-dev] [PATCH 08/15] net/bnxt: switch CFA code to dynamic mbuf field

Quoted 3 lines · Thomas Monjalon

The CFA code from mark was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

We convert from a 64 bits (with only upper 32 bits filled) to a 32 bits field. Worth a comment on the API change for users (if any).

Signature · 1 line
David Marchand
#26 lore raw

Re: [dpdk-dev] [PATCH 08/15] net/bnxt: switch CFA code to dynamic mbuf field

26/10/2020 11:42, David Marchand:

Quoted 7 lines · Thomas Monjalon
Quoted 3 lines

The CFA code from mark was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

We convert from a 64 bits (with only upper 32 bits filled) to a 32 bits field. Worth a comment on the API change for users (if any).

Yes
There is no good place to note this change except in the commit log.

#27 lore raw

PATCH 9/15 net/vmxnet3: switch MSS hint to dynamic mbuf field

In reply to Thomas Monjalon

The segment count, used for MSS guess,
was stored in the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 drivers/net/vmxnet3/vmxnet3_ethdev.c | 15 +++++++++++++++
 drivers/net/vmxnet3/vmxnet3_ethdev.h |  2 ++
 drivers/net/vmxnet3/vmxnet3_rxtx.c   | 10 ++++++----
 3 files changed, 23 insertions(+), 4 deletions(-)
drivers/net/vmxnet3/vmxnet3_ethdev.c +15 -0
index 6920ab568c..eeb1152b61 100644
@@ -59,6 +59,8 @@
 	 DEV_RX_OFFLOAD_JUMBO_FRAME |   \
 	 DEV_RX_OFFLOAD_RSS_HASH)
 
+int vmxnet3_segs_dynfield_offset;
+
 static int eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev);
 static int eth_vmxnet3_dev_uninit(struct rte_eth_dev *eth_dev);
 static int vmxnet3_dev_configure(struct rte_eth_dev *dev);
@@ -233,6 +235,11 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	struct vmxnet3_hw *hw = eth_dev->data->dev_private;
 	uint32_t mac_hi, mac_lo, ver;
 	struct rte_eth_link link;
+	static const struct rte_mbuf_dynfield vmxnet3_segs_dynfield_desc = {
+		.name = "rte_net_vmxnet3_dynfield_segs",
+		.size = sizeof(uint8_t),
+		.align = __alignof__(uint8_t),
+	};
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -242,6 +249,14 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
 	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 
+	/* extra mbuf field is required to guess MSS */
+	vmxnet3_segs_dynfield_offset =
+		rte_mbuf_dynfield_register(&vmxnet3_segs_dynfield_desc);
+	if (vmxnet3_segs_dynfield_offset < 0) {
+		PMD_INIT_LOG(ERR, "Cannot register mbuf field.");
+		return -rte_errno;
+	}
+
 	/*
 	 * for secondary processes, we don't initialize any further as primary
 	 * has already done this work.
drivers/net/vmxnet3/vmxnet3_ethdev.h +2 -0
index dd685b02b7..5730e94d50 100644
@@ -193,4 +193,6 @@ uint16_t vmxnet3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 uint16_t vmxnet3_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 			uint16_t nb_pkts);
 
+extern int vmxnet3_segs_dynfield_offset;
+
 #endif /* _VMXNET3_ETHDEV_H_ */
drivers/net/vmxnet3/vmxnet3_rxtx.c +6 -4
index e10f9ee870..6655622f94 100644
@@ -674,6 +674,7 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	struct rte_ipv6_hdr *ipv6_hdr;
 	struct rte_tcp_hdr *tcp_hdr;
 	char *ptr;
+	uint8_t segs;
 
 	RTE_ASSERT(rcd->tcp);
 
@@ -710,9 +711,9 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	tcp_hdr = (struct rte_tcp_hdr *)(ptr + hlen);
 	hlen += (tcp_hdr->data_off & 0xf0) >> 2;
 
-	if (rxm->udata64 > 1)
-		return (rte_pktmbuf_pkt_len(rxm) - hlen +
-				rxm->udata64 - 1) / rxm->udata64;
+	segs = *RTE_MBUF_DYNFIELD(rxm, vmxnet3_segs_dynfield_offset, uint8_t *);
+	if (segs > 1)
+		return (rte_pktmbuf_pkt_len(rxm) - hlen + segs - 1) / segs;
 	else
 		return hw->mtu - hlen + sizeof(struct rte_ether_hdr);
 }
@@ -737,7 +738,8 @@ vmxnet3_rx_offload(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 					(const Vmxnet3_RxCompDescExt *)rcd;
 
 			rxm->tso_segsz = rcde->mss;
-			rxm->udata64 = rcde->segCnt;
+			*RTE_MBUF_DYNFIELD(rxm, vmxnet3_segs_dynfield_offset,
+					uint8_t *) = rcde->segCnt;
 			ol_flags |= PKT_RX_LRO;
 		}
 	} else { /* Offloads set in eop */
Signature · 1 line
2.28.0
#28 lore raw

Re: [dpdk-dev] [PATCH 09/15] net/vmxnet3: switch MSS hint to dynamic mbuf field

Quoted 89 lines · Thomas Monjalon

The segment count, used for MSS guess,
was stored in the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 drivers/net/vmxnet3/vmxnet3_ethdev.c | 15 +++++++++++++++
 drivers/net/vmxnet3/vmxnet3_ethdev.h |  2 ++
 drivers/net/vmxnet3/vmxnet3_rxtx.c   | 10 ++++++----
 3 files changed, 23 insertions(+), 4 deletions(-)
drivers/net/vmxnet3/vmxnet3_ethdev.c +15 -0
index 6920ab568c..eeb1152b61 100644
@@ -59,6 +59,8 @@
 	 DEV_RX_OFFLOAD_JUMBO_FRAME |   \
 	 DEV_RX_OFFLOAD_RSS_HASH)
 
+int vmxnet3_segs_dynfield_offset;
+
 static int eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev);
 static int eth_vmxnet3_dev_uninit(struct rte_eth_dev *eth_dev);
 static int vmxnet3_dev_configure(struct rte_eth_dev *dev);
@@ -233,6 +235,11 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	struct vmxnet3_hw *hw = eth_dev->data->dev_private;
 	uint32_t mac_hi, mac_lo, ver;
 	struct rte_eth_link link;
+	static const struct rte_mbuf_dynfield vmxnet3_segs_dynfield_desc = {
+		.name = "rte_net_vmxnet3_dynfield_segs",
+		.size = sizeof(uint8_t),
+		.align = __alignof__(uint8_t),
+	};
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -242,6 +249,14 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
 	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 
+	/* extra mbuf field is required to guess MSS */
+	vmxnet3_segs_dynfield_offset =
+		rte_mbuf_dynfield_register(&vmxnet3_segs_dynfield_desc);
+	if (vmxnet3_segs_dynfield_offset < 0) {
+		PMD_INIT_LOG(ERR, "Cannot register mbuf field.");
+		return -rte_errno;
+	}
+
 	/*
 	 * for secondary processes, we don't initialize any further as primary
 	 * has already done this work.
drivers/net/vmxnet3/vmxnet3_ethdev.h +2 -0
index dd685b02b7..5730e94d50 100644
@@ -193,4 +193,6 @@ uint16_t vmxnet3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 uint16_t vmxnet3_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 			uint16_t nb_pkts);
 
+extern int vmxnet3_segs_dynfield_offset;
+
 #endif /* _VMXNET3_ETHDEV_H_ */
drivers/net/vmxnet3/vmxnet3_rxtx.c +4 -3
index e10f9ee870..6655622f94 100644
@@ -674,6 +674,7 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	struct rte_ipv6_hdr *ipv6_hdr;
 	struct rte_tcp_hdr *tcp_hdr;
 	char *ptr;
+	uint8_t segs;
 
 	RTE_ASSERT(rcd->tcp);
 
@@ -710,9 +711,9 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	tcp_hdr = (struct rte_tcp_hdr *)(ptr + hlen);
 	hlen += (tcp_hdr->data_off & 0xf0) >> 2;
 
-	if (rxm->udata64 > 1)
-		return (rte_pktmbuf_pkt_len(rxm) - hlen +
-				rxm->udata64 - 1) / rxm->udata64;
+	segs = *RTE_MBUF_DYNFIELD(rxm, vmxnet3_segs_dynfield_offset, uint8_t *);
+	if (segs > 1)
+		return (rte_pktmbuf_pkt_len(rxm) - hlen + segs - 1) / segs;
 	else
 		return hw->mtu - hlen + sizeof(struct rte_ether_hdr);
 }

drivers/net/vmxnet3/vmxnet3_rxtx.c vmxnet3_rx_offload(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd, · line 745

Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_rxtx.c +2 -1
@@ -737,7 +738,8 @@ vmxnet3_rx_offload(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 					(const Vmxnet3_RxCompDescExt *)rcd;
 
 			rxm->tso_segsz = rcde->mss;
-			rxm->udata64 = rcde->segCnt;
+			*RTE_MBUF_DYNFIELD(rxm, vmxnet3_segs_dynfield_offset,
+					uint8_t *) = rcde->segCnt;
 			ol_flags |= PKT_RX_LRO;
 		}
 	} else { /* Offloads set in eop */

I think it should be a rule of thumb to introduce helper macro to access a dynamic field (as you do in few of previous patches).

It should be just nearby declaration of the the offset variable.

#29 lore raw

Re: [dpdk-dev] [PATCH 09/15] net/vmxnet3: switch MSS hint to dynamic mbuf field

Quoted 104 lines · Andrew Rybchenko
Quoted 89 lines · Thomas Monjalon

The segment count, used for MSS guess,
was stored in the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 drivers/net/vmxnet3/vmxnet3_ethdev.c | 15 +++++++++++++++
 drivers/net/vmxnet3/vmxnet3_ethdev.h |  2 ++
 drivers/net/vmxnet3/vmxnet3_rxtx.c   | 10 ++++++----
 3 files changed, 23 insertions(+), 4 deletions(-)
drivers/net/vmxnet3/vmxnet3_ethdev.c +15 -0
index 6920ab568c..eeb1152b61 100644
@@ -59,6 +59,8 @@
 	 DEV_RX_OFFLOAD_JUMBO_FRAME |   \
 	 DEV_RX_OFFLOAD_RSS_HASH)
 
+int vmxnet3_segs_dynfield_offset;
+
 static int eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev);
 static int eth_vmxnet3_dev_uninit(struct rte_eth_dev *eth_dev);
 static int vmxnet3_dev_configure(struct rte_eth_dev *dev);
@@ -233,6 +235,11 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	struct vmxnet3_hw *hw = eth_dev->data->dev_private;
 	uint32_t mac_hi, mac_lo, ver;
 	struct rte_eth_link link;
+	static const struct rte_mbuf_dynfield vmxnet3_segs_dynfield_desc = {
+		.name = "rte_net_vmxnet3_dynfield_segs",
+		.size = sizeof(uint8_t),
+		.align = __alignof__(uint8_t),
+	};
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -242,6 +249,14 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
 	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 
+	/* extra mbuf field is required to guess MSS */
+	vmxnet3_segs_dynfield_offset =
+		rte_mbuf_dynfield_register(&vmxnet3_segs_dynfield_desc);
+	if (vmxnet3_segs_dynfield_offset < 0) {
+		PMD_INIT_LOG(ERR, "Cannot register mbuf field.");
+		return -rte_errno;
+	}
+
 	/*
 	 * for secondary processes, we don't initialize any further as primary
 	 * has already done this work.
drivers/net/vmxnet3/vmxnet3_ethdev.h +2 -0
index dd685b02b7..5730e94d50 100644
@@ -193,4 +193,6 @@ uint16_t vmxnet3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 uint16_t vmxnet3_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 			uint16_t nb_pkts);
 
+extern int vmxnet3_segs_dynfield_offset;
+
 #endif /* _VMXNET3_ETHDEV_H_ */
drivers/net/vmxnet3/vmxnet3_rxtx.c +4 -3
index e10f9ee870..6655622f94 100644
@@ -674,6 +674,7 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	struct rte_ipv6_hdr *ipv6_hdr;
 	struct rte_tcp_hdr *tcp_hdr;
 	char *ptr;
+	uint8_t segs;
 
 	RTE_ASSERT(rcd->tcp);
 
@@ -710,9 +711,9 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	tcp_hdr = (struct rte_tcp_hdr *)(ptr + hlen);
 	hlen += (tcp_hdr->data_off & 0xf0) >> 2;
 
-	if (rxm->udata64 > 1)
-		return (rte_pktmbuf_pkt_len(rxm) - hlen +
-				rxm->udata64 - 1) / rxm->udata64;
+	segs = *RTE_MBUF_DYNFIELD(rxm, vmxnet3_segs_dynfield_offset, uint8_t *);
+	if (segs > 1)
+		return (rte_pktmbuf_pkt_len(rxm) - hlen + segs - 1) / segs;
 	else
 		return hw->mtu - hlen + sizeof(struct rte_ether_hdr);
 }

drivers/net/vmxnet3/vmxnet3_rxtx.c vmxnet3_rx_offload(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd, · line 745

Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_rxtx.c +2 -1
@@ -737,7 +738,8 @@ vmxnet3_rx_offload(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 					(const Vmxnet3_RxCompDescExt *)rcd;
 
 			rxm->tso_segsz = rcde->mss;
-			rxm->udata64 = rcde->segCnt;
+			*RTE_MBUF_DYNFIELD(rxm, vmxnet3_segs_dynfield_offset,
+					uint8_t *) = rcde->segCnt;
 			ol_flags |= PKT_RX_LRO;
 		}
 	} else { /* Offloads set in eop */

I think it should be a rule of thumb to introduce helper macro to access a dynamic field (as you do in few of previous patches).

Quoted 3 lines

It should be just nearby declaration of the the offset variable.

May be inline function is even better since, IMHO, if you both ways are possible, inline function is the right choice. In this particular case inline function will not add value from type safety point of view, but it is still better as an example to follow. In some case inline function could be used as a place to put build assertion to check size.

#30 lore raw

Re: [dpdk-dev] [PATCH 09/15] net/vmxnet3: switch MSS hint to dynamic mbuf field

26/10/2020 16:21, Andrew Rybchenko:

Quoted 13 lines · Andrew Rybchenko
Quoted 11 lines · Thomas Monjalon

drivers/net/vmxnet3/vmxnet3_rxtx.c vmxnet3_rx_offload(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd, · line 742

Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_rxtx.c +2 -1
-			rxm->udata64 = rcde->segCnt;
+			*RTE_MBUF_DYNFIELD(rxm, vmxnet3_segs_dynfield_offset,
+					uint8_t *) = rcde->segCnt;

I think it should be a rule of thumb to introduce helper macro to access a dynamic field (as you do in few of previous patches).

It should be just nearby declaration of the the offset variable.

Quoted 6 lines

May be inline function is even better since, IMHO, if you both ways are possible, inline function is the right choice. In this particular case inline function will not add value from type safety point of view, but it is still better as an example to follow. In some case inline function could be used as a place to put build assertion to check size.

OK I will review the patches to provide a static inline getter function for each dynamic field.

#31 lore raw

Re: [dpdk-dev] [PATCH 09/15] net/vmxnet3: switch MSS hint to dynamic mbuf field

26/10/2020 17:50, Thomas Monjalon:

Quoted 21 lines

26/10/2020 16:21, Andrew Rybchenko:

Quoted 13 lines · Andrew Rybchenko
Quoted 11 lines · Thomas Monjalon

drivers/net/vmxnet3/vmxnet3_rxtx.c vmxnet3_rx_offload(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd, · line 742

Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_rxtx.c +2 -1
-			rxm->udata64 = rcde->segCnt;
+			*RTE_MBUF_DYNFIELD(rxm, vmxnet3_segs_dynfield_offset,
+					uint8_t *) = rcde->segCnt;

I think it should be a rule of thumb to introduce helper macro to access a dynamic field (as you do in few of previous patches).

It should be just nearby declaration of the the offset variable.

Quoted 6 lines

May be inline function is even better since, IMHO, if you both ways are possible, inline function is the right choice. In this particular case inline function will not add value from type safety point of view, but it is still better as an example to follow. In some case inline function could be used as a place to put build assertion to check size.

Quoted 2 lines

OK I will review the patches to provide a static inline getter function for each dynamic field.

After more thoughts, I think it is good to have static inline returning a pointer to the field in general case:

static inline my_type *
rte_foo_dynfield_bar(struct rte_mbuf * mbuf)

{
	return RTE_MBUF_DYNFIELD(mbuf, my_dynfield_offset, my_type *);
}

But when the scope is limited, it is easier to read a macro which contains dereferencing of the field pointer with the right type:

#define MY_DYNFIELD(mbuf) \
(*RTE_MBUF_DYNFIELD(mbuf, my_dynfield_offset, my_type *))

If type cast is never needed, this form allows simple assignment:

	MY_DYNFIELD(mbuf) = field_value;

I would tend to use this latter form for tests or small apps.

#32 lore raw

PATCH 10/15 test/distributor: switch sequence to dynamic mbuf field

In reply to Thomas Monjalon

The test used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 app/test/test_distributor.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)
app/test/test_distributor.c +22 -5
index eb889b91d1..074a06f4a2 100644
@@ -10,6 +10,7 @@
 #include <rte_errno.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_distributor.h>
 #include <rte_string_fns.h>
 
@@ -17,6 +18,10 @@
 #define BURST 32
 #define BIG_BATCH 1024
 
+static int seq_dynfield_offset;
+#define SEQ_FIELD(mbuf) \
+	(*RTE_MBUF_DYNFIELD(mbuf, seq_dynfield_offset, uint32_t *))
+
 struct worker_params {
 	char name[64];
 	struct rte_distributor *dist;
@@ -578,7 +583,7 @@ handle_and_mark_work(void *arg)
 		__atomic_fetch_add(&worker_stats[id].handled_packets, num,
 				__ATOMIC_RELAXED);
 		for (i = 0; i < num; i++)
-			buf[i]->udata64 += id + 1;
+			SEQ_FIELD(buf[i]) += id + 1;
 		num = rte_distributor_get_pkt(db, id,
 				buf, buf, num);
 	}
@@ -631,10 +636,10 @@ sanity_mark_test(struct worker_params *wp, struct rte_mempool *p)
 			<< shift;
 	}
 	/* Assign a sequence number to each packet. The sequence is shifted,
-	 * so that lower bits of the udate64 will hold mark from worker.
+	 * so that lower bits will hold mark from worker.
 	 */
 	for (i = 0; i < buf_count; i++)
-		bufs[i]->udata64 = i << seq_shift;
+		SEQ_FIELD(bufs[i]) = i << seq_shift;
 
 	count = 0;
 	for (i = 0; i < buf_count/burst; i++) {
@@ -660,8 +665,8 @@ sanity_mark_test(struct worker_params *wp, struct rte_mempool *p)
 
 	/* Sort returned packets by sent order (sequence numbers). */
 	for (i = 0; i < buf_count; i++) {
-		seq = returns[i]->udata64 >> seq_shift;
-		id = returns[i]->udata64 - (seq << seq_shift);
+		seq = SEQ_FIELD(returns[i]) >> seq_shift;
+		id = SEQ_FIELD(returns[i]) - (seq << seq_shift);
 		sorted[seq] = id;
 	}
 
@@ -805,6 +810,18 @@ test_distributor(void)
 	static struct rte_mempool *p;
 	int i;
 
+	static const struct rte_mbuf_dynfield seq_dynfield_desc = {
+		.name = "test_distributor_dynfield_seq",
+		.size = sizeof(uint32_t),
+		.align = __alignof__(uint32_t),
+	};
+	seq_dynfield_offset =
+		rte_mbuf_dynfield_register(&seq_dynfield_desc);
+	if (seq_dynfield_offset < 0) {
+		printf("Error registering mbuf field\n");
+		return TEST_FAILED;
+	}
+
 	if (rte_lcore_count() < 2) {
 		printf("Not enough cores for distributor_autotest, expecting at least 2\n");
 		return TEST_SKIPPED;
Signature · 1 line
2.28.0
Acked-by Tested-by on v1 10/15
#33 lore raw

Re: [dpdk-dev] [PATCH 10/15] test/distributor: switch sequence to dynamic mbuf field

Changes in distributor tests look good.
All tests pass

W dniu 26.10.2020 o 06:21, Thomas Monjalon pisze:

Quoted 4 lines

The test used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

Quoted 79 lines
---
  app/test/test_distributor.c | 27 ++++++++++++++++++++++-----
  1 file changed, 22 insertions(+), 5 deletions(-)
app/test/test_distributor.c +22 -5
index eb889b91d1..074a06f4a2 100644
@@ -10,6 +10,7 @@
  #include <rte_errno.h>
  #include <rte_mempool.h>
  #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
  #include <rte_distributor.h>
  #include <rte_string_fns.h>
 
@@ -17,6 +18,10 @@
  #define BURST 32
  #define BIG_BATCH 1024
 
+static int seq_dynfield_offset;
+#define SEQ_FIELD(mbuf) \
+	(*RTE_MBUF_DYNFIELD(mbuf, seq_dynfield_offset, uint32_t *))
+
  struct worker_params {
  	char name[64];
  	struct rte_distributor *dist;
@@ -578,7 +583,7 @@ handle_and_mark_work(void *arg)
  		__atomic_fetch_add(&worker_stats[id].handled_packets, num,
  				__ATOMIC_RELAXED);
  		for (i = 0; i < num; i++)
-			buf[i]->udata64 += id + 1;
+			SEQ_FIELD(buf[i]) += id + 1;
  		num = rte_distributor_get_pkt(db, id,
  				buf, buf, num);
  	}
@@ -631,10 +636,10 @@ sanity_mark_test(struct worker_params *wp, struct rte_mempool *p)
  			<< shift;
  	}
  	/* Assign a sequence number to each packet. The sequence is shifted,
-	 * so that lower bits of the udate64 will hold mark from worker.
+	 * so that lower bits will hold mark from worker.
  	 */
  	for (i = 0; i < buf_count; i++)
-		bufs[i]->udata64 = i << seq_shift;
+		SEQ_FIELD(bufs[i]) = i << seq_shift;
 
  	count = 0;
  	for (i = 0; i < buf_count/burst; i++) {
@@ -660,8 +665,8 @@ sanity_mark_test(struct worker_params *wp, struct rte_mempool *p)
 
  	/* Sort returned packets by sent order (sequence numbers). */
  	for (i = 0; i < buf_count; i++) {
-		seq = returns[i]->udata64 >> seq_shift;
-		id = returns[i]->udata64 - (seq << seq_shift);
+		seq = SEQ_FIELD(returns[i]) >> seq_shift;
+		id = SEQ_FIELD(returns[i]) - (seq << seq_shift);
  		sorted[seq] = id;
  	}
 
@@ -805,6 +810,18 @@ test_distributor(void)
  	static struct rte_mempool *p;
  	int i;
 
+	static const struct rte_mbuf_dynfield seq_dynfield_desc = {
+		.name = "test_distributor_dynfield_seq",
+		.size = sizeof(uint32_t),
+		.align = __alignof__(uint32_t),
+	};
+	seq_dynfield_offset =
+		rte_mbuf_dynfield_register(&seq_dynfield_desc);
+	if (seq_dynfield_offset < 0) {
+		printf("Error registering mbuf field\n");
+		return TEST_FAILED;
+	}
+
  	if (rte_lcore_count() < 2) {
  		printf("Not enough cores for distributor_autotest, expecting at least 2\n");
  		return TEST_SKIPPED;
Signature · 7 lines
Lukasz Wojciechowski
Principal Software Engineer

Samsung R&D Institute Poland
Samsung Electronics
Office +48 22 377 88 25
[email protected]
#34 lore raw

PATCH 11/15 test/graph: switch user data to dynamic mbuf field

In reply to Thomas Monjalon

The test used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 app/test/test_graph.c | 93 +++++++++++++++++++++++++------------------
 1 file changed, 55 insertions(+), 38 deletions(-)
app/test/test_graph.c +55 -38
index ed69eda997..74d8e78353 100644
@@ -12,6 +12,7 @@
 #include <rte_graph.h>
 #include <rte_graph_worker.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_random.h>
 
 #include "test.h"
@@ -39,6 +40,10 @@ static uint16_t test_node3_worker(struct rte_graph *graph,
 #define MBUFF_SIZE 512
 #define MAX_NODES  4
 
+static int graph_dynfield_offset;
+#define GRAPH_FIELD(mbuf) \
+	(*RTE_MBUF_DYNFIELD(mbuf, graph_dynfield_offset, uint64_t *))
+
 static struct rte_mbuf mbuf[MAX_NODES + 1][MBUFF_SIZE];
 static void *mbuf_p[MAX_NODES + 1][MBUFF_SIZE];
 static rte_graph_t graph_id;
@@ -162,9 +167,9 @@ test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
 	next_stream = rte_node_next_stream_get(graph, node, next, obj_node0);
 	for (i = 0; i < obj_node0; i++) {
 		data = &mbuf[0][i];
-		data->udata64 = ((uint64_t)tm->test_node[0].idx << 32) | i;
+		GRAPH_FIELD(data) = ((uint64_t)tm->test_node[0].idx << 32) | i;
 		if ((i + 1) == obj_node0)
-			data->udata64 |= (1 << 16);
+			GRAPH_FIELD(data) |= (1 << 16);
 		next_stream[i] = &mbuf[0][i];
 	}
 	rte_node_next_stream_put(graph, node, next, obj_node0);
@@ -175,9 +180,9 @@ test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
 	next_stream = rte_node_next_stream_get(graph, node, next, obj_node1);
 	for (i = 0; i < obj_node1; i++) {
 		data = &mbuf[0][obj_node0 + i];
-		data->udata64 = ((uint64_t)tm->test_node[1].idx << 32) | i;
+		GRAPH_FIELD(data) = ((uint64_t)tm->test_node[1].idx << 32) | i;
 		if ((i + 1) == obj_node1)
-			data->udata64 |= (1 << 16);
+			GRAPH_FIELD(data) |= (1 << 16);
 		next_stream[i] = &mbuf[0][obj_node0 + i];
 	}
 
@@ -205,23 +210,23 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 
 		for (i = 0; i < nb_objs; i++) {
 			data = (struct rte_mbuf *)objs[i];
-			if ((data->udata64 >> 32) != tm->test_node[0].idx) {
+			if ((GRAPH_FIELD(data) >> 32) != tm->test_node[0].idx) {
 				printf("Data idx miss match at node 0, expected"
 				       " = %u got = %u\n",
 				       tm->test_node[0].idx,
-				       (uint32_t)(data->udata64 >> 32));
+				       (uint32_t)(GRAPH_FIELD(data) >> 32));
 				goto end;
 			}
 
-			if ((data->udata64 & 0xffff) != (i - count)) {
+			if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 				printf("Expected buff count miss match at "
 				       "node 0\n");
 				goto end;
 			}
 
-			if (data->udata64 & (0x1 << 16))
+			if (GRAPH_FIELD(data) & (0x1 << 16))
 				count = i + 1;
-			if (data->udata64 & (0x1 << 17))
+			if (GRAPH_FIELD(data) & (0x1 << 17))
 				second_pass = 1;
 		}
 
@@ -233,12 +238,12 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node0 = nb_objs * obj_node0 * 0.01;
 		for (i = 0; i < obj_node0; i++) {
 			data = &mbuf[1][i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[1].idx << 32) | i;
 			if ((i + 1) == obj_node0)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 			if (second_pass)
-				data->udata64 |= (1 << 17);
+				GRAPH_FIELD(data) |= (1 << 17);
 		}
 		rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[1][0],
 				 obj_node0);
@@ -246,12 +251,12 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node1 = nb_objs - obj_node0;
 		for (i = 0; i < obj_node1; i++) {
 			data = &mbuf[1][obj_node0 + i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[2].idx << 32) | i;
 			if ((i + 1) == obj_node1)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 			if (second_pass)
-				data->udata64 |= (1 << 17);
+				GRAPH_FIELD(data) |= (1 << 17);
 		}
 		rte_node_enqueue(graph, node, 1, (void **)&mbuf_p[1][obj_node0],
 				 obj_node1);
@@ -285,22 +290,22 @@ test_node1_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	fn_calls[2] += 1;
 	for (i = 0; i < nb_objs; i++) {
 		data = (struct rte_mbuf *)objs[i];
-		if ((data->udata64 >> 32) != tm->test_node[1].idx) {
+		if ((GRAPH_FIELD(data) >> 32) != tm->test_node[1].idx) {
 			printf("Data idx miss match at node 1, expected = %u"
 			       " got = %u\n",
 			       tm->test_node[1].idx,
-			       (uint32_t)(data->udata64 >> 32));
+			       (uint32_t)(GRAPH_FIELD(data) >> 32));
 			goto end;
 		}
 
-		if ((data->udata64 & 0xffff) != (i - count)) {
+		if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 			printf("Expected buff count miss match at node 1\n");
 			goto end;
 		}
 
-		if (data->udata64 & (0x1 << 16))
+		if (GRAPH_FIELD(data) & (0x1 << 16))
 			count = i + 1;
-		if (data->udata64 & (0x1 << 17))
+		if (GRAPH_FIELD(data) & (0x1 << 17))
 			second_pass = 1;
 	}
 
@@ -312,11 +317,11 @@ test_node1_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	obj_node0 = nb_objs;
 	for (i = 0; i < obj_node0; i++) {
 		data = &mbuf[2][i];
-		data->udata64 = ((uint64_t)tm->test_node[2].idx << 32) | i;
+		GRAPH_FIELD(data) = ((uint64_t)tm->test_node[2].idx << 32) | i;
 		if ((i + 1) == obj_node0)
-			data->udata64 |= (1 << 16);
+			GRAPH_FIELD(data) |= (1 << 16);
 		if (second_pass)
-			data->udata64 |= (1 << 17);
+			GRAPH_FIELD(data) |= (1 << 17);
 	}
 	rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[2][0], obj_node0);
 
@@ -339,22 +344,22 @@ test_node2_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	fn_calls[3] += 1;
 	for (i = 0; i < nb_objs; i++) {
 		data = (struct rte_mbuf *)objs[i];
-		if ((data->udata64 >> 32) != tm->test_node[2].idx) {
+		if ((GRAPH_FIELD(data) >> 32) != tm->test_node[2].idx) {
 			printf("Data idx miss match at node 2, expected = %u"
 			       " got = %u\n",
 			       tm->test_node[2].idx,
-			       (uint32_t)(data->udata64 >> 32));
+			       (uint32_t)(GRAPH_FIELD(data) >> 32));
 			goto end;
 		}
 
-		if ((data->udata64 & 0xffff) != (i - count)) {
+		if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 			printf("Expected buff count miss match at node 2\n");
 			goto end;
 		}
 
-		if (data->udata64 & (0x1 << 16))
+		if (GRAPH_FIELD(data) & (0x1 << 16))
 			count = i + 1;
-		if (data->udata64 & (0x1 << 17))
+		if (GRAPH_FIELD(data) & (0x1 << 17))
 			second_pass = 1;
 	}
 
@@ -367,10 +372,10 @@ test_node2_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node0 = nb_objs;
 		for (i = 0; i < obj_node0; i++) {
 			data = &mbuf[3][i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[3].idx << 32) | i;
 			if ((i + 1) == obj_node0)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 		}
 		rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[3][0],
 				 obj_node0);
@@ -395,22 +400,22 @@ test_node3_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	fn_calls[4] += 1;
 	for (i = 0; i < nb_objs; i++) {
 		data = (struct rte_mbuf *)objs[i];
-		if ((data->udata64 >> 32) != tm->test_node[3].idx) {
+		if ((GRAPH_FIELD(data) >> 32) != tm->test_node[3].idx) {
 			printf("Data idx miss match at node 3, expected = %u"
 			       " got = %u\n",
 			       tm->test_node[3].idx,
-			       (uint32_t)(data->udata64 >> 32));
+			       (uint32_t)(GRAPH_FIELD(data) >> 32));
 			goto end;
 		}
 
-		if ((data->udata64 & 0xffff) != (i - count)) {
+		if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 			printf("Expected buff count miss match at node 3\n");
 			goto end;
 		}
 
-		if (data->udata64 & (0x1 << 16))
+		if (GRAPH_FIELD(data) & (0x1 << 16))
 			count = i + 1;
-		if (data->udata64 & (0x1 << 17))
+		if (GRAPH_FIELD(data) & (0x1 << 17))
 			second_pass = 1;
 	}
 
@@ -426,11 +431,11 @@ test_node3_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node0 = nb_objs * 2;
 		for (i = 0; i < obj_node0; i++) {
 			data = &mbuf[4][i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[0].idx << 32) | i;
-			data->udata64 |= (1 << 17);
+			GRAPH_FIELD(data) |= (1 << 17);
 			if ((i + 1) == obj_node0)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 		}
 		rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[4][0],
 				 obj_node0);
@@ -765,6 +770,18 @@ graph_setup(void)
 {
 	int i, j;
 
+	static const struct rte_mbuf_dynfield graph_dynfield_desc = {
+		.name = "test_graph_dynfield",
+		.size = sizeof(uint64_t),
+		.align = __alignof__(uint64_t),
+	};
+	graph_dynfield_offset =
+		rte_mbuf_dynfield_register(&graph_dynfield_desc);
+	if (graph_dynfield_offset < 0) {
+		printf("Cannot register mbuf field\n");
+		return TEST_FAILED;
+	}
+
 	for (i = 0; i <= MAX_NODES; i++) {
 		for (j = 0; j < MBUFF_SIZE; j++)
 			mbuf_p[i][j] = &mbuf[i][j];
Signature · 1 line
2.28.0
#35 lore raw

PATCH 12/15 app/eventdev: switch flow ID to dynamic mbuf field

In reply to Thomas Monjalon

The order test stored the flow ID in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 app/test-eventdev/test_order_atq.c    |  4 ++--
 app/test-eventdev/test_order_common.c | 16 +++++++++++++++-
 app/test-eventdev/test_order_common.h |  5 +++++
 app/test-eventdev/test_order_queue.c  |  4 ++--
 4 files changed, 24 insertions(+), 5 deletions(-)
app/test-eventdev/test_order_atq.c +2 -2
index cfcb1dc4e9..4087c26fc5 100644
@@ -35,7 +35,7 @@ order_atq_worker(void *arg, const bool flow_id_cap)
 		}
 
 		if (!flow_id_cap)
-			ev.flow_id = ev.mbuf->udata64;
+			ev.flow_id = FLOW_ID(ev.mbuf);
 
 		if (ev.sub_event_type == 0) { /* stage 0 from producer */
 			order_atq_process_stage_0(&ev);
@@ -72,7 +72,7 @@ order_atq_worker_burst(void *arg, const bool flow_id_cap)
 
 		for (i = 0; i < nb_rx; i++) {
 			if (!flow_id_cap)
-				ev[i].flow_id = ev[i].mbuf->udata64;
+				ev[i].flow_id = FLOW_ID(ev[i].mbuf);
 
 			if (ev[i].sub_event_type == 0) { /*stage 0 */
 				order_atq_process_stage_0(&ev[i]);
app/test-eventdev/test_order_common.c +15 -1
index dc55d93921..fc82e3ff41 100644
@@ -4,6 +4,8 @@
 
 #include "test_order_common.h"
 
+int flow_id_dynfield_offset;
+
 int
 order_test_result(struct evt_test *test, struct evt_options *opt)
 {
@@ -49,7 +51,7 @@ order_producer(void *arg)
 		const uint32_t flow = (uintptr_t)m % nb_flows;
 		/* Maintain seq number per flow */
 		m->seqn = producer_flow_seq[flow]++;
-		m->udata64 = flow;
+		FLOW_ID(m) = flow;
 
 		ev.flow_id = flow;
 		ev.mbuf = m;
@@ -139,6 +141,18 @@ order_test_setup(struct evt_test *test, struct evt_options *opt)
 {
 	void *test_order;
 
+	static const struct rte_mbuf_dynfield flow_id_dynfield_desc = {
+		.name = "test_event_dynfield_flow_id",
+		.size = sizeof(uint32_t),
+		.align = __alignof__(uint32_t),
+	};
+	flow_id_dynfield_offset =
+		rte_mbuf_dynfield_register(&flow_id_dynfield_desc);
+	if (flow_id_dynfield_offset < 0) {
+		evt_err("failed to register mbuf field");
+		return -rte_errno;
+	}
+
 	test_order = rte_zmalloc_socket(test->name, sizeof(struct test_order),
 				RTE_CACHE_LINE_SIZE, opt->socket_id);
 	if (test_order  == NULL) {
app/test-eventdev/test_order_common.h +5 -0
index e0fe9c968a..13bf791564 100644
@@ -13,6 +13,7 @@
 #include <rte_lcore.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 #include "evt_common.h"
 #include "evt_options.h"
@@ -20,6 +21,10 @@
 
 #define BURST_SIZE 16
 
+extern int flow_id_dynfield_offset;
+#define FLOW_ID(mbuf) \
+	(*RTE_MBUF_DYNFIELD(mbuf, flow_id_dynfield_offset, uint32_t *))
+
 struct test_order;
 
 struct worker_data {
app/test-eventdev/test_order_queue.c +2 -2
index 1511c0092d..80c9c24af5 100644
@@ -35,7 +35,7 @@ order_queue_worker(void *arg, const bool flow_id_cap)
 		}
 
 		if (!flow_id_cap)
-			ev.flow_id = ev.mbuf->udata64;
+			ev.flow_id = FLOW_ID(ev.mbuf);
 
 		if (ev.queue_id == 0) { /* from ordered queue */
 			order_queue_process_stage_0(&ev);
@@ -73,7 +73,7 @@ order_queue_worker_burst(void *arg, const bool flow_id_cap)
 		for (i = 0; i < nb_rx; i++) {
 
 			if (!flow_id_cap)
-				ev[i].flow_id = ev[i].mbuf->udata64;
+				ev[i].flow_id = FLOW_ID(ev[i].mbuf);
 
 			if (ev[i].queue_id == 0) { /* from ordered queue */
 				order_queue_process_stage_0(&ev[i]);
Signature · 1 line
2.28.0
#36 lore raw

PATCH 13/15 examples/bbdev: switch to dynamic mbuf field

In reply to Thomas Monjalon

The example used the deprecated mbuf field udata64 as input mbuf pointer. It is moved to a dynamic field in order to allow removal of udata64.

---
 examples/bbdev_app/main.c | 37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)
examples/bbdev_app/main.c +27 -10
index e512c807cd..7a06f9c7d6 100644
@@ -28,6 +28,7 @@
 #include <rte_lcore.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_memory.h>
 #include <rte_mempool.h>
 #include <rte_log.h>
@@ -59,6 +60,10 @@
 	} \
 } while (0)
 
+static int input_dynfield_offset;
+#define INPUT_FIELD(mbuf) \
+	(*RTE_MBUF_DYNFIELD(mbuf, input_dynfield_offset, struct rte_mbuf **))
+
 static const struct rte_eth_conf port_conf = {
 	.rxmode = {
 		.mq_mode = ETH_MQ_RX_NONE,
@@ -294,11 +299,11 @@ pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int nb_to_free)
 }
 
 static inline void
-pktmbuf_userdata_free_bulk(struct rte_mbuf **mbufs, unsigned int nb_to_free)
+pktmbuf_input_free_bulk(struct rte_mbuf **mbufs, unsigned int nb_to_free)
 {
 	unsigned int i;
 	for (i = 0; i < nb_to_free; ++i) {
-		struct rte_mbuf *rx_pkt = mbufs[i]->userdata;
+		struct rte_mbuf *rx_pkt = INPUT_FIELD(mbufs[i]);
 		rte_pktmbuf_free(rx_pkt);
 		rte_pktmbuf_free(mbufs[i]);
 	}
@@ -429,7 +434,7 @@ verify_data(struct rte_mbuf **mbufs, uint16_t num_pkts)
 	uint16_t i;
 	for (i = 0; i < num_pkts; ++i) {
 		struct rte_mbuf *out = mbufs[i];
-		struct rte_mbuf *in = out->userdata;
+		struct rte_mbuf *in = INPUT_FIELD(out);
 
 		if (memcmp(rte_pktmbuf_mtod_offset(in, uint8_t *,
 				sizeof(struct rte_ether_hdr)),
@@ -731,7 +736,7 @@ run_encoding(struct lcore_conf *lcore_conf)
 				rte_pktmbuf_data_len(rx_pkts_burst[i]) -
 				sizeof(struct rte_ether_hdr);
 		/* save input mbuf pointer for later comparison */
-		enc_out_pkts[i]->userdata = rx_pkts_burst[i];
+		INPUT_FIELD(enc_out_pkts[i]) = rx_pkts_burst[i];
 
 		/* copy ethernet header */
 		rte_pktmbuf_reset(enc_out_pkts[i]);
@@ -775,7 +780,7 @@ run_encoding(struct lcore_conf *lcore_conf)
 	nb_enq = rte_bbdev_enqueue_enc_ops(bbdev_id, enc_queue_id,
 			bbdev_ops_burst, nb_rx);
 	if (unlikely(nb_enq < nb_rx)) {
-		pktmbuf_userdata_free_bulk(&enc_out_pkts[nb_enq],
+		pktmbuf_input_free_bulk(&enc_out_pkts[nb_enq],
 				nb_rx - nb_enq);
 		rte_bbdev_enc_op_free_bulk(&bbdev_ops_burst[nb_enq],
 				nb_rx - nb_enq);
@@ -805,7 +810,7 @@ run_encoding(struct lcore_conf *lcore_conf)
 	nb_sent = rte_ring_enqueue_burst(enc_to_dec_ring, (void **)enc_out_pkts,
 			nb_deq, NULL);
 	if (unlikely(nb_sent < nb_deq)) {
-		pktmbuf_userdata_free_bulk(&enc_out_pkts[nb_sent],
+		pktmbuf_input_free_bulk(&enc_out_pkts[nb_sent],
 				nb_deq - nb_sent);
 		lcore_stats->enc_to_dec_lost_packets += nb_deq - nb_sent;
 	}
@@ -842,7 +847,7 @@ run_decoding(struct lcore_conf *lcore_conf)
 
 	if (unlikely(rte_bbdev_dec_op_alloc_bulk(bbdev_op_pool, bbdev_ops_burst,
 			nb_recv) != 0)) {
-		pktmbuf_userdata_free_bulk(recv_pkts_burst, nb_recv);
+		pktmbuf_input_free_bulk(recv_pkts_burst, nb_recv);
 		lcore_stats->rx_lost_packets += nb_recv;
 		return;
 	}
@@ -871,7 +876,7 @@ run_decoding(struct lcore_conf *lcore_conf)
 	nb_enq = rte_bbdev_enqueue_dec_ops(bbdev_id, bbdev_queue_id,
 			bbdev_ops_burst, nb_recv);
 	if (unlikely(nb_enq < nb_recv)) {
-		pktmbuf_userdata_free_bulk(&recv_pkts_burst[nb_enq],
+		pktmbuf_input_free_bulk(&recv_pkts_burst[nb_enq],
 				nb_recv - nb_enq);
 		rte_bbdev_dec_op_free_bulk(&bbdev_ops_burst[nb_enq],
 				nb_recv - nb_enq);
@@ -898,12 +903,12 @@ run_decoding(struct lcore_conf *lcore_conf)
 
 	/* Free the RX mbufs after verification */
 	for (i = 0; i < nb_deq; ++i)
-		rte_pktmbuf_free(recv_pkts_burst[i]->userdata);
+		rte_pktmbuf_free(INPUT_FIELD(recv_pkts_burst[i]));
 
 	/* Transmit the packets */
 	nb_tx = rte_eth_tx_burst(port_id, tx_queue_id, recv_pkts_burst, nb_deq);
 	if (unlikely(nb_tx < nb_deq)) {
-		pktmbuf_userdata_free_bulk(&recv_pkts_burst[nb_tx],
+		pktmbuf_input_free_bulk(&recv_pkts_burst[nb_tx],
 				nb_deq - nb_tx);
 		lcore_stats->tx_lost_packets += nb_deq - nb_tx;
 	}
@@ -1046,6 +1051,12 @@ main(int argc, char **argv)
 	bool stats_thread_started = false;
 	unsigned int main_lcore_id = rte_get_main_lcore();
 
+	static const struct rte_mbuf_dynfield input_dynfield_desc = {
+		.name = "example_bbdev_dynfield_input",
+		.size = sizeof(void *),
+		.align = __alignof__(void *),
+	};
+
 	rte_atomic16_init(&global_exit_flag);
 
 	sigret = signal(SIGTERM, signal_handler);
@@ -1115,6 +1126,12 @@ main(int argc, char **argv)
 	if (bbdev_mbuf_mempool == NULL)
 		rte_exit(EXIT_FAILURE, "Cannot create ethdev mbuf mempool\n");
 
+	/* register mbuf field to store input pointer */
+	input_dynfield_offset =
+		rte_mbuf_dynfield_register(&input_dynfield_desc);
+	if (input_dynfield_offset < 0)
+		rte_exit(EXIT_FAILURE, "Cannot register mbuf field\n");
+
 	/* initialize ports */
 	ret = initialize_ports(&app_params, ethdev_mbuf_mempool);
 
Signature · 1 line
2.28.0
#37 lore raw

PATCH 14/15 examples/rxtx_callbacks: switch to dynamic mbuf field

In reply to Thomas Monjalon

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.

---
 doc/guides/sample_app_ug/rxtx_callbacks.rst |  4 ++--
 examples/rxtx_callbacks/main.c              | 19 +++++++++++++++++--
 2 files changed, 19 insertions(+), 4 deletions(-)
doc/guides/sample_app_ug/rxtx_callbacks.rst +2 -2
index 62d1f39d7e..8c3b49ae62 100644
@@ -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;
examples/rxtx_callbacks/main.c +17 -2
index 6fe39546dd..8f9852bf6f 100644
@@ -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)
Signature · 1 line
2.28.0
#38 lore raw

Re: [dpdk-dev] [PATCH 14/15] examples/rxtx_callbacks: switch to dynamic mbuf field

Quoted 5 lines · Thomas Monjalon

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?

Signature · 1 line
David Marchand
#39 lore raw

Re: [dpdk-dev] [PATCH 14/15] examples/rxtx_callbacks: switch to dynamic mbuf field

26/10/2020 11:43, David Marchand:

Quoted 10 lines · Thomas Monjalon
Quoted 5 lines

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.

#40 lore raw

Re: [dpdk-dev] [PATCH 14/15] examples/rxtx_callbacks: switch to dynamic mbuf field

Quoted 6 lines · On Mon, 26 Oct 2020 15:33:14 +0100 Thomas Monjalon <[email protected]> wrote:

26/10/2020 11:43, David Marchand:

Quoted 5 lines · Thomas Monjalon
Quoted 4 lines

The example used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

Quoted 10 lines
Quoted 5 lines
Quoted 1 line

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?

#41 lore raw

Re: [dpdk-dev] [PATCH 14/15] examples/rxtx_callbacks: switch to dynamic mbuf field

26/10/2020 15:53, Stephen Hemminger:

Quoted 11 lines
Quoted 8 lines · On Mon, 26 Oct 2020 15:33:14 +0100 Thomas Monjalon <[email protected]> wrote:

26/10/2020 11:43, David Marchand:

Quoted 7 lines · Thomas Monjalon
Quoted 5 lines

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.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

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).

#42 lore raw

PATCH 15/15 mbuf: remove userdata field

In reply to Thomas Monjalon

As announced in the deprecation note, the field userdata / udata64 is removed to give more space to the dynamic fields.

---
 doc/guides/rel_notes/deprecation.rst   | 1 -
 doc/guides/rel_notes/release_20_11.rst | 3 +++
 lib/librte_kni/rte_kni_common.h        | 3 +--
 lib/librte_mbuf/rte_mbuf_core.h        | 8 +-------
 4 files changed, 5 insertions(+), 10 deletions(-)
doc/guides/rel_notes/deprecation.rst +0 -1
index 2e082499b8..0f6f1df12a 100644
@@ -87,7 +87,6 @@ Deprecation Notices
   The following static fields will be moved as dynamic:
 
   - ``timestamp``
-  - ``userdata`` / ``udata64``
   - ``seqn``
 
   As a consequence, the layout of the ``struct rte_mbuf`` will be re-arranged,
doc/guides/rel_notes/release_20_11.rst +3 -0
index d8ac359e51..3cec526b6a 100644
@@ -426,6 +426,9 @@ API Changes
   the structures ``rte_mbuf`` and ``rte_mbuf_ext_shared_info``.
   The field ``refcnt`` is remaining from the old unions.
 
+* mbuf: Removed the unioned fields ``userdata`` and ``udata64``
+  from the structure ``rte_mbuf``. It is replaced with dynamic fields.
+
 * pci: Removed the ``rte_kernel_driver`` enum defined in rte_dev.h and
   replaced with a private enum in the PCI subsystem.
 
lib/librte_kni/rte_kni_common.h +1 -2
index 21b477f0aa..0db45e6a24 100644
@@ -86,8 +86,7 @@ struct rte_kni_mbuf {
 	uint16_t data_len;      /**< Amount of data in segment buffer. */
 
 	/* fields on second cache line */
-	char pad3[8] __attribute__((__aligned__(RTE_CACHE_LINE_MIN_SIZE)));
-	void *pool;
+	void *pool __attribute__((__aligned__(RTE_CACHE_LINE_MIN_SIZE)));
 	void *next;             /**< Physical address of next mbuf in kernel. */
 };
 
lib/librte_mbuf/rte_mbuf_core.h +1 -7
index 065d87d28a..a65eaaf692 100644
@@ -599,12 +599,6 @@ struct rte_mbuf {
 	/* second cache line - fields only used in slow path or on TX */
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
 
-	RTE_STD_C11
-	union {
-		void *userdata;   /**< Can be used for external metadata */
-		uint64_t udata64; /**< Allow 8-byte userdata on 32-bit */
-	};
-
 	struct rte_mempool *pool; /**< Pool from which mbuf was allocated. */
 	struct rte_mbuf *next;    /**< Next segment of scattered packet. */
 
@@ -662,7 +656,7 @@ struct rte_mbuf {
 	 */
 	struct rte_mbuf_ext_shared_info *shinfo;
 
-	uint64_t dynfield1[2]; /**< Reserved for dynamic fields. */
+	uint64_t dynfield1[3]; /**< Reserved for dynamic fields. */
 } __rte_cache_aligned;
 
 /**
Signature · 1 line
2.28.0
#43 lore raw

v2 cover remove mbuf userdata

In reply to Thomas Monjalon

The mbuf field userdata (aliased as udata64)
was announced to be removed for two reasons:
- applications, libraries and drivers used the same field for different purposes, with a risk of usage conflict.
- this field always used 8 bytes even if unneeded

Some dynamic fields are created when needed to replace the big static userdata field.
As a consequence, 8 bytes can be re-allocated to dynamic fields.

This mbuf layout change is important to allow adding more features (consuming more dynamic fields) during the next year.

v2 (thanks David & Andrew):
- fix some indentations
- return -rte_errno consistently
- make some type casts more precise
- define dynfield types in macros
- hide field description in rte_security
- do not lookup security dynfield in ipsec-secgw
- do not use the existing timestamp field for other purpose

Thomas Monjalon (15):
examples: enclose DPDK includes with angle brackets
kni: move header file from EAL
mbuf: fix typo in dynamic field convention note
node: switch IPv4 metadata to dynamic mbuf field
security: switch metadata to dynamic mbuf field event/sw: switch test counter to dynamic mbuf field net/ark: ignore user data
net/bnxt: switch CFA code to dynamic mbuf field net/vmxnet3: switch MSS hint to dynamic mbuf field test/distributor: switch sequence to dynamic mbuf field test/graph: switch user data to dynamic mbuf field app/eventdev: switch flow ID to dynamic mbuf field examples/bbdev: switch to dynamic mbuf field examples/rxtx_callbacks: switch to dynamic mbuf field
mbuf: remove userdata field

 app/test-eventdev/test_order_atq.c            |  4 +-
 app/test-eventdev/test_order_common.c         | 16 +++-
 app/test-eventdev/test_order_common.h         |  6 ++
 app/test-eventdev/test_order_queue.c          |  4 +-
 app/test/test_distributor.c                   | 28 +++++-
 app/test/test_graph.c                         | 94 +++++++++++--------
 doc/guides/prog_guide/rte_security.rst        |  9 +-
 doc/guides/rel_notes/deprecation.rst          |  1 -
 doc/guides/rel_notes/release_20_11.rst        |  3 +
 doc/guides/sample_app_ug/rxtx_callbacks.rst   |  4 +-
 drivers/crypto/octeontx2/otx2_cryptodev_sec.c |  5 +-
 drivers/event/sw/sw_evdev_selftest.c          | 23 ++++-
 drivers/net/ark/ark_ddm.h                     |  2 +-
 drivers/net/ark/ark_ethdev_rx.c               |  1 -
 drivers/net/ark/ark_ethdev_tx.c               |  1 -
 drivers/net/ark/ark_udm.h                     |  2 +-
 drivers/net/bnxt/bnxt_ethdev.c                | 19 ++++
 drivers/net/bnxt/bnxt_rxr.c                   |  2 +-
 drivers/net/bnxt/bnxt_rxr.h                   |  5 +
 drivers/net/bnxt/rte_pmd_bnxt.h               |  3 +
 drivers/net/ixgbe/ixgbe_ipsec.c               |  5 +-
 drivers/net/ixgbe/ixgbe_rxtx.c                |  6 +-
 drivers/net/octeontx2/otx2_ethdev.h           |  1 +
 drivers/net/octeontx2/otx2_ethdev_sec.c       |  5 +-
 drivers/net/octeontx2/otx2_ethdev_sec_tx.h    |  2 +-
 drivers/net/octeontx2/otx2_rx.h               |  2 +-
 drivers/net/vmxnet3/vmxnet3_ethdev.c          | 15 +++
 drivers/net/vmxnet3/vmxnet3_ethdev.h          |  6 ++
 drivers/net/vmxnet3/vmxnet3_rxtx.c            |  9 +-
 examples/bbdev_app/main.c                     | 68 +++++++++-----
 examples/bond/main.c                          | 11 +--
 examples/ipsec-secgw/ipsec-secgw.c            |  9 +-
 examples/ipsec-secgw/ipsec_worker.c           | 12 ++-
 examples/rxtx_callbacks/main.c                | 20 +++-
 examples/tep_termination/vxlan_setup.c        |  2 +-
 kernel/linux/kni/meson.build                  |  2 +-
 lib/librte_eal/linux/include/meson.build      |  1 -
 lib/librte_kni/meson.build                    |  2 +-
 .../include => librte_kni}/rte_kni_common.h   |  3 +-
 lib/librte_mbuf/rte_mbuf_core.h               |  8 +-
 lib/librte_mbuf/rte_mbuf_dyn.h                |  2 +-
 lib/librte_node/ip4_lookup.c                  |  7 ++
 lib/librte_node/ip4_rewrite.c                 | 10 ++
 lib/librte_node/node_private.h                | 12 ++-
 lib/librte_security/rte_security.c            | 22 +++++
 lib/librte_security/rte_security.h            | 32 +++++++
 lib/librte_security/rte_security_driver.h     |  3 +
 lib/librte_security/version.map               |  3 +
 48 files changed, 379 insertions(+), 133 deletions(-)
 rename lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h (97%)
Signature · 1 line
2.28.0
#44 lore raw

PATCH v2 1/15 examples: enclose DPDK includes with angle brackets

In examples, DPDK header files are external,
so they must be enclosed with angle brackets, not quotes.

---
 examples/bbdev_app/main.c              | 30 +++++++++++++-------------
 examples/bond/main.c                   | 11 ++++------
 examples/tep_termination/vxlan_setup.c |  2 +-
 3 files changed, 20 insertions(+), 23 deletions(-)
examples/bbdev_app/main.c +15 -15
index 43fe631760..e512c807cd 100644
@@ -18,21 +18,21 @@
 #include <getopt.h>
 #include <signal.h>
 
-#include "rte_atomic.h"
-#include "rte_common.h"
-#include "rte_eal.h"
-#include "rte_cycles.h"
-#include "rte_ether.h"
-#include "rte_ethdev.h"
-#include "rte_ip.h"
-#include "rte_lcore.h"
-#include "rte_malloc.h"
-#include "rte_mbuf.h"
-#include "rte_memory.h"
-#include "rte_mempool.h"
-#include "rte_log.h"
-#include "rte_bbdev.h"
-#include "rte_bbdev_op.h"
+#include <rte_atomic.h>
+#include <rte_common.h>
+#include <rte_eal.h>
+#include <rte_cycles.h>
+#include <rte_ether.h>
+#include <rte_ethdev.h>
+#include <rte_ip.h>
+#include <rte_lcore.h>
+#include <rte_malloc.h>
+#include <rte_mbuf.h>
+#include <rte_memory.h>
+#include <rte_mempool.h>
+#include <rte_log.h>
+#include <rte_bbdev.h>
+#include <rte_bbdev_op.h>
 
 /* LLR values - negative value for '1' bit */
 #define LLR_1_BIT 0x81
examples/bond/main.c +4 -7
index 398553b785..81a6fa976b 100644
@@ -41,6 +41,10 @@
 #include <rte_tcp.h>
 #include <rte_arp.h>
 #include <rte_spinlock.h>
+#include <rte_devargs.h>
+#include <rte_byteorder.h>
+#include <rte_cpuflags.h>
+#include <rte_eth_bond.h>
 
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
@@ -53,13 +57,6 @@
 
 #include "main.h"
 
-#include <rte_devargs.h>
-
-
-#include "rte_byteorder.h"
-#include "rte_cpuflags.h"
-#include "rte_eth_bond.h"
-
 #define RTE_LOGTYPE_DCB RTE_LOGTYPE_USER1
 
 #define NB_MBUF   (1024*8)
examples/tep_termination/vxlan_setup.c +1 -1
index 4b44ccc143..0bcd870b4a 100644
@@ -18,9 +18,9 @@
 #include <rte_ip.h>
 #include <rte_udp.h>
 #include <rte_tcp.h>
+#include <rte_vhost.h>
 
 #include "main.h"
-#include "rte_vhost.h"
 #include "vxlan.h"
 #include "vxlan_setup.h"
 
Signature · 1 line
2.28.0
#45 lore raw

PATCH v2 2/15 kni: move header file from EAL

In reply to Thomas Monjalon

Since the kernel module is not part of EAL anymore, there is no need to have the common KNI header file in EAL. The file rte_kni_common.h is moved to librte_kni.

---
 kernel/linux/kni/meson.build                                  | 2 +-
 lib/librte_eal/linux/include/meson.build                      | 1 -
 lib/librte_kni/meson.build                                    | 2 +-
 lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h | 0
 4 files changed, 2 insertions(+), 3 deletions(-)
 rename lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h (100%)
kernel/linux/kni/meson.build +1 -1
index d696347f22..07e0c9dae7 100644
@@ -18,7 +18,7 @@ custom_target('rte_kni',
 		'src=' + meson.current_source_dir(),
 		'MODULE_CFLAGS=-include ' + meson.source_root() + '/config/rte_config.h' +
 		' -I' + meson.source_root() + '/lib/librte_eal/include' +
-		' -I' + meson.source_root() + '/lib/librte_eal/linux/include' +
+		' -I' + meson.source_root() + '/lib/librte_kni' +
 		' -I' + meson.build_root() +
 		' -I' + meson.current_source_dir(),
 		'modules'],
lib/librte_eal/linux/include/meson.build +0 -1
index 1241894b3c..7d18dd52f1 100644
@@ -4,6 +4,5 @@
 includes += include_directories('.')
 
 headers += files(
-        'rte_kni_common.h',
         'rte_os.h',
 )
lib/librte_kni/meson.build +1 -1
index 963eae6fe0..ad598bb3d0 100644
@@ -6,5 +6,5 @@ if not is_linux or not dpdk_conf.get('RTE_ARCH_64')
 	reason = 'only supported on 64-bit linux'
 endif
 sources = files('rte_kni.c')
-headers = files('rte_kni.h')
+headers = files('rte_kni.h', 'rte_kni_common.h')
 deps += ['ethdev', 'pci']
lib/librte_kni/rte_kni_common.h renamed from lib/librte_eal/linux/include/rte_kni_common.h +0 -0
similarity index 100%
rename from lib/librte_eal/linux/include/rte_kni_common.h
rename to lib/librte_kni/rte_kni_common.h
Signature · 1 line
2.28.0
#46 lore raw

PATCH v2 3/15 mbuf: fix typo in dynamic field convention note

In reply to Thomas Monjalon

Replace "in a in PMD" with "in a PMD".

Fixes 4958ca3a443a ("mbuf: support dynamic fields and flags")
---
 lib/librte_mbuf/rte_mbuf_dyn.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_mbuf/rte_mbuf_dyn.h +1 -1
index 8407230ecf..0ebac88b83 100644
@@ -62,7 +62,7 @@
  * conventions than function names in dpdk:
  * - "rte_mbuf_dynfield_<name>" if defined in mbuf library
  * - "rte_<libname>_dynfield_<name>" if defined in another library
- * - "rte_net_<pmd>_dynfield_<name>" if defined in a in PMD
+ * - "rte_net_<pmd>_dynfield_<name>" if defined in a PMD
  * - any name that does not start with "rte_" in an application
  */
 
Signature · 1 line
2.28.0
#47 lore raw

PATCH v2 4/15 node: switch IPv4 metadata to dynamic mbuf field

In reply to Thomas Monjalon

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 lib/librte_node/ip4_lookup.c   |  7 +++++++
 lib/librte_node/ip4_rewrite.c  | 10 ++++++++++
 lib/librte_node/node_private.h | 12 ++++++++++--
 3 files changed, 27 insertions(+), 2 deletions(-)
lib/librte_node/ip4_lookup.c +7 -0
index 8835aab9dd..c2f6d653f9 100644
@@ -21,6 +21,8 @@
 
 #include "node_private.h"
 
+int node_mbuf_priv1_dynfield_offset;
+
 #define IPV4_L3FWD_LPM_MAX_RULES 1024
 #define IPV4_L3FWD_LPM_NUMBER_TBL8S (1 << 8)
 
@@ -178,6 +180,11 @@ ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node)
 	RTE_SET_USED(node);
 
 	if (!init_once) {
+		node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+				&node_mbuf_priv1_dynfield_desc);
+		if (node_mbuf_priv1_dynfield_offset < 0)
+			return -rte_errno;
+
 		/* Setup LPM tables for all sockets */
 		RTE_LCORE_FOREACH(lcore_id)
 		{
lib/librte_node/ip4_rewrite.c +10 -0
index bb7f671b5c..1c4e51968c 100644
@@ -248,9 +248,19 @@ ip4_rewrite_node_process(struct rte_graph *graph, struct rte_node *node,
 static int
 ip4_rewrite_node_init(const struct rte_graph *graph, struct rte_node *node)
 {
+	static bool init_once;
 
 	RTE_SET_USED(graph);
 	RTE_SET_USED(node);
+
+	if (!init_once) {
+		node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+				&node_mbuf_priv1_dynfield_desc);
+		if (node_mbuf_priv1_dynfield_offset < 0)
+			return -rte_errno;
+		init_once = true;
+	}
+
 	node_dbg("ip4_rewrite", "Initialized ip4_rewrite node initialized");
 
 	return 0;
lib/librte_node/node_private.h +10 -2
index ab7941c12b..359b40faed 100644
@@ -8,6 +8,7 @@
 #include <rte_common.h>
 #include <rte_log.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 extern int rte_node_logtype;
 #define NODE_LOG(level, node_name, ...)                                        \
@@ -21,7 +22,6 @@ extern int rte_node_logtype;
 #define node_dbg(node_name, ...) NODE_LOG(DEBUG, node_name, __VA_ARGS__)
 
 /**
- *
  * Node mbuf private data to store next hop, ttl and checksum.
  */
 struct node_mbuf_priv1 {
@@ -37,6 +37,13 @@ struct node_mbuf_priv1 {
 	};
 };
 
+static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = {
+	.name = "rte_node_dynfield_priv1",
+	.size = sizeof(struct node_mbuf_priv1 *),
+	.align = __alignof__(struct node_mbuf_priv1 *),
+};
+extern int node_mbuf_priv1_dynfield_offset;
+
 /**
  * Node mbuf private area 2.
  */
@@ -60,7 +67,8 @@ struct node_mbuf_priv2 {
 static __rte_always_inline struct node_mbuf_priv1 *
 node_mbuf_priv1(struct rte_mbuf *m)
 {
-	return (struct node_mbuf_priv1 *)&m->udata64;
+	return RTE_MBUF_DYNFIELD(m,
+		node_mbuf_priv1_dynfield_offset, struct node_mbuf_priv1 *);
 }
 
 /**
Signature · 1 line
2.28.0
#48 lore raw

Re: [dpdk-dev] [PATCH v2 04/15] node: switch IPv4 metadata to dynamic mbuf field

Hi Thomas,

Quoted 9 lines · Thomas Monjalon

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 lib/librte_node/ip4_lookup.c   |  7 +++++++
 lib/librte_node/ip4_rewrite.c  | 10 ++++++++++
 lib/librte_node/node_private.h | 12 ++++++++++--
 3 files changed, 27 insertions(+), 2 deletions(-)

<...>

Quoted 19 lines
lib/librte_node/node_private.h +1 -1
@@ -8,6 +8,7 @@
 #include <rte_common.h>
 #include <rte_log.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 extern int rte_node_logtype;
 #define NODE_LOG(level, node_name, ...)                                        \
@@ -21,7 +22,6 @@ extern int rte_node_logtype;
 #define node_dbg(node_name, ...) NODE_LOG(DEBUG, node_name, __VA_ARGS__)
 
 /**
- *
  * Node mbuf private data to store next hop, ttl and checksum.
  */
 struct node_mbuf_priv1 {

lib/librte_node/node_private.h struct node_mbuf_priv1 { · line 46

Quoted 10 lines
lib/librte_node/node_private.h +7 -0
@@ -37,6 +37,13 @@ struct node_mbuf_priv1 {
 	};
 };
 
+static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = {
+	.name = "rte_node_dynfield_priv1",
+	.size = sizeof(struct node_mbuf_priv1 *),
+	.align = __alignof__(struct node_mbuf_priv1 *),
+};
+extern int node_mbuf_priv1_dynfield_offset;
+

It should be "struct node_mbuf_priv1", not "struct node_mbuf_priv1 *"

#49 lore raw

Re: [dpdk-dev] [PATCH v2 04/15] node: switch IPv4 metadata to dynamic mbuf field

27/10/2020 10:32, Olivier Matz:

Quoted 10 lines · Thomas Monjalon

lib/librte_node/node_private.h struct node_mbuf_priv1 { · line 46

Quoted 7 lines
lib/librte_node/node_private.h +7 -0
+static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = {
+	.name = "rte_node_dynfield_priv1",
+	.size = sizeof(struct node_mbuf_priv1 *),
+	.align = __alignof__(struct node_mbuf_priv1 *),
+};
+extern int node_mbuf_priv1_dynfield_offset;
+

It should be "struct node_mbuf_priv1", not "struct node_mbuf_priv1 *"

Yes, will fix in v3.

#50 lore raw

Re: [dpdk-dev] [PATCH v2 04/15] node: switch IPv4 metadata to dynamic mbuf field

In reply to Thomas Monjalon
Quoted 15 lines · Thomas Monjalon

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 lib/librte_node/ip4_lookup.c   |  7 +++++++
 lib/librte_node/ip4_rewrite.c  | 10 ++++++++++
 lib/librte_node/node_private.h | 12 ++++++++++--
 3 files changed, 27 insertions(+), 2 deletions(-)
lib/librte_node/ip4_lookup.c +0 -0
index 8835aab9dd..c2f6d653f9 100644

lib/librte_node/ip4_lookup.c line 25

Quoted 5 lines
lib/librte_node/ip4_lookup.c +2 -0
@@ -21,6 +21,8 @@
 
 #include "node_private.h"
 
+int node_mbuf_priv1_dynfield_offset;
+

This change doesn't work in secondary as it is process local memory.

Quoted 74 lines
lib/librte_node/ip4_lookup.c +5 -0
 #define IPV4_L3FWD_LPM_MAX_RULES 1024
 #define IPV4_L3FWD_LPM_NUMBER_TBL8S (1 << 8)
 
@@ -178,6 +180,11 @@ ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node)
 	RTE_SET_USED(node);
 
 	if (!init_once) {
+		node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+				&node_mbuf_priv1_dynfield_desc);
+		if (node_mbuf_priv1_dynfield_offset < 0)
+			return -rte_errno;
+
 		/* Setup LPM tables for all sockets */
 		RTE_LCORE_FOREACH(lcore_id)
 		{
lib/librte_node/ip4_rewrite.c +10 -0
index bb7f671b5c..1c4e51968c 100644
@@ -248,9 +248,19 @@ ip4_rewrite_node_process(struct rte_graph *graph, struct rte_node *node,
 static int
 ip4_rewrite_node_init(const struct rte_graph *graph, struct rte_node *node)
 {
+	static bool init_once;
 
 	RTE_SET_USED(graph);
 	RTE_SET_USED(node);
+
+	if (!init_once) {
+		node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+				&node_mbuf_priv1_dynfield_desc);
+		if (node_mbuf_priv1_dynfield_offset < 0)
+			return -rte_errno;
+		init_once = true;
+	}
+
 	node_dbg("ip4_rewrite", "Initialized ip4_rewrite node initialized");
 
 	return 0;
lib/librte_node/node_private.h +8 -1
index ab7941c12b..359b40faed 100644
@@ -8,6 +8,7 @@
 #include <rte_common.h>
 #include <rte_log.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 extern int rte_node_logtype;
 #define NODE_LOG(level, node_name, ...)                                        \
@@ -21,7 +22,6 @@ extern int rte_node_logtype;
 #define node_dbg(node_name, ...) NODE_LOG(DEBUG, node_name, __VA_ARGS__)
 
 /**
- *
  * Node mbuf private data to store next hop, ttl and checksum.
  */
 struct node_mbuf_priv1 {
@@ -37,6 +37,13 @@ struct node_mbuf_priv1 {
 	};
 };
 
+static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = {
+	.name = "rte_node_dynfield_priv1",
+	.size = sizeof(struct node_mbuf_priv1 *),
+	.align = __alignof__(struct node_mbuf_priv1 *),
+};
+extern int node_mbuf_priv1_dynfield_offset;
+
 /**
  * Node mbuf private area 2.
  */

lib/librte_node/node_private.h struct node_mbuf_priv2 { · line 71

Quoted 6 lines
lib/librte_node/node_private.h +2 -1
@@ -60,7 +67,8 @@ struct node_mbuf_priv2 {
 static __rte_always_inline struct node_mbuf_priv1 *
 node_mbuf_priv1(struct rte_mbuf *m)
 {
-	return (struct node_mbuf_priv1 *)&m->udata64;
+	return RTE_MBUF_DYNFIELD(m,
+		node_mbuf_priv1_dynfield_offset, struct node_mbuf_priv1 *);

There is a performance regression of ~1.4% in our platform (Octeontx2) because
of this change.

Quoted 6 lines
lib/librte_node/node_private.h +0 -0
 }
 
 /**
Signature · 1 line
2.28.0
#51 lore raw

Re: [dpdk-dev] [PATCH v2 04/15] node: switch IPv4 metadata to dynamic mbuf field

27/10/2020 15:23, Nithin Dabilpuram:

Quoted 12 lines · Thomas Monjalon

lib/librte_node/ip4_lookup.c line 25

Quoted 9 lines

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---

lib/librte_node/ip4_lookup.c +2 -0
+int node_mbuf_priv1_dynfield_offset;
+

This change doesn't work in secondary as it is process local memory.

Yes that's an issue.
Can we copy the value when starting a secondary process?

[...]

Quoted 9 lines

lib/librte_node/ip4_lookup.c

Quoted 6 lines

static __rte_always_inline struct node_mbuf_priv1 * node_mbuf_priv1(struct rte_mbuf *m)
{

lib/librte_node/ip4_lookup.c +2 -1
-	return (struct node_mbuf_priv1 *)&m->udata64;
+	return RTE_MBUF_DYNFIELD(m,
+		node_mbuf_priv1_dynfield_offset, struct node_mbuf_priv1 *);

There is a performance regression of ~1.4% in our platform (Octeontx2) because
of this change.

Yes that's the price to pay for a more extensible DPDK. It is much cheaper than not having room for new features, or having features conflicting on the same mbuf field like here.

#52 lore raw

Re: [dpdk-dev] [PATCH v2 04/15] node: switch IPv4 metadata to dynamic mbuf field

Quoted 14 lines · Thomas Monjalon

27/10/2020 15:23, Nithin Dabilpuram:

Quoted 12 lines · Thomas Monjalon

lib/librte_node/ip4_lookup.c line 25

Quoted 9 lines

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---

lib/librte_node/ip4_lookup.c +2 -0
+int node_mbuf_priv1_dynfield_offset;
+

This change doesn't work in secondary as it is process local memory.

Quoted 2 lines

Yes that's an issue.
Can we copy the value when starting a secondary process?

Currently there is no call back which will be called only in secondary.

Can you move this value to node->ctx 8'th byte offset ? Node context is of size 16 bytes and should be sufficient.
Currently first 8 B of node->ctx is used to store that socket's lpm pointer.

Quoted 17 lines

[...]

Quoted 9 lines

lib/librte_node/ip4_lookup.c

Quoted 6 lines

static __rte_always_inline struct node_mbuf_priv1 * node_mbuf_priv1(struct rte_mbuf *m)
{

lib/librte_node/ip4_lookup.c +2 -1
-	return (struct node_mbuf_priv1 *)&m->udata64;
+	return RTE_MBUF_DYNFIELD(m,
+		node_mbuf_priv1_dynfield_offset, struct node_mbuf_priv1 *);

There is a performance regression of ~1.4% in our platform (Octeontx2) because
of this change.

Yes that's the price to pay for a more extensible DPDK. It is much cheaper than not having room for new features, or having features conflicting on the same mbuf field like here.

#53 lore raw

Re: [dpdk-dev] [PATCH v2 04/15] node: switch IPv4 metadata to dynamic mbuf field

27/10/2020 16:33, Nithin Dabilpuram:

Quoted 15 lines · Thomas Monjalon
Quoted 14 lines

27/10/2020 15:23, Nithin Dabilpuram:

Quoted 12 lines · Thomas Monjalon

lib/librte_node/ip4_lookup.c line 25

Quoted 9 lines

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---

lib/librte_node/ip4_lookup.c +2 -0
+int node_mbuf_priv1_dynfield_offset;
+

This change doesn't work in secondary as it is process local memory.

Quoted 8 lines
Quoted 2 lines

Yes that's an issue.
Can we copy the value when starting a secondary process?

Currently there is no call back which will be called only in secondary.

Can you move this value to node->ctx 8'th byte offset ? Node context is of size 16 bytes and should be sufficient.
Currently first 8 B of node->ctx is used to store that socket's lpm pointer.

Please would you be able to do such patch?

#54 lore raw

Re: [dpdk-dev] [PATCH v2 04/15] node: switch IPv4 metadata to dynamic mbuf field

Quoted 19 lines · Thomas Monjalon

27/10/2020 16:33, Nithin Dabilpuram:

Quoted 18 lines · Thomas Monjalon
Quoted 16 lines

27/10/2020 15:23, Nithin Dabilpuram:

Quoted 12 lines · Thomas Monjalon

lib/librte_node/ip4_lookup.c line 25

Quoted 9 lines

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---

lib/librte_node/ip4_lookup.c +2 -0
+int node_mbuf_priv1_dynfield_offset;
+

This change doesn't work in secondary as it is process local memory.

Yes that's an issue.
Can we copy the value when starting a secondary process?

Quoted 7 lines
Quoted 5 lines

Currently there is no call back which will be called only in secondary.

Can you move this value to node->ctx 8'th byte offset ? Node context is of size 16 bytes and should be sufficient.
Currently first 8 B of node->ctx is used to store that socket's lpm pointer.

Please would you be able to do such patch?

Ack, will send a patch on this thread so that you can include in next version.

Quoted 3 lines
#55 lore raw

Re: [dpdk-dev] [PATCH v2 04/15] node: switch IPv4 metadata to dynamic mbuf field

27/10/2020 17:16, Nithin Dabilpuram:

Quoted 22 lines · Thomas Monjalon
Quoted 21 lines

27/10/2020 16:33, Nithin Dabilpuram:

Quoted 20 lines · Thomas Monjalon
Quoted 14 lines

27/10/2020 15:23, Nithin Dabilpuram:

Quoted 12 lines · Thomas Monjalon

lib/librte_node/ip4_lookup.c line 25

Quoted 9 lines

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---

lib/librte_node/ip4_lookup.c +2 -0
+int node_mbuf_priv1_dynfield_offset;
+

This change doesn't work in secondary as it is process local memory.

Quoted 2 lines

Yes that's an issue.
Can we copy the value when starting a secondary process?

Currently there is no call back which will be called only in secondary.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Can you move this value to node->ctx 8'th byte offset ? Node context is of size 16 bytes and should be sufficient.
Currently first 8 B of node->ctx is used to store that socket's lpm pointer.

Please would you be able to do such patch?

Ack, will send a patch on this thread so that you can include in next version.

Thanks

#56 lore raw

PATCH v4 1/1 node: switch IPv4 metadata to dynamic mbuf field

From: Thomas Monjalon <[email protected]>

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 lib/librte_node/ip4_lookup.c      | 40 ++++++++++++++++++++++++--------
 lib/librte_node/ip4_lookup_neon.h | 20 +++++++---------
 lib/librte_node/ip4_lookup_sse.h  | 36 ++++++++++++++--------------
 lib/librte_node/ip4_rewrite.c     | 49 +++++++++++++++++++++++++++++----------
 lib/librte_node/node_private.h    | 13 ++++++++---
 5 files changed, 103 insertions(+), 55 deletions(-)
lib/librte_node/ip4_lookup.c +30 -10
index 8835aab..d083a72 100644
@@ -29,8 +29,23 @@ struct ip4_lookup_node_main {
 	struct rte_lpm *lpm_tbl[RTE_MAX_NUMA_NODES];
 };
 
+struct ip4_lookup_node_ctx {
+	/* Socket's LPM table */
+	struct rte_lpm *lpm;
+	/* Dynamic offset to mbuf priv1 */
+	int mbuf_priv1_off;
+};
+
+int node_mbuf_priv1_dynfield_offset = -1;
+
 static struct ip4_lookup_node_main ip4_lookup_nm;
 
+#define IP4_LOOKUP_NODE_LPM(ctx) \
+	(((struct ip4_lookup_node_ctx *)ctx)->lpm)
+
+#define IP4_LOOKUP_NODE_PRIV1_OFF(ctx) \
+	(((struct ip4_lookup_node_ctx *)ctx)->mbuf_priv1_off)
+
 #if defined(__ARM_NEON)
 #include "ip4_lookup_neon.h"
 #elif defined(RTE_ARCH_X86)
@@ -41,12 +56,13 @@ static uint16_t
 ip4_lookup_node_process_scalar(struct rte_graph *graph, struct rte_node *node,
 			void **objs, uint16_t nb_objs)
 {
+	struct rte_lpm *lpm = IP4_LOOKUP_NODE_LPM(node->ctx);
+	const int dyn = IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx);
 	struct rte_ipv4_hdr *ipv4_hdr;
 	void **to_next, **from;
 	uint16_t last_spec = 0;
 	struct rte_mbuf *mbuf;
 	rte_edge_t next_index;
-	struct rte_lpm *lpm;
 	uint16_t held = 0;
 	uint32_t drop_nh;
 	int i, rc;
@@ -55,9 +71,6 @@ ip4_lookup_node_process_scalar(struct rte_graph *graph, struct rte_node *node,
 	next_index = RTE_NODE_IP4_LOOKUP_NEXT_REWRITE;
 	/* Drop node */
 	drop_nh = ((uint32_t)RTE_NODE_IP4_LOOKUP_NEXT_PKT_DROP) << 16;
-
-	/* Get socket specific LPM from ctx */
-	lpm = *((struct rte_lpm **)node->ctx);
 	from = objs;
 
 	/* Get stream for the speculated next node */
@@ -72,14 +85,14 @@ ip4_lookup_node_process_scalar(struct rte_graph *graph, struct rte_node *node,
 		ipv4_hdr = rte_pktmbuf_mtod_offset(mbuf, struct rte_ipv4_hdr *,
 				sizeof(struct rte_ether_hdr));
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		rc = rte_lpm_lookup(lpm, rte_be_to_cpu_32(ipv4_hdr->dst_addr),
 				    &next_hop);
 		next_hop = (rc == 0) ? next_hop : drop_nh;
 
-		node_mbuf_priv1(mbuf)->nh = (uint16_t)next_hop;
+		node_mbuf_priv1(mbuf, dyn)->nh = (uint16_t)next_hop;
 		next_hop = next_hop >> 16;
 		next = (uint16_t)next_hop;
 
@@ -169,15 +182,19 @@ setup_lpm(struct ip4_lookup_node_main *nm, int socket)
 static int
 ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node)
 {
-	struct rte_lpm **lpm_p = (struct rte_lpm **)&node->ctx;
 	uint16_t socket, lcore_id;
 	static uint8_t init_once;
 	int rc;
 
 	RTE_SET_USED(graph);
-	RTE_SET_USED(node);
+	RTE_BUILD_BUG_ON(sizeof(struct ip4_lookup_node_ctx) > RTE_NODE_CTX_SZ);
 
 	if (!init_once) {
+		node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+				&node_mbuf_priv1_dynfield_desc);
+		if (node_mbuf_priv1_dynfield_offset < 0)
+			return -rte_errno;
+
 		/* Setup LPM tables for all sockets */
 		RTE_LCORE_FOREACH(lcore_id)
 		{
@@ -192,7 +209,10 @@ ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node)
 		}
 		init_once = 1;
 	}
-	*lpm_p = ip4_lookup_nm.lpm_tbl[graph->socket];
+
+	/* Update socket's LPM and mbuf dyn priv1 offset in node ctx */
+	IP4_LOOKUP_NODE_LPM(node->ctx) = ip4_lookup_nm.lpm_tbl[graph->socket];
+	IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx) = node_mbuf_priv1_dynfield_offset;
 
 #if defined(__ARM_NEON) || defined(RTE_ARCH_X86)
 	if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128)
lib/librte_node/ip4_lookup_neon.h +9 -11
index 0ad2763..d5c8da3 100644
@@ -11,12 +11,13 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 			void **objs, uint16_t nb_objs)
 {
 	struct rte_mbuf *mbuf0, *mbuf1, *mbuf2, *mbuf3, **pkts;
+	struct rte_lpm *lpm = IP4_LOOKUP_NODE_LPM(node->ctx);
+	const int dyn = IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx);
 	struct rte_ipv4_hdr *ipv4_hdr;
 	void **to_next, **from;
 	uint16_t last_spec = 0;
 	rte_edge_t next_index;
 	uint16_t n_left_from;
-	struct rte_lpm *lpm;
 	uint16_t held = 0;
 	uint32_t drop_nh;
 	rte_xmm_t result;
@@ -30,9 +31,6 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 	/* Drop node */
 	drop_nh = ((uint32_t)RTE_NODE_IP4_LOOKUP_NEXT_PKT_DROP) << 16;
 
-	/* Get socket specific LPM from ctx */
-	lpm = *((struct rte_lpm **)node->ctx);
-
 	pkts = (struct rte_mbuf **)objs;
 	from = objs;
 	n_left_from = nb_objs;
@@ -119,10 +117,10 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 		priv23.u16[0] = result.u16[4];
 		priv23.u16[4] = result.u16[6];
 
-		node_mbuf_priv1(mbuf0)->u = priv01.u64[0];
-		node_mbuf_priv1(mbuf1)->u = priv01.u64[1];
-		node_mbuf_priv1(mbuf2)->u = priv23.u64[0];
-		node_mbuf_priv1(mbuf3)->u = priv23.u64[1];
+		node_mbuf_priv1(mbuf0, dyn)->u = priv01.u64[0];
+		node_mbuf_priv1(mbuf1, dyn)->u = priv01.u64[1];
+		node_mbuf_priv1(mbuf2, dyn)->u = priv23.u64[0];
+		node_mbuf_priv1(mbuf3, dyn)->u = priv23.u64[1];
 
 		/* Enqueue four to next node */
 		rte_edge_t fix_spec = ((next_index == result.u16[1]) &&
@@ -197,14 +195,14 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 		ipv4_hdr = rte_pktmbuf_mtod_offset(mbuf0, struct rte_ipv4_hdr *,
 						sizeof(struct rte_ether_hdr));
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf0)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf0)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf0, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf0, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		rc = rte_lpm_lookup(lpm, rte_be_to_cpu_32(ipv4_hdr->dst_addr),
 				    &next_hop);
 		next_hop = (rc == 0) ? next_hop : drop_nh;
 
-		node_mbuf_priv1(mbuf0)->nh = (uint16_t)next_hop;
+		node_mbuf_priv1(mbuf0, dyn)->nh = (uint16_t)next_hop;
 		next_hop = next_hop >> 16;
 		next0 = (uint16_t)next_hop;
 
lib/librte_node/ip4_lookup_sse.h +17 -19
index 264c986..74dbf97 100644
@@ -11,13 +11,14 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 			void **objs, uint16_t nb_objs)
 {
 	struct rte_mbuf *mbuf0, *mbuf1, *mbuf2, *mbuf3, **pkts;
+	struct rte_lpm *lpm = IP4_LOOKUP_NODE_LPM(node->ctx);
+	const int dyn = IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx);
 	rte_edge_t next0, next1, next2, next3, next_index;
 	struct rte_ipv4_hdr *ipv4_hdr;
 	uint32_t ip0, ip1, ip2, ip3;
 	void **to_next, **from;
 	uint16_t last_spec = 0;
 	uint16_t n_left_from;
-	struct rte_lpm *lpm;
 	uint16_t held = 0;
 	uint32_t drop_nh;
 	rte_xmm_t dst;
@@ -29,9 +30,6 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 	/* Drop node */
 	drop_nh = ((uint32_t)RTE_NODE_IP4_LOOKUP_NEXT_PKT_DROP) << 16;
 
-	/* Get socket specific LPM from ctx */
-	lpm = *((struct rte_lpm **)node->ctx);
-
 	pkts = (struct rte_mbuf **)objs;
 	from = objs;
 	n_left_from = nb_objs;
@@ -78,24 +76,24 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 						sizeof(struct rte_ether_hdr));
 		ip0 = ipv4_hdr->dst_addr;
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf0)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf0)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf0, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf0, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		/* Extract DIP of mbuf1 */
 		ipv4_hdr = rte_pktmbuf_mtod_offset(mbuf1, struct rte_ipv4_hdr *,
 						sizeof(struct rte_ether_hdr));
 		ip1 = ipv4_hdr->dst_addr;
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf1)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf1)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf1, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf1, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		/* Extract DIP of mbuf2 */
 		ipv4_hdr = rte_pktmbuf_mtod_offset(mbuf2, struct rte_ipv4_hdr *,
 						sizeof(struct rte_ether_hdr));
 		ip2 = ipv4_hdr->dst_addr;
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf2)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf2)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf2, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf2, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		/* Extract DIP of mbuf3 */
 		ipv4_hdr = rte_pktmbuf_mtod_offset(mbuf3, struct rte_ipv4_hdr *,
@@ -111,23 +109,23 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 		dip = _mm_shuffle_epi8(dip, bswap_mask);
 
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf3)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf3)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf3, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf3, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		/* Perform LPM lookup to get NH and next node */
 		rte_lpm_lookupx4(lpm, dip, dst.u32, drop_nh);
 
 		/* Extract next node id and NH */
-		node_mbuf_priv1(mbuf0)->nh = dst.u32[0] & 0xFFFF;
+		node_mbuf_priv1(mbuf0, dyn)->nh = dst.u32[0] & 0xFFFF;
 		next0 = (dst.u32[0] >> 16);
 
-		node_mbuf_priv1(mbuf1)->nh = dst.u32[1] & 0xFFFF;
+		node_mbuf_priv1(mbuf1, dyn)->nh = dst.u32[1] & 0xFFFF;
 		next1 = (dst.u32[1] >> 16);
 
-		node_mbuf_priv1(mbuf2)->nh = dst.u32[2] & 0xFFFF;
+		node_mbuf_priv1(mbuf2, dyn)->nh = dst.u32[2] & 0xFFFF;
 		next2 = (dst.u32[2] >> 16);
 
-		node_mbuf_priv1(mbuf3)->nh = dst.u32[3] & 0xFFFF;
+		node_mbuf_priv1(mbuf3, dyn)->nh = dst.u32[3] & 0xFFFF;
 		next3 = (dst.u32[3] >> 16);
 
 		/* Enqueue four to next node */
@@ -202,14 +200,14 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 		ipv4_hdr = rte_pktmbuf_mtod_offset(mbuf0, struct rte_ipv4_hdr *,
 						sizeof(struct rte_ether_hdr));
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf0)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf0)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf0, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf0, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		rc = rte_lpm_lookup(lpm, rte_be_to_cpu_32(ipv4_hdr->dst_addr),
 				    &next_hop);
 		next_hop = (rc == 0) ? next_hop : drop_nh;
 
-		node_mbuf_priv1(mbuf0)->nh = next_hop & 0xFFFF;
+		node_mbuf_priv1(mbuf0, dyn)->nh = next_hop & 0xFFFF;
 		next0 = (next_hop >> 16);
 
 		if (unlikely(next_index ^ next0)) {
lib/librte_node/ip4_rewrite.c +37 -12

101 lines not on this page · raw message

lib/librte_node/node_private.h +10 -3
index ab7941c..8c73d5d 100644
@@ -8,6 +8,7 @@
 #include <rte_common.h>
 #include <rte_log.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 extern int rte_node_logtype;
 #define NODE_LOG(level, node_name, ...)                                        \
@@ -21,7 +22,6 @@ extern int rte_node_logtype;
 #define node_dbg(node_name, ...) NODE_LOG(DEBUG, node_name, __VA_ARGS__)
 
 /**
- *
  * Node mbuf private data to store next hop, ttl and checksum.
  */
 struct node_mbuf_priv1 {
@@ -37,6 +37,13 @@ struct node_mbuf_priv1 {
 	};
 };
 
+static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = {
+	.name = "rte_node_dynfield_priv1",
+	.size = sizeof(struct node_mbuf_priv1),
+	.align = __alignof__(struct node_mbuf_priv1),
+};
+extern int node_mbuf_priv1_dynfield_offset;
+
 /**
  * Node mbuf private area 2.
  */
@@ -58,9 +65,9 @@ struct node_mbuf_priv2 {
  *   Pointer to the mbuf_priv1.
  */
 static __rte_always_inline struct node_mbuf_priv1 *
-node_mbuf_priv1(struct rte_mbuf *m)
+node_mbuf_priv1(struct rte_mbuf *m, const int offset)
 {
-	return (struct node_mbuf_priv1 *)&m->udata64;
+	return RTE_MBUF_DYNFIELD(m, offset, struct node_mbuf_priv1 *);
 }
 
 /**
Signature · 1 line
2.8.4
#57 lore raw

Re: [dpdk-dev] [PATCH v4] node: switch IPv4 metadata to dynamic mbuf field

28/10/2020 10:30, Nithin Dabilpuram:

Quoted 7 lines

From: Thomas Monjalon <[email protected]>

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

[...]

lib/librte_node/ip4_lookup.c ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node) · line 215

Quoted 1 line
lib/librte_node/ip4_lookup.c +1 -0
+	IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx) = node_mbuf_priv1_dynfield_offset;

That's interesting.
You copy the offset in the node context for better performance. How much is it better than with global offset variable? How much it decreases compared to a static mbuf field?

#58 lore raw

Re: [dpdk-dev] [PATCH v4] node: switch IPv4 metadata to dynamic mbuf field

Quoted 20 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Thomas Monjalon
Sent: Wednesday, October 28, 2020 10:09 AM
To: Nithin Dabilpuram <[email protected]>
Cc: Pavan Nikhilesh <[email protected]>; Jerin Jacob <[email protected]>; Ruifeng Wang <[email protected]>; Richardson, Bruce <[email protected]>; Ananyev, Konstantin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v4] node: switch IPv4 metadata to dynamic mbuf field

28/10/2020 10:30, Nithin Dabilpuram:

Quoted 7 lines

From: Thomas Monjalon <[email protected]>

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

Quoted 8 lines

[...]

Review

Quoted 1 line
(quoted diff) +1 -0
+	IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx) =

node_mbuf_priv1_dynfield_offset;

That's interesting.
You copy the offset in the node context for better performance. How much is it better than with global offset variable? How much it decreases compared to a static mbuf field?

Also interested in this topic, I'll offer the logical/theory point of view;

With a static field, the offset into the mbuf can be encoded in the instruction stream, meaning there are no d-cache loads to identify particular dynamic field.

With a static/global variable, the cache line where the value resides is presumably not hot in cache per burst (assuming an application that does significant work, so not in cache since last burst). Hence overhead estimate could be 1x cache line load per burst.

With the data copied into the node, the offset is presumably on a hot cache line as the node is using other data-members of its context. As a result, perhaps a cold static cache line load is converted to a hot node-context line re-use.

Real world overhead likely depends on A) does the application cache-trash enough to make the static/global line fall out of cache - causing perf degradation due to reload, and B) does the node->ctx still fit in the same number of lines as before if the value is copied there.

#59 lore raw

Re: [dpdk-dev] [PATCH v4] node: switch IPv4 metadata to dynamic mbuf field

Quoted 38 lines · Harry
Quoted 20 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Thomas Monjalon
Sent: Wednesday, October 28, 2020 10:09 AM
To: Nithin Dabilpuram <[email protected]>
Cc: Pavan Nikhilesh <[email protected]>; Jerin Jacob <[email protected]>; Ruifeng Wang <[email protected]>; Richardson, Bruce <[email protected]>; Ananyev, Konstantin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v4] node: switch IPv4 metadata to dynamic mbuf field

28/10/2020 10:30, Nithin Dabilpuram:

Quoted 7 lines

From: Thomas Monjalon <[email protected]>

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

Quoted 8 lines

[...]

Review

Quoted 1 line
(quoted diff) +1 -0
+	IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx) =

node_mbuf_priv1_dynfield_offset;

That's interesting.
You copy the offset in the node context for better performance. How much is it better than with global offset variable? How much it decreases compared to a static mbuf field?

Also interested in this topic, I'll offer the logical/theory point of view;

With a static field, the offset into the mbuf can be encoded in the instruction stream, meaning there are no d-cache loads to identify particular dynamic field.

With a static/global variable, the cache line where the value resides is presumably not hot in cache per burst (assuming an application that does significant work, so not in cache since last burst). Hence overhead estimate could be 1x cache line load per burst.

Quoted 7 lines

With the data copied into the node, the offset is presumably on a hot cache line as the node is using other data-members of its context. As a result, perhaps a cold static cache line load is converted to a hot node-context line re-use.

Real world overhead likely depends on A) does the application cache-trash enough to make the static/global line fall out of cache - causing perf degradation due to reload, and B) does the node->ctx still fit in the same number of lines as before if the value is copied there.

Agreed, node->ctx is already referred to get other data (lpm pointer). So referening another 4 bytes might even convert that to load pair which is at no extra cost.

Number's wise,
it decreases by ~1.4 % from static mbuf field to global offset variable and it decreases by ~1% from static mbuf field to node context field cached per process call

#60 lore raw

Re: [dpdk-dev] [PATCH v4] node: switch IPv4 metadata to dynamic mbuf field

28/10/2020 11:42, Nithin Dabilpuram:

Quoted 36 lines · Harry
Quoted 27 lines

From: Thomas Monjalon

Quoted 8 lines

28/10/2020 10:30, Nithin Dabilpuram:

Quoted 7 lines

From: Thomas Monjalon <[email protected]>

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

Quoted 8 lines

[...]

Review

Quoted 1 line
(quoted diff) +1 -0
+	IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx) =

node_mbuf_priv1_dynfield_offset;

That's interesting.
You copy the offset in the node context for better performance. How much is it better than with global offset variable? How much it decreases compared to a static mbuf field?

Also interested in this topic, I'll offer the logical/theory point of view;

With a static field, the offset into the mbuf can be encoded in the instruction stream, meaning there are no d-cache loads to identify particular dynamic field.

With a static/global variable, the cache line where the value resides is presumably not hot in cache per burst (assuming an application that does significant work, so not in cache since last burst). Hence overhead estimate could be 1x cache line load per burst.

Quoted 7 lines

With the data copied into the node, the offset is presumably on a hot cache line as the node is using other data-members of its context. As a result, perhaps a cold static cache line load is converted to a hot node-context line re-use.

Real world overhead likely depends on A) does the application cache-trash enough to make the static/global line fall out of cache - causing perf degradation due to reload, and B) does the node->ctx still fit in the same number of lines as before if the value is copied there.

Quoted 8 lines

Agreed, node->ctx is already referred to get other data (lpm pointer). So referening another 4 bytes might even convert that to load pair which is at no extra cost.

Number's wise,
it decreases by ~1.4 % from static mbuf field to global offset variable and it decreases by ~1% from static mbuf field to node context field cached per process call

OK thanks for providing these numbers.

#61 lore raw

Re: [dpdk-dev] [PATCH v4] node: switch IPv4 metadata to dynamic mbuf field

In reply to Van Haaren, Harry

28/10/2020 11:24, Van Haaren, Harry:

Quoted 8 lines

From: Thomas Monjalon

Quoted 6 lines

lib/librte_node/ip4_lookup.c ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node) · line 215

Quoted 1 line
lib/librte_node/ip4_lookup.c +1 -0
+	IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx) = node_mbuf_priv1_dynfield_offset;

That's interesting.
You copy the offset in the node context for better performance. How much is it better than with global offset variable? How much it decreases compared to a static mbuf field?

Quoted 8 lines

Also interested in this topic, I'll offer the logical/theory point of view;

With a static field, the offset into the mbuf can be encoded in the instruction stream, meaning there are no d-cache loads to identify particular dynamic field.

With a static/global variable, the cache line where the value resides is presumably not hot in cache per burst (assuming an application that does significant work, so not in cache since last burst). Hence overhead estimate could be 1x cache line load per burst.

Would it help to group all dynfields and dynflags offsets in the same cache line?

#62 lore raw

Re: [dpdk-dev] [PATCH v4] node: switch IPv4 metadata to dynamic mbuf field

Quoted 28 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Wednesday, October 28, 2020 6:08 PM
To: Nithin Dabilpuram <[email protected]>; Van Haaren, Harry <[email protected]>
Cc: [email protected]; Pavan Nikhilesh <[email protected]>; Jerin Jacob <[email protected]>; Ruifeng Wang <[email protected]>; Richardson, Bruce <[email protected]>; Ananyev, Konstantin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v4] node: switch IPv4 metadata to dynamic mbuf field

28/10/2020 11:24, Van Haaren, Harry:

Quoted 2 lines

From: Thomas Monjalon

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+	IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx) =

node_mbuf_priv1_dynfield_offset;

Quoted 11 lines
Quoted 5 lines

That's interesting.
You copy the offset in the node context for better performance. How much is it better than with global offset variable? How much it decreases compared to a static mbuf field?

Also interested in this topic, I'll offer the logical/theory point of view;

With a static field, the offset into the mbuf can be encoded in the instruction stream, meaning there are no d-cache loads to identify particular dynamic field.

Quoted 8 lines
Quoted 2 lines

With a static/global variable, the cache line where the value resides is presumably not hot in cache per burst (assuming an application that does significant work, so

not

Quoted 1 line

in cache since last burst). Hence overhead estimate could be 1x cache line load per

burst.

Would it help to group all dynfields and dynflags offsets in the same cache line?

It could - but if/how-much it would benefit depends on the workload I think.

Using each cache line fully is always good, so if grouping the offsets together is reasonable to do, it seems a good idea.

My assumptions is that registration of dynamic fields/flags is expected at init time, and that the values remain constant at runtime. That would make this a cache-line in "shared" state in each core that uses the dynfields of mbuf.

Overall, it is unlikely to have much impact on a real-world application.. but DPDK puts performance first! And packing a single cache-line full of hot data is best practice :)

#63 lore raw

Re: [dpdk-dev] [PATCH v4] node: switch IPv4 metadata to dynamic mbuf field

In reply to Thomas Monjalon
Quoted 8 lines · Thomas Monjalon

28/10/2020 10:30, Nithin Dabilpuram:

Quoted 7 lines

From: Thomas Monjalon <[email protected]>

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

Quoted 7 lines

[...]

lib/librte_node/ip4_lookup.c ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node) · line 215

Quoted 1 line
lib/librte_node/ip4_lookup.c +1 -0
+	IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx) = node_mbuf_priv1_dynfield_offset;

That's interesting.
You copy the offset in the node context for better performance. How much is it better than with global offset variable? How much it decreases compared to a static mbuf field?

Moving it to node context was not for performance but for functionality as for graph's created in primary can be looked up in secondary and graph walk can be called on them. So having the dyn offset in global variable doesn't reflect in secondary.

This is partially better than referring global offset variable directly in node_mbuf_priv1() as it is caching the dyn offset locally and passing it to node_mbuf_priv1() instead of loading from global variable for every mbuf.

As mentioned earlier, this is done only because currently there is no mechanism to have a callback triggered in secondary alone where we can update the global variable.

Quoted 4 lines
#64 lore raw

PATCH v2 5/15 security: switch metadata to dynamic mbuf field

In reply to Thomas Monjalon

The device-specific metadata was stored in the deprecated field udata64. It is moved to a dynamic mbuf field in order to allow removal of udata64.

---
 doc/guides/prog_guide/rte_security.rst        |  9 +++---
 drivers/crypto/octeontx2/otx2_cryptodev_sec.c |  5 ++-
 drivers/net/ixgbe/ixgbe_ipsec.c               |  5 ++-
 drivers/net/ixgbe/ixgbe_rxtx.c                |  6 ++--
 drivers/net/octeontx2/otx2_ethdev.h           |  1 +
 drivers/net/octeontx2/otx2_ethdev_sec.c       |  5 ++-
 drivers/net/octeontx2/otx2_ethdev_sec_tx.h    |  2 +-
 drivers/net/octeontx2/otx2_rx.h               |  2 +-
 examples/ipsec-secgw/ipsec-secgw.c            |  9 +++---
 examples/ipsec-secgw/ipsec_worker.c           | 12 ++++---
 lib/librte_security/rte_security.c            | 22 +++++++++++++
 lib/librte_security/rte_security.h            | 32 +++++++++++++++++++
 lib/librte_security/rte_security_driver.h     |  3 ++
 lib/librte_security/version.map               |  3 ++
 14 files changed, 96 insertions(+), 20 deletions(-)
doc/guides/prog_guide/rte_security.rst +5 -4
index c64aef3de9..f72bc8a78f 100644
@@ -125,8 +125,9 @@ ESP/AH headers will be removed from the packet and the received packet
 will contains the decrypted packet only. The driver Rx path checks the
 descriptors and based on the crypto status sets additional flags in
 ``rte_mbuf.ol_flags`` field. The driver would also set device-specific
-metadata in ``rte_mbuf.udata64`` field. This will allow the application
-to identify the security processing done on the packet.
+metadata in ``RTE_SECURITY_DYNFIELD_NAME`` field.
+This will allow the application to identify the security processing
+done on the packet.
 
 .. note::
 
@@ -568,8 +569,8 @@ security session which processed the packet.
 
 .. note::
 
-    In case of inline processed packets, ``rte_mbuf.udata64`` field would be
-    used by the driver to relay information on the security processing
+    In case of inline processed packets, ``RTE_SECURITY_DYNFIELD_NAME`` field
+    would be used by the driver to relay information on the security processing
     associated with the packet. In ingress, the driver would set this in Rx
     path while in egress, ``rte_security_set_pkt_metadata()`` would perform a
     similar operation. The application is expected not to modify the field
drivers/crypto/octeontx2/otx2_cryptodev_sec.c +4 -1
index b80ec7bff2..2e5e73143b 100644
@@ -455,6 +455,9 @@ otx2_crypto_sec_session_create(void *device,
 	if (conf->action_type != RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL)
 		return -ENOTSUP;
 
+	if (rte_security_dynfield_register() < 0)
+		return -rte_errno;
+
 	if (rte_mempool_get(mempool, (void **)&priv)) {
 		otx2_err("Could not allocate security session private data");
 		return -ENOMEM;
@@ -514,7 +517,7 @@ otx2_crypto_sec_set_pkt_mdata(void *device __rte_unused,
 			      struct rte_mbuf *m, void *params __rte_unused)
 {
 	/* Set security session as the pkt metadata */
-	m->udata64 = (uint64_t)session;
+	*rte_security_dynfield(m) = (RTE_SECURITY_DYNFIELD_TYPE)session;
 
 	return 0;
 }
drivers/net/ixgbe/ixgbe_ipsec.c +4 -1
index 48f5082d49..62f2a5f764 100644
@@ -484,7 +484,8 @@ ixgbe_crypto_update_mb(void *device __rte_unused,
 			get_sec_session_private_data(session);
 	if (ic_session->op == IXGBE_OP_AUTHENTICATED_ENCRYPTION) {
 		union ixgbe_crypto_tx_desc_md *mdata =
-			(union ixgbe_crypto_tx_desc_md *)&m->udata64;
+			(union ixgbe_crypto_tx_desc_md *)
+				rte_security_dynfield(m);
 		mdata->enc = 1;
 		mdata->sa_idx = ic_session->sa_index;
 		mdata->pad_len = ixgbe_crypto_compute_pad_len(m);
@@ -751,5 +752,7 @@ ixgbe_ipsec_ctx_create(struct rte_eth_dev *dev)
 			return -ENOMEM;
 		}
 	}
+	if (rte_security_dynfield_register() < 0)
+		return -rte_errno;
 	return 0;
 }
drivers/net/ixgbe/ixgbe_rxtx.c +4 -2
index 5f19972031..6cfbb582e2 100644
@@ -34,6 +34,7 @@
 #include <rte_mbuf.h>
 #include <rte_ether.h>
 #include <rte_ethdev_driver.h>
+#include <rte_security_driver.h>
 #include <rte_prefetch.h>
 #include <rte_udp.h>
 #include <rte_tcp.h>
@@ -694,7 +695,7 @@ ixgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 			if (use_ipsec) {
 				union ixgbe_crypto_tx_desc_md *ipsec_mdata =
 					(union ixgbe_crypto_tx_desc_md *)
-							&tx_pkt->udata64;
+						rte_security_dynfield(tx_pkt);
 				tx_offload.sa_idx = ipsec_mdata->sa_idx;
 				tx_offload.sec_pad_len = ipsec_mdata->pad_len;
 			}
@@ -859,7 +860,8 @@ ixgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 				}
 
 				ixgbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req,
-					tx_offload, &tx_pkt->udata64);
+					tx_offload,
+					rte_security_dynfield(tx_pkt));
 
 				txe->last_id = tx_last;
 				tx_id = txe->next_id;
drivers/net/octeontx2/otx2_ethdev.h +1 -0
index b20f399a15..3b9871f4dc 100644
@@ -13,6 +13,7 @@
 #include <rte_kvargs.h>
 #include <rte_mbuf.h>
 #include <rte_mempool.h>
+#include <rte_security_driver.h>
 #include <rte_string_fns.h>
 #include <rte_time.h>
 
drivers/net/octeontx2/otx2_ethdev_sec.c +4 -1
index 4e0dd4e49e..78c5bbeb99 100644
@@ -684,7 +684,7 @@ otx2_eth_sec_set_pkt_mdata(void *device __rte_unused,
 			    struct rte_mbuf *m, void *params __rte_unused)
 {
 	/* Set security session as the pkt metadata */
-	m->udata64 = (uint64_t)session;
+	*rte_security_dynfield(m) = (RTE_SECURITY_DYNFIELD_TYPE)session;
 
 	return 0;
 }
@@ -831,6 +831,9 @@ otx2_eth_sec_init(struct rte_eth_dev *eth_dev)
 	    !(dev->rx_offloads & DEV_RX_OFFLOAD_SECURITY))
 		return 0;
 
+	if (rte_security_dynfield_register() < 0)
+		return -rte_errno;
+
 	nb_sa = dev->ipsec_in_max_spi;
 	mz_sz = nb_sa * sa_width;
 	in_sa_mz_name_get(name, RTE_MEMZONE_NAMESIZE, port);
drivers/net/octeontx2/otx2_ethdev_sec_tx.h +1 -1
index 5bf8c19995..284bcd5367 100644
@@ -55,7 +55,7 @@ otx2_sec_event_tx(struct otx2_ssogws *ws, struct rte_event *ev,
 		struct nix_iova_s nix_iova;
 	} *sd;
 
-	priv = get_sec_session_private_data((void *)(m->udata64));
+	priv = get_sec_session_private_data((void *)(*rte_security_dynfield(m)));
 	sess = &priv->ipsec.ip;
 	sa = &sess->out_sa;
 
drivers/net/octeontx2/otx2_rx.h +1 -1
index f29a0542f9..61a5c436dd 100644
@@ -241,7 +241,7 @@ nix_rx_sec_mbuf_update(const struct nix_cqe_hdr_s *cq, struct rte_mbuf *m,
 	spi = cq->tag & 0xFFFFF;
 
 	sa = nix_rx_sec_sa_get(lookup_mem, spi, m->port);
-	m->udata64 = (uint64_t)sa->userdata;
+	*rte_security_dynfield(m) = sa->udata64;
 
 	data = rte_pktmbuf_mtod(m, char *);
 
examples/ipsec-secgw/ipsec-secgw.c +4 -5
index 2219148285..bbe7ce48d9 100644
@@ -426,7 +426,8 @@ prepare_one_packet(struct rte_mbuf *pkt, struct ipsec_traffic *t)
 	 * with the security session.
 	 */
 
-	if (pkt->ol_flags & PKT_RX_SEC_OFFLOAD) {
+	if (pkt->ol_flags & PKT_RX_SEC_OFFLOAD &&
+			rte_security_dynfield_is_registered()) {
 		struct ipsec_sa *sa;
 		struct ipsec_mbuf_metadata *priv;
 		struct rte_security_ctx *ctx = (struct rte_security_ctx *)
@@ -436,10 +437,8 @@ prepare_one_packet(struct rte_mbuf *pkt, struct ipsec_traffic *t)
 		/* Retrieve the userdata registered. Here, the userdata
 		 * registered is the SA pointer.
 		 */
-
-		sa = (struct ipsec_sa *)
-				rte_security_get_userdata(ctx, pkt->udata64);
-
+		sa = (struct ipsec_sa *)rte_security_get_userdata(ctx,
+				*rte_security_dynfield(pkt));
 		if (sa == NULL) {
 			/* userdata could not be retrieved */
 			return;
examples/ipsec-secgw/ipsec_worker.c +8 -4
index b6c851f257..647e22df59 100644
@@ -208,7 +208,7 @@ process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt,
 					"Inbound security offload failed\n");
 				goto drop_pkt_and_exit;
 			}
-			sa = pkt->userdata;
+			sa = *(struct ipsec_sa **)rte_security_dynfield(pkt);
 		}
 
 		/* Check if we have a match */
@@ -226,7 +226,7 @@ process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt,
 					"Inbound security offload failed\n");
 				goto drop_pkt_and_exit;
 			}
-			sa = pkt->userdata;
+			sa = *(struct ipsec_sa **)rte_security_dynfield(pkt);
 		}
 
 		/* Check if we have a match */
@@ -357,7 +357,8 @@ process_ipsec_ev_outbound(struct ipsec_ctx *ctx, struct route_table *rt,
 	}
 
 	if (sess->security.ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
-		pkt->userdata = sess->security.ses;
+		*(struct rte_security_session **)rte_security_dynfield(pkt) =
+				sess->security.ses;
 
 	/* Mark the packet for Tx security offload */
 	pkt->ol_flags |= PKT_TX_SEC_OFFLOAD;
@@ -465,7 +466,10 @@ ipsec_wrkr_non_burst_int_port_drv_mode(struct eh_event_link_info *links,
 			}
 
 			/* Save security session */
-			pkt->userdata = sess_tbl[port_id];
+			if (rte_security_dynfield_is_registered())
+				*(struct rte_security_session **)
+					rte_security_dynfield(pkt) =
+						sess_tbl[port_id];
 
 			/* Mark the packet for Tx security offload */
 			pkt->ol_flags |= PKT_TX_SEC_OFFLOAD;
lib/librte_security/rte_security.c +22 -0
index ee4666026a..4fb0b797e9 100644
@@ -23,6 +23,28 @@
 	RTE_PTR_OR_ERR_RET(p1->p2->p3, last_retval);			\
 } while (0)
 
+#define RTE_SECURITY_DYNFIELD_NAME "rte_security_dynfield_metadata"
+int rte_security_dynfield_offset = -1;
+
+int
+rte_security_dynfield_register(void)
+{
+	static const struct rte_mbuf_dynfield dynfield_desc = {
+		.name = RTE_SECURITY_DYNFIELD_NAME,
+		.size = sizeof(RTE_SECURITY_DYNFIELD_TYPE),
+		.align = __alignof__(RTE_SECURITY_DYNFIELD_TYPE),
+	};
+	rte_security_dynfield_offset =
+		rte_mbuf_dynfield_register(&dynfield_desc);
+	return rte_security_dynfield_offset;
+}
+
+bool
+rte_security_dynfield_is_registered(void)
+{
+	return rte_security_dynfield_offset >= 0;
+}
+
 struct rte_security_session *
 rte_security_session_create(struct rte_security_ctx *instance,
 			    struct rte_security_session_conf *conf,
lib/librte_security/rte_security.h +32 -0
index 271531af12..7fbdee99cc 100644
@@ -27,6 +27,7 @@ extern "C" {
 #include <rte_common.h>
 #include <rte_crypto.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_memory.h>
 #include <rte_mempool.h>
 
@@ -451,6 +452,37 @@ int
 rte_security_session_destroy(struct rte_security_ctx *instance,
 			     struct rte_security_session *sess);
 
+/** Device-specific metadata field type */
+#define RTE_SECURITY_DYNFIELD_TYPE uint64_t
+/** Dynamic mbuf field for device-specific metadata */
+extern int rte_security_dynfield_offset;
+
+/**
+ * Get pointer to mbuf field for device-specific metadata.
+ *
+ * For performance reason, no check is done,
+ * the dynamic field may not be registered.
+ * @see rte_security_dynfield_is_registered
+ *
+ * @param	mbuf	packet to access
+ * @return pointer to mbuf field
+ */
+static inline RTE_SECURITY_DYNFIELD_TYPE *
+rte_security_dynfield(struct rte_mbuf *mbuf)
+{
+	return RTE_MBUF_DYNFIELD(mbuf,
+		rte_security_dynfield_offset,
+		RTE_SECURITY_DYNFIELD_TYPE *);
+}
+
+/**
+ * Check whether the dynamic field is registered.
+ *
+ * @return true if rte_security_dynfield_register() has been called.
+ */
+__rte_experimental
+bool rte_security_dynfield_is_registered(void);
+
 /**
  *  Updates the buffer with device-specific defined metadata
  *
lib/librte_security/rte_security_driver.h +3 -0
index 1b561f8528..c5abb07990 100644
@@ -89,6 +89,9 @@ typedef int (*security_session_stats_get_t)(void *device,
 		struct rte_security_session *sess,
 		struct rte_security_stats *stats);
 
+__rte_experimental
+int rte_security_dynfield_register(void);
+
 /**
  * Update the mbuf with provided metadata.
  *
lib/librte_security/version.map +3 -0
index d84eec0a88..f2fbec28e6 100644
@@ -15,6 +15,9 @@ DPDK_21 {
 EXPERIMENTAL {
 	global:
 
+	rte_security_dynfield_is_registered;
+	rte_security_dynfield_offset;
+	rte_security_dynfield_register;
 	rte_security_get_userdata;
 	rte_security_session_stats_get;
 	rte_security_session_update;
Signature · 1 line
2.28.0
Acked-by on v2 5/15
#65 lore raw

Re: [dpdk-dev] [PATCH v2 05/15] security: switch metadata to dynamic mbuf field

Quoted 17 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, October 27, 2020 06:20
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; [email protected]; Richardson, Bruce <[email protected]>; [email protected]; [email protected]; [email protected]; Doherty, Declan <[email protected]>; Ankur Dwivedi <[email protected]>; Anoob Joseph <[email protected]>; Guo, Jia <[email protected]>; Wang, Haiyue <[email protected]>; Jerin Jacob <[email protected]>; Nithin Dabilpuram <[email protected]>; Kiran Kumar K <[email protected]>; Nicolau, Radu <[email protected]>; Ray Kinsella <[email protected]>; Neil Horman <[email protected]>
Subject: [PATCH v2 05/15] security: switch metadata to dynamic mbuf field

The device-specific metadata was stored in the deprecated field udata64. It is moved to a dynamic mbuf field in order to allow removal of udata64.

Quoted 17 lines
---
 doc/guides/prog_guide/rte_security.rst        |  9 +++---
 drivers/crypto/octeontx2/otx2_cryptodev_sec.c |  5 ++-
 drivers/net/ixgbe/ixgbe_ipsec.c               |  5 ++-
 drivers/net/ixgbe/ixgbe_rxtx.c                |  6 ++--
 drivers/net/octeontx2/otx2_ethdev.h           |  1 +
 drivers/net/octeontx2/otx2_ethdev_sec.c       |  5 ++-
 drivers/net/octeontx2/otx2_ethdev_sec_tx.h    |  2 +-
 drivers/net/octeontx2/otx2_rx.h               |  2 +-
 examples/ipsec-secgw/ipsec-secgw.c            |  9 +++---
 examples/ipsec-secgw/ipsec_worker.c           | 12 ++++---
 lib/librte_security/rte_security.c            | 22 +++++++++++++
 lib/librte_security/rte_security.h            | 32 +++++++++++++++++++
 lib/librte_security/rte_security_driver.h     |  3 ++
 lib/librte_security/version.map               |  3 ++
 14 files changed, 96 insertions(+), 20 deletions(-)

For ixgbe PMD,

But I feel that 'rte_security_dynfield' name is too generic, can it be more specific about what the field is used for ?

Like below ;-)

#define RTE_SECURITY_DEV_METADATA(m) \
	RTE_MBUF_DYNFIELD((m), \
			  rte_security_dev_metadata_offset, \
			  RTE_SECURITY_DEV_METADATA_TYPE *)
Quoted 20 lines
lib/librte_security/rte_security.h +17 -1
+/**
+ * Get pointer to mbuf field for device-specific metadata.
+ *
+ * For performance reason, no check is done,
+ * the dynamic field may not be registered.
+ * @see rte_security_dynfield_is_registered
+ *
+ * @param	mbuf	packet to access
+ * @return pointer to mbuf field
+ */
+static inline RTE_SECURITY_DYNFIELD_TYPE *
+rte_security_dynfield(struct rte_mbuf *mbuf)
+{
+	return RTE_MBUF_DYNFIELD(mbuf,
+		rte_security_dynfield_offset,
+		RTE_SECURITY_DYNFIELD_TYPE *);
+}
 
--

2.28.0

#66 lore raw

Re: [dpdk-dev] [PATCH v2 05/15] security: switch metadata to dynamic mbuf field

27/10/2020 03:01, Wang, Haiyue:

Quoted 8 lines

From: Thomas Monjalon <[email protected]>
For ixgbe PMD,

But I feel that 'rte_security_dynfield' name is too generic, can it be more specific about what the field is used for ?

Quoted 6 lines

Like below ;-)

#define RTE_SECURITY_DEV_METADATA(m) \
	RTE_MBUF_DYNFIELD((m), \
			  rte_security_dev_metadata_offset, \
			  RTE_SECURITY_DEV_METADATA_TYPE *)

Yes rte_security_dynfield is too much generic, as well as RTE_SECURITY_DEV_METADATA.
It seems there are different data stored in this field. We should have different fields for different data. But such cleanup is another step for someone else.

#67 lore raw

Re: [dpdk-dev] [PATCH v2 05/15] security: switch metadata to dynamic mbuf field

Quoted 28 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, October 27, 2020 16:52
To: Wang, Haiyue <[email protected]>
Cc: [email protected]; Yigit, Ferruh <[email protected]>; [email protected]; Richardson, Bruce <[email protected]>; [email protected]; [email protected]; [email protected]; Doherty, Declan <[email protected]>; Ankur Dwivedi <[email protected]>; Anoob Joseph <[email protected]>; Guo, Jia <[email protected]>; Jerin Jacob <[email protected]>; Nithin Dabilpuram <[email protected]>; Kiran Kumar K <[email protected]>; Nicolau, Radu <[email protected]>; Ray Kinsella <[email protected]>; Neil Horman <[email protected]>
Subject: Re: [PATCH v2 05/15] security: switch metadata to dynamic mbuf field

27/10/2020 03:01, Wang, Haiyue:

Quoted 8 lines

From: Thomas Monjalon <[email protected]>
For ixgbe PMD,

But I feel that 'rte_security_dynfield' name is too generic, can it be more specific about what the field is used for ?

Quoted 6 lines

Like below ;-)

#define RTE_SECURITY_DEV_METADATA(m) \
	RTE_MBUF_DYNFIELD((m), \
			  rte_security_dev_metadata_offset, \
			  RTE_SECURITY_DEV_METADATA_TYPE *)
Quoted 5 lines

Yes rte_security_dynfield is too much generic, as well as RTE_SECURITY_DEV_METADATA.
It seems there are different data stored in this field. We should have different fields for different data. But such cleanup is another step for someone else.

Understood, thanks, then 'DEV_METADATA' is also generic.

Quoted 2 lines
#68 lore raw

Re: [dpdk-dev] [PATCH v2 05/15] security: switch metadata to dynamic mbuf field

In reply to Thomas Monjalon
Quoted 21 lines · Thomas Monjalon

The device-specific metadata was stored in the deprecated field udata64. It is moved to a dynamic mbuf field in order to allow removal of udata64.

---
 doc/guides/prog_guide/rte_security.rst        |  9 +++---
 drivers/crypto/octeontx2/otx2_cryptodev_sec.c |  5 ++-
 drivers/net/ixgbe/ixgbe_ipsec.c               |  5 ++-
 drivers/net/ixgbe/ixgbe_rxtx.c                |  6 ++--
 drivers/net/octeontx2/otx2_ethdev.h           |  1 +
 drivers/net/octeontx2/otx2_ethdev_sec.c       |  5 ++-
 drivers/net/octeontx2/otx2_ethdev_sec_tx.h    |  2 +-
 drivers/net/octeontx2/otx2_rx.h               |  2 +-
 examples/ipsec-secgw/ipsec-secgw.c            |  9 +++---
 examples/ipsec-secgw/ipsec_worker.c           | 12 ++++---
 lib/librte_security/rte_security.c            | 22 +++++++++++++
 lib/librte_security/rte_security.h            | 32 +++++++++++++++++++
 lib/librte_security/rte_security_driver.h     |  3 ++
 lib/librte_security/version.map               |  3 ++
 14 files changed, 96 insertions(+), 20 deletions(-)

<...>

Quoted 31 lines
examples/ipsec-secgw/ipsec_worker.c +4 -3
@@ -208,7 +208,7 @@ process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt,
 					"Inbound security offload failed\n");
 				goto drop_pkt_and_exit;
 			}
-			sa = pkt->userdata;
+			sa = *(struct ipsec_sa **)rte_security_dynfield(pkt);
 		}
 
 		/* Check if we have a match */
@@ -226,7 +226,7 @@ process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt,
 					"Inbound security offload failed\n");
 				goto drop_pkt_and_exit;
 			}
-			sa = pkt->userdata;
+			sa = *(struct ipsec_sa **)rte_security_dynfield(pkt);
 		}
 
 		/* Check if we have a match */
@@ -357,7 +357,8 @@ process_ipsec_ev_outbound(struct ipsec_ctx *ctx, struct route_table *rt,
 	}
 
 	if (sess->security.ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
-		pkt->userdata = sess->security.ses;
+		*(struct rte_security_session **)rte_security_dynfield(pkt) =
+				sess->security.ses;
 
 	/* Mark the packet for Tx security offload */
 	pkt->ol_flags |= PKT_TX_SEC_OFFLOAD;

examples/ipsec-secgw/ipsec_worker.c ipsec_wrkr_non_burst_int_port_drv_mode(struct eh_event_link_info *links, · line 473

Quoted 9 lines
examples/ipsec-secgw/ipsec_worker.c +4 -1
@@ -465,7 +466,10 @@ ipsec_wrkr_non_burst_int_port_drv_mode(struct eh_event_link_info *links,
 			}
 
 			/* Save security session */
-			pkt->userdata = sess_tbl[port_id];
+			if (rte_security_dynfield_is_registered())
+				*(struct rte_security_session **)
+					rte_security_dynfield(pkt) =
+						sess_tbl[port_id];
 

Maybe the last 2 lines can be on the same line (a bit more than 80, but less than 100 chars).

This is not clear to me why you need to call rte_security_dynfield_is_registered() here, and not in other places.

Would it make sense instead to always register the dynfield at some place in rte_security, so that we are sure that as soon as we use rte_security, the dynfield is registered. A good place would be an init function, but I don't see one.

Quoted 22 lines
examples/ipsec-secgw/ipsec_worker.c +0 -0
 			/* Mark the packet for Tx security offload */
 			pkt->ol_flags |= PKT_TX_SEC_OFFLOAD;
lib/librte_security/rte_security.c +12 -0
index ee4666026a..4fb0b797e9 100644
@@ -23,6 +23,28 @@
 	RTE_PTR_OR_ERR_RET(p1->p2->p3, last_retval);			\
 } while (0)
 
+#define RTE_SECURITY_DYNFIELD_NAME "rte_security_dynfield_metadata"
+int rte_security_dynfield_offset = -1;
+
+int
+rte_security_dynfield_register(void)
+{
+	static const struct rte_mbuf_dynfield dynfield_desc = {
+		.name = RTE_SECURITY_DYNFIELD_NAME,
+		.size = sizeof(RTE_SECURITY_DYNFIELD_TYPE),
+		.align = __alignof__(RTE_SECURITY_DYNFIELD_TYPE),
+	};
+	rte_security_dynfield_offset =

lib/librte_security/rte_security.c line 47

Quoted 10 lines
lib/librte_security/rte_security.c +10 -0
+		rte_mbuf_dynfield_register(&dynfield_desc);
+	return rte_security_dynfield_offset;
+}
+
+bool
+rte_security_dynfield_is_registered(void)
+{
+	return rte_security_dynfield_offset >= 0;
+}
+

Wouldn't it be better to have it in a static inline function? The point is just to check that offset is >= 0, and it is used in data path.

Quoted 16 lines
lib/librte_security/rte_security.c +0 -0
 struct rte_security_session *
 rte_security_session_create(struct rte_security_ctx *instance,
 			    struct rte_security_session_conf *conf,
lib/librte_security/rte_security.h +1 -0
index 271531af12..7fbdee99cc 100644
@@ -27,6 +27,7 @@ extern "C" {
 #include <rte_common.h>
 #include <rte_crypto.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_memory.h>
 #include <rte_mempool.h>
 

lib/librte_security/rte_security.h int · line 456

Quoted 5 lines
lib/librte_security/rte_security.h +2 -0
@@ -451,6 +452,37 @@ int
 rte_security_session_destroy(struct rte_security_ctx *instance,
 			     struct rte_security_session *sess);
 
+/** Device-specific metadata field type */
+#define RTE_SECURITY_DYNFIELD_TYPE uint64_t

What about using a typedef instead of a #define?
It could be in lowercase: rte_security_dynfield_t

#69 lore raw

Re: [dpdk-dev] [PATCH v2 05/15] security: switch metadata to dynamic mbuf field

27/10/2020 11:05, Olivier Matz:

Quoted 6 lines · Thomas Monjalon
Quoted 4 lines

The device-specific metadata was stored in the deprecated field udata64. It is moved to a dynamic mbuf field in order to allow removal of udata64.

<...>

Quoted 10 lines

examples/ipsec-secgw/ipsec_worker.c ipsec_wrkr_non_burst_int_port_drv_mode(struct eh_event_link_info *links, · line 472

Quoted 7 lines
examples/ipsec-secgw/ipsec_worker.c +4 -1
 			/* Save security session */
-			pkt->userdata = sess_tbl[port_id];
+			if (rte_security_dynfield_is_registered())
+				*(struct rte_security_session **)
+					rte_security_dynfield(pkt) =
+						sess_tbl[port_id];

Maybe the last 2 lines can be on the same line (a bit more than 80, but less than 100 chars).

I prefer limiting to 80 if possible.

Quoted 2 lines

This is not clear to me why you need to call rte_security_dynfield_is_registered() here, and not in other places.

I think other places are paths for rte_security only.

Quoted 4 lines

Would it make sense instead to always register the dynfield at some place in rte_security, so that we are sure that as soon as we use rte_security, the dynfield is registered. A good place would be an init function, but I don't see one.

Indeed there is no such place in rte_security.
I keep thinking this is not a real library.

Quoted 10 lines

lib/librte_security/rte_security.c line 47

Quoted 6 lines
lib/librte_security/rte_security.c +6 -0
+bool
+rte_security_dynfield_is_registered(void)
+{
+	return rte_security_dynfield_offset >= 0;
+}
+

Wouldn't it be better to have it in a static inline function? The point is just to check that offset is >= 0, and it is used in data path.

Yes I'll make it inline

Quoted 5 lines

lib/librte_security/rte_security.h int · line 456

Quoted 2 lines
lib/librte_security/rte_security.h +2 -0
+/** Device-specific metadata field type */
+#define RTE_SECURITY_DYNFIELD_TYPE uint64_t

What about using a typedef instead of a #define?
It could be in lowercase: rte_security_dynfield_t

Yes

#70 lore raw

PATCH v2 6/15 event/sw: switch test counter to dynamic mbuf field

In reply to Thomas Monjalon

The test worker_loopback used the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 drivers/event/sw/sw_evdev_selftest.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/event/sw/sw_evdev_selftest.c +20 -3
index 5c7e527917..9af20cecf1 100644
@@ -40,6 +40,11 @@ struct test {
 	uint32_t service_id;
 };
 
+static int counter_dynfield_offset;
+#define COUNTER_FIELD_TYPE uint8_t
+#define COUNTER_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		counter_dynfield_offset, COUNTER_FIELD_TYPE *))
+
 static struct rte_event release_ev;
 
 static inline struct rte_mbuf *
@@ -2987,8 +2992,8 @@ worker_loopback_worker_fn(void *arg)
 			}
 
 			ev[i].queue_id = 0;
-			ev[i].mbuf->udata64++;
-			if (ev[i].mbuf->udata64 != 16) {
+			COUNTER_FIELD(ev[i].mbuf)++;
+			if (COUNTER_FIELD(ev[i].mbuf) != 16) {
 				ev[i].op = RTE_EVENT_OP_FORWARD;
 				enqd = rte_event_enqueue_burst(evdev, port,
 						&ev[i], 1);
@@ -3028,7 +3033,7 @@ worker_loopback_producer_fn(void *arg)
 			m = rte_pktmbuf_alloc(t->mbuf_pool);
 		} while (m == NULL);
 
-		m->udata64 = 0;
+		COUNTER_FIELD(m) = 0;
 
 		struct rte_event ev = {
 				.op = RTE_EVENT_OP_NEW,
@@ -3061,6 +3066,18 @@ worker_loopback(struct test *t, uint8_t disable_implicit_release)
 	int err;
 	int w_lcore, p_lcore;
 
+	static const struct rte_mbuf_dynfield counter_dynfield_desc = {
+		.name = "rte_event_sw_dynfield_selftest_counter",
+		.size = sizeof(COUNTER_FIELD_TYPE),
+		.align = __alignof__(COUNTER_FIELD_TYPE),
+	};
+	counter_dynfield_offset =
+		rte_mbuf_dynfield_register(&counter_dynfield_desc);
+	if (counter_dynfield_offset < 0) {
+		printf("Error registering mbuf field\n");
+		return -rte_errno;
+	}
+
 	if (init(t, 8, 2) < 0 ||
 			create_atomic_qids(t, 8) < 0) {
 		printf("%d: Error initializing device\n", __LINE__);
Signature · 1 line
2.28.0
#71 lore raw

Re: [dpdk-dev] [PATCH v2 06/15] event/sw: switch test counter to dynamic mbuf field

Quoted 14 lines · Thomas Monjalon

The test worker_loopback used the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 drivers/event/sw/sw_evdev_selftest.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/event/sw/sw_evdev_selftest.c +0 -0
index 5c7e527917..9af20cecf1 100644

drivers/event/sw/sw_evdev_selftest.c struct test { · line 43

Quoted 4 lines
drivers/event/sw/sw_evdev_selftest.c +1 -0
@@ -40,6 +40,11 @@ struct test {
 	uint32_t service_id;
 };
 
+static int counter_dynfield_offset;

In general, I wonder if we shouldn't initialize offset to -1.

drivers/event/sw/sw_evdev_selftest.c struct test { · line 44

Quoted 1 line
drivers/event/sw/sw_evdev_selftest.c +1 -0
+#define COUNTER_FIELD_TYPE uint8_t

Another general comment, I suggest to use a typedef instead of a define when relevant.

drivers/event/sw/sw_evdev_selftest.c struct test { · line 47

Quoted 3 lines
drivers/event/sw/sw_evdev_selftest.c +3 -0
+#define COUNTER_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		counter_dynfield_offset, COUNTER_FIELD_TYPE *))
+

I'm not sure this comment applies here, but since it's a simple example, it's a good place for another general comment. The RTE_MBUF_DYNFIELD() macro is convenient because it can be used to set or get a value of any type, but in my opinion it is not always easy to read:

  RTE_MBUF_DYNFIELD(m, off, type) = value;

In some situations, having wrappers may make the code more readable:

  static inline void mbuf_set_counter(struct rte_mbuf *m, counter_field_t counter);
  static inline counter_field_t mbuf_get_counter(struct rte_mbuf *m);
  static inline void mbuf_inc_counter(struct rte_mbuf *m);
Quoted 45 lines
drivers/event/sw/sw_evdev_selftest.c +15 -3
 static struct rte_event release_ev;
 
 static inline struct rte_mbuf *
@@ -2987,8 +2992,8 @@ worker_loopback_worker_fn(void *arg)
 			}
 
 			ev[i].queue_id = 0;
-			ev[i].mbuf->udata64++;
-			if (ev[i].mbuf->udata64 != 16) {
+			COUNTER_FIELD(ev[i].mbuf)++;
+			if (COUNTER_FIELD(ev[i].mbuf) != 16) {
 				ev[i].op = RTE_EVENT_OP_FORWARD;
 				enqd = rte_event_enqueue_burst(evdev, port,
 						&ev[i], 1);
@@ -3028,7 +3033,7 @@ worker_loopback_producer_fn(void *arg)
 			m = rte_pktmbuf_alloc(t->mbuf_pool);
 		} while (m == NULL);
 
-		m->udata64 = 0;
+		COUNTER_FIELD(m) = 0;
 
 		struct rte_event ev = {
 				.op = RTE_EVENT_OP_NEW,
@@ -3061,6 +3066,18 @@ worker_loopback(struct test *t, uint8_t disable_implicit_release)
 	int err;
 	int w_lcore, p_lcore;
 
+	static const struct rte_mbuf_dynfield counter_dynfield_desc = {
+		.name = "rte_event_sw_dynfield_selftest_counter",
+		.size = sizeof(COUNTER_FIELD_TYPE),
+		.align = __alignof__(COUNTER_FIELD_TYPE),
+	};
+	counter_dynfield_offset =
+		rte_mbuf_dynfield_register(&counter_dynfield_desc);
+	if (counter_dynfield_offset < 0) {
+		printf("Error registering mbuf field\n");
+		return -rte_errno;
+	}
+
 	if (init(t, 8, 2) < 0 ||
 			create_atomic_qids(t, 8) < 0) {
 		printf("%d: Error initializing device\n", __LINE__);
Signature · 1 line
2.28.0
#72 lore raw

Re: [dpdk-dev] [PATCH v2 06/15] event/sw: switch test counter to dynamic mbuf field

27/10/2020 11:15, Olivier Matz:

Quoted 7 lines · Thomas Monjalon
Quoted 6 lines

The test worker_loopback used the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---

[...]

Quoted 3 lines
Quoted 1 line

+static int counter_dynfield_offset;

In general, I wonder if we shouldn't initialize offset to -1.

Yes good idea.

Quoted 4 lines
Quoted 1 line

+#define COUNTER_FIELD_TYPE uint8_t

Another general comment, I suggest to use a typedef instead of a define when relevant.

Yes

Quoted 9 lines

drivers/event/sw/sw_evdev_selftest.c struct test { · line 47

Quoted 3 lines
drivers/event/sw/sw_evdev_selftest.c +3 -0
+#define COUNTER_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		counter_dynfield_offset, COUNTER_FIELD_TYPE *))
+

I'm not sure this comment applies here, but since it's a simple example, it's a good place for another general comment. The RTE_MBUF_DYNFIELD() macro is convenient because it can be used to set or get a value of any type, but in my opinion it is not always easy to read:

Quoted 7 lines
  RTE_MBUF_DYNFIELD(m, off, type) = value;

In some situations, having wrappers may make the code more readable:

  static inline void mbuf_set_counter(struct rte_mbuf *m, counter_field_t counter);
  static inline counter_field_t mbuf_get_counter(struct rte_mbuf *m);
  static inline void mbuf_inc_counter(struct rte_mbuf *m);

I agree, I will add some wrapper functions.

#73 lore raw

PATCH v2 7/15 net/ark: ignore user data

In reply to Thomas Monjalon

The second field of metadata is reserved for user data which is a deprecated mbuf field.
The usage of mbuf udata64 is removed
and the corresponding ark metadata field is annotated as ignored.

---
 drivers/net/ark/ark_ddm.h       | 2 +-
 drivers/net/ark/ark_ethdev_rx.c | 1 -
 drivers/net/ark/ark_ethdev_tx.c | 1 -
 drivers/net/ark/ark_udm.h       | 2 +-
 4 files changed, 2 insertions(+), 4 deletions(-)
drivers/net/ark/ark_ddm.h +1 -1
index 5456b4b5cc..99eded8524 100644
@@ -19,7 +19,7 @@
 /* struct defining Tx meta data --  fixed in FPGA -- 16 bytes */
 struct ark_tx_meta {
 	uint64_t physaddr;
-	uint32_t user1;
+	uint32_t user1;		/* ignored */
 	uint16_t data_len;		/* of this MBUF */
 #define   ARK_DDM_EOP   0x01
 #define   ARK_DDM_SOP   0x02
drivers/net/ark/ark_ethdev_rx.c +0 -1
index 2f8d05099c..5ead67e6b8 100644
@@ -272,7 +272,6 @@ eth_ark_recv_pkts(void *rx_queue,
 		mbuf->pkt_len = meta->pkt_len;
 		mbuf->data_len = meta->pkt_len;
 		mbuf->timestamp = meta->timestamp;
-		mbuf->udata64 = meta->user_data;
 
 		if (ARK_DEBUG_CORE) {	/* debug sanity checks */
 			if ((meta->pkt_len > (1024 * 16)) ||
drivers/net/ark/ark_ethdev_tx.c +0 -1
index a0e35af880..8a0a9381f7 100644
@@ -70,7 +70,6 @@ eth_ark_tx_meta_from_mbuf(struct ark_tx_meta *meta,
 			  uint8_t flags)
 {
 	meta->physaddr = rte_mbuf_data_iova(mbuf);
-	meta->user1 = (uint32_t)mbuf->udata64;
 	meta->data_len = rte_pktmbuf_data_len(mbuf);
 	meta->flags = flags;
 }
drivers/net/ark/ark_udm.h +1 -1
index 5846c825b8..ba436ee25b 100644
@@ -18,7 +18,7 @@
 /* Meta data structure apssed from FPGA, must match layout in FPGA */
 struct ark_rx_meta {
 	uint64_t timestamp;
-	uint64_t user_data;
+	uint64_t user_data; /* ignored */
 	uint8_t port;
 	uint8_t dst_queue;
 	uint16_t pkt_len;
Signature · 1 line
2.28.0
#74 lore raw

Re: [dpdk-dev] [PATCH v2 07/15] net/ark: ignore user data

HI Thomas,
Atomic Rules will be submitting a patch to connect user_data into the mbuf stuct using
the dynfield interface restoring lost functionality from this patch.

You can expect a patch in the next few days. Are you targeting this patch series for the 20.11 release?
Thanks
Ed.

Quoted 67 lines · Thomas Monjalon

The second field of metadata is reserved for user data which is a deprecated mbuf field.
The usage of mbuf udata64 is removed
and the corresponding ark metadata field is annotated as ignored.

---
 drivers/net/ark/ark_ddm.h       | 2 +-
 drivers/net/ark/ark_ethdev_rx.c | 1 -
 drivers/net/ark/ark_ethdev_tx.c | 1 -
 drivers/net/ark/ark_udm.h       | 2 +-
 4 files changed, 2 insertions(+), 4 deletions(-)
drivers/net/ark/ark_ddm.h +1 -1
index 5456b4b5cc..99eded8524 100644
@@ -19,7 +19,7 @@
 /* struct defining Tx meta data --  fixed in FPGA -- 16 bytes */
 struct ark_tx_meta {
        uint64_t physaddr;
-       uint32_t user1;
+       uint32_t user1;         /* ignored */
        uint16_t data_len;              /* of this MBUF */
 #define   ARK_DDM_EOP   0x01
 #define   ARK_DDM_SOP   0x02
drivers/net/ark/ark_ethdev_rx.c +0 -1
index 2f8d05099c..5ead67e6b8 100644
@@ -272,7 +272,6 @@ eth_ark_recv_pkts(void *rx_queue,
                mbuf->pkt_len = meta->pkt_len;
                mbuf->data_len = meta->pkt_len;
                mbuf->timestamp = meta->timestamp;
-               mbuf->udata64 = meta->user_data;
 
                if (ARK_DEBUG_CORE) {   /* debug sanity checks */
                        if ((meta->pkt_len > (1024 * 16)) ||
drivers/net/ark/ark_ethdev_tx.c +0 -1
index a0e35af880..8a0a9381f7 100644
@@ -70,7 +70,6 @@ eth_ark_tx_meta_from_mbuf(struct ark_tx_meta *meta,
                          uint8_t flags)
 {
        meta->physaddr = rte_mbuf_data_iova(mbuf);
-       meta->user1 = (uint32_t)mbuf->udata64;
        meta->data_len = rte_pktmbuf_data_len(mbuf);
        meta->flags = flags;
 }
drivers/net/ark/ark_udm.h +1 -2
index 5846c825b8..ba436ee25b 100644
@@ -18,7 +18,7 @@
 /* Meta data structure apssed from FPGA, must match layout in FPGA */
 struct ark_rx_meta {
        uint64_t timestamp;
-       uint64_t user_data;
+       uint64_t user_data; /* ignored */
        uint8_t port;
        uint8_t dst_queue;
        uint16_t pkt_len;
--

2.28.0

#75 lore raw

Re: [dpdk-dev] [PATCH v2 07/15] net/ark: ignore user data

27/10/2020 16:32, Ed Czeck:

Quoted 4 lines

HI Thomas,
Atomic Rules will be submitting a patch to connect user_data into the mbuf stuct using
the dynfield interface restoring lost functionality from this patch.

I don't understand what you are looking for.
The user data has no meaning, and is removed.
Please explain your use case and what you need.

Does it mean you ack this patch?

Quoted 2 lines

You can expect a patch in the next few days. Are you targeting this patch series for the 20.11 release?

Yes 20.11-rc2 (this week) is the target.

Quoted 67 lines · Thomas Monjalon
Quoted 66 lines

The second field of metadata is reserved for user data which is a deprecated mbuf field.
The usage of mbuf udata64 is removed
and the corresponding ark metadata field is annotated as ignored.

---
 drivers/net/ark/ark_ddm.h       | 2 +-
 drivers/net/ark/ark_ethdev_rx.c | 1 -
 drivers/net/ark/ark_ethdev_tx.c | 1 -
 drivers/net/ark/ark_udm.h       | 2 +-
 4 files changed, 2 insertions(+), 4 deletions(-)
drivers/net/ark/ark_ddm.h +1 -1
index 5456b4b5cc..99eded8524 100644
@@ -19,7 +19,7 @@
 /* struct defining Tx meta data --  fixed in FPGA -- 16 bytes */
 struct ark_tx_meta {
        uint64_t physaddr;
-       uint32_t user1;
+       uint32_t user1;         /* ignored */
        uint16_t data_len;              /* of this MBUF */
 #define   ARK_DDM_EOP   0x01
 #define   ARK_DDM_SOP   0x02
drivers/net/ark/ark_ethdev_rx.c +0 -1
index 2f8d05099c..5ead67e6b8 100644
@@ -272,7 +272,6 @@ eth_ark_recv_pkts(void *rx_queue,
                mbuf->pkt_len = meta->pkt_len;
                mbuf->data_len = meta->pkt_len;
                mbuf->timestamp = meta->timestamp;
-               mbuf->udata64 = meta->user_data;
 
                if (ARK_DEBUG_CORE) {   /* debug sanity checks */
                        if ((meta->pkt_len > (1024 * 16)) ||
drivers/net/ark/ark_ethdev_tx.c +0 -1
index a0e35af880..8a0a9381f7 100644
@@ -70,7 +70,6 @@ eth_ark_tx_meta_from_mbuf(struct ark_tx_meta *meta,
                          uint8_t flags)
 {
        meta->physaddr = rte_mbuf_data_iova(mbuf);
-       meta->user1 = (uint32_t)mbuf->udata64;
        meta->data_len = rte_pktmbuf_data_len(mbuf);
        meta->flags = flags;
 }
drivers/net/ark/ark_udm.h +1 -2
index 5846c825b8..ba436ee25b 100644
@@ -18,7 +18,7 @@
 /* Meta data structure apssed from FPGA, must match layout in FPGA */
 struct ark_rx_meta {
        uint64_t timestamp;
-       uint64_t user_data;
+       uint64_t user_data; /* ignored */
        uint8_t port;
        uint8_t dst_queue;
        uint16_t pkt_len;
--

2.28.0

#76 lore raw

Re: [dpdk-dev] [PATCH v2 07/15] net/ark: ignore user data

27/10/2020 16:55, Thomas Monjalon:

Quoted 10 lines

27/10/2020 16:32, Ed Czeck:

Quoted 4 lines

HI Thomas,
Atomic Rules will be submitting a patch to connect user_data into the mbuf stuct using
the dynfield interface restoring lost functionality from this patch.

I don't understand what you are looking for.
The user data has no meaning, and is removed.
Please explain your use case and what you need.

Quoted 6 lines

Does it mean you ack this patch?

Quoted 2 lines

You can expect a patch in the next few days. Are you targeting this patch series for the 20.11 release?

Yes 20.11-rc2 (this week) is the target.

Please be aware that seqn field could be removed as well.

#77 lore raw

PATCH v2 8/15 net/bnxt: switch CFA code to dynamic mbuf field

In reply to Thomas Monjalon

The CFA code from mark was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

Note: the new field has 32 bits, smaller than udata64.

---
 drivers/net/bnxt/bnxt_ethdev.c  | 19 +++++++++++++++++++
 drivers/net/bnxt/bnxt_rxr.c     |  2 +-
 drivers/net/bnxt/bnxt_rxr.h     |  5 +++++
 drivers/net/bnxt/rte_pmd_bnxt.h |  3 +++
 4 files changed, 28 insertions(+), 1 deletion(-)
drivers/net/bnxt/bnxt_ethdev.c +19 -0
index 1c7d1b758d..1090d28341 100644
@@ -31,6 +31,7 @@
 #include "bnxt_nvm_defs.h"
 #include "bnxt_tf_common.h"
 #include "ulp_flow_db.h"
+#include "rte_pmd_bnxt.h"
 
 #define DRV_MODULE_NAME		"bnxt"
 static const char bnxt_version[] =
@@ -163,6 +164,8 @@ static const char *const bnxt_dev_args[] = {
  */
 #define BNXT_DEVARG_REP_FC_F2R_INVALID(rep_fc_f2r)	((rep_fc_f2r) > 1)
 
+int bnxt_cfa_code_dynfield_offset;
+
 /*
  * max_num_kflows must be >= 32
  * and must be a power-of-2 supported value
@@ -6021,6 +6024,22 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev, void *params __rte_unused)
 	    pci_dev->id.device_id == BROADCOM_DEV_ID_58802_VF)
 		bp->flags |= BNXT_FLAG_STINGRAY;
 
+	if (BNXT_TRUFLOW_EN(bp)) {
+		/* extra mbuf field is required to store CFA code from mark */
+		static const struct rte_mbuf_dynfield bnxt_cfa_code_dynfield_desc = {
+			.name = RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME,
+			.size = sizeof(BNXT_CFA_CODE_DYNFIELD_TYPE),
+			.align = __alignof__(BNXT_CFA_CODE_DYNFIELD_TYPE),
+		};
+		bnxt_cfa_code_dynfield_offset =
+			rte_mbuf_dynfield_register(&bnxt_cfa_code_dynfield_desc);
+		if (bnxt_cfa_code_dynfield_offset < 0) {
+			PMD_DRV_LOG(ERR,
+			    "Failed to register mbuf field for TruFlow mark\n");
+			return -rte_errno;
+		}
+	}
+
 	rc = bnxt_init_board(eth_dev);
 	if (rc) {
 		PMD_DRV_LOG(ERR,
drivers/net/bnxt/bnxt_rxr.c +1 -1
index 039217fa60..7156ce7dd8 100644
@@ -606,7 +606,7 @@ bnxt_ulp_set_mark_in_mbuf(struct bnxt *bp, struct rx_pkt_cmpl_hi *rxcmp1,
 			return mark_id;
 		/* Got the mark, write it to the mbuf and return */
 		mbuf->hash.fdir.hi = mark_id;
-		mbuf->udata64 = (cfa_code & 0xffffffffull) << 32;
+		BNXT_CFA_CODE_DYNFIELD(mbuf) = cfa_code & 0xffffffffull;
 		mbuf->hash.fdir.id = rxcmp1->cfa_code;
 		mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
 		return mark_id;
drivers/net/bnxt/bnxt_rxr.h +5 -0
index b874e54a8c..e01d3e4f18 100644
@@ -95,6 +95,11 @@ void bnxt_set_mark_in_mbuf(struct bnxt *bp,
 			   struct rx_pkt_cmpl_hi *rxcmp1,
 			   struct rte_mbuf *mbuf);
 
+extern int bnxt_cfa_code_dynfield_offset;
+#define BNXT_CFA_CODE_DYNFIELD_TYPE uint32_t
+#define BNXT_CFA_CODE_DYNFIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		bnxt_cfa_code_dynfield_offset, BNXT_CFA_CODE_DYNFIELD_TYPE *))
+
 #define BNXT_RX_META_CFA_CODE_SHIFT		19
 #define BNXT_CFA_CODE_META_SHIFT		16
 #define BNXT_RX_META_CFA_CODE_INT_ACT_REC_BIT	0x8000000
drivers/net/bnxt/rte_pmd_bnxt.h +3 -0
index 81d0d0e032..8d3303bb0f 100644
@@ -9,6 +9,9 @@
 #include <rte_ethdev.h>
 #include <rte_ether.h>
 
+/* mbuf dynfield where CFA code is stored */
+#define RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME "rte_net_bnxt_dynfield_cfa_code"
+
 /*
  * Response sent back to the caller after callback
  */
Signature · 1 line
2.28.0
Acked-by on v2 8/15
#78 lore raw

Re: [dpdk-dev] [PATCH v2 08/15] net/bnxt: switch CFA code to dynamic mbuf field

Quoted 7 lines · Thomas Monjalon

The CFA code from mark was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

Note: the new field has 32 bits, smaller than udata64.

Quoted 98 lines
---
 drivers/net/bnxt/bnxt_ethdev.c  | 19 +++++++++++++++++++
 drivers/net/bnxt/bnxt_rxr.c     |  2 +-
 drivers/net/bnxt/bnxt_rxr.h     |  5 +++++
 drivers/net/bnxt/rte_pmd_bnxt.h |  3 +++
 4 files changed, 28 insertions(+), 1 deletion(-)
drivers/net/bnxt/bnxt_ethdev.c +19 -0
index 1c7d1b758d..1090d28341 100644
@@ -31,6 +31,7 @@
 #include "bnxt_nvm_defs.h"
 #include "bnxt_tf_common.h"
 #include "ulp_flow_db.h"
+#include "rte_pmd_bnxt.h"
 
 #define DRV_MODULE_NAME                "bnxt"
 static const char bnxt_version[] =
@@ -163,6 +164,8 @@ static const char *const bnxt_dev_args[] = {
  */
 #define BNXT_DEVARG_REP_FC_F2R_INVALID(rep_fc_f2r)     ((rep_fc_f2r) > 1)
 
+int bnxt_cfa_code_dynfield_offset;
+
 /*
  * max_num_kflows must be >= 32
  * and must be a power-of-2 supported value
@@ -6021,6 +6024,22 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev, void *params __rte_unused)
            pci_dev->id.device_id == BROADCOM_DEV_ID_58802_VF)
                bp->flags |= BNXT_FLAG_STINGRAY;
 
+       if (BNXT_TRUFLOW_EN(bp)) {
+               /* extra mbuf field is required to store CFA code from mark */
+               static const struct rte_mbuf_dynfield bnxt_cfa_code_dynfield_desc = {
+                       .name = RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME,
+                       .size = sizeof(BNXT_CFA_CODE_DYNFIELD_TYPE),
+                       .align = __alignof__(BNXT_CFA_CODE_DYNFIELD_TYPE),
+               };
+               bnxt_cfa_code_dynfield_offset =
+                       rte_mbuf_dynfield_register(&bnxt_cfa_code_dynfield_desc);
+               if (bnxt_cfa_code_dynfield_offset < 0) {
+                       PMD_DRV_LOG(ERR,
+                           "Failed to register mbuf field for TruFlow mark\n");
+                       return -rte_errno;
+               }
+       }
+
        rc = bnxt_init_board(eth_dev);
        if (rc) {
                PMD_DRV_LOG(ERR,
drivers/net/bnxt/bnxt_rxr.c +1 -1
index 039217fa60..7156ce7dd8 100644
@@ -606,7 +606,7 @@ bnxt_ulp_set_mark_in_mbuf(struct bnxt *bp, struct rx_pkt_cmpl_hi *rxcmp1,
                        return mark_id;
                /* Got the mark, write it to the mbuf and return */
                mbuf->hash.fdir.hi = mark_id;
-               mbuf->udata64 = (cfa_code & 0xffffffffull) << 32;
+               BNXT_CFA_CODE_DYNFIELD(mbuf) = cfa_code & 0xffffffffull;
                mbuf->hash.fdir.id = rxcmp1->cfa_code;
                mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
                return mark_id;
drivers/net/bnxt/bnxt_rxr.h +5 -0
index b874e54a8c..e01d3e4f18 100644
@@ -95,6 +95,11 @@ void bnxt_set_mark_in_mbuf(struct bnxt *bp,
                           struct rx_pkt_cmpl_hi *rxcmp1,
                           struct rte_mbuf *mbuf);
 
+extern int bnxt_cfa_code_dynfield_offset;
+#define BNXT_CFA_CODE_DYNFIELD_TYPE uint32_t
+#define BNXT_CFA_CODE_DYNFIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+               bnxt_cfa_code_dynfield_offset, BNXT_CFA_CODE_DYNFIELD_TYPE *))
+
 #define BNXT_RX_META_CFA_CODE_SHIFT            19
 #define BNXT_CFA_CODE_META_SHIFT               16
 #define BNXT_RX_META_CFA_CODE_INT_ACT_REC_BIT  0x8000000
drivers/net/bnxt/rte_pmd_bnxt.h +3 -1
index 81d0d0e032..8d3303bb0f 100644
@@ -9,6 +9,9 @@
 #include <rte_ethdev.h>
 #include <rte_ether.h>
 
+/* mbuf dynfield where CFA code is stored */
+#define RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME "rte_net_bnxt_dynfield_cfa_code"
+
 /*
  * Response sent back to the caller after callback
  */
--

2.28.0

#79 lore raw

Re: [dpdk-dev] [PATCH v2 08/15] net/bnxt: switch CFA code to dynamic mbuf field

In reply to Thomas Monjalon
Quoted 6 lines · Thomas Monjalon

The CFA code from mark was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

Note: the new field has 32 bits, smaller than udata64.

How is it used by an application?
It seems that the cfa code is not always set. Is there a flag to know when the field is valid?

Also, for ice and iavf PMDs, we were discussing what is the better way to export the offset.

Note that there is an open discussion about how to export dynamic fields offset for PMDs:
http://inbox.dpdk.org/dev/[email protected]/T/#mab79dd5cbb7d199a33515b7456dfe1831cf473bc

Quoted 97 lines
---
 drivers/net/bnxt/bnxt_ethdev.c  | 19 +++++++++++++++++++
 drivers/net/bnxt/bnxt_rxr.c     |  2 +-
 drivers/net/bnxt/bnxt_rxr.h     |  5 +++++
 drivers/net/bnxt/rte_pmd_bnxt.h |  3 +++
 4 files changed, 28 insertions(+), 1 deletion(-)
drivers/net/bnxt/bnxt_ethdev.c +19 -0
index 1c7d1b758d..1090d28341 100644
@@ -31,6 +31,7 @@
 #include "bnxt_nvm_defs.h"
 #include "bnxt_tf_common.h"
 #include "ulp_flow_db.h"
+#include "rte_pmd_bnxt.h"
 
 #define DRV_MODULE_NAME		"bnxt"
 static const char bnxt_version[] =
@@ -163,6 +164,8 @@ static const char *const bnxt_dev_args[] = {
  */
 #define BNXT_DEVARG_REP_FC_F2R_INVALID(rep_fc_f2r)	((rep_fc_f2r) > 1)
 
+int bnxt_cfa_code_dynfield_offset;
+
 /*
  * max_num_kflows must be >= 32
  * and must be a power-of-2 supported value
@@ -6021,6 +6024,22 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev, void *params __rte_unused)
 	    pci_dev->id.device_id == BROADCOM_DEV_ID_58802_VF)
 		bp->flags |= BNXT_FLAG_STINGRAY;
 
+	if (BNXT_TRUFLOW_EN(bp)) {
+		/* extra mbuf field is required to store CFA code from mark */
+		static const struct rte_mbuf_dynfield bnxt_cfa_code_dynfield_desc = {
+			.name = RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME,
+			.size = sizeof(BNXT_CFA_CODE_DYNFIELD_TYPE),
+			.align = __alignof__(BNXT_CFA_CODE_DYNFIELD_TYPE),
+		};
+		bnxt_cfa_code_dynfield_offset =
+			rte_mbuf_dynfield_register(&bnxt_cfa_code_dynfield_desc);
+		if (bnxt_cfa_code_dynfield_offset < 0) {
+			PMD_DRV_LOG(ERR,
+			    "Failed to register mbuf field for TruFlow mark\n");
+			return -rte_errno;
+		}
+	}
+
 	rc = bnxt_init_board(eth_dev);
 	if (rc) {
 		PMD_DRV_LOG(ERR,
drivers/net/bnxt/bnxt_rxr.c +1 -1
index 039217fa60..7156ce7dd8 100644
@@ -606,7 +606,7 @@ bnxt_ulp_set_mark_in_mbuf(struct bnxt *bp, struct rx_pkt_cmpl_hi *rxcmp1,
 			return mark_id;
 		/* Got the mark, write it to the mbuf and return */
 		mbuf->hash.fdir.hi = mark_id;
-		mbuf->udata64 = (cfa_code & 0xffffffffull) << 32;
+		BNXT_CFA_CODE_DYNFIELD(mbuf) = cfa_code & 0xffffffffull;
 		mbuf->hash.fdir.id = rxcmp1->cfa_code;
 		mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
 		return mark_id;
drivers/net/bnxt/bnxt_rxr.h +5 -0
index b874e54a8c..e01d3e4f18 100644
@@ -95,6 +95,11 @@ void bnxt_set_mark_in_mbuf(struct bnxt *bp,
 			   struct rx_pkt_cmpl_hi *rxcmp1,
 			   struct rte_mbuf *mbuf);
 
+extern int bnxt_cfa_code_dynfield_offset;
+#define BNXT_CFA_CODE_DYNFIELD_TYPE uint32_t
+#define BNXT_CFA_CODE_DYNFIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		bnxt_cfa_code_dynfield_offset, BNXT_CFA_CODE_DYNFIELD_TYPE *))
+
 #define BNXT_RX_META_CFA_CODE_SHIFT		19
 #define BNXT_CFA_CODE_META_SHIFT		16
 #define BNXT_RX_META_CFA_CODE_INT_ACT_REC_BIT	0x8000000
drivers/net/bnxt/rte_pmd_bnxt.h +3 -0
index 81d0d0e032..8d3303bb0f 100644
@@ -9,6 +9,9 @@
 #include <rte_ethdev.h>
 #include <rte_ether.h>
 
+/* mbuf dynfield where CFA code is stored */
+#define RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME "rte_net_bnxt_dynfield_cfa_code"
+
 /*
  * Response sent back to the caller after callback
  */
Signature · 1 line
2.28.0
#80 lore raw

Re: [dpdk-dev] [PATCH v2 08/15] net/bnxt: switch CFA code to dynamic mbuf field

27/10/2020 11:31, Olivier Matz:

Quoted 11 lines · Thomas Monjalon
Quoted 6 lines

The CFA code from mark was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

Note: the new field has 32 bits, smaller than udata64.

How is it used by an application?
It seems that the cfa code is not always set. Is there a flag to know when the field is valid?

I don't know, and it is PMD-specific,
but this behaviour is equivalent with what was before.

Quoted 6 lines

Also, for ice and iavf PMDs, we were discussing what is the better way to export the offset.

Note that there is an open discussion about how to export dynamic fields offset for PMDs:
http://inbox.dpdk.org/dev/[email protected]/T/#mab79dd5cbb7d199a33515b7456dfe1831cf473bc

In general I think it is better not exporting the offset, but keep a local copy of it.

#81 lore raw

PATCH v2 9/15 net/vmxnet3: switch MSS hint to dynamic mbuf field

In reply to Thomas Monjalon

The segment count, used for MSS guess,
was stored in the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 drivers/net/vmxnet3/vmxnet3_ethdev.c | 15 +++++++++++++++
 drivers/net/vmxnet3/vmxnet3_ethdev.h |  6 ++++++
 drivers/net/vmxnet3/vmxnet3_rxtx.c   |  9 +++++----
 3 files changed, 26 insertions(+), 4 deletions(-)
drivers/net/vmxnet3/vmxnet3_ethdev.c +15 -0
index 6920ab568c..6e99b67b5a 100644
@@ -59,6 +59,8 @@
 	 DEV_RX_OFFLOAD_JUMBO_FRAME |   \
 	 DEV_RX_OFFLOAD_RSS_HASH)
 
+int vmxnet3_segs_dynfield_offset;
+
 static int eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev);
 static int eth_vmxnet3_dev_uninit(struct rte_eth_dev *eth_dev);
 static int vmxnet3_dev_configure(struct rte_eth_dev *dev);
@@ -233,6 +235,11 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	struct vmxnet3_hw *hw = eth_dev->data->dev_private;
 	uint32_t mac_hi, mac_lo, ver;
 	struct rte_eth_link link;
+	static const struct rte_mbuf_dynfield vmxnet3_segs_dynfield_desc = {
+		.name = VMXNET3_SEGS_DYNFIELD_NAME,
+		.size = sizeof(VMXNET3_SEGS_DYNFIELD_TYPE),
+		.align = __alignof__(VMXNET3_SEGS_DYNFIELD_TYPE),
+	};
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -242,6 +249,14 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
 	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 
+	/* extra mbuf field is required to guess MSS */
+	vmxnet3_segs_dynfield_offset =
+		rte_mbuf_dynfield_register(&vmxnet3_segs_dynfield_desc);
+	if (vmxnet3_segs_dynfield_offset < 0) {
+		PMD_INIT_LOG(ERR, "Cannot register mbuf field.");
+		return -rte_errno;
+	}
+
 	/*
 	 * for secondary processes, we don't initialize any further as primary
 	 * has already done this work.
drivers/net/vmxnet3/vmxnet3_ethdev.h +6 -0
index dd685b02b7..e35edf07be 100644
@@ -193,4 +193,10 @@ uint16_t vmxnet3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 uint16_t vmxnet3_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 			uint16_t nb_pkts);
 
+extern int vmxnet3_segs_dynfield_offset;
+#define VMXNET3_SEGS_DYNFIELD_NAME "rte_net_vmxnet3_dynfield_segs"
+#define VMXNET3_SEGS_DYNFIELD_TYPE uint8_t
+#define VMXNET3_SEGS_DYNFIELD(mbuf) (*RTE_MBUF_DYNFIELD(rxm, \
+		vmxnet3_segs_dynfield_offset, VMXNET3_SEGS_DYNFIELD_TYPE *))
+
 #endif /* _VMXNET3_ETHDEV_H_ */
drivers/net/vmxnet3/vmxnet3_rxtx.c +5 -4
index e10f9ee870..2b0e2e6f19 100644
@@ -674,6 +674,7 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	struct rte_ipv6_hdr *ipv6_hdr;
 	struct rte_tcp_hdr *tcp_hdr;
 	char *ptr;
+	uint8_t segs;
 
 	RTE_ASSERT(rcd->tcp);
 
@@ -710,9 +711,9 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	tcp_hdr = (struct rte_tcp_hdr *)(ptr + hlen);
 	hlen += (tcp_hdr->data_off & 0xf0) >> 2;
 
-	if (rxm->udata64 > 1)
-		return (rte_pktmbuf_pkt_len(rxm) - hlen +
-				rxm->udata64 - 1) / rxm->udata64;
+	segs = VMXNET3_SEGS_DYNFIELD(rxm);
+	if (segs > 1)
+		return (rte_pktmbuf_pkt_len(rxm) - hlen + segs - 1) / segs;
 	else
 		return hw->mtu - hlen + sizeof(struct rte_ether_hdr);
 }
@@ -737,7 +738,7 @@ vmxnet3_rx_offload(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 					(const Vmxnet3_RxCompDescExt *)rcd;
 
 			rxm->tso_segsz = rcde->mss;
-			rxm->udata64 = rcde->segCnt;
+			VMXNET3_SEGS_DYNFIELD(rxm) = rcde->segCnt;
 			ol_flags |= PKT_RX_LRO;
 		}
 	} else { /* Offloads set in eop */
Signature · 1 line
2.28.0
#82 lore raw

Re: [dpdk-dev] [PATCH v2 09/15] net/vmxnet3: switch MSS hint to dynamic mbuf field

Quoted 5 lines · Thomas Monjalon

The segment count, used for MSS guess,
was stored in the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

After seeing this commit, I wonder if we shouldn't introduce an enhancement in the dynamic field API.

Previously, the driver used udata64 only internally, so without any risk. The risky usages of udata64 were when the mbuf goes out of a module.

Changing to dynamic field makes the code safe for any use, but consumes more memory.

I wonder if we shouldn't (later) introduce a flag RTE_MBUF_DYN_F_SHARED, or something similar, to say that this field is only used inside a module, and that its memory can be shared with other dynamic fields.

Quoted 98 lines
---
 drivers/net/vmxnet3/vmxnet3_ethdev.c | 15 +++++++++++++++
 drivers/net/vmxnet3/vmxnet3_ethdev.h |  6 ++++++
 drivers/net/vmxnet3/vmxnet3_rxtx.c   |  9 +++++----
 3 files changed, 26 insertions(+), 4 deletions(-)
drivers/net/vmxnet3/vmxnet3_ethdev.c +15 -0
index 6920ab568c..6e99b67b5a 100644
@@ -59,6 +59,8 @@
 	 DEV_RX_OFFLOAD_JUMBO_FRAME |   \
 	 DEV_RX_OFFLOAD_RSS_HASH)
 
+int vmxnet3_segs_dynfield_offset;
+
 static int eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev);
 static int eth_vmxnet3_dev_uninit(struct rte_eth_dev *eth_dev);
 static int vmxnet3_dev_configure(struct rte_eth_dev *dev);
@@ -233,6 +235,11 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	struct vmxnet3_hw *hw = eth_dev->data->dev_private;
 	uint32_t mac_hi, mac_lo, ver;
 	struct rte_eth_link link;
+	static const struct rte_mbuf_dynfield vmxnet3_segs_dynfield_desc = {
+		.name = VMXNET3_SEGS_DYNFIELD_NAME,
+		.size = sizeof(VMXNET3_SEGS_DYNFIELD_TYPE),
+		.align = __alignof__(VMXNET3_SEGS_DYNFIELD_TYPE),
+	};
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -242,6 +249,14 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
 	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 
+	/* extra mbuf field is required to guess MSS */
+	vmxnet3_segs_dynfield_offset =
+		rte_mbuf_dynfield_register(&vmxnet3_segs_dynfield_desc);
+	if (vmxnet3_segs_dynfield_offset < 0) {
+		PMD_INIT_LOG(ERR, "Cannot register mbuf field.");
+		return -rte_errno;
+	}
+
 	/*
 	 * for secondary processes, we don't initialize any further as primary
 	 * has already done this work.
drivers/net/vmxnet3/vmxnet3_ethdev.h +6 -0
index dd685b02b7..e35edf07be 100644
@@ -193,4 +193,10 @@ uint16_t vmxnet3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 uint16_t vmxnet3_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 			uint16_t nb_pkts);
 
+extern int vmxnet3_segs_dynfield_offset;
+#define VMXNET3_SEGS_DYNFIELD_NAME "rte_net_vmxnet3_dynfield_segs"
+#define VMXNET3_SEGS_DYNFIELD_TYPE uint8_t
+#define VMXNET3_SEGS_DYNFIELD(mbuf) (*RTE_MBUF_DYNFIELD(rxm, \
+		vmxnet3_segs_dynfield_offset, VMXNET3_SEGS_DYNFIELD_TYPE *))
+
 #endif /* _VMXNET3_ETHDEV_H_ */
drivers/net/vmxnet3/vmxnet3_rxtx.c +5 -4
index e10f9ee870..2b0e2e6f19 100644
@@ -674,6 +674,7 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	struct rte_ipv6_hdr *ipv6_hdr;
 	struct rte_tcp_hdr *tcp_hdr;
 	char *ptr;
+	uint8_t segs;
 
 	RTE_ASSERT(rcd->tcp);
 
@@ -710,9 +711,9 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	tcp_hdr = (struct rte_tcp_hdr *)(ptr + hlen);
 	hlen += (tcp_hdr->data_off & 0xf0) >> 2;
 
-	if (rxm->udata64 > 1)
-		return (rte_pktmbuf_pkt_len(rxm) - hlen +
-				rxm->udata64 - 1) / rxm->udata64;
+	segs = VMXNET3_SEGS_DYNFIELD(rxm);
+	if (segs > 1)
+		return (rte_pktmbuf_pkt_len(rxm) - hlen + segs - 1) / segs;
 	else
 		return hw->mtu - hlen + sizeof(struct rte_ether_hdr);
 }
@@ -737,7 +738,7 @@ vmxnet3_rx_offload(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 					(const Vmxnet3_RxCompDescExt *)rcd;
 
 			rxm->tso_segsz = rcde->mss;
-			rxm->udata64 = rcde->segCnt;
+			VMXNET3_SEGS_DYNFIELD(rxm) = rcde->segCnt;
 			ol_flags |= PKT_RX_LRO;
 		}
 	} else { /* Offloads set in eop */
Signature · 1 line
2.28.0
#83 lore raw

Re: [dpdk-dev] [PATCH v2 09/15] net/vmxnet3: switch MSS hint to dynamic mbuf field

27/10/2020 11:45, Olivier Matz:

Quoted 14 lines · Thomas Monjalon
Quoted 5 lines

The segment count, used for MSS guess,
was stored in the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

After seeing this commit, I wonder if we shouldn't introduce an enhancement in the dynamic field API.

Previously, the driver used udata64 only internally, so without any risk. The risky usages of udata64 were when the mbuf goes out of a module.

Quoted 6 lines

Changing to dynamic field makes the code safe for any use, but consumes more memory.

I wonder if we shouldn't (later) introduce a flag RTE_MBUF_DYN_F_SHARED, or something similar, to say that this field is only used inside a module, and that its memory can be shared with other dynamic fields.

Yes can be a later improvement if the sharing limitations are properly defined.
We can also share some offsets which are used differently in Rx and Tx.

#84 lore raw

PATCH v2 10/15 test/distributor: switch sequence to dynamic mbuf field

In reply to Thomas Monjalon

The test used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 app/test/test_distributor.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
app/test/test_distributor.c +23 -5
index eb889b91d1..4a8bed5ae4 100644
@@ -10,6 +10,7 @@
 #include <rte_errno.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_distributor.h>
 #include <rte_string_fns.h>
 
@@ -17,6 +18,11 @@
 #define BURST 32
 #define BIG_BATCH 1024
 
+static int seq_dynfield_offset;
+#define SEQ_FIELD_TYPE uint32_t
+#define SEQ_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		seq_dynfield_offset, SEQ_FIELD_TYPE *))
+
 struct worker_params {
 	char name[64];
 	struct rte_distributor *dist;
@@ -578,7 +584,7 @@ handle_and_mark_work(void *arg)
 		__atomic_fetch_add(&worker_stats[id].handled_packets, num,
 				__ATOMIC_RELAXED);
 		for (i = 0; i < num; i++)
-			buf[i]->udata64 += id + 1;
+			SEQ_FIELD(buf[i]) += id + 1;
 		num = rte_distributor_get_pkt(db, id,
 				buf, buf, num);
 	}
@@ -631,10 +637,10 @@ sanity_mark_test(struct worker_params *wp, struct rte_mempool *p)
 			<< shift;
 	}
 	/* Assign a sequence number to each packet. The sequence is shifted,
-	 * so that lower bits of the udate64 will hold mark from worker.
+	 * so that lower bits will hold mark from worker.
 	 */
 	for (i = 0; i < buf_count; i++)
-		bufs[i]->udata64 = i << seq_shift;
+		SEQ_FIELD(bufs[i]) = i << seq_shift;
 
 	count = 0;
 	for (i = 0; i < buf_count/burst; i++) {
@@ -660,8 +666,8 @@ sanity_mark_test(struct worker_params *wp, struct rte_mempool *p)
 
 	/* Sort returned packets by sent order (sequence numbers). */
 	for (i = 0; i < buf_count; i++) {
-		seq = returns[i]->udata64 >> seq_shift;
-		id = returns[i]->udata64 - (seq << seq_shift);
+		seq = SEQ_FIELD(returns[i]) >> seq_shift;
+		id = SEQ_FIELD(returns[i]) - (seq << seq_shift);
 		sorted[seq] = id;
 	}
 
@@ -805,6 +811,18 @@ test_distributor(void)
 	static struct rte_mempool *p;
 	int i;
 
+	static const struct rte_mbuf_dynfield seq_dynfield_desc = {
+		.name = "test_distributor_dynfield_seq",
+		.size = sizeof(SEQ_FIELD_TYPE),
+		.align = __alignof__(SEQ_FIELD_TYPE),
+	};
+	seq_dynfield_offset =
+		rte_mbuf_dynfield_register(&seq_dynfield_desc);
+	if (seq_dynfield_offset < 0) {
+		printf("Error registering mbuf field\n");
+		return TEST_FAILED;
+	}
+
 	if (rte_lcore_count() < 2) {
 		printf("Not enough cores for distributor_autotest, expecting at least 2\n");
 		return TEST_SKIPPED;
Signature · 1 line
2.28.0
#85 lore raw

PATCH v2 11/15 test/graph: switch user data to dynamic mbuf field

In reply to Thomas Monjalon

The test used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 app/test/test_graph.c | 94 ++++++++++++++++++++++++++-----------------
 1 file changed, 56 insertions(+), 38 deletions(-)
app/test/test_graph.c +56 -38
index ed69eda997..d6b9e368e0 100644
@@ -12,6 +12,7 @@
 #include <rte_graph.h>
 #include <rte_graph_worker.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_random.h>
 
 #include "test.h"
@@ -39,6 +40,11 @@ static uint16_t test_node3_worker(struct rte_graph *graph,
 #define MBUFF_SIZE 512
 #define MAX_NODES  4
 
+static int graph_dynfield_offset;
+#define GRAPH_FIELD_TYPE uint64_t
+#define GRAPH_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		graph_dynfield_offset, GRAPH_FIELD_TYPE *))
+
 static struct rte_mbuf mbuf[MAX_NODES + 1][MBUFF_SIZE];
 static void *mbuf_p[MAX_NODES + 1][MBUFF_SIZE];
 static rte_graph_t graph_id;
@@ -162,9 +168,9 @@ test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
 	next_stream = rte_node_next_stream_get(graph, node, next, obj_node0);
 	for (i = 0; i < obj_node0; i++) {
 		data = &mbuf[0][i];
-		data->udata64 = ((uint64_t)tm->test_node[0].idx << 32) | i;
+		GRAPH_FIELD(data) = ((uint64_t)tm->test_node[0].idx << 32) | i;
 		if ((i + 1) == obj_node0)
-			data->udata64 |= (1 << 16);
+			GRAPH_FIELD(data) |= (1 << 16);
 		next_stream[i] = &mbuf[0][i];
 	}
 	rte_node_next_stream_put(graph, node, next, obj_node0);
@@ -175,9 +181,9 @@ test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
 	next_stream = rte_node_next_stream_get(graph, node, next, obj_node1);
 	for (i = 0; i < obj_node1; i++) {
 		data = &mbuf[0][obj_node0 + i];
-		data->udata64 = ((uint64_t)tm->test_node[1].idx << 32) | i;
+		GRAPH_FIELD(data) = ((uint64_t)tm->test_node[1].idx << 32) | i;
 		if ((i + 1) == obj_node1)
-			data->udata64 |= (1 << 16);
+			GRAPH_FIELD(data) |= (1 << 16);
 		next_stream[i] = &mbuf[0][obj_node0 + i];
 	}
 
@@ -205,23 +211,23 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 
 		for (i = 0; i < nb_objs; i++) {
 			data = (struct rte_mbuf *)objs[i];
-			if ((data->udata64 >> 32) != tm->test_node[0].idx) {
+			if ((GRAPH_FIELD(data) >> 32) != tm->test_node[0].idx) {
 				printf("Data idx miss match at node 0, expected"
 				       " = %u got = %u\n",
 				       tm->test_node[0].idx,
-				       (uint32_t)(data->udata64 >> 32));
+				       (uint32_t)(GRAPH_FIELD(data) >> 32));
 				goto end;
 			}
 
-			if ((data->udata64 & 0xffff) != (i - count)) {
+			if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 				printf("Expected buff count miss match at "
 				       "node 0\n");
 				goto end;
 			}
 
-			if (data->udata64 & (0x1 << 16))
+			if (GRAPH_FIELD(data) & (0x1 << 16))
 				count = i + 1;
-			if (data->udata64 & (0x1 << 17))
+			if (GRAPH_FIELD(data) & (0x1 << 17))
 				second_pass = 1;
 		}
 
@@ -233,12 +239,12 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node0 = nb_objs * obj_node0 * 0.01;
 		for (i = 0; i < obj_node0; i++) {
 			data = &mbuf[1][i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[1].idx << 32) | i;
 			if ((i + 1) == obj_node0)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 			if (second_pass)
-				data->udata64 |= (1 << 17);
+				GRAPH_FIELD(data) |= (1 << 17);
 		}
 		rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[1][0],
 				 obj_node0);
@@ -246,12 +252,12 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node1 = nb_objs - obj_node0;
 		for (i = 0; i < obj_node1; i++) {
 			data = &mbuf[1][obj_node0 + i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[2].idx << 32) | i;
 			if ((i + 1) == obj_node1)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 			if (second_pass)
-				data->udata64 |= (1 << 17);
+				GRAPH_FIELD(data) |= (1 << 17);
 		}
 		rte_node_enqueue(graph, node, 1, (void **)&mbuf_p[1][obj_node0],
 				 obj_node1);
@@ -285,22 +291,22 @@ test_node1_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	fn_calls[2] += 1;
 	for (i = 0; i < nb_objs; i++) {
 		data = (struct rte_mbuf *)objs[i];
-		if ((data->udata64 >> 32) != tm->test_node[1].idx) {
+		if ((GRAPH_FIELD(data) >> 32) != tm->test_node[1].idx) {
 			printf("Data idx miss match at node 1, expected = %u"
 			       " got = %u\n",
 			       tm->test_node[1].idx,
-			       (uint32_t)(data->udata64 >> 32));
+			       (uint32_t)(GRAPH_FIELD(data) >> 32));
 			goto end;
 		}
 
-		if ((data->udata64 & 0xffff) != (i - count)) {
+		if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 			printf("Expected buff count miss match at node 1\n");
 			goto end;
 		}
 
-		if (data->udata64 & (0x1 << 16))
+		if (GRAPH_FIELD(data) & (0x1 << 16))
 			count = i + 1;
-		if (data->udata64 & (0x1 << 17))
+		if (GRAPH_FIELD(data) & (0x1 << 17))
 			second_pass = 1;
 	}
 
@@ -312,11 +318,11 @@ test_node1_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	obj_node0 = nb_objs;
 	for (i = 0; i < obj_node0; i++) {
 		data = &mbuf[2][i];
-		data->udata64 = ((uint64_t)tm->test_node[2].idx << 32) | i;
+		GRAPH_FIELD(data) = ((uint64_t)tm->test_node[2].idx << 32) | i;
 		if ((i + 1) == obj_node0)
-			data->udata64 |= (1 << 16);
+			GRAPH_FIELD(data) |= (1 << 16);
 		if (second_pass)
-			data->udata64 |= (1 << 17);
+			GRAPH_FIELD(data) |= (1 << 17);
 	}
 	rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[2][0], obj_node0);
 
@@ -339,22 +345,22 @@ test_node2_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	fn_calls[3] += 1;
 	for (i = 0; i < nb_objs; i++) {
 		data = (struct rte_mbuf *)objs[i];
-		if ((data->udata64 >> 32) != tm->test_node[2].idx) {
+		if ((GRAPH_FIELD(data) >> 32) != tm->test_node[2].idx) {
 			printf("Data idx miss match at node 2, expected = %u"
 			       " got = %u\n",
 			       tm->test_node[2].idx,
-			       (uint32_t)(data->udata64 >> 32));
+			       (uint32_t)(GRAPH_FIELD(data) >> 32));
 			goto end;
 		}
 
-		if ((data->udata64 & 0xffff) != (i - count)) {
+		if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 			printf("Expected buff count miss match at node 2\n");
 			goto end;
 		}
 
-		if (data->udata64 & (0x1 << 16))
+		if (GRAPH_FIELD(data) & (0x1 << 16))
 			count = i + 1;
-		if (data->udata64 & (0x1 << 17))
+		if (GRAPH_FIELD(data) & (0x1 << 17))
 			second_pass = 1;
 	}
 
@@ -367,10 +373,10 @@ test_node2_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node0 = nb_objs;
 		for (i = 0; i < obj_node0; i++) {
 			data = &mbuf[3][i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[3].idx << 32) | i;
 			if ((i + 1) == obj_node0)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 		}
 		rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[3][0],
 				 obj_node0);
@@ -395,22 +401,22 @@ test_node3_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	fn_calls[4] += 1;
 	for (i = 0; i < nb_objs; i++) {
 		data = (struct rte_mbuf *)objs[i];
-		if ((data->udata64 >> 32) != tm->test_node[3].idx) {
+		if ((GRAPH_FIELD(data) >> 32) != tm->test_node[3].idx) {
 			printf("Data idx miss match at node 3, expected = %u"
 			       " got = %u\n",
 			       tm->test_node[3].idx,
-			       (uint32_t)(data->udata64 >> 32));
+			       (uint32_t)(GRAPH_FIELD(data) >> 32));
 			goto end;
 		}
 
-		if ((data->udata64 & 0xffff) != (i - count)) {
+		if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 			printf("Expected buff count miss match at node 3\n");
 			goto end;
 		}
 
-		if (data->udata64 & (0x1 << 16))
+		if (GRAPH_FIELD(data) & (0x1 << 16))
 			count = i + 1;
-		if (data->udata64 & (0x1 << 17))
+		if (GRAPH_FIELD(data) & (0x1 << 17))
 			second_pass = 1;
 	}
 
@@ -426,11 +432,11 @@ test_node3_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node0 = nb_objs * 2;
 		for (i = 0; i < obj_node0; i++) {
 			data = &mbuf[4][i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[0].idx << 32) | i;
-			data->udata64 |= (1 << 17);
+			GRAPH_FIELD(data) |= (1 << 17);
 			if ((i + 1) == obj_node0)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 		}
 		rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[4][0],
 				 obj_node0);
@@ -765,6 +771,18 @@ graph_setup(void)
 {
 	int i, j;
 
+	static const struct rte_mbuf_dynfield graph_dynfield_desc = {
+		.name = "test_graph_dynfield",
+		.size = sizeof(GRAPH_FIELD_TYPE),
+		.align = __alignof__(GRAPH_FIELD_TYPE),
+	};
+	graph_dynfield_offset =
+		rte_mbuf_dynfield_register(&graph_dynfield_desc);
+	if (graph_dynfield_offset < 0) {
+		printf("Cannot register mbuf field\n");
+		return TEST_FAILED;
+	}
+
 	for (i = 0; i <= MAX_NODES; i++) {
 		for (j = 0; j < MBUFF_SIZE; j++)
 			mbuf_p[i][j] = &mbuf[i][j];
Signature · 1 line
2.28.0
#86 lore raw

PATCH v2 12/15 app/eventdev: switch flow ID to dynamic mbuf field

In reply to Thomas Monjalon

The order test stored the flow ID in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 app/test-eventdev/test_order_atq.c    |  4 ++--
 app/test-eventdev/test_order_common.c | 16 +++++++++++++++-
 app/test-eventdev/test_order_common.h |  6 ++++++
 app/test-eventdev/test_order_queue.c  |  4 ++--
 4 files changed, 25 insertions(+), 5 deletions(-)
app/test-eventdev/test_order_atq.c +2 -2
index cfcb1dc4e9..4087c26fc5 100644
@@ -35,7 +35,7 @@ order_atq_worker(void *arg, const bool flow_id_cap)
 		}
 
 		if (!flow_id_cap)
-			ev.flow_id = ev.mbuf->udata64;
+			ev.flow_id = FLOW_ID(ev.mbuf);
 
 		if (ev.sub_event_type == 0) { /* stage 0 from producer */
 			order_atq_process_stage_0(&ev);
@@ -72,7 +72,7 @@ order_atq_worker_burst(void *arg, const bool flow_id_cap)
 
 		for (i = 0; i < nb_rx; i++) {
 			if (!flow_id_cap)
-				ev[i].flow_id = ev[i].mbuf->udata64;
+				ev[i].flow_id = FLOW_ID(ev[i].mbuf);
 
 			if (ev[i].sub_event_type == 0) { /*stage 0 */
 				order_atq_process_stage_0(&ev[i]);
app/test-eventdev/test_order_common.c +15 -1
index dc55d93921..3721dbabd9 100644
@@ -4,6 +4,8 @@
 
 #include "test_order_common.h"
 
+int flow_id_dynfield_offset;
+
 int
 order_test_result(struct evt_test *test, struct evt_options *opt)
 {
@@ -49,7 +51,7 @@ order_producer(void *arg)
 		const uint32_t flow = (uintptr_t)m % nb_flows;
 		/* Maintain seq number per flow */
 		m->seqn = producer_flow_seq[flow]++;
-		m->udata64 = flow;
+		FLOW_ID(m) = flow;
 
 		ev.flow_id = flow;
 		ev.mbuf = m;
@@ -139,6 +141,18 @@ order_test_setup(struct evt_test *test, struct evt_options *opt)
 {
 	void *test_order;
 
+	static const struct rte_mbuf_dynfield flow_id_dynfield_desc = {
+		.name = "test_event_dynfield_flow_id",
+		.size = sizeof(FLOW_ID_TYPE),
+		.align = __alignof__(FLOW_ID_TYPE),
+	};
+	flow_id_dynfield_offset =
+		rte_mbuf_dynfield_register(&flow_id_dynfield_desc);
+	if (flow_id_dynfield_offset < 0) {
+		evt_err("failed to register mbuf field");
+		return -rte_errno;
+	}
+
 	test_order = rte_zmalloc_socket(test->name, sizeof(struct test_order),
 				RTE_CACHE_LINE_SIZE, opt->socket_id);
 	if (test_order  == NULL) {
app/test-eventdev/test_order_common.h +6 -0
index e0fe9c968a..e384856710 100644
@@ -13,6 +13,7 @@
 #include <rte_lcore.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 #include "evt_common.h"
 #include "evt_options.h"
@@ -20,6 +21,11 @@
 
 #define BURST_SIZE 16
 
+extern int flow_id_dynfield_offset;
+#define FLOW_ID_TYPE uint32_t
+#define FLOW_ID(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		flow_id_dynfield_offset, FLOW_ID_TYPE *))
+
 struct test_order;
 
 struct worker_data {
app/test-eventdev/test_order_queue.c +2 -2
index 1511c0092d..80c9c24af5 100644
@@ -35,7 +35,7 @@ order_queue_worker(void *arg, const bool flow_id_cap)
 		}
 
 		if (!flow_id_cap)
-			ev.flow_id = ev.mbuf->udata64;
+			ev.flow_id = FLOW_ID(ev.mbuf);
 
 		if (ev.queue_id == 0) { /* from ordered queue */
 			order_queue_process_stage_0(&ev);
@@ -73,7 +73,7 @@ order_queue_worker_burst(void *arg, const bool flow_id_cap)
 		for (i = 0; i < nb_rx; i++) {
 
 			if (!flow_id_cap)
-				ev[i].flow_id = ev[i].mbuf->udata64;
+				ev[i].flow_id = FLOW_ID(ev[i].mbuf);
 
 			if (ev[i].queue_id == 0) { /* from ordered queue */
 				order_queue_process_stage_0(&ev[i]);
Signature · 1 line
2.28.0
#87 lore raw

PATCH v2 13/15 examples/bbdev: switch to dynamic mbuf field

In reply to Thomas Monjalon

The example used the deprecated mbuf field udata64 as input mbuf pointer. It is moved to a dynamic field in order to allow removal of udata64.

---
 examples/bbdev_app/main.c | 38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)
examples/bbdev_app/main.c +28 -10
index e512c807cd..e7918264d1 100644
@@ -28,6 +28,7 @@
 #include <rte_lcore.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_memory.h>
 #include <rte_mempool.h>
 #include <rte_log.h>
@@ -59,6 +60,11 @@
 	} \
 } while (0)
 
+static int input_dynfield_offset;
+#define INPUT_FIELD_TYPE struct rte_mbuf *
+#define INPUT_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		input_dynfield_offset, INPUT_FIELD_TYPE *))
+
 static const struct rte_eth_conf port_conf = {
 	.rxmode = {
 		.mq_mode = ETH_MQ_RX_NONE,
@@ -294,11 +300,11 @@ pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int nb_to_free)
 }
 
 static inline void
-pktmbuf_userdata_free_bulk(struct rte_mbuf **mbufs, unsigned int nb_to_free)
+pktmbuf_input_free_bulk(struct rte_mbuf **mbufs, unsigned int nb_to_free)
 {
 	unsigned int i;
 	for (i = 0; i < nb_to_free; ++i) {
-		struct rte_mbuf *rx_pkt = mbufs[i]->userdata;
+		struct rte_mbuf *rx_pkt = INPUT_FIELD(mbufs[i]);
 		rte_pktmbuf_free(rx_pkt);
 		rte_pktmbuf_free(mbufs[i]);
 	}
@@ -429,7 +435,7 @@ verify_data(struct rte_mbuf **mbufs, uint16_t num_pkts)
 	uint16_t i;
 	for (i = 0; i < num_pkts; ++i) {
 		struct rte_mbuf *out = mbufs[i];
-		struct rte_mbuf *in = out->userdata;
+		struct rte_mbuf *in = INPUT_FIELD(out);
 
 		if (memcmp(rte_pktmbuf_mtod_offset(in, uint8_t *,
 				sizeof(struct rte_ether_hdr)),
@@ -731,7 +737,7 @@ run_encoding(struct lcore_conf *lcore_conf)
 				rte_pktmbuf_data_len(rx_pkts_burst[i]) -
 				sizeof(struct rte_ether_hdr);
 		/* save input mbuf pointer for later comparison */
-		enc_out_pkts[i]->userdata = rx_pkts_burst[i];
+		INPUT_FIELD(enc_out_pkts[i]) = rx_pkts_burst[i];
 
 		/* copy ethernet header */
 		rte_pktmbuf_reset(enc_out_pkts[i]);
@@ -775,7 +781,7 @@ run_encoding(struct lcore_conf *lcore_conf)
 	nb_enq = rte_bbdev_enqueue_enc_ops(bbdev_id, enc_queue_id,
 			bbdev_ops_burst, nb_rx);
 	if (unlikely(nb_enq < nb_rx)) {
-		pktmbuf_userdata_free_bulk(&enc_out_pkts[nb_enq],
+		pktmbuf_input_free_bulk(&enc_out_pkts[nb_enq],
 				nb_rx - nb_enq);
 		rte_bbdev_enc_op_free_bulk(&bbdev_ops_burst[nb_enq],
 				nb_rx - nb_enq);
@@ -805,7 +811,7 @@ run_encoding(struct lcore_conf *lcore_conf)
 	nb_sent = rte_ring_enqueue_burst(enc_to_dec_ring, (void **)enc_out_pkts,
 			nb_deq, NULL);
 	if (unlikely(nb_sent < nb_deq)) {
-		pktmbuf_userdata_free_bulk(&enc_out_pkts[nb_sent],
+		pktmbuf_input_free_bulk(&enc_out_pkts[nb_sent],
 				nb_deq - nb_sent);
 		lcore_stats->enc_to_dec_lost_packets += nb_deq - nb_sent;
 	}
@@ -842,7 +848,7 @@ run_decoding(struct lcore_conf *lcore_conf)
 
 	if (unlikely(rte_bbdev_dec_op_alloc_bulk(bbdev_op_pool, bbdev_ops_burst,
 			nb_recv) != 0)) {
-		pktmbuf_userdata_free_bulk(recv_pkts_burst, nb_recv);
+		pktmbuf_input_free_bulk(recv_pkts_burst, nb_recv);
 		lcore_stats->rx_lost_packets += nb_recv;
 		return;
 	}
@@ -871,7 +877,7 @@ run_decoding(struct lcore_conf *lcore_conf)
 	nb_enq = rte_bbdev_enqueue_dec_ops(bbdev_id, bbdev_queue_id,
 			bbdev_ops_burst, nb_recv);
 	if (unlikely(nb_enq < nb_recv)) {
-		pktmbuf_userdata_free_bulk(&recv_pkts_burst[nb_enq],
+		pktmbuf_input_free_bulk(&recv_pkts_burst[nb_enq],
 				nb_recv - nb_enq);
 		rte_bbdev_dec_op_free_bulk(&bbdev_ops_burst[nb_enq],
 				nb_recv - nb_enq);
@@ -898,12 +904,12 @@ run_decoding(struct lcore_conf *lcore_conf)
 
 	/* Free the RX mbufs after verification */
 	for (i = 0; i < nb_deq; ++i)
-		rte_pktmbuf_free(recv_pkts_burst[i]->userdata);
+		rte_pktmbuf_free(INPUT_FIELD(recv_pkts_burst[i]));
 
 	/* Transmit the packets */
 	nb_tx = rte_eth_tx_burst(port_id, tx_queue_id, recv_pkts_burst, nb_deq);
 	if (unlikely(nb_tx < nb_deq)) {
-		pktmbuf_userdata_free_bulk(&recv_pkts_burst[nb_tx],
+		pktmbuf_input_free_bulk(&recv_pkts_burst[nb_tx],
 				nb_deq - nb_tx);
 		lcore_stats->tx_lost_packets += nb_deq - nb_tx;
 	}
@@ -1046,6 +1052,12 @@ main(int argc, char **argv)
 	bool stats_thread_started = false;
 	unsigned int main_lcore_id = rte_get_main_lcore();
 
+	static const struct rte_mbuf_dynfield input_dynfield_desc = {
+		.name = "example_bbdev_dynfield_input",
+		.size = sizeof(INPUT_FIELD_TYPE),
+		.align = __alignof__(INPUT_FIELD_TYPE),
+	};
+
 	rte_atomic16_init(&global_exit_flag);
 
 	sigret = signal(SIGTERM, signal_handler);
@@ -1115,6 +1127,12 @@ main(int argc, char **argv)
 	if (bbdev_mbuf_mempool == NULL)
 		rte_exit(EXIT_FAILURE, "Cannot create ethdev mbuf mempool\n");
 
+	/* register mbuf field to store input pointer */
+	input_dynfield_offset =
+		rte_mbuf_dynfield_register(&input_dynfield_desc);
+	if (input_dynfield_offset < 0)
+		rte_exit(EXIT_FAILURE, "Cannot register mbuf field\n");
+
 	/* initialize ports */
 	ret = initialize_ports(&app_params, ethdev_mbuf_mempool);
 
Signature · 1 line
2.28.0
#88 lore raw

PATCH v2 14/15 examples/rxtx_callbacks: switch to dynamic mbuf field

In reply to Thomas Monjalon

The example used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 doc/guides/sample_app_ug/rxtx_callbacks.rst |  4 ++--
 examples/rxtx_callbacks/main.c              | 20 ++++++++++++++++++--
 2 files changed, 20 insertions(+), 4 deletions(-)
doc/guides/sample_app_ug/rxtx_callbacks.rst +2 -2
index 62d1f39d7e..56c4293a1a 100644
@@ -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;
examples/rxtx_callbacks/main.c +18 -2
index 6fe39546dd..db3412dafe 100644
@@ -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
 
+static int tsc_dynfield_offset;
+#define TSC_FIELD_TYPE uint64_t
+#define TSC_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		tsc_dynfield_offset, TSC_FIELD_TYPE *))
+
 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_FIELD_TYPE),
+		.align = __alignof__(TSC_FIELD_TYPE),
+	};
 
 	/* 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)
Signature · 1 line
2.28.0
#89 lore raw

PATCH v2 15/15 mbuf: remove userdata field

In reply to Thomas Monjalon

As announced in the deprecation note, the field userdata / udata64 is removed to give more space to the dynamic fields.

---
 doc/guides/rel_notes/deprecation.rst   | 1 -
 doc/guides/rel_notes/release_20_11.rst | 3 +++
 lib/librte_kni/rte_kni_common.h        | 3 +--
 lib/librte_mbuf/rte_mbuf_core.h        | 8 +-------
 4 files changed, 5 insertions(+), 10 deletions(-)
doc/guides/rel_notes/deprecation.rst +0 -1
index 2e082499b8..0f6f1df12a 100644
@@ -87,7 +87,6 @@ Deprecation Notices
   The following static fields will be moved as dynamic:
 
   - ``timestamp``
-  - ``userdata`` / ``udata64``
   - ``seqn``
 
   As a consequence, the layout of the ``struct rte_mbuf`` will be re-arranged,
doc/guides/rel_notes/release_20_11.rst +3 -0
index d8ac359e51..3cec526b6a 100644
@@ -426,6 +426,9 @@ API Changes
   the structures ``rte_mbuf`` and ``rte_mbuf_ext_shared_info``.
   The field ``refcnt`` is remaining from the old unions.
 
+* mbuf: Removed the unioned fields ``userdata`` and ``udata64``
+  from the structure ``rte_mbuf``. It is replaced with dynamic fields.
+
 * pci: Removed the ``rte_kernel_driver`` enum defined in rte_dev.h and
   replaced with a private enum in the PCI subsystem.
 
lib/librte_kni/rte_kni_common.h +1 -2
index 21b477f0aa..0db45e6a24 100644
@@ -86,8 +86,7 @@ struct rte_kni_mbuf {
 	uint16_t data_len;      /**< Amount of data in segment buffer. */
 
 	/* fields on second cache line */
-	char pad3[8] __attribute__((__aligned__(RTE_CACHE_LINE_MIN_SIZE)));
-	void *pool;
+	void *pool __attribute__((__aligned__(RTE_CACHE_LINE_MIN_SIZE)));
 	void *next;             /**< Physical address of next mbuf in kernel. */
 };
 
lib/librte_mbuf/rte_mbuf_core.h +1 -7
index 065d87d28a..a65eaaf692 100644
@@ -599,12 +599,6 @@ struct rte_mbuf {
 	/* second cache line - fields only used in slow path or on TX */
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
 
-	RTE_STD_C11
-	union {
-		void *userdata;   /**< Can be used for external metadata */
-		uint64_t udata64; /**< Allow 8-byte userdata on 32-bit */
-	};
-
 	struct rte_mempool *pool; /**< Pool from which mbuf was allocated. */
 	struct rte_mbuf *next;    /**< Next segment of scattered packet. */
 
@@ -662,7 +656,7 @@ struct rte_mbuf {
 	 */
 	struct rte_mbuf_ext_shared_info *shinfo;
 
-	uint64_t dynfield1[2]; /**< Reserved for dynamic fields. */
+	uint64_t dynfield1[3]; /**< Reserved for dynamic fields. */
 } __rte_cache_aligned;
 
 /**
Signature · 1 line
2.28.0
#91 lore raw

v3 cover remove mbuf userdata

In reply to Thomas Monjalon

The mbuf field userdata (aliased as udata64)
was announced to be removed for two reasons:
- applications, libraries and drivers used the same field for different purposes, with a risk of usage conflict.
- this field always used 8 bytes even if unneeded

Some dynamic fields are created when needed to replace the big static userdata field.
As a consequence, 8 bytes can be re-allocated to dynamic fields.

This mbuf layout change is important to allow adding more features (consuming more dynamic fields) during the next year.

v3 (thanks Olivier):
- use typedef for new field types
- fix node field type
- initialize offsets to -1
- add more inline functions
- inline rte_security_dynfield_is_registered
- add PMD-specific userdata field for ARK

v2 (thanks David & Andrew):
- fix some indentations
- return -rte_errno consistently
- make some type casts more precise
- define dynfield types in macros
- hide field description in rte_security
- do not lookup security dynfield in ipsec-secgw
- do not use the existing timestamp field for other purpose

Thomas Monjalon (15):
examples: enclose DPDK includes with angle brackets
kni: move header file from EAL
mbuf: fix typo in dynamic field convention note
node: switch IPv4 metadata to dynamic mbuf field
security: switch metadata to dynamic mbuf field event/sw: switch test counter to dynamic mbuf field net/ark: switch user data to dynamic mbuf field net/bnxt: switch CFA code to dynamic mbuf field net/vmxnet3: switch MSS hint to dynamic mbuf field test/distributor: switch sequence to dynamic mbuf field test/graph: switch user data to dynamic mbuf field app/eventdev: switch flow ID to dynamic mbuf field examples/bbdev: switch to dynamic mbuf field examples/rxtx_callbacks: switch to dynamic mbuf field
mbuf: remove userdata field

 app/test-eventdev/test_order_atq.c            |  4 +-
 app/test-eventdev/test_order_common.c         | 21 ++++-
 app/test-eventdev/test_order_common.h         | 19 ++++
 app/test-eventdev/test_order_queue.c          |  4 +-
 app/test/test_distributor.c                   | 28 +++++-
 app/test/test_graph.c                         | 94 +++++++++++--------
 doc/api/doxy-api-index.md                     |  1 +
 doc/api/doxy-api.conf.in                      |  1 +
 doc/guides/prog_guide/rte_security.rst        |  9 +-
 doc/guides/rel_notes/deprecation.rst          |  1 -
 doc/guides/rel_notes/release_20_11.rst        |  3 +
 doc/guides/sample_app_ug/rxtx_callbacks.rst   |  4 +-
 drivers/crypto/octeontx2/otx2_cryptodev_sec.c |  5 +-
 drivers/event/sw/sw_evdev_selftest.c          | 23 ++++-
 drivers/net/ark/ark_ethdev.c                  | 18 ++++
 drivers/net/ark/ark_ethdev_rx.c               |  3 +-
 drivers/net/ark/ark_ethdev_tx.c               |  3 +-
 drivers/net/ark/rte_pmd_ark.h                 | 56 +++++++++++
 drivers/net/bnxt/bnxt_ethdev.c                | 19 ++++
 drivers/net/bnxt/bnxt_rxr.c                   |  2 +-
 drivers/net/bnxt/bnxt_rxr.h                   |  5 +
 drivers/net/bnxt/rte_pmd_bnxt.h               |  3 +
 drivers/net/ixgbe/ixgbe_ipsec.c               |  5 +-
 drivers/net/ixgbe/ixgbe_rxtx.c                |  6 +-
 drivers/net/octeontx2/otx2_ethdev.h           |  1 +
 drivers/net/octeontx2/otx2_ethdev_sec.c       |  5 +-
 drivers/net/octeontx2/otx2_ethdev_sec_tx.h    |  2 +-
 drivers/net/octeontx2/otx2_rx.h               |  2 +-
 drivers/net/vmxnet3/vmxnet3_ethdev.c          | 15 +++
 drivers/net/vmxnet3/vmxnet3_ethdev.h          |  6 ++
 drivers/net/vmxnet3/vmxnet3_rxtx.c            |  9 +-
 examples/bbdev_app/main.c                     | 79 +++++++++++-----
 examples/bond/main.c                          | 11 +--
 examples/ipsec-secgw/ipsec-secgw.c            |  9 +-
 examples/ipsec-secgw/ipsec_worker.c           | 12 ++-
 examples/rxtx_callbacks/main.c                | 20 +++-
 examples/tep_termination/vxlan_setup.c        |  2 +-
 kernel/linux/kni/meson.build                  |  2 +-
 lib/librte_eal/linux/include/meson.build      |  1 -
 lib/librte_kni/meson.build                    |  2 +-
 .../include => librte_kni}/rte_kni_common.h   |  3 +-
 lib/librte_mbuf/rte_mbuf_core.h               |  8 +-
 lib/librte_mbuf/rte_mbuf_dyn.h                |  2 +-
 lib/librte_node/ip4_lookup.c                  |  7 ++
 lib/librte_node/ip4_rewrite.c                 | 10 ++
 lib/librte_node/node_private.h                | 12 ++-
 lib/librte_security/rte_security.c            | 16 ++++
 lib/librte_security/rte_security.h            | 42 +++++++++
 lib/librte_security/rte_security_driver.h     |  3 +
 lib/librte_security/version.map               |  2 +
 50 files changed, 485 insertions(+), 135 deletions(-)
 create mode 100644 drivers/net/ark/rte_pmd_ark.h
 rename lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h (97%)
Signature · 1 line
2.28.0
#92 lore raw

PATCH v3 1/15 examples: enclose DPDK includes with angle brackets

In examples, DPDK header files are external,
so they must be enclosed with angle brackets, not quotes.

---
 examples/bbdev_app/main.c              | 30 +++++++++++++-------------
 examples/bond/main.c                   | 11 ++++------
 examples/tep_termination/vxlan_setup.c |  2 +-
 3 files changed, 20 insertions(+), 23 deletions(-)
examples/bbdev_app/main.c +15 -15
index 43fe631760..e512c807cd 100644
@@ -18,21 +18,21 @@
 #include <getopt.h>
 #include <signal.h>
 
-#include "rte_atomic.h"
-#include "rte_common.h"
-#include "rte_eal.h"
-#include "rte_cycles.h"
-#include "rte_ether.h"
-#include "rte_ethdev.h"
-#include "rte_ip.h"
-#include "rte_lcore.h"
-#include "rte_malloc.h"
-#include "rte_mbuf.h"
-#include "rte_memory.h"
-#include "rte_mempool.h"
-#include "rte_log.h"
-#include "rte_bbdev.h"
-#include "rte_bbdev_op.h"
+#include <rte_atomic.h>
+#include <rte_common.h>
+#include <rte_eal.h>
+#include <rte_cycles.h>
+#include <rte_ether.h>
+#include <rte_ethdev.h>
+#include <rte_ip.h>
+#include <rte_lcore.h>
+#include <rte_malloc.h>
+#include <rte_mbuf.h>
+#include <rte_memory.h>
+#include <rte_mempool.h>
+#include <rte_log.h>
+#include <rte_bbdev.h>
+#include <rte_bbdev_op.h>
 
 /* LLR values - negative value for '1' bit */
 #define LLR_1_BIT 0x81
examples/bond/main.c +4 -7
index 398553b785..81a6fa976b 100644
@@ -41,6 +41,10 @@
 #include <rte_tcp.h>
 #include <rte_arp.h>
 #include <rte_spinlock.h>
+#include <rte_devargs.h>
+#include <rte_byteorder.h>
+#include <rte_cpuflags.h>
+#include <rte_eth_bond.h>
 
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
@@ -53,13 +57,6 @@
 
 #include "main.h"
 
-#include <rte_devargs.h>
-
-
-#include "rte_byteorder.h"
-#include "rte_cpuflags.h"
-#include "rte_eth_bond.h"
-
 #define RTE_LOGTYPE_DCB RTE_LOGTYPE_USER1
 
 #define NB_MBUF   (1024*8)
examples/tep_termination/vxlan_setup.c +1 -1
index 4b44ccc143..0bcd870b4a 100644
@@ -18,9 +18,9 @@
 #include <rte_ip.h>
 #include <rte_udp.h>
 #include <rte_tcp.h>
+#include <rte_vhost.h>
 
 #include "main.h"
-#include "rte_vhost.h"
 #include "vxlan.h"
 #include "vxlan_setup.h"
 
Signature · 1 line
2.28.0
#93 lore raw

PATCH v3 2/15 kni: move header file from EAL

In reply to Thomas Monjalon

Since the kernel module is not part of EAL anymore, there is no need to have the common KNI header file in EAL. The file rte_kni_common.h is moved to librte_kni.

---
 kernel/linux/kni/meson.build                                  | 2 +-
 lib/librte_eal/linux/include/meson.build                      | 1 -
 lib/librte_kni/meson.build                                    | 2 +-
 lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h | 0
 4 files changed, 2 insertions(+), 3 deletions(-)
 rename lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h (100%)
kernel/linux/kni/meson.build +1 -1
index d696347f22..07e0c9dae7 100644
@@ -18,7 +18,7 @@ custom_target('rte_kni',
 		'src=' + meson.current_source_dir(),
 		'MODULE_CFLAGS=-include ' + meson.source_root() + '/config/rte_config.h' +
 		' -I' + meson.source_root() + '/lib/librte_eal/include' +
-		' -I' + meson.source_root() + '/lib/librte_eal/linux/include' +
+		' -I' + meson.source_root() + '/lib/librte_kni' +
 		' -I' + meson.build_root() +
 		' -I' + meson.current_source_dir(),
 		'modules'],
lib/librte_eal/linux/include/meson.build +0 -1
index 1241894b3c..7d18dd52f1 100644
@@ -4,6 +4,5 @@
 includes += include_directories('.')
 
 headers += files(
-        'rte_kni_common.h',
         'rte_os.h',
 )
lib/librte_kni/meson.build +1 -1
index 963eae6fe0..ad598bb3d0 100644
@@ -6,5 +6,5 @@ if not is_linux or not dpdk_conf.get('RTE_ARCH_64')
 	reason = 'only supported on 64-bit linux'
 endif
 sources = files('rte_kni.c')
-headers = files('rte_kni.h')
+headers = files('rte_kni.h', 'rte_kni_common.h')
 deps += ['ethdev', 'pci']
lib/librte_kni/rte_kni_common.h renamed from lib/librte_eal/linux/include/rte_kni_common.h +0 -0
similarity index 100%
rename from lib/librte_eal/linux/include/rte_kni_common.h
rename to lib/librte_kni/rte_kni_common.h
Signature · 1 line
2.28.0
#94 lore raw

PATCH v3 3/15 mbuf: fix typo in dynamic field convention note

In reply to Thomas Monjalon

Replace "in a in PMD" with "in a PMD".

Fixes 4958ca3a443a ("mbuf: support dynamic fields and flags")
---
 lib/librte_mbuf/rte_mbuf_dyn.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_mbuf/rte_mbuf_dyn.h +1 -1
index 8407230ecf..0ebac88b83 100644
@@ -62,7 +62,7 @@
  * conventions than function names in dpdk:
  * - "rte_mbuf_dynfield_<name>" if defined in mbuf library
  * - "rte_<libname>_dynfield_<name>" if defined in another library
- * - "rte_net_<pmd>_dynfield_<name>" if defined in a in PMD
+ * - "rte_net_<pmd>_dynfield_<name>" if defined in a PMD
  * - any name that does not start with "rte_" in an application
  */
 
Signature · 1 line
2.28.0
#95 lore raw

PATCH v3 4/15 node: switch IPv4 metadata to dynamic mbuf field

In reply to Thomas Monjalon

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

WARNING: this change should be replaced with another solution proposed by Nithin. Waiting for the patch to be integrated.

---
 lib/librte_node/ip4_lookup.c   |  7 +++++++
 lib/librte_node/ip4_rewrite.c  | 10 ++++++++++
 lib/librte_node/node_private.h | 12 ++++++++++--
 3 files changed, 27 insertions(+), 2 deletions(-)
lib/librte_node/ip4_lookup.c +7 -0
index 8835aab9dd..3bd7c179ab 100644
@@ -21,6 +21,8 @@
 
 #include "node_private.h"
 
+int node_mbuf_priv1_dynfield_offset = -1;
+
 #define IPV4_L3FWD_LPM_MAX_RULES 1024
 #define IPV4_L3FWD_LPM_NUMBER_TBL8S (1 << 8)
 
@@ -178,6 +180,11 @@ ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node)
 	RTE_SET_USED(node);
 
 	if (!init_once) {
+		node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+				&node_mbuf_priv1_dynfield_desc);
+		if (node_mbuf_priv1_dynfield_offset < 0)
+			return -rte_errno;
+
 		/* Setup LPM tables for all sockets */
 		RTE_LCORE_FOREACH(lcore_id)
 		{
lib/librte_node/ip4_rewrite.c +10 -0
index bb7f671b5c..1c4e51968c 100644
@@ -248,9 +248,19 @@ ip4_rewrite_node_process(struct rte_graph *graph, struct rte_node *node,
 static int
 ip4_rewrite_node_init(const struct rte_graph *graph, struct rte_node *node)
 {
+	static bool init_once;
 
 	RTE_SET_USED(graph);
 	RTE_SET_USED(node);
+
+	if (!init_once) {
+		node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+				&node_mbuf_priv1_dynfield_desc);
+		if (node_mbuf_priv1_dynfield_offset < 0)
+			return -rte_errno;
+		init_once = true;
+	}
+
 	node_dbg("ip4_rewrite", "Initialized ip4_rewrite node initialized");
 
 	return 0;
lib/librte_node/node_private.h +10 -2
index ab7941c12b..9258082df0 100644
@@ -8,6 +8,7 @@
 #include <rte_common.h>
 #include <rte_log.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 extern int rte_node_logtype;
 #define NODE_LOG(level, node_name, ...)                                        \
@@ -21,7 +22,6 @@ extern int rte_node_logtype;
 #define node_dbg(node_name, ...) NODE_LOG(DEBUG, node_name, __VA_ARGS__)
 
 /**
- *
  * Node mbuf private data to store next hop, ttl and checksum.
  */
 struct node_mbuf_priv1 {
@@ -37,6 +37,13 @@ struct node_mbuf_priv1 {
 	};
 };
 
+static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = {
+	.name = "rte_node_dynfield_priv1",
+	.size = sizeof(struct node_mbuf_priv1),
+	.align = __alignof__(struct node_mbuf_priv1),
+};
+extern int node_mbuf_priv1_dynfield_offset;
+
 /**
  * Node mbuf private area 2.
  */
@@ -60,7 +67,8 @@ struct node_mbuf_priv2 {
 static __rte_always_inline struct node_mbuf_priv1 *
 node_mbuf_priv1(struct rte_mbuf *m)
 {
-	return (struct node_mbuf_priv1 *)&m->udata64;
+	return RTE_MBUF_DYNFIELD(m,
+		node_mbuf_priv1_dynfield_offset, struct node_mbuf_priv1 *);
 }
 
 /**
Signature · 1 line
2.28.0
#96 lore raw

PATCH v3 5/15 security: switch metadata to dynamic mbuf field

In reply to Thomas Monjalon

The device-specific metadata was stored in the deprecated field udata64. It is moved to a dynamic mbuf field in order to allow removal of udata64.

The name rte_security_dynfield is not very descriptive
but it should be replaced later by separate fields for each type of data that drivers pass to the upper layer.

---
 doc/guides/prog_guide/rte_security.rst        |  9 ++--
 drivers/crypto/octeontx2/otx2_cryptodev_sec.c |  5 ++-
 drivers/net/ixgbe/ixgbe_ipsec.c               |  5 ++-
 drivers/net/ixgbe/ixgbe_rxtx.c                |  6 ++-
 drivers/net/octeontx2/otx2_ethdev.h           |  1 +
 drivers/net/octeontx2/otx2_ethdev_sec.c       |  5 ++-
 drivers/net/octeontx2/otx2_ethdev_sec_tx.h    |  2 +-
 drivers/net/octeontx2/otx2_rx.h               |  2 +-
 examples/ipsec-secgw/ipsec-secgw.c            |  9 ++--
 examples/ipsec-secgw/ipsec_worker.c           | 12 ++++--
 lib/librte_security/rte_security.c            | 16 +++++++
 lib/librte_security/rte_security.h            | 42 +++++++++++++++++++
 lib/librte_security/rte_security_driver.h     |  3 ++
 lib/librte_security/version.map               |  2 +
 14 files changed, 99 insertions(+), 20 deletions(-)
doc/guides/prog_guide/rte_security.rst +5 -4
index c64aef3de9..f72bc8a78f 100644
@@ -125,8 +125,9 @@ ESP/AH headers will be removed from the packet and the received packet
 will contains the decrypted packet only. The driver Rx path checks the
 descriptors and based on the crypto status sets additional flags in
 ``rte_mbuf.ol_flags`` field. The driver would also set device-specific
-metadata in ``rte_mbuf.udata64`` field. This will allow the application
-to identify the security processing done on the packet.
+metadata in ``RTE_SECURITY_DYNFIELD_NAME`` field.
+This will allow the application to identify the security processing
+done on the packet.
 
 .. note::
 
@@ -568,8 +569,8 @@ security session which processed the packet.
 
 .. note::
 
-    In case of inline processed packets, ``rte_mbuf.udata64`` field would be
-    used by the driver to relay information on the security processing
+    In case of inline processed packets, ``RTE_SECURITY_DYNFIELD_NAME`` field
+    would be used by the driver to relay information on the security processing
     associated with the packet. In ingress, the driver would set this in Rx
     path while in egress, ``rte_security_set_pkt_metadata()`` would perform a
     similar operation. The application is expected not to modify the field
drivers/crypto/octeontx2/otx2_cryptodev_sec.c +4 -1
index b80ec7bff2..4e2a0e3afe 100644
@@ -455,6 +455,9 @@ otx2_crypto_sec_session_create(void *device,
 	if (conf->action_type != RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL)
 		return -ENOTSUP;
 
+	if (rte_security_dynfield_register() < 0)
+		return -rte_errno;
+
 	if (rte_mempool_get(mempool, (void **)&priv)) {
 		otx2_err("Could not allocate security session private data");
 		return -ENOMEM;
@@ -514,7 +517,7 @@ otx2_crypto_sec_set_pkt_mdata(void *device __rte_unused,
 			      struct rte_mbuf *m, void *params __rte_unused)
 {
 	/* Set security session as the pkt metadata */
-	m->udata64 = (uint64_t)session;
+	*rte_security_dynfield(m) = (rte_security_dynfield_t)session;
 
 	return 0;
 }
drivers/net/ixgbe/ixgbe_ipsec.c +4 -1
index 48f5082d49..62f2a5f764 100644
@@ -484,7 +484,8 @@ ixgbe_crypto_update_mb(void *device __rte_unused,
 			get_sec_session_private_data(session);
 	if (ic_session->op == IXGBE_OP_AUTHENTICATED_ENCRYPTION) {
 		union ixgbe_crypto_tx_desc_md *mdata =
-			(union ixgbe_crypto_tx_desc_md *)&m->udata64;
+			(union ixgbe_crypto_tx_desc_md *)
+				rte_security_dynfield(m);
 		mdata->enc = 1;
 		mdata->sa_idx = ic_session->sa_index;
 		mdata->pad_len = ixgbe_crypto_compute_pad_len(m);
@@ -751,5 +752,7 @@ ixgbe_ipsec_ctx_create(struct rte_eth_dev *dev)
 			return -ENOMEM;
 		}
 	}
+	if (rte_security_dynfield_register() < 0)
+		return -rte_errno;
 	return 0;
 }
drivers/net/ixgbe/ixgbe_rxtx.c +4 -2
index 5f19972031..6cfbb582e2 100644
@@ -34,6 +34,7 @@
 #include <rte_mbuf.h>
 #include <rte_ether.h>
 #include <rte_ethdev_driver.h>
+#include <rte_security_driver.h>
 #include <rte_prefetch.h>
 #include <rte_udp.h>
 #include <rte_tcp.h>
@@ -694,7 +695,7 @@ ixgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 			if (use_ipsec) {
 				union ixgbe_crypto_tx_desc_md *ipsec_mdata =
 					(union ixgbe_crypto_tx_desc_md *)
-							&tx_pkt->udata64;
+						rte_security_dynfield(tx_pkt);
 				tx_offload.sa_idx = ipsec_mdata->sa_idx;
 				tx_offload.sec_pad_len = ipsec_mdata->pad_len;
 			}
@@ -859,7 +860,8 @@ ixgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 				}
 
 				ixgbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req,
-					tx_offload, &tx_pkt->udata64);
+					tx_offload,
+					rte_security_dynfield(tx_pkt));
 
 				txe->last_id = tx_last;
 				tx_id = txe->next_id;
drivers/net/octeontx2/otx2_ethdev.h +1 -0
index b20f399a15..3b9871f4dc 100644
@@ -13,6 +13,7 @@
 #include <rte_kvargs.h>
 #include <rte_mbuf.h>
 #include <rte_mempool.h>
+#include <rte_security_driver.h>
 #include <rte_string_fns.h>
 #include <rte_time.h>
 
drivers/net/octeontx2/otx2_ethdev_sec.c +4 -1
index 4e0dd4e49e..1ee597ff6e 100644
@@ -684,7 +684,7 @@ otx2_eth_sec_set_pkt_mdata(void *device __rte_unused,
 			    struct rte_mbuf *m, void *params __rte_unused)
 {
 	/* Set security session as the pkt metadata */
-	m->udata64 = (uint64_t)session;
+	*rte_security_dynfield(m) = (rte_security_dynfield_t)session;
 
 	return 0;
 }
@@ -831,6 +831,9 @@ otx2_eth_sec_init(struct rte_eth_dev *eth_dev)
 	    !(dev->rx_offloads & DEV_RX_OFFLOAD_SECURITY))
 		return 0;
 
+	if (rte_security_dynfield_register() < 0)
+		return -rte_errno;
+
 	nb_sa = dev->ipsec_in_max_spi;
 	mz_sz = nb_sa * sa_width;
 	in_sa_mz_name_get(name, RTE_MEMZONE_NAMESIZE, port);
drivers/net/octeontx2/otx2_ethdev_sec_tx.h +1 -1
index 5bf8c19995..284bcd5367 100644
@@ -55,7 +55,7 @@ otx2_sec_event_tx(struct otx2_ssogws *ws, struct rte_event *ev,
 		struct nix_iova_s nix_iova;
 	} *sd;
 
-	priv = get_sec_session_private_data((void *)(m->udata64));
+	priv = get_sec_session_private_data((void *)(*rte_security_dynfield(m)));
 	sess = &priv->ipsec.ip;
 	sa = &sess->out_sa;
 
drivers/net/octeontx2/otx2_rx.h +1 -1
index f29a0542f9..61a5c436dd 100644
@@ -241,7 +241,7 @@ nix_rx_sec_mbuf_update(const struct nix_cqe_hdr_s *cq, struct rte_mbuf *m,
 	spi = cq->tag & 0xFFFFF;
 
 	sa = nix_rx_sec_sa_get(lookup_mem, spi, m->port);
-	m->udata64 = (uint64_t)sa->userdata;
+	*rte_security_dynfield(m) = sa->udata64;
 
 	data = rte_pktmbuf_mtod(m, char *);
 
examples/ipsec-secgw/ipsec-secgw.c +4 -5
index 2219148285..bbe7ce48d9 100644
@@ -426,7 +426,8 @@ prepare_one_packet(struct rte_mbuf *pkt, struct ipsec_traffic *t)
 	 * with the security session.
 	 */
 
-	if (pkt->ol_flags & PKT_RX_SEC_OFFLOAD) {
+	if (pkt->ol_flags & PKT_RX_SEC_OFFLOAD &&
+			rte_security_dynfield_is_registered()) {
 		struct ipsec_sa *sa;
 		struct ipsec_mbuf_metadata *priv;
 		struct rte_security_ctx *ctx = (struct rte_security_ctx *)
@@ -436,10 +437,8 @@ prepare_one_packet(struct rte_mbuf *pkt, struct ipsec_traffic *t)
 		/* Retrieve the userdata registered. Here, the userdata
 		 * registered is the SA pointer.
 		 */
-
-		sa = (struct ipsec_sa *)
-				rte_security_get_userdata(ctx, pkt->udata64);
-
+		sa = (struct ipsec_sa *)rte_security_get_userdata(ctx,
+				*rte_security_dynfield(pkt));
 		if (sa == NULL) {
 			/* userdata could not be retrieved */
 			return;
examples/ipsec-secgw/ipsec_worker.c +8 -4
index b6c851f257..647e22df59 100644
@@ -208,7 +208,7 @@ process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt,
 					"Inbound security offload failed\n");
 				goto drop_pkt_and_exit;
 			}
-			sa = pkt->userdata;
+			sa = *(struct ipsec_sa **)rte_security_dynfield(pkt);
 		}
 
 		/* Check if we have a match */
@@ -226,7 +226,7 @@ process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt,
 					"Inbound security offload failed\n");
 				goto drop_pkt_and_exit;
 			}
-			sa = pkt->userdata;
+			sa = *(struct ipsec_sa **)rte_security_dynfield(pkt);
 		}
 
 		/* Check if we have a match */
@@ -357,7 +357,8 @@ process_ipsec_ev_outbound(struct ipsec_ctx *ctx, struct route_table *rt,
 	}
 
 	if (sess->security.ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
-		pkt->userdata = sess->security.ses;
+		*(struct rte_security_session **)rte_security_dynfield(pkt) =
+				sess->security.ses;
 
 	/* Mark the packet for Tx security offload */
 	pkt->ol_flags |= PKT_TX_SEC_OFFLOAD;
@@ -465,7 +466,10 @@ ipsec_wrkr_non_burst_int_port_drv_mode(struct eh_event_link_info *links,
 			}
 
 			/* Save security session */
-			pkt->userdata = sess_tbl[port_id];
+			if (rte_security_dynfield_is_registered())
+				*(struct rte_security_session **)
+					rte_security_dynfield(pkt) =
+						sess_tbl[port_id];
 
 			/* Mark the packet for Tx security offload */
 			pkt->ol_flags |= PKT_TX_SEC_OFFLOAD;
lib/librte_security/rte_security.c +16 -0
index ee4666026a..e8116d5447 100644
@@ -23,6 +23,22 @@
 	RTE_PTR_OR_ERR_RET(p1->p2->p3, last_retval);			\
 } while (0)
 
+#define RTE_SECURITY_DYNFIELD_NAME "rte_security_dynfield_metadata"
+int rte_security_dynfield_offset = -1;
+
+int
+rte_security_dynfield_register(void)
+{
+	static const struct rte_mbuf_dynfield dynfield_desc = {
+		.name = RTE_SECURITY_DYNFIELD_NAME,
+		.size = sizeof(rte_security_dynfield_t),
+		.align = __alignof__(rte_security_dynfield_t),
+	};
+	rte_security_dynfield_offset =
+		rte_mbuf_dynfield_register(&dynfield_desc);
+	return rte_security_dynfield_offset;
+}
+
 struct rte_security_session *
 rte_security_session_create(struct rte_security_ctx *instance,
 			    struct rte_security_session_conf *conf,
lib/librte_security/rte_security.h +42 -0

54 lines not on this page · raw message

lib/librte_security/rte_security_driver.h +3 -0
index 1b561f8528..c5abb07990 100644
@@ -89,6 +89,9 @@ typedef int (*security_session_stats_get_t)(void *device,
 		struct rte_security_session *sess,
 		struct rte_security_stats *stats);
 
+__rte_experimental
+int rte_security_dynfield_register(void);
+
 /**
  * Update the mbuf with provided metadata.
  *
lib/librte_security/version.map +2 -0
index d84eec0a88..22775558c8 100644
@@ -15,6 +15,8 @@ DPDK_21 {
 EXPERIMENTAL {
 	global:
 
+	rte_security_dynfield_offset;
+	rte_security_dynfield_register;
 	rte_security_get_userdata;
 	rte_security_session_stats_get;
 	rte_security_session_update;
Signature · 1 line
2.28.0
#97 lore raw

PATCH v3 6/15 event/sw: switch test counter to dynamic mbuf field

In reply to Thomas Monjalon

The test worker_loopback used the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 drivers/event/sw/sw_evdev_selftest.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/event/sw/sw_evdev_selftest.c +20 -3
index 5c7e527917..ad4fc0eed7 100644
@@ -40,6 +40,11 @@ struct test {
 	uint32_t service_id;
 };
 
+typedef uint8_t counter_dynfield_t;
+static int counter_dynfield_offset = -1;
+#define COUNTER_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		counter_dynfield_offset, counter_dynfield_t *))
+
 static struct rte_event release_ev;
 
 static inline struct rte_mbuf *
@@ -2987,8 +2992,8 @@ worker_loopback_worker_fn(void *arg)
 			}
 
 			ev[i].queue_id = 0;
-			ev[i].mbuf->udata64++;
-			if (ev[i].mbuf->udata64 != 16) {
+			COUNTER_FIELD(ev[i].mbuf)++;
+			if (COUNTER_FIELD(ev[i].mbuf) != 16) {
 				ev[i].op = RTE_EVENT_OP_FORWARD;
 				enqd = rte_event_enqueue_burst(evdev, port,
 						&ev[i], 1);
@@ -3028,7 +3033,7 @@ worker_loopback_producer_fn(void *arg)
 			m = rte_pktmbuf_alloc(t->mbuf_pool);
 		} while (m == NULL);
 
-		m->udata64 = 0;
+		COUNTER_FIELD(m) = 0;
 
 		struct rte_event ev = {
 				.op = RTE_EVENT_OP_NEW,
@@ -3061,6 +3066,18 @@ worker_loopback(struct test *t, uint8_t disable_implicit_release)
 	int err;
 	int w_lcore, p_lcore;
 
+	static const struct rte_mbuf_dynfield counter_dynfield_desc = {
+		.name = "rte_event_sw_dynfield_selftest_counter",
+		.size = sizeof(counter_dynfield_t),
+		.align = __alignof__(counter_dynfield_t),
+	};
+	counter_dynfield_offset =
+		rte_mbuf_dynfield_register(&counter_dynfield_desc);
+	if (counter_dynfield_offset < 0) {
+		printf("Error registering mbuf field\n");
+		return -rte_errno;
+	}
+
 	if (init(t, 8, 2) < 0 ||
 			create_atomic_qids(t, 8) < 0) {
 		printf("%d: Error initializing device\n", __LINE__);
Signature · 1 line
2.28.0
#98 lore raw

PATCH v3 7/15 net/ark: switch user data to dynamic mbuf field

In reply to Thomas Monjalon

The second field of metadata is reserved for user data which was using a deprecated mbuf field.
It is moved to a dynamic field in order to allow removal of udata64.

---
 doc/api/doxy-api-index.md       |  1 +
 doc/api/doxy-api.conf.in        |  1 +
 drivers/net/ark/ark_ethdev.c    | 18 +++++++++++
 drivers/net/ark/ark_ethdev_rx.c |  3 +-
 drivers/net/ark/ark_ethdev_tx.c |  3 +-
 drivers/net/ark/rte_pmd_ark.h   | 56 +++++++++++++++++++++++++++++++++
 6 files changed, 80 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ark/rte_pmd_ark.h
doc/api/doxy-api-index.md +1 -0
index a9c12d1a2f..b865a51e8c 100644
@@ -41,6 +41,7 @@ The public API headers are grouped by topics:
   [vhost]              (@ref rte_vhost.h),
   [vdpa]               (@ref rte_vdpa.h),
   [KNI]                (@ref rte_kni.h),
+  [ark]                (@ref rte_pmd_ark.h),
   [ixgbe]              (@ref rte_pmd_ixgbe.h),
   [i40e]               (@ref rte_pmd_i40e.h),
   [ice]                (@ref rte_pmd_ice.h),
doc/api/doxy-api.conf.in +1 -0
index e37f8c2e80..c5b01a1814 100644
@@ -8,6 +8,7 @@ INPUT                   = @TOPDIR@/doc/api/doxy-api-index.md \
                           @TOPDIR@/drivers/bus/vdev \
                           @TOPDIR@/drivers/crypto/scheduler \
                           @TOPDIR@/drivers/mempool/dpaa2 \
+                          @TOPDIR@/drivers/net/ark \
                           @TOPDIR@/drivers/net/bnxt \
                           @TOPDIR@/drivers/net/bonding \
                           @TOPDIR@/drivers/net/dpaa \
drivers/net/ark/ark_ethdev.c +18 -0
index 168b3659d6..5f19d8d1ea 100644
@@ -10,6 +10,7 @@
 #include <rte_ethdev_pci.h>
 #include <rte_kvargs.h>
 
+#include "rte_pmd_ark.h"
 #include "ark_global.h"
 #include "ark_logs.h"
 #include "ark_ethdev_tx.h"
@@ -78,6 +79,8 @@ static int  eth_ark_set_mtu(struct rte_eth_dev *dev, uint16_t size);
 #define ARK_TX_MAX_QUEUE (4096 * 4)
 #define ARK_TX_MIN_QUEUE (256)
 
+int rte_pmd_ark_userdata_dynfield_offset = -1;
+
 static const char * const valid_arguments[] = {
 	ARK_PKTGEN_ARG,
 	ARK_PKTCHKR_ARG,
@@ -245,6 +248,11 @@ eth_ark_dev_init(struct rte_eth_dev *dev)
 	int ret;
 	int port_count = 1;
 	int p;
+	static const struct rte_mbuf_dynfield ark_userdata_dynfield_desc = {
+		.name = RTE_PMD_ARK_USERDATA_DYNFIELD_NAME,
+		.size = sizeof(rte_pmd_ark_userdata_t),
+		.align = __alignof__(rte_pmd_ark_userdata_t),
+	};
 
 	ark->eth_dev = dev;
 
@@ -254,6 +262,16 @@ eth_ark_dev_init(struct rte_eth_dev *dev)
 	ret = check_for_ext(ark);
 	if (ret)
 		return ret;
+
+	/* Extra mbuf field for user data */
+	rte_pmd_ark_userdata_dynfield_offset =
+		rte_mbuf_dynfield_register(&ark_userdata_dynfield_desc);
+	if (rte_pmd_ark_userdata_dynfield_offset < 0) {
+		ARK_PMD_LOG(ERR,
+				"Failed to register mbuf field for userdata\n");
+		return -rte_errno;
+	}
+
 	pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 	rte_eth_copy_pci_info(dev, pci_dev);
 	dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
drivers/net/ark/ark_ethdev_rx.c +2 -1
index 2f8d05099c..c5788498b3 100644
@@ -4,6 +4,7 @@
 
 #include <unistd.h>
 
+#include "rte_pmd_ark.h"
 #include "ark_ethdev_rx.h"
 #include "ark_global.h"
 #include "ark_logs.h"
@@ -272,7 +273,7 @@ eth_ark_recv_pkts(void *rx_queue,
 		mbuf->pkt_len = meta->pkt_len;
 		mbuf->data_len = meta->pkt_len;
 		mbuf->timestamp = meta->timestamp;
-		mbuf->udata64 = meta->user_data;
+		rte_pmd_ark_mbuf_userdata_set(mbuf, meta->user_data);
 
 		if (ARK_DEBUG_CORE) {	/* debug sanity checks */
 			if ((meta->pkt_len > (1024 * 16)) ||
drivers/net/ark/ark_ethdev_tx.c +2 -1
index a0e35af880..ab488d83f2 100644
@@ -4,6 +4,7 @@
 
 #include <unistd.h>
 
+#include "rte_pmd_ark.h"
 #include "ark_ethdev_tx.h"
 #include "ark_global.h"
 #include "ark_mpu.h"
@@ -70,7 +71,7 @@ eth_ark_tx_meta_from_mbuf(struct ark_tx_meta *meta,
 			  uint8_t flags)
 {
 	meta->physaddr = rte_mbuf_data_iova(mbuf);
-	meta->user1 = (uint32_t)mbuf->udata64;
+	meta->user1 = (uint32_t)rte_pmd_ark_mbuf_userdata_get(mbuf);
 	meta->data_len = rte_pktmbuf_data_len(mbuf);
 	meta->flags = flags;
 }
drivers/net/ark/rte_pmd_ark.h new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.28.0
#99 lore raw

Re: [dpdk-dev] [PATCH v3 07/15] net/ark: switch user data to dynamic mbuf field

27/10/2020 22:01, Thomas Monjalon:

Quoted 5 lines

The second field of metadata is reserved for user data which was using a deprecated mbuf field.
It is moved to a dynamic field in order to allow removal of udata64.

Quoted 8 lines
---
 doc/api/doxy-api-index.md       |  1 +
 doc/api/doxy-api.conf.in        |  1 +
 drivers/net/ark/ark_ethdev.c    | 18 +++++++++++
 drivers/net/ark/ark_ethdev_rx.c |  3 +-
 drivers/net/ark/ark_ethdev_tx.c |  3 +-
 drivers/net/ark/rte_pmd_ark.h   | 56 +++++++++++++++++++++++++++++++++
 6 files changed, 80 insertions(+), 2 deletions(-)

Missing changes (for future v4):

drivers/net/ark/rte_pmd_ark.h +1 -0
@@ -43,6 +43,7 @@ rte_pmd_ark_mbuf_userdata_get(const struct rte_mbuf *mbuf)
  * Write user data to mbuf.
  *
  * @param mbuf Structure to write into.
+ * @param data User data.
  */
 __rte_experimental
 static inline void
drivers/net/ark/version.map +4 -0
@@ -1,3 +1,7 @@
 DPDK_21 {
+       global:
+
+       rte_pmd_ark_userdata_dynfield_offset;
+
        local: *;
 };
#100 lore raw

PATCH v3 8/15 net/bnxt: switch CFA code to dynamic mbuf field

In reply to Thomas Monjalon

The CFA code from mark was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

Note: the new field has 32 bits, smaller than udata64.

---
 drivers/net/bnxt/bnxt_ethdev.c  | 19 +++++++++++++++++++
 drivers/net/bnxt/bnxt_rxr.c     |  2 +-
 drivers/net/bnxt/bnxt_rxr.h     |  5 +++++
 drivers/net/bnxt/rte_pmd_bnxt.h |  3 +++
 4 files changed, 28 insertions(+), 1 deletion(-)
drivers/net/bnxt/bnxt_ethdev.c +19 -0
index 1c7d1b758d..f1350d39da 100644
@@ -31,6 +31,7 @@
 #include "bnxt_nvm_defs.h"
 #include "bnxt_tf_common.h"
 #include "ulp_flow_db.h"
+#include "rte_pmd_bnxt.h"
 
 #define DRV_MODULE_NAME		"bnxt"
 static const char bnxt_version[] =
@@ -163,6 +164,8 @@ static const char *const bnxt_dev_args[] = {
  */
 #define BNXT_DEVARG_REP_FC_F2R_INVALID(rep_fc_f2r)	((rep_fc_f2r) > 1)
 
+int bnxt_cfa_code_dynfield_offset = -1;
+
 /*
  * max_num_kflows must be >= 32
  * and must be a power-of-2 supported value
@@ -6021,6 +6024,22 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev, void *params __rte_unused)
 	    pci_dev->id.device_id == BROADCOM_DEV_ID_58802_VF)
 		bp->flags |= BNXT_FLAG_STINGRAY;
 
+	if (BNXT_TRUFLOW_EN(bp)) {
+		/* extra mbuf field is required to store CFA code from mark */
+		static const struct rte_mbuf_dynfield bnxt_cfa_code_dynfield_desc = {
+			.name = RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME,
+			.size = sizeof(bnxt_cfa_code_dynfield_t),
+			.align = __alignof__(bnxt_cfa_code_dynfield_t),
+		};
+		bnxt_cfa_code_dynfield_offset =
+			rte_mbuf_dynfield_register(&bnxt_cfa_code_dynfield_desc);
+		if (bnxt_cfa_code_dynfield_offset < 0) {
+			PMD_DRV_LOG(ERR,
+			    "Failed to register mbuf field for TruFlow mark\n");
+			return -rte_errno;
+		}
+	}
+
 	rc = bnxt_init_board(eth_dev);
 	if (rc) {
 		PMD_DRV_LOG(ERR,
drivers/net/bnxt/bnxt_rxr.c +1 -1
index 039217fa60..7156ce7dd8 100644
@@ -606,7 +606,7 @@ bnxt_ulp_set_mark_in_mbuf(struct bnxt *bp, struct rx_pkt_cmpl_hi *rxcmp1,
 			return mark_id;
 		/* Got the mark, write it to the mbuf and return */
 		mbuf->hash.fdir.hi = mark_id;
-		mbuf->udata64 = (cfa_code & 0xffffffffull) << 32;
+		BNXT_CFA_CODE_DYNFIELD(mbuf) = cfa_code & 0xffffffffull;
 		mbuf->hash.fdir.id = rxcmp1->cfa_code;
 		mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
 		return mark_id;
drivers/net/bnxt/bnxt_rxr.h +5 -0
index b874e54a8c..2d16a551ce 100644
@@ -95,6 +95,11 @@ void bnxt_set_mark_in_mbuf(struct bnxt *bp,
 			   struct rx_pkt_cmpl_hi *rxcmp1,
 			   struct rte_mbuf *mbuf);
 
+typedef uint32_t bnxt_cfa_code_dynfield_t;
+extern int bnxt_cfa_code_dynfield_offset;
+#define BNXT_CFA_CODE_DYNFIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		bnxt_cfa_code_dynfield_offset, bnxt_cfa_code_dynfield_t *))
+
 #define BNXT_RX_META_CFA_CODE_SHIFT		19
 #define BNXT_CFA_CODE_META_SHIFT		16
 #define BNXT_RX_META_CFA_CODE_INT_ACT_REC_BIT	0x8000000
drivers/net/bnxt/rte_pmd_bnxt.h +3 -0
index 81d0d0e032..f538b6550e 100644
@@ -9,6 +9,9 @@
 #include <rte_ethdev.h>
 #include <rte_ether.h>
 
+/** mbuf dynamic field where CFA code is stored */
+#define RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME "rte_net_bnxt_dynfield_cfa_code"
+
 /*
  * Response sent back to the caller after callback
  */
Signature · 1 line
2.28.0
#101 lore raw

PATCH v3 9/15 net/vmxnet3: switch MSS hint to dynamic mbuf field

In reply to Thomas Monjalon

The segment count, used for MSS guess,
was stored in the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 drivers/net/vmxnet3/vmxnet3_ethdev.c | 15 +++++++++++++++
 drivers/net/vmxnet3/vmxnet3_ethdev.h |  6 ++++++
 drivers/net/vmxnet3/vmxnet3_rxtx.c   |  9 +++++----
 3 files changed, 26 insertions(+), 4 deletions(-)
drivers/net/vmxnet3/vmxnet3_ethdev.c +15 -0
index 6920ab568c..23a2ebbefa 100644
@@ -59,6 +59,8 @@
 	 DEV_RX_OFFLOAD_JUMBO_FRAME |   \
 	 DEV_RX_OFFLOAD_RSS_HASH)
 
+int vmxnet3_segs_dynfield_offset = -1;
+
 static int eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev);
 static int eth_vmxnet3_dev_uninit(struct rte_eth_dev *eth_dev);
 static int vmxnet3_dev_configure(struct rte_eth_dev *dev);
@@ -233,6 +235,11 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	struct vmxnet3_hw *hw = eth_dev->data->dev_private;
 	uint32_t mac_hi, mac_lo, ver;
 	struct rte_eth_link link;
+	static const struct rte_mbuf_dynfield vmxnet3_segs_dynfield_desc = {
+		.name = VMXNET3_SEGS_DYNFIELD_NAME,
+		.size = sizeof(vmxnet3_segs_dynfield_t),
+		.align = __alignof__(vmxnet3_segs_dynfield_t),
+	};
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -242,6 +249,14 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
 	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 
+	/* extra mbuf field is required to guess MSS */
+	vmxnet3_segs_dynfield_offset =
+		rte_mbuf_dynfield_register(&vmxnet3_segs_dynfield_desc);
+	if (vmxnet3_segs_dynfield_offset < 0) {
+		PMD_INIT_LOG(ERR, "Cannot register mbuf field.");
+		return -rte_errno;
+	}
+
 	/*
 	 * for secondary processes, we don't initialize any further as primary
 	 * has already done this work.
drivers/net/vmxnet3/vmxnet3_ethdev.h +6 -0
index dd685b02b7..e19718ce64 100644
@@ -193,4 +193,10 @@ uint16_t vmxnet3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 uint16_t vmxnet3_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 			uint16_t nb_pkts);
 
+#define VMXNET3_SEGS_DYNFIELD_NAME "rte_net_vmxnet3_dynfield_segs"
+typedef uint8_t vmxnet3_segs_dynfield_t;
+extern int vmxnet3_segs_dynfield_offset;
+#define VMXNET3_SEGS_DYNFIELD(mbuf) (*RTE_MBUF_DYNFIELD(rxm, \
+		vmxnet3_segs_dynfield_offset, vmxnet3_segs_dynfield_t *))
+
 #endif /* _VMXNET3_ETHDEV_H_ */
drivers/net/vmxnet3/vmxnet3_rxtx.c +5 -4
index e10f9ee870..2b0e2e6f19 100644
@@ -674,6 +674,7 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	struct rte_ipv6_hdr *ipv6_hdr;
 	struct rte_tcp_hdr *tcp_hdr;
 	char *ptr;
+	uint8_t segs;
 
 	RTE_ASSERT(rcd->tcp);
 
@@ -710,9 +711,9 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	tcp_hdr = (struct rte_tcp_hdr *)(ptr + hlen);
 	hlen += (tcp_hdr->data_off & 0xf0) >> 2;
 
-	if (rxm->udata64 > 1)
-		return (rte_pktmbuf_pkt_len(rxm) - hlen +
-				rxm->udata64 - 1) / rxm->udata64;
+	segs = VMXNET3_SEGS_DYNFIELD(rxm);
+	if (segs > 1)
+		return (rte_pktmbuf_pkt_len(rxm) - hlen + segs - 1) / segs;
 	else
 		return hw->mtu - hlen + sizeof(struct rte_ether_hdr);
 }
@@ -737,7 +738,7 @@ vmxnet3_rx_offload(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 					(const Vmxnet3_RxCompDescExt *)rcd;
 
 			rxm->tso_segsz = rcde->mss;
-			rxm->udata64 = rcde->segCnt;
+			VMXNET3_SEGS_DYNFIELD(rxm) = rcde->segCnt;
 			ol_flags |= PKT_RX_LRO;
 		}
 	} else { /* Offloads set in eop */
Signature · 1 line
2.28.0
#102 lore raw

PATCH v3 10/15 test/distributor: switch sequence to dynamic mbuf field

In reply to Thomas Monjalon

The test used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 app/test/test_distributor.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
app/test/test_distributor.c +23 -5
index eb889b91d1..24ee824eef 100644
@@ -10,6 +10,7 @@
 #include <rte_errno.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_distributor.h>
 #include <rte_string_fns.h>
 
@@ -17,6 +18,11 @@
 #define BURST 32
 #define BIG_BATCH 1024
 
+typedef uint32_t seq_dynfield_t;
+static int seq_dynfield_offset = -1;
+#define SEQ_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		seq_dynfield_offset, seq_dynfield_t *))
+
 struct worker_params {
 	char name[64];
 	struct rte_distributor *dist;
@@ -578,7 +584,7 @@ handle_and_mark_work(void *arg)
 		__atomic_fetch_add(&worker_stats[id].handled_packets, num,
 				__ATOMIC_RELAXED);
 		for (i = 0; i < num; i++)
-			buf[i]->udata64 += id + 1;
+			SEQ_FIELD(buf[i]) += id + 1;
 		num = rte_distributor_get_pkt(db, id,
 				buf, buf, num);
 	}
@@ -631,10 +637,10 @@ sanity_mark_test(struct worker_params *wp, struct rte_mempool *p)
 			<< shift;
 	}
 	/* Assign a sequence number to each packet. The sequence is shifted,
-	 * so that lower bits of the udate64 will hold mark from worker.
+	 * so that lower bits will hold mark from worker.
 	 */
 	for (i = 0; i < buf_count; i++)
-		bufs[i]->udata64 = i << seq_shift;
+		SEQ_FIELD(bufs[i]) = i << seq_shift;
 
 	count = 0;
 	for (i = 0; i < buf_count/burst; i++) {
@@ -660,8 +666,8 @@ sanity_mark_test(struct worker_params *wp, struct rte_mempool *p)
 
 	/* Sort returned packets by sent order (sequence numbers). */
 	for (i = 0; i < buf_count; i++) {
-		seq = returns[i]->udata64 >> seq_shift;
-		id = returns[i]->udata64 - (seq << seq_shift);
+		seq = SEQ_FIELD(returns[i]) >> seq_shift;
+		id = SEQ_FIELD(returns[i]) - (seq << seq_shift);
 		sorted[seq] = id;
 	}
 
@@ -805,6 +811,18 @@ test_distributor(void)
 	static struct rte_mempool *p;
 	int i;
 
+	static const struct rte_mbuf_dynfield seq_dynfield_desc = {
+		.name = "test_distributor_dynfield_seq",
+		.size = sizeof(seq_dynfield_t),
+		.align = __alignof__(seq_dynfield_t),
+	};
+	seq_dynfield_offset =
+		rte_mbuf_dynfield_register(&seq_dynfield_desc);
+	if (seq_dynfield_offset < 0) {
+		printf("Error registering mbuf field\n");
+		return TEST_FAILED;
+	}
+
 	if (rte_lcore_count() < 2) {
 		printf("Not enough cores for distributor_autotest, expecting at least 2\n");
 		return TEST_SKIPPED;
Signature · 1 line
2.28.0
#103 lore raw

PATCH v3 11/15 test/graph: switch user data to dynamic mbuf field

In reply to Thomas Monjalon

The test used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 app/test/test_graph.c | 94 ++++++++++++++++++++++++++-----------------
 1 file changed, 56 insertions(+), 38 deletions(-)
app/test/test_graph.c +56 -38
index ed69eda997..164486911f 100644
@@ -12,6 +12,7 @@
 #include <rte_graph.h>
 #include <rte_graph_worker.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_random.h>
 
 #include "test.h"
@@ -39,6 +40,11 @@ static uint16_t test_node3_worker(struct rte_graph *graph,
 #define MBUFF_SIZE 512
 #define MAX_NODES  4
 
+typedef uint64_t graph_dynfield_t;
+static int graph_dynfield_offset = -1;
+#define GRAPH_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		graph_dynfield_offset, graph_dynfield_t *))
+
 static struct rte_mbuf mbuf[MAX_NODES + 1][MBUFF_SIZE];
 static void *mbuf_p[MAX_NODES + 1][MBUFF_SIZE];
 static rte_graph_t graph_id;
@@ -162,9 +168,9 @@ test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
 	next_stream = rte_node_next_stream_get(graph, node, next, obj_node0);
 	for (i = 0; i < obj_node0; i++) {
 		data = &mbuf[0][i];
-		data->udata64 = ((uint64_t)tm->test_node[0].idx << 32) | i;
+		GRAPH_FIELD(data) = ((uint64_t)tm->test_node[0].idx << 32) | i;
 		if ((i + 1) == obj_node0)
-			data->udata64 |= (1 << 16);
+			GRAPH_FIELD(data) |= (1 << 16);
 		next_stream[i] = &mbuf[0][i];
 	}
 	rte_node_next_stream_put(graph, node, next, obj_node0);
@@ -175,9 +181,9 @@ test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
 	next_stream = rte_node_next_stream_get(graph, node, next, obj_node1);
 	for (i = 0; i < obj_node1; i++) {
 		data = &mbuf[0][obj_node0 + i];
-		data->udata64 = ((uint64_t)tm->test_node[1].idx << 32) | i;
+		GRAPH_FIELD(data) = ((uint64_t)tm->test_node[1].idx << 32) | i;
 		if ((i + 1) == obj_node1)
-			data->udata64 |= (1 << 16);
+			GRAPH_FIELD(data) |= (1 << 16);
 		next_stream[i] = &mbuf[0][obj_node0 + i];
 	}
 
@@ -205,23 +211,23 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 
 		for (i = 0; i < nb_objs; i++) {
 			data = (struct rte_mbuf *)objs[i];
-			if ((data->udata64 >> 32) != tm->test_node[0].idx) {
+			if ((GRAPH_FIELD(data) >> 32) != tm->test_node[0].idx) {
 				printf("Data idx miss match at node 0, expected"
 				       " = %u got = %u\n",
 				       tm->test_node[0].idx,
-				       (uint32_t)(data->udata64 >> 32));
+				       (uint32_t)(GRAPH_FIELD(data) >> 32));
 				goto end;
 			}
 
-			if ((data->udata64 & 0xffff) != (i - count)) {
+			if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 				printf("Expected buff count miss match at "
 				       "node 0\n");
 				goto end;
 			}
 
-			if (data->udata64 & (0x1 << 16))
+			if (GRAPH_FIELD(data) & (0x1 << 16))
 				count = i + 1;
-			if (data->udata64 & (0x1 << 17))
+			if (GRAPH_FIELD(data) & (0x1 << 17))
 				second_pass = 1;
 		}
 
@@ -233,12 +239,12 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node0 = nb_objs * obj_node0 * 0.01;
 		for (i = 0; i < obj_node0; i++) {
 			data = &mbuf[1][i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[1].idx << 32) | i;
 			if ((i + 1) == obj_node0)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 			if (second_pass)
-				data->udata64 |= (1 << 17);
+				GRAPH_FIELD(data) |= (1 << 17);
 		}
 		rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[1][0],
 				 obj_node0);
@@ -246,12 +252,12 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node1 = nb_objs - obj_node0;
 		for (i = 0; i < obj_node1; i++) {
 			data = &mbuf[1][obj_node0 + i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[2].idx << 32) | i;
 			if ((i + 1) == obj_node1)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 			if (second_pass)
-				data->udata64 |= (1 << 17);
+				GRAPH_FIELD(data) |= (1 << 17);
 		}
 		rte_node_enqueue(graph, node, 1, (void **)&mbuf_p[1][obj_node0],
 				 obj_node1);
@@ -285,22 +291,22 @@ test_node1_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	fn_calls[2] += 1;
 	for (i = 0; i < nb_objs; i++) {
 		data = (struct rte_mbuf *)objs[i];
-		if ((data->udata64 >> 32) != tm->test_node[1].idx) {
+		if ((GRAPH_FIELD(data) >> 32) != tm->test_node[1].idx) {
 			printf("Data idx miss match at node 1, expected = %u"
 			       " got = %u\n",
 			       tm->test_node[1].idx,
-			       (uint32_t)(data->udata64 >> 32));
+			       (uint32_t)(GRAPH_FIELD(data) >> 32));
 			goto end;
 		}
 
-		if ((data->udata64 & 0xffff) != (i - count)) {
+		if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 			printf("Expected buff count miss match at node 1\n");
 			goto end;
 		}
 
-		if (data->udata64 & (0x1 << 16))
+		if (GRAPH_FIELD(data) & (0x1 << 16))
 			count = i + 1;
-		if (data->udata64 & (0x1 << 17))
+		if (GRAPH_FIELD(data) & (0x1 << 17))
 			second_pass = 1;
 	}
 
@@ -312,11 +318,11 @@ test_node1_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	obj_node0 = nb_objs;
 	for (i = 0; i < obj_node0; i++) {
 		data = &mbuf[2][i];
-		data->udata64 = ((uint64_t)tm->test_node[2].idx << 32) | i;
+		GRAPH_FIELD(data) = ((uint64_t)tm->test_node[2].idx << 32) | i;
 		if ((i + 1) == obj_node0)
-			data->udata64 |= (1 << 16);
+			GRAPH_FIELD(data) |= (1 << 16);
 		if (second_pass)
-			data->udata64 |= (1 << 17);
+			GRAPH_FIELD(data) |= (1 << 17);
 	}
 	rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[2][0], obj_node0);
 
@@ -339,22 +345,22 @@ test_node2_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	fn_calls[3] += 1;
 	for (i = 0; i < nb_objs; i++) {
 		data = (struct rte_mbuf *)objs[i];
-		if ((data->udata64 >> 32) != tm->test_node[2].idx) {
+		if ((GRAPH_FIELD(data) >> 32) != tm->test_node[2].idx) {
 			printf("Data idx miss match at node 2, expected = %u"
 			       " got = %u\n",
 			       tm->test_node[2].idx,
-			       (uint32_t)(data->udata64 >> 32));
+			       (uint32_t)(GRAPH_FIELD(data) >> 32));
 			goto end;
 		}
 
-		if ((data->udata64 & 0xffff) != (i - count)) {
+		if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 			printf("Expected buff count miss match at node 2\n");
 			goto end;
 		}
 
-		if (data->udata64 & (0x1 << 16))
+		if (GRAPH_FIELD(data) & (0x1 << 16))
 			count = i + 1;
-		if (data->udata64 & (0x1 << 17))
+		if (GRAPH_FIELD(data) & (0x1 << 17))
 			second_pass = 1;
 	}
 
@@ -367,10 +373,10 @@ test_node2_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node0 = nb_objs;
 		for (i = 0; i < obj_node0; i++) {
 			data = &mbuf[3][i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[3].idx << 32) | i;
 			if ((i + 1) == obj_node0)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 		}
 		rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[3][0],
 				 obj_node0);
@@ -395,22 +401,22 @@ test_node3_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	fn_calls[4] += 1;
 	for (i = 0; i < nb_objs; i++) {
 		data = (struct rte_mbuf *)objs[i];
-		if ((data->udata64 >> 32) != tm->test_node[3].idx) {
+		if ((GRAPH_FIELD(data) >> 32) != tm->test_node[3].idx) {
 			printf("Data idx miss match at node 3, expected = %u"
 			       " got = %u\n",
 			       tm->test_node[3].idx,
-			       (uint32_t)(data->udata64 >> 32));
+			       (uint32_t)(GRAPH_FIELD(data) >> 32));
 			goto end;
 		}
 
-		if ((data->udata64 & 0xffff) != (i - count)) {
+		if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 			printf("Expected buff count miss match at node 3\n");
 			goto end;
 		}
 
-		if (data->udata64 & (0x1 << 16))
+		if (GRAPH_FIELD(data) & (0x1 << 16))
 			count = i + 1;
-		if (data->udata64 & (0x1 << 17))
+		if (GRAPH_FIELD(data) & (0x1 << 17))
 			second_pass = 1;
 	}
 
@@ -426,11 +432,11 @@ test_node3_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node0 = nb_objs * 2;
 		for (i = 0; i < obj_node0; i++) {
 			data = &mbuf[4][i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[0].idx << 32) | i;
-			data->udata64 |= (1 << 17);
+			GRAPH_FIELD(data) |= (1 << 17);
 			if ((i + 1) == obj_node0)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 		}
 		rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[4][0],
 				 obj_node0);
@@ -765,6 +771,18 @@ graph_setup(void)
 {
 	int i, j;
 
+	static const struct rte_mbuf_dynfield graph_dynfield_desc = {
+		.name = "test_graph_dynfield",
+		.size = sizeof(graph_dynfield_t),
+		.align = __alignof__(graph_dynfield_t),
+	};
+	graph_dynfield_offset =
+		rte_mbuf_dynfield_register(&graph_dynfield_desc);
+	if (graph_dynfield_offset < 0) {
+		printf("Cannot register mbuf field\n");
+		return TEST_FAILED;
+	}
+
 	for (i = 0; i <= MAX_NODES; i++) {
 		for (j = 0; j < MBUFF_SIZE; j++)
 			mbuf_p[i][j] = &mbuf[i][j];
Signature · 1 line
2.28.0
#104 lore raw

PATCH v3 12/15 app/eventdev: switch flow ID to dynamic mbuf field

In reply to Thomas Monjalon

The order test stored the flow ID in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 app/test-eventdev/test_order_atq.c    |  4 ++--
 app/test-eventdev/test_order_common.c | 21 ++++++++++++++++-----
 app/test-eventdev/test_order_common.h | 19 +++++++++++++++++++
 app/test-eventdev/test_order_queue.c  |  4 ++--
 4 files changed, 39 insertions(+), 9 deletions(-)
app/test-eventdev/test_order_atq.c +2 -2
index cfcb1dc4e9..b135ac4e55 100644
@@ -35,7 +35,7 @@ order_atq_worker(void *arg, const bool flow_id_cap)
 		}
 
 		if (!flow_id_cap)
-			ev.flow_id = ev.mbuf->udata64;
+			flow_id_copy_from_mbuf(&ev);
 
 		if (ev.sub_event_type == 0) { /* stage 0 from producer */
 			order_atq_process_stage_0(&ev);
@@ -72,7 +72,7 @@ order_atq_worker_burst(void *arg, const bool flow_id_cap)
 
 		for (i = 0; i < nb_rx; i++) {
 			if (!flow_id_cap)
-				ev[i].flow_id = ev[i].mbuf->udata64;
+				flow_id_copy_from_mbuf(&ev[i]);
 
 			if (ev[i].sub_event_type == 0) { /*stage 0 */
 				order_atq_process_stage_0(&ev[i]);
app/test-eventdev/test_order_common.c +16 -5
index dc55d93921..c5f7317440 100644
@@ -4,6 +4,8 @@
 
 #include "test_order_common.h"
 
+int flow_id_dynfield_offset = -1;
+
 int
 order_test_result(struct evt_test *test, struct evt_options *opt)
 {
@@ -46,13 +48,10 @@ order_producer(void *arg)
 		if (m == NULL)
 			continue;
 
-		const uint32_t flow = (uintptr_t)m % nb_flows;
+		const flow_id_t flow = (uintptr_t)m % nb_flows;
 		/* Maintain seq number per flow */
 		m->seqn = producer_flow_seq[flow]++;
-		m->udata64 = flow;
-
-		ev.flow_id = flow;
-		ev.mbuf = m;
+		flow_id_save(flow, m, &ev);
 
 		while (rte_event_enqueue_burst(dev_id, port, &ev, 1) != 1) {
 			if (t->err)
@@ -139,6 +138,18 @@ order_test_setup(struct evt_test *test, struct evt_options *opt)
 {
 	void *test_order;
 
+	static const struct rte_mbuf_dynfield flow_id_dynfield_desc = {
+		.name = "test_event_dynfield_flow_id",
+		.size = sizeof(flow_id_t),
+		.align = __alignof__(flow_id_t),
+	};
+	flow_id_dynfield_offset =
+		rte_mbuf_dynfield_register(&flow_id_dynfield_desc);
+	if (flow_id_dynfield_offset < 0) {
+		evt_err("failed to register mbuf field");
+		return -rte_errno;
+	}
+
 	test_order = rte_zmalloc_socket(test->name, sizeof(struct test_order),
 				RTE_CACHE_LINE_SIZE, opt->socket_id);
 	if (test_order  == NULL) {
app/test-eventdev/test_order_common.h +19 -0
index e0fe9c968a..9e3415e421 100644
@@ -13,6 +13,7 @@
 #include <rte_lcore.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 #include "evt_common.h"
 #include "evt_options.h"
@@ -20,6 +21,24 @@
 
 #define BURST_SIZE 16
 
+typedef uint32_t flow_id_t;
+extern int flow_id_dynfield_offset;
+
+static inline void
+flow_id_copy_from_mbuf(struct rte_event *event)
+{
+	event->flow_id = *RTE_MBUF_DYNFIELD(event->mbuf,
+			flow_id_dynfield_offset, flow_id_t *);
+}
+
+static inline void
+flow_id_save(flow_id_t flow, struct rte_mbuf *mbuf, struct rte_event *event)
+{
+	*RTE_MBUF_DYNFIELD(mbuf, flow_id_dynfield_offset, flow_id_t *) = flow;
+	event->flow_id = flow;
+	event->mbuf = mbuf;
+}
+
 struct test_order;
 
 struct worker_data {
app/test-eventdev/test_order_queue.c +2 -2
index 1511c0092d..42950626c9 100644
@@ -35,7 +35,7 @@ order_queue_worker(void *arg, const bool flow_id_cap)
 		}
 
 		if (!flow_id_cap)
-			ev.flow_id = ev.mbuf->udata64;
+			flow_id_copy_from_mbuf(&ev);
 
 		if (ev.queue_id == 0) { /* from ordered queue */
 			order_queue_process_stage_0(&ev);
@@ -73,7 +73,7 @@ order_queue_worker_burst(void *arg, const bool flow_id_cap)
 		for (i = 0; i < nb_rx; i++) {
 
 			if (!flow_id_cap)
-				ev[i].flow_id = ev[i].mbuf->udata64;
+				flow_id_copy_from_mbuf(&ev[i]);
 
 			if (ev[i].queue_id == 0) { /* from ordered queue */
 				order_queue_process_stage_0(&ev[i]);
Signature · 1 line
2.28.0
#105 lore raw

Re: [dpdk-dev] [PATCH v3 12/15] app/eventdev: switch flow ID to dynamic mbuf field

Quoted 11 lines · Thomas Monjalon

The order test stored the flow ID in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 app/test-eventdev/test_order_atq.c    |  4 ++--
 app/test-eventdev/test_order_common.c | 21 ++++++++++++++++-----
 app/test-eventdev/test_order_common.h | 19 +++++++++++++++++++
 app/test-eventdev/test_order_queue.c  |  4 ++--
 4 files changed, 39 insertions(+), 9 deletions(-)

+ [email protected]

Quoted 28 lines
app/test-eventdev/test_order_atq.c +2 -2
index cfcb1dc4e9..b135ac4e55 100644
@@ -35,7 +35,7 @@ order_atq_worker(void *arg, const bool flow_id_cap)
                }
 
                if (!flow_id_cap)
-                       ev.flow_id = ev.mbuf->udata64;
+                       flow_id_copy_from_mbuf(&ev);
 
                if (ev.sub_event_type == 0) { /* stage 0 from producer */
                        order_atq_process_stage_0(&ev);
@@ -72,7 +72,7 @@ order_atq_worker_burst(void *arg, const bool flow_id_cap)
 
                for (i = 0; i < nb_rx; i++) {
                        if (!flow_id_cap)
-                               ev[i].flow_id = ev[i].mbuf->udata64;
+                               flow_id_copy_from_mbuf(&ev[i]);
 
                        if (ev[i].sub_event_type == 0) { /*stage 0 */
                                order_atq_process_stage_0(&ev[i]);
app/test-eventdev/test_order_common.c +0 -0
index dc55d93921..c5f7317440 100644

app/test-eventdev/test_order_common.c line 7

Quoted 4 lines
app/test-eventdev/test_order_common.c +1 -0
@@ -4,6 +4,8 @@
 
 #include "test_order_common.h"
 
+int flow_id_dynfield_offset = -1;

See below,

Quoted 21 lines
app/test-eventdev/test_order_common.c +3 -5
+
 int
 order_test_result(struct evt_test *test, struct evt_options *opt)
 {
@@ -46,13 +48,10 @@ order_producer(void *arg)
                if (m == NULL)
                        continue;
 
-               const uint32_t flow = (uintptr_t)m % nb_flows;
+               const flow_id_t flow = (uintptr_t)m % nb_flows;
                /* Maintain seq number per flow */
                m->seqn = producer_flow_seq[flow]++;
-               m->udata64 = flow;
-
-               ev.flow_id = flow;
-               ev.mbuf = m;
+               flow_id_save(flow, m, &ev);
 
                while (rte_event_enqueue_burst(dev_id, port, &ev, 1) != 1) {
                        if (t->err)

app/test-eventdev/test_order_common.c order_test_setup(struct evt_test *test, struct evt_options *opt) · line 147

Quoted 10 lines
app/test-eventdev/test_order_common.c +7 -0
@@ -139,6 +138,18 @@ order_test_setup(struct evt_test *test, struct evt_options *opt)
 {
        void *test_order;
 
+       static const struct rte_mbuf_dynfield flow_id_dynfield_desc = {
+               .name = "test_event_dynfield_flow_id",
+               .size = sizeof(flow_id_t),
+               .align = __alignof__(flow_id_t),
+       };
+       flow_id_dynfield_offset =
+               rte_mbuf_dynfield_register(&flow_id_dynfield_desc);

Since this path used in fastpath, could you move flow_id_dynfield_offset to test_order's initial entry as that cache will be warm always.

app/test-eventdev/test_order_common.c order_test_setup(struct evt_test *test, struct evt_options *opt) · line 154

Quoted 7 lines
app/test-eventdev/test_order_common.c +5 -0
+       if (flow_id_dynfield_offset < 0) {
+               evt_err("failed to register mbuf field");
+               return -rte_errno;
+       }
+
        test_order = rte_zmalloc_socket(test->name, sizeof(struct test_order),
                                RTE_CACHE_LINE_SIZE, opt->socket_id);

See above

The rest of the eventdev and Graph changes are fine.

#106 lore raw

Re: [dpdk-dev] [PATCH v3 12/15] app/eventdev: switch flow ID to dynamic mbuf field

28/10/2020 05:54, Jerin Jacob:

Quoted 16 lines · Thomas Monjalon

app/test-eventdev/test_order_common.c order_test_setup(struct evt_test *test, struct evt_options *opt) · line 147

Quoted 13 lines

The order test stored the flow ID in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---

app/test-eventdev/test_order_common.c +7 -0
+       static const struct rte_mbuf_dynfield flow_id_dynfield_desc = {
+               .name = "test_event_dynfield_flow_id",
+               .size = sizeof(flow_id_t),
+               .align = __alignof__(flow_id_t),
+       };
+       flow_id_dynfield_offset =
+               rte_mbuf_dynfield_register(&flow_id_dynfield_desc);
Quoted 2 lines

Since this path used in fastpath, could you move flow_id_dynfield_offset to test_order's initial entry as that cache will be warm always.

I don't understand. Are you talking about the offset value? This field will be in the second part of mbuf, as udata64 was. Or are you talking about the storage of the offset variable?

Quoted 9 lines

app/test-eventdev/test_order_common.c order_test_setup(struct evt_test *test, struct evt_options *opt) · line 154

Quoted 7 lines
app/test-eventdev/test_order_common.c +5 -0
+       if (flow_id_dynfield_offset < 0) {
+               evt_err("failed to register mbuf field");
+               return -rte_errno;
+       }
+
        test_order = rte_zmalloc_socket(test->name, sizeof(struct test_order),
                                RTE_CACHE_LINE_SIZE, opt->socket_id);

See above

You mean the offset should be stored in this struct test_order?

#107 lore raw

Re: [dpdk-dev] [PATCH v3 12/15] app/eventdev: switch flow ID to dynamic mbuf field

Quoted 18 lines · Thomas Monjalon

28/10/2020 05:54, Jerin Jacob:

Quoted 16 lines · Thomas Monjalon
Quoted 13 lines

The order test stored the flow ID in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---

app/test-eventdev/test_order_common.c +7 -0
+       static const struct rte_mbuf_dynfield flow_id_dynfield_desc = {
+               .name = "test_event_dynfield_flow_id",
+               .size = sizeof(flow_id_t),
+               .align = __alignof__(flow_id_t),
+       };
+       flow_id_dynfield_offset =
+               rte_mbuf_dynfield_register(&flow_id_dynfield_desc);
Quoted 6 lines
Quoted 2 lines

Since this path used in fastpath, could you move flow_id_dynfield_offset to test_order's initial entry as that cache will be warm always.

I don't understand. Are you talking about the offset value? This field will be in the second part of mbuf, as udata64 was. Or are you talking about the storage of the offset variable?

Yes. Storage of the offset variable.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
app/test-eventdev/test_order_common.c +5 -0
+       if (flow_id_dynfield_offset < 0) {
+               evt_err("failed to register mbuf field");
+               return -rte_errno;
+       }
+
        test_order = rte_zmalloc_socket(test->name, sizeof(struct test_order),
                                RTE_CACHE_LINE_SIZE, opt->socket_id);
Quoted 3 lines
Quoted 1 line

See above

You mean the offset should be stored in this struct test_order?

Yes. Instead of a global variable flow_id_dynfield_offset

Quoted 3 lines
#108 lore raw

PATCH v3 13/15 examples/bbdev: switch to dynamic mbuf field

In reply to Thomas Monjalon

The example used the deprecated mbuf field udata64 as input mbuf pointer. It is moved to a dynamic field in order to allow removal of udata64.

---
 examples/bbdev_app/main.c | 49 +++++++++++++++++++++++++++++++--------
 1 file changed, 39 insertions(+), 10 deletions(-)
examples/bbdev_app/main.c +39 -10
index e512c807cd..63e8b18e44 100644
@@ -28,6 +28,7 @@
 #include <rte_lcore.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_memory.h>
 #include <rte_mempool.h>
 #include <rte_log.h>
@@ -59,6 +60,22 @@
 	} \
 } while (0)
 
+static int input_dynfield_offset = -1;
+
+static inline struct rte_mbuf *
+get_mbuf_input(struct rte_mbuf *mbuf)
+{
+	return *RTE_MBUF_DYNFIELD(mbuf,
+			input_dynfield_offset, struct rte_mbuf **);
+}
+
+static inline void
+set_mbuf_input(struct rte_mbuf *mbuf, struct rte_mbuf *input)
+{
+	*RTE_MBUF_DYNFIELD(mbuf,
+			input_dynfield_offset, struct rte_mbuf **) = input;
+}
+
 static const struct rte_eth_conf port_conf = {
 	.rxmode = {
 		.mq_mode = ETH_MQ_RX_NONE,
@@ -294,11 +311,11 @@ pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int nb_to_free)
 }
 
 static inline void
-pktmbuf_userdata_free_bulk(struct rte_mbuf **mbufs, unsigned int nb_to_free)
+pktmbuf_input_free_bulk(struct rte_mbuf **mbufs, unsigned int nb_to_free)
 {
 	unsigned int i;
 	for (i = 0; i < nb_to_free; ++i) {
-		struct rte_mbuf *rx_pkt = mbufs[i]->userdata;
+		struct rte_mbuf *rx_pkt = get_mbuf_input(mbufs[i]);
 		rte_pktmbuf_free(rx_pkt);
 		rte_pktmbuf_free(mbufs[i]);
 	}
@@ -429,7 +446,7 @@ verify_data(struct rte_mbuf **mbufs, uint16_t num_pkts)
 	uint16_t i;
 	for (i = 0; i < num_pkts; ++i) {
 		struct rte_mbuf *out = mbufs[i];
-		struct rte_mbuf *in = out->userdata;
+		struct rte_mbuf *in = get_mbuf_input(out);
 
 		if (memcmp(rte_pktmbuf_mtod_offset(in, uint8_t *,
 				sizeof(struct rte_ether_hdr)),
@@ -731,7 +748,7 @@ run_encoding(struct lcore_conf *lcore_conf)
 				rte_pktmbuf_data_len(rx_pkts_burst[i]) -
 				sizeof(struct rte_ether_hdr);
 		/* save input mbuf pointer for later comparison */
-		enc_out_pkts[i]->userdata = rx_pkts_burst[i];
+		set_mbuf_input(enc_out_pkts[i], rx_pkts_burst[i]);
 
 		/* copy ethernet header */
 		rte_pktmbuf_reset(enc_out_pkts[i]);
@@ -775,7 +792,7 @@ run_encoding(struct lcore_conf *lcore_conf)
 	nb_enq = rte_bbdev_enqueue_enc_ops(bbdev_id, enc_queue_id,
 			bbdev_ops_burst, nb_rx);
 	if (unlikely(nb_enq < nb_rx)) {
-		pktmbuf_userdata_free_bulk(&enc_out_pkts[nb_enq],
+		pktmbuf_input_free_bulk(&enc_out_pkts[nb_enq],
 				nb_rx - nb_enq);
 		rte_bbdev_enc_op_free_bulk(&bbdev_ops_burst[nb_enq],
 				nb_rx - nb_enq);
@@ -805,7 +822,7 @@ run_encoding(struct lcore_conf *lcore_conf)
 	nb_sent = rte_ring_enqueue_burst(enc_to_dec_ring, (void **)enc_out_pkts,
 			nb_deq, NULL);
 	if (unlikely(nb_sent < nb_deq)) {
-		pktmbuf_userdata_free_bulk(&enc_out_pkts[nb_sent],
+		pktmbuf_input_free_bulk(&enc_out_pkts[nb_sent],
 				nb_deq - nb_sent);
 		lcore_stats->enc_to_dec_lost_packets += nb_deq - nb_sent;
 	}
@@ -842,7 +859,7 @@ run_decoding(struct lcore_conf *lcore_conf)
 
 	if (unlikely(rte_bbdev_dec_op_alloc_bulk(bbdev_op_pool, bbdev_ops_burst,
 			nb_recv) != 0)) {
-		pktmbuf_userdata_free_bulk(recv_pkts_burst, nb_recv);
+		pktmbuf_input_free_bulk(recv_pkts_burst, nb_recv);
 		lcore_stats->rx_lost_packets += nb_recv;
 		return;
 	}
@@ -871,7 +888,7 @@ run_decoding(struct lcore_conf *lcore_conf)
 	nb_enq = rte_bbdev_enqueue_dec_ops(bbdev_id, bbdev_queue_id,
 			bbdev_ops_burst, nb_recv);
 	if (unlikely(nb_enq < nb_recv)) {
-		pktmbuf_userdata_free_bulk(&recv_pkts_burst[nb_enq],
+		pktmbuf_input_free_bulk(&recv_pkts_burst[nb_enq],
 				nb_recv - nb_enq);
 		rte_bbdev_dec_op_free_bulk(&bbdev_ops_burst[nb_enq],
 				nb_recv - nb_enq);
@@ -898,12 +915,12 @@ run_decoding(struct lcore_conf *lcore_conf)
 
 	/* Free the RX mbufs after verification */
 	for (i = 0; i < nb_deq; ++i)
-		rte_pktmbuf_free(recv_pkts_burst[i]->userdata);
+		rte_pktmbuf_free(get_mbuf_input(recv_pkts_burst[i]));
 
 	/* Transmit the packets */
 	nb_tx = rte_eth_tx_burst(port_id, tx_queue_id, recv_pkts_burst, nb_deq);
 	if (unlikely(nb_tx < nb_deq)) {
-		pktmbuf_userdata_free_bulk(&recv_pkts_burst[nb_tx],
+		pktmbuf_input_free_bulk(&recv_pkts_burst[nb_tx],
 				nb_deq - nb_tx);
 		lcore_stats->tx_lost_packets += nb_deq - nb_tx;
 	}
@@ -1046,6 +1063,12 @@ main(int argc, char **argv)
 	bool stats_thread_started = false;
 	unsigned int main_lcore_id = rte_get_main_lcore();
 
+	static const struct rte_mbuf_dynfield input_dynfield_desc = {
+		.name = "example_bbdev_dynfield_input",
+		.size = sizeof(struct rte_mbuf *),
+		.align = __alignof__(struct rte_mbuf *),
+	};
+
 	rte_atomic16_init(&global_exit_flag);
 
 	sigret = signal(SIGTERM, signal_handler);
@@ -1115,6 +1138,12 @@ main(int argc, char **argv)
 	if (bbdev_mbuf_mempool == NULL)
 		rte_exit(EXIT_FAILURE, "Cannot create ethdev mbuf mempool\n");
 
+	/* register mbuf field to store input pointer */
+	input_dynfield_offset =
+		rte_mbuf_dynfield_register(&input_dynfield_desc);
+	if (input_dynfield_offset < 0)
+		rte_exit(EXIT_FAILURE, "Cannot register mbuf field\n");
+
 	/* initialize ports */
 	ret = initialize_ports(&app_params, ethdev_mbuf_mempool);
 
Signature · 1 line
2.28.0
#109 lore raw

PATCH v3 14/15 examples/rxtx_callbacks: switch to dynamic mbuf field

In reply to Thomas Monjalon

The example used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 doc/guides/sample_app_ug/rxtx_callbacks.rst |  4 ++--
 examples/rxtx_callbacks/main.c              | 20 ++++++++++++++++++--
 2 files changed, 20 insertions(+), 4 deletions(-)
doc/guides/sample_app_ug/rxtx_callbacks.rst +2 -2
index 62d1f39d7e..56c4293a1a 100644
@@ -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;
examples/rxtx_callbacks/main.c +18 -2
index 6fe39546dd..b9a98ceddc 100644
@@ -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)
Signature · 1 line
2.28.0
#110 lore raw

PATCH v3 15/15 mbuf: remove userdata field

In reply to Thomas Monjalon

As announced in the deprecation note, the field userdata / udata64 is removed to give more space to the dynamic fields.

This is how the mbuf layout looks like (pahole-style):

word  type                              name                byte  size
 0    void *                            buf_addr;         /*   0 +  8 */
 1    rte_iova_t                        buf_iova          /*   8 +  8 */
      /* --- RTE_MARKER64               rearm_data;                   */
 2    uint16_t                          data_off;         /*  16 +  2 */
      uint16_t                          refcnt;           /*  18 +  2 */
      uint16_t                          nb_segs;          /*  20 +  2 */
      uint16_t                          port;             /*  22 +  2 */
 3    uint64_t                          ol_flags;         /*  24 +  8 */
      /* --- RTE_MARKER                 rx_descriptor_fields1;        */
 4    uint32_t             union        packet_type;      /*  32 +  4 */
      uint32_t                          pkt_len;          /*  36 +  4 */
 5    uint16_t                          data_len;         /*  40 +  2 */
      uint16_t                          vlan_tci;         /*  42 +  2 */
 5.5  uint64_t             union        hash;             /*  44 +  8 */
 6.5  uint16_t                          vlan_tci_outer;   /*  52 +  2 */
      uint16_t                          buf_len;          /*  54 +  2 */
 7    uint64_t                          timestamp;        /*  56 +  8 */
      /* --- RTE_MARKER                 cacheline1;                   */
 8    struct rte_mempool *              pool;             /*  64 +  8 */
 9    struct rte_mbuf *                 next;             /*  72 +  8 */
10    uint64_t             union        tx_offload;       /*  80 +  8 */
11    uint16_t                          priv_size;        /*  88 +  2 */
      uint16_t                          timesync;         /*  90 +  2 */
      uint32_t                          seqn;             /*  92 +  4 */
12    struct rte_mbuf_ext_shared_info * shinfo;           /*  96 +  8 */
13    uint64_t                          dynfield1[3];     /* 104 + 24 */
16    /* --- END                                             128      */
---
 doc/guides/rel_notes/deprecation.rst   | 1 -
 doc/guides/rel_notes/release_20_11.rst | 3 +++
 lib/librte_kni/rte_kni_common.h        | 3 +--
 lib/librte_mbuf/rte_mbuf_core.h        | 8 +-------
 4 files changed, 5 insertions(+), 10 deletions(-)
doc/guides/rel_notes/deprecation.rst +0 -1
index 2e082499b8..0f6f1df12a 100644
@@ -87,7 +87,6 @@ Deprecation Notices
   The following static fields will be moved as dynamic:
 
   - ``timestamp``
-  - ``userdata`` / ``udata64``
   - ``seqn``
 
   As a consequence, the layout of the ``struct rte_mbuf`` will be re-arranged,
doc/guides/rel_notes/release_20_11.rst +3 -0
index d8ac359e51..3cec526b6a 100644
@@ -426,6 +426,9 @@ API Changes
   the structures ``rte_mbuf`` and ``rte_mbuf_ext_shared_info``.
   The field ``refcnt`` is remaining from the old unions.
 
+* mbuf: Removed the unioned fields ``userdata`` and ``udata64``
+  from the structure ``rte_mbuf``. It is replaced with dynamic fields.
+
 * pci: Removed the ``rte_kernel_driver`` enum defined in rte_dev.h and
   replaced with a private enum in the PCI subsystem.
 
lib/librte_kni/rte_kni_common.h +1 -2
index 21b477f0aa..0db45e6a24 100644
@@ -86,8 +86,7 @@ struct rte_kni_mbuf {
 	uint16_t data_len;      /**< Amount of data in segment buffer. */
 
 	/* fields on second cache line */
-	char pad3[8] __attribute__((__aligned__(RTE_CACHE_LINE_MIN_SIZE)));
-	void *pool;
+	void *pool __attribute__((__aligned__(RTE_CACHE_LINE_MIN_SIZE)));
 	void *next;             /**< Physical address of next mbuf in kernel. */
 };
 
lib/librte_mbuf/rte_mbuf_core.h +1 -7
index 065d87d28a..a65eaaf692 100644
@@ -599,12 +599,6 @@ struct rte_mbuf {
 	/* second cache line - fields only used in slow path or on TX */
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
 
-	RTE_STD_C11
-	union {
-		void *userdata;   /**< Can be used for external metadata */
-		uint64_t udata64; /**< Allow 8-byte userdata on 32-bit */
-	};
-
 	struct rte_mempool *pool; /**< Pool from which mbuf was allocated. */
 	struct rte_mbuf *next;    /**< Next segment of scattered packet. */
 
@@ -662,7 +656,7 @@ struct rte_mbuf {
 	 */
 	struct rte_mbuf_ext_shared_info *shinfo;
 
-	uint64_t dynfield1[2]; /**< Reserved for dynamic fields. */
+	uint64_t dynfield1[3]; /**< Reserved for dynamic fields. */
 } __rte_cache_aligned;
 
 /**
Signature · 1 line
2.28.0
#111 lore raw

v4 cover remove mbuf userdata

In reply to Thomas Monjalon

The mbuf field userdata (aliased as udata64)
was announced to be removed for two reasons:
- applications, libraries and drivers used the same field for different purposes, with a risk of usage conflict.
- this field always used 8 bytes even if unneeded

Some dynamic fields are created when needed to replace the big static userdata field.
As a consequence, 8 bytes can be re-allocated to dynamic fields.

This mbuf layout change is important to allow adding more features (consuming more dynamic fields) during the next year.

v4 (thanks Jerin, Nithin and Ed):
- move rte_node dynfield offset to hotter context in cache
- move test-eventdev dynfield offset to hotter context in cache
- split ARK user data for Rx and Tx + more ARK fixes

v3 (thanks Olivier):
- use typedef for new field types
- fix node field type
- initialize offsets to -1
- add more inline functions
- inline rte_security_dynfield_is_registered
- add PMD-specific userdata field for ARK

v2 (thanks David & Andrew):
- fix some indentations
- return -rte_errno consistently
- make some type casts more precise
- define dynfield types in macros
- hide field description in rte_security
- do not lookup security dynfield in ipsec-secgw
- do not use the existing timestamp field for other purpose

Ed Czeck (1):
net/ark: switch user data to dynamic mbuf fields

Nithin Dabilpuram (1):
node: switch IPv4 metadata to dynamic mbuf field

Thomas Monjalon (13):
examples: enclose DPDK includes with angle brackets
kni: move header file from EAL
mbuf: fix typo in dynamic field convention note
security: switch metadata to dynamic mbuf field event/sw: switch test counter to dynamic mbuf field net/bnxt: switch CFA code to dynamic mbuf field net/vmxnet3: switch MSS hint to dynamic mbuf field test/distributor: switch sequence to dynamic mbuf field test/graph: switch user data to dynamic mbuf field app/eventdev: switch flow ID to dynamic mbuf field examples/bbdev: switch to dynamic mbuf field examples/rxtx_callbacks: switch to dynamic mbuf field
mbuf: remove userdata field

 app/test-eventdev/test_order_atq.c            |   4 +-
 app/test-eventdev/test_order_common.c         |  21 ++-
 app/test-eventdev/test_order_common.h         |  21 +++
 app/test-eventdev/test_order_queue.c          |   4 +-
 app/test/test_distributor.c                   |  28 +++-
 app/test/test_graph.c                         |  94 +++++++------
 doc/api/doxy-api-index.md                     |   1 +
 doc/api/doxy-api.conf.in                      |   1 +
 doc/guides/prog_guide/rte_security.rst        |   9 +-
 doc/guides/rel_notes/deprecation.rst          |   1 -
 doc/guides/rel_notes/release_20_11.rst        |   3 +
 doc/guides/sample_app_ug/rxtx_callbacks.rst   |   4 +-
 drivers/crypto/octeontx2/otx2_cryptodev_sec.c |   5 +-
 drivers/event/sw/sw_evdev_selftest.c          |  23 +++-
 drivers/net/ark/ark_ethdev.c                  |  39 ++++++
 drivers/net/ark/ark_ethdev_rx.c               |   3 +-
 drivers/net/ark/ark_ethdev_tx.c               |   3 +-
 drivers/net/ark/meson.build                   |   2 +
 drivers/net/ark/rte_pmd_ark.h                 | 123 ++++++++++++++++++
 drivers/net/ark/version.map                   |   7 +
 drivers/net/bnxt/bnxt_ethdev.c                |  19 +++
 drivers/net/bnxt/bnxt_rxr.c                   |   2 +-
 drivers/net/bnxt/bnxt_rxr.h                   |   5 +
 drivers/net/bnxt/rte_pmd_bnxt.h               |   3 +
 drivers/net/ixgbe/ixgbe_ipsec.c               |   5 +-
 drivers/net/ixgbe/ixgbe_rxtx.c                |   6 +-
 drivers/net/octeontx2/otx2_ethdev.h           |   1 +
 drivers/net/octeontx2/otx2_ethdev_sec.c       |   5 +-
 drivers/net/octeontx2/otx2_ethdev_sec_tx.h    |   2 +-
 drivers/net/octeontx2/otx2_rx.h               |   2 +-
 drivers/net/vmxnet3/vmxnet3_ethdev.c          |  15 +++
 drivers/net/vmxnet3/vmxnet3_ethdev.h          |   6 +
 drivers/net/vmxnet3/vmxnet3_rxtx.c            |   9 +-
 examples/bbdev_app/main.c                     |  79 +++++++----
 examples/bond/main.c                          |  11 +-
 examples/ipsec-secgw/ipsec-secgw.c            |   9 +-
 examples/ipsec-secgw/ipsec_worker.c           |  12 +-
 examples/rxtx_callbacks/main.c                |  20 ++-
 examples/tep_termination/vxlan_setup.c        |   2 +-
 kernel/linux/kni/meson.build                  |   2 +-
 lib/librte_eal/linux/include/meson.build      |   1 -
 lib/librte_kni/meson.build                    |   2 +-
 .../include => librte_kni}/rte_kni_common.h   |   3 +-
 lib/librte_mbuf/rte_mbuf_core.h               |   8 +-
 lib/librte_mbuf/rte_mbuf_dyn.h                |   2 +-
 lib/librte_node/ip4_lookup.c                  |  40 ++++--
 lib/librte_node/ip4_lookup_neon.h             |  20 ++-
 lib/librte_node/ip4_lookup_sse.h              |  36 +++--
 lib/librte_node/ip4_rewrite.c                 |  49 +++++--
 lib/librte_node/node_private.h                |  13 +-
 lib/librte_security/rte_security.c            |  16 +++
 lib/librte_security/rte_security.h            |  42 ++++++
 lib/librte_security/rte_security_driver.h     |   3 +
 lib/librte_security/version.map               |   2 +
 54 files changed, 659 insertions(+), 189 deletions(-)
 create mode 100644 drivers/net/ark/rte_pmd_ark.h
 rename lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h (97%)
Signature · 1 line
2.28.0
#112 lore raw

PATCH v4 1/15 examples: enclose DPDK includes with angle brackets

In examples, DPDK header files are external,
so they must be enclosed with angle brackets, not quotes.

---
 examples/bbdev_app/main.c              | 30 +++++++++++++-------------
 examples/bond/main.c                   | 11 ++++------
 examples/tep_termination/vxlan_setup.c |  2 +-
 3 files changed, 20 insertions(+), 23 deletions(-)
examples/bbdev_app/main.c +15 -15
index 43fe631760..e512c807cd 100644
@@ -18,21 +18,21 @@
 #include <getopt.h>
 #include <signal.h>
 
-#include "rte_atomic.h"
-#include "rte_common.h"
-#include "rte_eal.h"
-#include "rte_cycles.h"
-#include "rte_ether.h"
-#include "rte_ethdev.h"
-#include "rte_ip.h"
-#include "rte_lcore.h"
-#include "rte_malloc.h"
-#include "rte_mbuf.h"
-#include "rte_memory.h"
-#include "rte_mempool.h"
-#include "rte_log.h"
-#include "rte_bbdev.h"
-#include "rte_bbdev_op.h"
+#include <rte_atomic.h>
+#include <rte_common.h>
+#include <rte_eal.h>
+#include <rte_cycles.h>
+#include <rte_ether.h>
+#include <rte_ethdev.h>
+#include <rte_ip.h>
+#include <rte_lcore.h>
+#include <rte_malloc.h>
+#include <rte_mbuf.h>
+#include <rte_memory.h>
+#include <rte_mempool.h>
+#include <rte_log.h>
+#include <rte_bbdev.h>
+#include <rte_bbdev_op.h>
 
 /* LLR values - negative value for '1' bit */
 #define LLR_1_BIT 0x81
examples/bond/main.c +4 -7
index 398553b785..81a6fa976b 100644
@@ -41,6 +41,10 @@
 #include <rte_tcp.h>
 #include <rte_arp.h>
 #include <rte_spinlock.h>
+#include <rte_devargs.h>
+#include <rte_byteorder.h>
+#include <rte_cpuflags.h>
+#include <rte_eth_bond.h>
 
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
@@ -53,13 +57,6 @@
 
 #include "main.h"
 
-#include <rte_devargs.h>
-
-
-#include "rte_byteorder.h"
-#include "rte_cpuflags.h"
-#include "rte_eth_bond.h"
-
 #define RTE_LOGTYPE_DCB RTE_LOGTYPE_USER1
 
 #define NB_MBUF   (1024*8)
examples/tep_termination/vxlan_setup.c +1 -1
index 4b44ccc143..0bcd870b4a 100644
@@ -18,9 +18,9 @@
 #include <rte_ip.h>
 #include <rte_udp.h>
 #include <rte_tcp.h>
+#include <rte_vhost.h>
 
 #include "main.h"
-#include "rte_vhost.h"
 #include "vxlan.h"
 #include "vxlan_setup.h"
 
Signature · 1 line
2.28.0
#113 lore raw

PATCH v4 2/15 kni: move header file from EAL

In reply to Thomas Monjalon

Since the kernel module is not part of EAL anymore, there is no need to have the common KNI header file in EAL. The file rte_kni_common.h is moved to librte_kni.

---
 kernel/linux/kni/meson.build                                  | 2 +-
 lib/librte_eal/linux/include/meson.build                      | 1 -
 lib/librte_kni/meson.build                                    | 2 +-
 lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h | 0
 4 files changed, 2 insertions(+), 3 deletions(-)
 rename lib/{librte_eal/linux/include => librte_kni}/rte_kni_common.h (100%)
kernel/linux/kni/meson.build +1 -1
index d696347f22..07e0c9dae7 100644
@@ -18,7 +18,7 @@ custom_target('rte_kni',
 		'src=' + meson.current_source_dir(),
 		'MODULE_CFLAGS=-include ' + meson.source_root() + '/config/rte_config.h' +
 		' -I' + meson.source_root() + '/lib/librte_eal/include' +
-		' -I' + meson.source_root() + '/lib/librte_eal/linux/include' +
+		' -I' + meson.source_root() + '/lib/librte_kni' +
 		' -I' + meson.build_root() +
 		' -I' + meson.current_source_dir(),
 		'modules'],
lib/librte_eal/linux/include/meson.build +0 -1
index 1241894b3c..7d18dd52f1 100644
@@ -4,6 +4,5 @@
 includes += include_directories('.')
 
 headers += files(
-        'rte_kni_common.h',
         'rte_os.h',
 )
lib/librte_kni/meson.build +1 -1
index 963eae6fe0..ad598bb3d0 100644
@@ -6,5 +6,5 @@ if not is_linux or not dpdk_conf.get('RTE_ARCH_64')
 	reason = 'only supported on 64-bit linux'
 endif
 sources = files('rte_kni.c')
-headers = files('rte_kni.h')
+headers = files('rte_kni.h', 'rte_kni_common.h')
 deps += ['ethdev', 'pci']
lib/librte_kni/rte_kni_common.h renamed from lib/librte_eal/linux/include/rte_kni_common.h +0 -0
similarity index 100%
rename from lib/librte_eal/linux/include/rte_kni_common.h
rename to lib/librte_kni/rte_kni_common.h
Signature · 1 line
2.28.0
#114 lore raw

PATCH v4 3/15 mbuf: fix typo in dynamic field convention note

In reply to Thomas Monjalon

Replace "in a in PMD" with "in a PMD".

Fixes 4958ca3a443a ("mbuf: support dynamic fields and flags")
---
 lib/librte_mbuf/rte_mbuf_dyn.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_mbuf/rte_mbuf_dyn.h +1 -1
index 8407230ecf..0ebac88b83 100644
@@ -62,7 +62,7 @@
  * conventions than function names in dpdk:
  * - "rte_mbuf_dynfield_<name>" if defined in mbuf library
  * - "rte_<libname>_dynfield_<name>" if defined in another library
- * - "rte_net_<pmd>_dynfield_<name>" if defined in a in PMD
+ * - "rte_net_<pmd>_dynfield_<name>" if defined in a PMD
  * - any name that does not start with "rte_" in an application
  */
 
Signature · 1 line
2.28.0
#115 lore raw

PATCH v4 4/15 node: switch IPv4 metadata to dynamic mbuf field

In reply to Thomas Monjalon

From: Nithin Dabilpuram <[email protected]>

The node_mbuf_priv1 was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 lib/librte_node/ip4_lookup.c      | 40 ++++++++++++++++++-------
 lib/librte_node/ip4_lookup_neon.h | 20 ++++++-------
 lib/librte_node/ip4_lookup_sse.h  | 36 +++++++++++------------
 lib/librte_node/ip4_rewrite.c     | 49 +++++++++++++++++++++++--------
 lib/librte_node/node_private.h    | 13 ++++++--
 5 files changed, 103 insertions(+), 55 deletions(-)
lib/librte_node/ip4_lookup.c +30 -10
index 8835aab9dd..d083a725fc 100644
@@ -29,8 +29,23 @@ struct ip4_lookup_node_main {
 	struct rte_lpm *lpm_tbl[RTE_MAX_NUMA_NODES];
 };
 
+struct ip4_lookup_node_ctx {
+	/* Socket's LPM table */
+	struct rte_lpm *lpm;
+	/* Dynamic offset to mbuf priv1 */
+	int mbuf_priv1_off;
+};
+
+int node_mbuf_priv1_dynfield_offset = -1;
+
 static struct ip4_lookup_node_main ip4_lookup_nm;
 
+#define IP4_LOOKUP_NODE_LPM(ctx) \
+	(((struct ip4_lookup_node_ctx *)ctx)->lpm)
+
+#define IP4_LOOKUP_NODE_PRIV1_OFF(ctx) \
+	(((struct ip4_lookup_node_ctx *)ctx)->mbuf_priv1_off)
+
 #if defined(__ARM_NEON)
 #include "ip4_lookup_neon.h"
 #elif defined(RTE_ARCH_X86)
@@ -41,12 +56,13 @@ static uint16_t
 ip4_lookup_node_process_scalar(struct rte_graph *graph, struct rte_node *node,
 			void **objs, uint16_t nb_objs)
 {
+	struct rte_lpm *lpm = IP4_LOOKUP_NODE_LPM(node->ctx);
+	const int dyn = IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx);
 	struct rte_ipv4_hdr *ipv4_hdr;
 	void **to_next, **from;
 	uint16_t last_spec = 0;
 	struct rte_mbuf *mbuf;
 	rte_edge_t next_index;
-	struct rte_lpm *lpm;
 	uint16_t held = 0;
 	uint32_t drop_nh;
 	int i, rc;
@@ -55,9 +71,6 @@ ip4_lookup_node_process_scalar(struct rte_graph *graph, struct rte_node *node,
 	next_index = RTE_NODE_IP4_LOOKUP_NEXT_REWRITE;
 	/* Drop node */
 	drop_nh = ((uint32_t)RTE_NODE_IP4_LOOKUP_NEXT_PKT_DROP) << 16;
-
-	/* Get socket specific LPM from ctx */
-	lpm = *((struct rte_lpm **)node->ctx);
 	from = objs;
 
 	/* Get stream for the speculated next node */
@@ -72,14 +85,14 @@ ip4_lookup_node_process_scalar(struct rte_graph *graph, struct rte_node *node,
 		ipv4_hdr = rte_pktmbuf_mtod_offset(mbuf, struct rte_ipv4_hdr *,
 				sizeof(struct rte_ether_hdr));
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		rc = rte_lpm_lookup(lpm, rte_be_to_cpu_32(ipv4_hdr->dst_addr),
 				    &next_hop);
 		next_hop = (rc == 0) ? next_hop : drop_nh;
 
-		node_mbuf_priv1(mbuf)->nh = (uint16_t)next_hop;
+		node_mbuf_priv1(mbuf, dyn)->nh = (uint16_t)next_hop;
 		next_hop = next_hop >> 16;
 		next = (uint16_t)next_hop;
 
@@ -169,15 +182,19 @@ setup_lpm(struct ip4_lookup_node_main *nm, int socket)
 static int
 ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node)
 {
-	struct rte_lpm **lpm_p = (struct rte_lpm **)&node->ctx;
 	uint16_t socket, lcore_id;
 	static uint8_t init_once;
 	int rc;
 
 	RTE_SET_USED(graph);
-	RTE_SET_USED(node);
+	RTE_BUILD_BUG_ON(sizeof(struct ip4_lookup_node_ctx) > RTE_NODE_CTX_SZ);
 
 	if (!init_once) {
+		node_mbuf_priv1_dynfield_offset = rte_mbuf_dynfield_register(
+				&node_mbuf_priv1_dynfield_desc);
+		if (node_mbuf_priv1_dynfield_offset < 0)
+			return -rte_errno;
+
 		/* Setup LPM tables for all sockets */
 		RTE_LCORE_FOREACH(lcore_id)
 		{
@@ -192,7 +209,10 @@ ip4_lookup_node_init(const struct rte_graph *graph, struct rte_node *node)
 		}
 		init_once = 1;
 	}
-	*lpm_p = ip4_lookup_nm.lpm_tbl[graph->socket];
+
+	/* Update socket's LPM and mbuf dyn priv1 offset in node ctx */
+	IP4_LOOKUP_NODE_LPM(node->ctx) = ip4_lookup_nm.lpm_tbl[graph->socket];
+	IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx) = node_mbuf_priv1_dynfield_offset;
 
 #if defined(__ARM_NEON) || defined(RTE_ARCH_X86)
 	if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128)
lib/librte_node/ip4_lookup_neon.h +9 -11
index 0ad2763b82..d5c8da3719 100644
@@ -11,12 +11,13 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 			void **objs, uint16_t nb_objs)
 {
 	struct rte_mbuf *mbuf0, *mbuf1, *mbuf2, *mbuf3, **pkts;
+	struct rte_lpm *lpm = IP4_LOOKUP_NODE_LPM(node->ctx);
+	const int dyn = IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx);
 	struct rte_ipv4_hdr *ipv4_hdr;
 	void **to_next, **from;
 	uint16_t last_spec = 0;
 	rte_edge_t next_index;
 	uint16_t n_left_from;
-	struct rte_lpm *lpm;
 	uint16_t held = 0;
 	uint32_t drop_nh;
 	rte_xmm_t result;
@@ -30,9 +31,6 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 	/* Drop node */
 	drop_nh = ((uint32_t)RTE_NODE_IP4_LOOKUP_NEXT_PKT_DROP) << 16;
 
-	/* Get socket specific LPM from ctx */
-	lpm = *((struct rte_lpm **)node->ctx);
-
 	pkts = (struct rte_mbuf **)objs;
 	from = objs;
 	n_left_from = nb_objs;
@@ -119,10 +117,10 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 		priv23.u16[0] = result.u16[4];
 		priv23.u16[4] = result.u16[6];
 
-		node_mbuf_priv1(mbuf0)->u = priv01.u64[0];
-		node_mbuf_priv1(mbuf1)->u = priv01.u64[1];
-		node_mbuf_priv1(mbuf2)->u = priv23.u64[0];
-		node_mbuf_priv1(mbuf3)->u = priv23.u64[1];
+		node_mbuf_priv1(mbuf0, dyn)->u = priv01.u64[0];
+		node_mbuf_priv1(mbuf1, dyn)->u = priv01.u64[1];
+		node_mbuf_priv1(mbuf2, dyn)->u = priv23.u64[0];
+		node_mbuf_priv1(mbuf3, dyn)->u = priv23.u64[1];
 
 		/* Enqueue four to next node */
 		rte_edge_t fix_spec = ((next_index == result.u16[1]) &&
@@ -197,14 +195,14 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 		ipv4_hdr = rte_pktmbuf_mtod_offset(mbuf0, struct rte_ipv4_hdr *,
 						sizeof(struct rte_ether_hdr));
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf0)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf0)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf0, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf0, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		rc = rte_lpm_lookup(lpm, rte_be_to_cpu_32(ipv4_hdr->dst_addr),
 				    &next_hop);
 		next_hop = (rc == 0) ? next_hop : drop_nh;
 
-		node_mbuf_priv1(mbuf0)->nh = (uint16_t)next_hop;
+		node_mbuf_priv1(mbuf0, dyn)->nh = (uint16_t)next_hop;
 		next_hop = next_hop >> 16;
 		next0 = (uint16_t)next_hop;
 
lib/librte_node/ip4_lookup_sse.h +17 -19
index 264c986071..74dbf97533 100644
@@ -11,13 +11,14 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 			void **objs, uint16_t nb_objs)
 {
 	struct rte_mbuf *mbuf0, *mbuf1, *mbuf2, *mbuf3, **pkts;
+	struct rte_lpm *lpm = IP4_LOOKUP_NODE_LPM(node->ctx);
+	const int dyn = IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx);
 	rte_edge_t next0, next1, next2, next3, next_index;
 	struct rte_ipv4_hdr *ipv4_hdr;
 	uint32_t ip0, ip1, ip2, ip3;
 	void **to_next, **from;
 	uint16_t last_spec = 0;
 	uint16_t n_left_from;
-	struct rte_lpm *lpm;
 	uint16_t held = 0;
 	uint32_t drop_nh;
 	rte_xmm_t dst;
@@ -29,9 +30,6 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 	/* Drop node */
 	drop_nh = ((uint32_t)RTE_NODE_IP4_LOOKUP_NEXT_PKT_DROP) << 16;
 
-	/* Get socket specific LPM from ctx */
-	lpm = *((struct rte_lpm **)node->ctx);
-
 	pkts = (struct rte_mbuf **)objs;
 	from = objs;
 	n_left_from = nb_objs;
@@ -78,24 +76,24 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 						sizeof(struct rte_ether_hdr));
 		ip0 = ipv4_hdr->dst_addr;
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf0)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf0)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf0, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf0, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		/* Extract DIP of mbuf1 */
 		ipv4_hdr = rte_pktmbuf_mtod_offset(mbuf1, struct rte_ipv4_hdr *,
 						sizeof(struct rte_ether_hdr));
 		ip1 = ipv4_hdr->dst_addr;
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf1)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf1)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf1, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf1, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		/* Extract DIP of mbuf2 */
 		ipv4_hdr = rte_pktmbuf_mtod_offset(mbuf2, struct rte_ipv4_hdr *,
 						sizeof(struct rte_ether_hdr));
 		ip2 = ipv4_hdr->dst_addr;
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf2)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf2)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf2, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf2, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		/* Extract DIP of mbuf3 */
 		ipv4_hdr = rte_pktmbuf_mtod_offset(mbuf3, struct rte_ipv4_hdr *,
@@ -111,23 +109,23 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 		dip = _mm_shuffle_epi8(dip, bswap_mask);
 
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf3)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf3)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf3, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf3, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		/* Perform LPM lookup to get NH and next node */
 		rte_lpm_lookupx4(lpm, dip, dst.u32, drop_nh);
 
 		/* Extract next node id and NH */
-		node_mbuf_priv1(mbuf0)->nh = dst.u32[0] & 0xFFFF;
+		node_mbuf_priv1(mbuf0, dyn)->nh = dst.u32[0] & 0xFFFF;
 		next0 = (dst.u32[0] >> 16);
 
-		node_mbuf_priv1(mbuf1)->nh = dst.u32[1] & 0xFFFF;
+		node_mbuf_priv1(mbuf1, dyn)->nh = dst.u32[1] & 0xFFFF;
 		next1 = (dst.u32[1] >> 16);
 
-		node_mbuf_priv1(mbuf2)->nh = dst.u32[2] & 0xFFFF;
+		node_mbuf_priv1(mbuf2, dyn)->nh = dst.u32[2] & 0xFFFF;
 		next2 = (dst.u32[2] >> 16);
 
-		node_mbuf_priv1(mbuf3)->nh = dst.u32[3] & 0xFFFF;
+		node_mbuf_priv1(mbuf3, dyn)->nh = dst.u32[3] & 0xFFFF;
 		next3 = (dst.u32[3] >> 16);
 
 		/* Enqueue four to next node */
@@ -202,14 +200,14 @@ ip4_lookup_node_process_vec(struct rte_graph *graph, struct rte_node *node,
 		ipv4_hdr = rte_pktmbuf_mtod_offset(mbuf0, struct rte_ipv4_hdr *,
 						sizeof(struct rte_ether_hdr));
 		/* Extract cksum, ttl as ipv4 hdr is in cache */
-		node_mbuf_priv1(mbuf0)->cksum = ipv4_hdr->hdr_checksum;
-		node_mbuf_priv1(mbuf0)->ttl = ipv4_hdr->time_to_live;
+		node_mbuf_priv1(mbuf0, dyn)->cksum = ipv4_hdr->hdr_checksum;
+		node_mbuf_priv1(mbuf0, dyn)->ttl = ipv4_hdr->time_to_live;
 
 		rc = rte_lpm_lookup(lpm, rte_be_to_cpu_32(ipv4_hdr->dst_addr),
 				    &next_hop);
 		next_hop = (rc == 0) ? next_hop : drop_nh;
 
-		node_mbuf_priv1(mbuf0)->nh = next_hop & 0xFFFF;
+		node_mbuf_priv1(mbuf0, dyn)->nh = next_hop & 0xFFFF;
 		next0 = (next_hop >> 16);
 
 		if (unlikely(next_index ^ next0)) {
lib/librte_node/ip4_rewrite.c +37 -12

101 lines not on this page · raw message

lib/librte_node/node_private.h +10 -3
index ab7941c12b..8c73d5dc10 100644
@@ -8,6 +8,7 @@
 #include <rte_common.h>
 #include <rte_log.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 extern int rte_node_logtype;
 #define NODE_LOG(level, node_name, ...)                                        \
@@ -21,7 +22,6 @@ extern int rte_node_logtype;
 #define node_dbg(node_name, ...) NODE_LOG(DEBUG, node_name, __VA_ARGS__)
 
 /**
- *
  * Node mbuf private data to store next hop, ttl and checksum.
  */
 struct node_mbuf_priv1 {
@@ -37,6 +37,13 @@ struct node_mbuf_priv1 {
 	};
 };
 
+static const struct rte_mbuf_dynfield node_mbuf_priv1_dynfield_desc = {
+	.name = "rte_node_dynfield_priv1",
+	.size = sizeof(struct node_mbuf_priv1),
+	.align = __alignof__(struct node_mbuf_priv1),
+};
+extern int node_mbuf_priv1_dynfield_offset;
+
 /**
  * Node mbuf private area 2.
  */
@@ -58,9 +65,9 @@ struct node_mbuf_priv2 {
  *   Pointer to the mbuf_priv1.
  */
 static __rte_always_inline struct node_mbuf_priv1 *
-node_mbuf_priv1(struct rte_mbuf *m)
+node_mbuf_priv1(struct rte_mbuf *m, const int offset)
 {
-	return (struct node_mbuf_priv1 *)&m->udata64;
+	return RTE_MBUF_DYNFIELD(m, offset, struct node_mbuf_priv1 *);
 }
 
 /**
Signature · 1 line
2.28.0
#116 lore raw

PATCH v4 5/15 security: switch metadata to dynamic mbuf field

In reply to Thomas Monjalon

The device-specific metadata was stored in the deprecated field udata64. It is moved to a dynamic mbuf field in order to allow removal of udata64.

The name rte_security_dynfield is not very descriptive
but it should be replaced later by separate fields for each type of data that drivers pass to the upper layer.

---
 doc/guides/prog_guide/rte_security.rst        |  9 ++--
 drivers/crypto/octeontx2/otx2_cryptodev_sec.c |  5 ++-
 drivers/net/ixgbe/ixgbe_ipsec.c               |  5 ++-
 drivers/net/ixgbe/ixgbe_rxtx.c                |  6 ++-
 drivers/net/octeontx2/otx2_ethdev.h           |  1 +
 drivers/net/octeontx2/otx2_ethdev_sec.c       |  5 ++-
 drivers/net/octeontx2/otx2_ethdev_sec_tx.h    |  2 +-
 drivers/net/octeontx2/otx2_rx.h               |  2 +-
 examples/ipsec-secgw/ipsec-secgw.c            |  9 ++--
 examples/ipsec-secgw/ipsec_worker.c           | 12 ++++--
 lib/librte_security/rte_security.c            | 16 +++++++
 lib/librte_security/rte_security.h            | 42 +++++++++++++++++++
 lib/librte_security/rte_security_driver.h     |  3 ++
 lib/librte_security/version.map               |  2 +
 14 files changed, 99 insertions(+), 20 deletions(-)
doc/guides/prog_guide/rte_security.rst +5 -4
index c64aef3de9..f72bc8a78f 100644
@@ -125,8 +125,9 @@ ESP/AH headers will be removed from the packet and the received packet
 will contains the decrypted packet only. The driver Rx path checks the
 descriptors and based on the crypto status sets additional flags in
 ``rte_mbuf.ol_flags`` field. The driver would also set device-specific
-metadata in ``rte_mbuf.udata64`` field. This will allow the application
-to identify the security processing done on the packet.
+metadata in ``RTE_SECURITY_DYNFIELD_NAME`` field.
+This will allow the application to identify the security processing
+done on the packet.
 
 .. note::
 
@@ -568,8 +569,8 @@ security session which processed the packet.
 
 .. note::
 
-    In case of inline processed packets, ``rte_mbuf.udata64`` field would be
-    used by the driver to relay information on the security processing
+    In case of inline processed packets, ``RTE_SECURITY_DYNFIELD_NAME`` field
+    would be used by the driver to relay information on the security processing
     associated with the packet. In ingress, the driver would set this in Rx
     path while in egress, ``rte_security_set_pkt_metadata()`` would perform a
     similar operation. The application is expected not to modify the field
drivers/crypto/octeontx2/otx2_cryptodev_sec.c +4 -1
index b80ec7bff2..4e2a0e3afe 100644
@@ -455,6 +455,9 @@ otx2_crypto_sec_session_create(void *device,
 	if (conf->action_type != RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL)
 		return -ENOTSUP;
 
+	if (rte_security_dynfield_register() < 0)
+		return -rte_errno;
+
 	if (rte_mempool_get(mempool, (void **)&priv)) {
 		otx2_err("Could not allocate security session private data");
 		return -ENOMEM;
@@ -514,7 +517,7 @@ otx2_crypto_sec_set_pkt_mdata(void *device __rte_unused,
 			      struct rte_mbuf *m, void *params __rte_unused)
 {
 	/* Set security session as the pkt metadata */
-	m->udata64 = (uint64_t)session;
+	*rte_security_dynfield(m) = (rte_security_dynfield_t)session;
 
 	return 0;
 }
drivers/net/ixgbe/ixgbe_ipsec.c +4 -1
index 48f5082d49..62f2a5f764 100644
@@ -484,7 +484,8 @@ ixgbe_crypto_update_mb(void *device __rte_unused,
 			get_sec_session_private_data(session);
 	if (ic_session->op == IXGBE_OP_AUTHENTICATED_ENCRYPTION) {
 		union ixgbe_crypto_tx_desc_md *mdata =
-			(union ixgbe_crypto_tx_desc_md *)&m->udata64;
+			(union ixgbe_crypto_tx_desc_md *)
+				rte_security_dynfield(m);
 		mdata->enc = 1;
 		mdata->sa_idx = ic_session->sa_index;
 		mdata->pad_len = ixgbe_crypto_compute_pad_len(m);
@@ -751,5 +752,7 @@ ixgbe_ipsec_ctx_create(struct rte_eth_dev *dev)
 			return -ENOMEM;
 		}
 	}
+	if (rte_security_dynfield_register() < 0)
+		return -rte_errno;
 	return 0;
 }
drivers/net/ixgbe/ixgbe_rxtx.c +4 -2
index 5f19972031..6cfbb582e2 100644
@@ -34,6 +34,7 @@
 #include <rte_mbuf.h>
 #include <rte_ether.h>
 #include <rte_ethdev_driver.h>
+#include <rte_security_driver.h>
 #include <rte_prefetch.h>
 #include <rte_udp.h>
 #include <rte_tcp.h>
@@ -694,7 +695,7 @@ ixgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 			if (use_ipsec) {
 				union ixgbe_crypto_tx_desc_md *ipsec_mdata =
 					(union ixgbe_crypto_tx_desc_md *)
-							&tx_pkt->udata64;
+						rte_security_dynfield(tx_pkt);
 				tx_offload.sa_idx = ipsec_mdata->sa_idx;
 				tx_offload.sec_pad_len = ipsec_mdata->pad_len;
 			}
@@ -859,7 +860,8 @@ ixgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 				}
 
 				ixgbe_set_xmit_ctx(txq, ctx_txd, tx_ol_req,
-					tx_offload, &tx_pkt->udata64);
+					tx_offload,
+					rte_security_dynfield(tx_pkt));
 
 				txe->last_id = tx_last;
 				tx_id = txe->next_id;
drivers/net/octeontx2/otx2_ethdev.h +1 -0
index b20f399a15..3b9871f4dc 100644
@@ -13,6 +13,7 @@
 #include <rte_kvargs.h>
 #include <rte_mbuf.h>
 #include <rte_mempool.h>
+#include <rte_security_driver.h>
 #include <rte_string_fns.h>
 #include <rte_time.h>
 
drivers/net/octeontx2/otx2_ethdev_sec.c +4 -1
index 4e0dd4e49e..1ee597ff6e 100644
@@ -684,7 +684,7 @@ otx2_eth_sec_set_pkt_mdata(void *device __rte_unused,
 			    struct rte_mbuf *m, void *params __rte_unused)
 {
 	/* Set security session as the pkt metadata */
-	m->udata64 = (uint64_t)session;
+	*rte_security_dynfield(m) = (rte_security_dynfield_t)session;
 
 	return 0;
 }
@@ -831,6 +831,9 @@ otx2_eth_sec_init(struct rte_eth_dev *eth_dev)
 	    !(dev->rx_offloads & DEV_RX_OFFLOAD_SECURITY))
 		return 0;
 
+	if (rte_security_dynfield_register() < 0)
+		return -rte_errno;
+
 	nb_sa = dev->ipsec_in_max_spi;
 	mz_sz = nb_sa * sa_width;
 	in_sa_mz_name_get(name, RTE_MEMZONE_NAMESIZE, port);
drivers/net/octeontx2/otx2_ethdev_sec_tx.h +1 -1
index 5bf8c19995..284bcd5367 100644
@@ -55,7 +55,7 @@ otx2_sec_event_tx(struct otx2_ssogws *ws, struct rte_event *ev,
 		struct nix_iova_s nix_iova;
 	} *sd;
 
-	priv = get_sec_session_private_data((void *)(m->udata64));
+	priv = get_sec_session_private_data((void *)(*rte_security_dynfield(m)));
 	sess = &priv->ipsec.ip;
 	sa = &sess->out_sa;
 
drivers/net/octeontx2/otx2_rx.h +1 -1
index f29a0542f9..61a5c436dd 100644
@@ -241,7 +241,7 @@ nix_rx_sec_mbuf_update(const struct nix_cqe_hdr_s *cq, struct rte_mbuf *m,
 	spi = cq->tag & 0xFFFFF;
 
 	sa = nix_rx_sec_sa_get(lookup_mem, spi, m->port);
-	m->udata64 = (uint64_t)sa->userdata;
+	*rte_security_dynfield(m) = sa->udata64;
 
 	data = rte_pktmbuf_mtod(m, char *);
 
examples/ipsec-secgw/ipsec-secgw.c +4 -5
index 2219148285..bbe7ce48d9 100644
@@ -426,7 +426,8 @@ prepare_one_packet(struct rte_mbuf *pkt, struct ipsec_traffic *t)
 	 * with the security session.
 	 */
 
-	if (pkt->ol_flags & PKT_RX_SEC_OFFLOAD) {
+	if (pkt->ol_flags & PKT_RX_SEC_OFFLOAD &&
+			rte_security_dynfield_is_registered()) {
 		struct ipsec_sa *sa;
 		struct ipsec_mbuf_metadata *priv;
 		struct rte_security_ctx *ctx = (struct rte_security_ctx *)
@@ -436,10 +437,8 @@ prepare_one_packet(struct rte_mbuf *pkt, struct ipsec_traffic *t)
 		/* Retrieve the userdata registered. Here, the userdata
 		 * registered is the SA pointer.
 		 */
-
-		sa = (struct ipsec_sa *)
-				rte_security_get_userdata(ctx, pkt->udata64);
-
+		sa = (struct ipsec_sa *)rte_security_get_userdata(ctx,
+				*rte_security_dynfield(pkt));
 		if (sa == NULL) {
 			/* userdata could not be retrieved */
 			return;
examples/ipsec-secgw/ipsec_worker.c +8 -4
index b6c851f257..647e22df59 100644
@@ -208,7 +208,7 @@ process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt,
 					"Inbound security offload failed\n");
 				goto drop_pkt_and_exit;
 			}
-			sa = pkt->userdata;
+			sa = *(struct ipsec_sa **)rte_security_dynfield(pkt);
 		}
 
 		/* Check if we have a match */
@@ -226,7 +226,7 @@ process_ipsec_ev_inbound(struct ipsec_ctx *ctx, struct route_table *rt,
 					"Inbound security offload failed\n");
 				goto drop_pkt_and_exit;
 			}
-			sa = pkt->userdata;
+			sa = *(struct ipsec_sa **)rte_security_dynfield(pkt);
 		}
 
 		/* Check if we have a match */
@@ -357,7 +357,8 @@ process_ipsec_ev_outbound(struct ipsec_ctx *ctx, struct route_table *rt,
 	}
 
 	if (sess->security.ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA)
-		pkt->userdata = sess->security.ses;
+		*(struct rte_security_session **)rte_security_dynfield(pkt) =
+				sess->security.ses;
 
 	/* Mark the packet for Tx security offload */
 	pkt->ol_flags |= PKT_TX_SEC_OFFLOAD;
@@ -465,7 +466,10 @@ ipsec_wrkr_non_burst_int_port_drv_mode(struct eh_event_link_info *links,
 			}
 
 			/* Save security session */
-			pkt->userdata = sess_tbl[port_id];
+			if (rte_security_dynfield_is_registered())
+				*(struct rte_security_session **)
+					rte_security_dynfield(pkt) =
+						sess_tbl[port_id];
 
 			/* Mark the packet for Tx security offload */
 			pkt->ol_flags |= PKT_TX_SEC_OFFLOAD;
lib/librte_security/rte_security.c +16 -0
index ee4666026a..e8116d5447 100644
@@ -23,6 +23,22 @@
 	RTE_PTR_OR_ERR_RET(p1->p2->p3, last_retval);			\
 } while (0)
 
+#define RTE_SECURITY_DYNFIELD_NAME "rte_security_dynfield_metadata"
+int rte_security_dynfield_offset = -1;
+
+int
+rte_security_dynfield_register(void)
+{
+	static const struct rte_mbuf_dynfield dynfield_desc = {
+		.name = RTE_SECURITY_DYNFIELD_NAME,
+		.size = sizeof(rte_security_dynfield_t),
+		.align = __alignof__(rte_security_dynfield_t),
+	};
+	rte_security_dynfield_offset =
+		rte_mbuf_dynfield_register(&dynfield_desc);
+	return rte_security_dynfield_offset;
+}
+
 struct rte_security_session *
 rte_security_session_create(struct rte_security_ctx *instance,
 			    struct rte_security_session_conf *conf,
lib/librte_security/rte_security.h +42 -0

54 lines not on this page · raw message

lib/librte_security/rte_security_driver.h +3 -0
index 1b561f8528..c5abb07990 100644
@@ -89,6 +89,9 @@ typedef int (*security_session_stats_get_t)(void *device,
 		struct rte_security_session *sess,
 		struct rte_security_stats *stats);
 
+__rte_experimental
+int rte_security_dynfield_register(void);
+
 /**
  * Update the mbuf with provided metadata.
  *
lib/librte_security/version.map +2 -0
index d84eec0a88..22775558c8 100644
@@ -15,6 +15,8 @@ DPDK_21 {
 EXPERIMENTAL {
 	global:
 
+	rte_security_dynfield_offset;
+	rte_security_dynfield_register;
 	rte_security_get_userdata;
 	rte_security_session_stats_get;
 	rte_security_session_update;
Signature · 1 line
2.28.0
#117 lore raw

PATCH v4 6/15 event/sw: switch test counter to dynamic mbuf field

In reply to Thomas Monjalon

The test worker_loopback used the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 drivers/event/sw/sw_evdev_selftest.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/event/sw/sw_evdev_selftest.c +20 -3
index 5c7e527917..ad4fc0eed7 100644
@@ -40,6 +40,11 @@ struct test {
 	uint32_t service_id;
 };
 
+typedef uint8_t counter_dynfield_t;
+static int counter_dynfield_offset = -1;
+#define COUNTER_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		counter_dynfield_offset, counter_dynfield_t *))
+
 static struct rte_event release_ev;
 
 static inline struct rte_mbuf *
@@ -2987,8 +2992,8 @@ worker_loopback_worker_fn(void *arg)
 			}
 
 			ev[i].queue_id = 0;
-			ev[i].mbuf->udata64++;
-			if (ev[i].mbuf->udata64 != 16) {
+			COUNTER_FIELD(ev[i].mbuf)++;
+			if (COUNTER_FIELD(ev[i].mbuf) != 16) {
 				ev[i].op = RTE_EVENT_OP_FORWARD;
 				enqd = rte_event_enqueue_burst(evdev, port,
 						&ev[i], 1);
@@ -3028,7 +3033,7 @@ worker_loopback_producer_fn(void *arg)
 			m = rte_pktmbuf_alloc(t->mbuf_pool);
 		} while (m == NULL);
 
-		m->udata64 = 0;
+		COUNTER_FIELD(m) = 0;
 
 		struct rte_event ev = {
 				.op = RTE_EVENT_OP_NEW,
@@ -3061,6 +3066,18 @@ worker_loopback(struct test *t, uint8_t disable_implicit_release)
 	int err;
 	int w_lcore, p_lcore;
 
+	static const struct rte_mbuf_dynfield counter_dynfield_desc = {
+		.name = "rte_event_sw_dynfield_selftest_counter",
+		.size = sizeof(counter_dynfield_t),
+		.align = __alignof__(counter_dynfield_t),
+	};
+	counter_dynfield_offset =
+		rte_mbuf_dynfield_register(&counter_dynfield_desc);
+	if (counter_dynfield_offset < 0) {
+		printf("Error registering mbuf field\n");
+		return -rte_errno;
+	}
+
 	if (init(t, 8, 2) < 0 ||
 			create_atomic_qids(t, 8) < 0) {
 		printf("%d: Error initializing device\n", __LINE__);
Signature · 1 line
2.28.0
#118 lore raw

PATCH v4 7/15 net/ark: switch user data to dynamic mbuf fields

In reply to Thomas Monjalon

From: Ed Czeck <[email protected]>

The second field of metadata is reserved for user data which was using a deprecated mbuf field.
It is moved to dynamic fields in order to allow removal of udata64.

The use of meta data must be enabled with a compile-time flag RTE_PMD_ARK_{TX,RX}_USERDATA_ENABLE.
User data on Tx and Rx paths can be defined and used separately.

---
 doc/api/doxy-api-index.md       |   1 +
 doc/api/doxy-api.conf.in        |   1 +
 drivers/net/ark/ark_ethdev.c    |  39 ++++++++++
 drivers/net/ark/ark_ethdev_rx.c |   3 +-
 drivers/net/ark/ark_ethdev_tx.c |   3 +-
 drivers/net/ark/meson.build     |   2 +
 drivers/net/ark/rte_pmd_ark.h   | 123 ++++++++++++++++++++++++++++++++
 drivers/net/ark/version.map     |   7 ++
 8 files changed, 177 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ark/rte_pmd_ark.h
doc/api/doxy-api-index.md +1 -0
index a9c12d1a2f..b865a51e8c 100644
@@ -41,6 +41,7 @@ The public API headers are grouped by topics:
   [vhost]              (@ref rte_vhost.h),
   [vdpa]               (@ref rte_vdpa.h),
   [KNI]                (@ref rte_kni.h),
+  [ark]                (@ref rte_pmd_ark.h),
   [ixgbe]              (@ref rte_pmd_ixgbe.h),
   [i40e]               (@ref rte_pmd_i40e.h),
   [ice]                (@ref rte_pmd_ice.h),
doc/api/doxy-api.conf.in +1 -0
index e37f8c2e80..c5b01a1814 100644
@@ -8,6 +8,7 @@ INPUT                   = @TOPDIR@/doc/api/doxy-api-index.md \
                           @TOPDIR@/drivers/bus/vdev \
                           @TOPDIR@/drivers/crypto/scheduler \
                           @TOPDIR@/drivers/mempool/dpaa2 \
+                          @TOPDIR@/drivers/net/ark \
                           @TOPDIR@/drivers/net/bnxt \
                           @TOPDIR@/drivers/net/bonding \
                           @TOPDIR@/drivers/net/dpaa \
drivers/net/ark/ark_ethdev.c +39 -0
index 168b3659d6..7b03f0fbc2 100644
@@ -10,6 +10,7 @@
 #include <rte_ethdev_pci.h>
 #include <rte_kvargs.h>
 
+#include "rte_pmd_ark.h"
 #include "ark_global.h"
 #include "ark_logs.h"
 #include "ark_ethdev_tx.h"
@@ -78,6 +79,9 @@ static int  eth_ark_set_mtu(struct rte_eth_dev *dev, uint16_t size);
 #define ARK_TX_MAX_QUEUE (4096 * 4)
 #define ARK_TX_MIN_QUEUE (256)
 
+int rte_pmd_ark_rx_userdata_dynfield_offset = -1;
+int rte_pmd_ark_tx_userdata_dynfield_offset = -1;
+
 static const char * const valid_arguments[] = {
 	ARK_PKTGEN_ARG,
 	ARK_PKTCHKR_ARG,
@@ -245,6 +249,16 @@ eth_ark_dev_init(struct rte_eth_dev *dev)
 	int ret;
 	int port_count = 1;
 	int p;
+	static const struct rte_mbuf_dynfield ark_tx_userdata_dynfield_desc = {
+		.name = RTE_PMD_ARK_TX_USERDATA_DYNFIELD_NAME,
+		.size = sizeof(rte_pmd_ark_userdata_t),
+		.align = __alignof__(rte_pmd_ark_userdata_t),
+	};
+	static const struct rte_mbuf_dynfield ark_rx_userdata_dynfield_desc = {
+		.name = RTE_PMD_ARK_RX_USERDATA_DYNFIELD_NAME,
+		.size = sizeof(rte_pmd_ark_userdata_t),
+		.align = __alignof__(rte_pmd_ark_userdata_t),
+	};
 
 	ark->eth_dev = dev;
 
@@ -254,6 +268,31 @@ eth_ark_dev_init(struct rte_eth_dev *dev)
 	ret = check_for_ext(ark);
 	if (ret)
 		return ret;
+
+	/* Extra mbuf fields for user data */
+	if (RTE_PMD_ARK_TX_USERDATA_ENABLE) {
+		rte_pmd_ark_tx_userdata_dynfield_offset =
+		    rte_mbuf_dynfield_register(&ark_tx_userdata_dynfield_desc);
+		if (rte_pmd_ark_tx_userdata_dynfield_offset < 0) {
+			ARK_PMD_LOG(ERR,
+				    "Failed to register mbuf field for tx userdata\n");
+			return -rte_errno;
+		}
+		ARK_PMD_LOG(INFO, "Registered TX-meta dynamic field at %d\n",
+			    rte_pmd_ark_tx_userdata_dynfield_offset);
+	}
+	if (RTE_PMD_ARK_RX_USERDATA_ENABLE) {
+		rte_pmd_ark_rx_userdata_dynfield_offset =
+		    rte_mbuf_dynfield_register(&ark_rx_userdata_dynfield_desc);
+		if (rte_pmd_ark_rx_userdata_dynfield_offset < 0) {
+			ARK_PMD_LOG(ERR,
+				    "Failed to register mbuf field for rx userdata\n");
+			return -rte_errno;
+		}
+		ARK_PMD_LOG(INFO, "Registered RX-meta dynamic field at %d\n",
+			    rte_pmd_ark_rx_userdata_dynfield_offset);
+	}
+
 	pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 	rte_eth_copy_pci_info(dev, pci_dev);
 	dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
drivers/net/ark/ark_ethdev_rx.c +2 -1
index 2f8d05099c..825b4791be 100644
@@ -4,6 +4,7 @@
 
 #include <unistd.h>
 
+#include "rte_pmd_ark.h"
 #include "ark_ethdev_rx.h"
 #include "ark_global.h"
 #include "ark_logs.h"
@@ -272,7 +273,7 @@ eth_ark_recv_pkts(void *rx_queue,
 		mbuf->pkt_len = meta->pkt_len;
 		mbuf->data_len = meta->pkt_len;
 		mbuf->timestamp = meta->timestamp;
-		mbuf->udata64 = meta->user_data;
+		rte_pmd_ark_mbuf_rx_userdata_set(mbuf, meta->user_data);
 
 		if (ARK_DEBUG_CORE) {	/* debug sanity checks */
 			if ((meta->pkt_len > (1024 * 16)) ||
drivers/net/ark/ark_ethdev_tx.c +2 -1
index a0e35af880..612d918e33 100644
@@ -4,6 +4,7 @@
 
 #include <unistd.h>
 
+#include "rte_pmd_ark.h"
 #include "ark_ethdev_tx.h"
 #include "ark_global.h"
 #include "ark_mpu.h"
@@ -70,7 +71,7 @@ eth_ark_tx_meta_from_mbuf(struct ark_tx_meta *meta,
 			  uint8_t flags)
 {
 	meta->physaddr = rte_mbuf_data_iova(mbuf);
-	meta->user1 = (uint32_t)mbuf->udata64;
+	meta->user1 = rte_pmd_ark_mbuf_tx_userdata_get(mbuf);
 	meta->data_len = rte_pktmbuf_data_len(mbuf);
 	meta->flags = flags;
 }
drivers/net/ark/meson.build +2 -0
index 99151bba1d..80bce94e1a 100644
@@ -1,6 +1,8 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Intel Corporation
 
+headers = files('rte_pmd_ark.h')
+
 sources = files('ark_ddm.c',
 	'ark_ethdev.c',
 	'ark_ethdev_rx.c',
drivers/net/ark/rte_pmd_ark.h new file +123 -0

123 lines not on this page · raw message

drivers/net/ark/version.map +7 -0
index 4a76d1d52d..954bea6796 100644
@@ -1,3 +1,10 @@
 DPDK_21 {
 	local: *;
 };
+
+EXPERIMENTAL {
+	global:
+
+	rte_pmd_ark_tx_userdata_dynfield_offset;
+	rte_pmd_ark_rx_userdata_dynfield_offset;
+};
Signature · 1 line
2.28.0
#119 lore raw

PATCH v4 8/15 net/bnxt: switch CFA code to dynamic mbuf field

In reply to Thomas Monjalon

The CFA code from mark was stored in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

Note: the new field has 32 bits, smaller than udata64.

---
 drivers/net/bnxt/bnxt_ethdev.c  | 19 +++++++++++++++++++
 drivers/net/bnxt/bnxt_rxr.c     |  2 +-
 drivers/net/bnxt/bnxt_rxr.h     |  5 +++++
 drivers/net/bnxt/rte_pmd_bnxt.h |  3 +++
 4 files changed, 28 insertions(+), 1 deletion(-)
drivers/net/bnxt/bnxt_ethdev.c +19 -0
index 1c7d1b758d..f1350d39da 100644
@@ -31,6 +31,7 @@
 #include "bnxt_nvm_defs.h"
 #include "bnxt_tf_common.h"
 #include "ulp_flow_db.h"
+#include "rte_pmd_bnxt.h"
 
 #define DRV_MODULE_NAME		"bnxt"
 static const char bnxt_version[] =
@@ -163,6 +164,8 @@ static const char *const bnxt_dev_args[] = {
  */
 #define BNXT_DEVARG_REP_FC_F2R_INVALID(rep_fc_f2r)	((rep_fc_f2r) > 1)
 
+int bnxt_cfa_code_dynfield_offset = -1;
+
 /*
  * max_num_kflows must be >= 32
  * and must be a power-of-2 supported value
@@ -6021,6 +6024,22 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev, void *params __rte_unused)
 	    pci_dev->id.device_id == BROADCOM_DEV_ID_58802_VF)
 		bp->flags |= BNXT_FLAG_STINGRAY;
 
+	if (BNXT_TRUFLOW_EN(bp)) {
+		/* extra mbuf field is required to store CFA code from mark */
+		static const struct rte_mbuf_dynfield bnxt_cfa_code_dynfield_desc = {
+			.name = RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME,
+			.size = sizeof(bnxt_cfa_code_dynfield_t),
+			.align = __alignof__(bnxt_cfa_code_dynfield_t),
+		};
+		bnxt_cfa_code_dynfield_offset =
+			rte_mbuf_dynfield_register(&bnxt_cfa_code_dynfield_desc);
+		if (bnxt_cfa_code_dynfield_offset < 0) {
+			PMD_DRV_LOG(ERR,
+			    "Failed to register mbuf field for TruFlow mark\n");
+			return -rte_errno;
+		}
+	}
+
 	rc = bnxt_init_board(eth_dev);
 	if (rc) {
 		PMD_DRV_LOG(ERR,
drivers/net/bnxt/bnxt_rxr.c +1 -1
index 039217fa60..7156ce7dd8 100644
@@ -606,7 +606,7 @@ bnxt_ulp_set_mark_in_mbuf(struct bnxt *bp, struct rx_pkt_cmpl_hi *rxcmp1,
 			return mark_id;
 		/* Got the mark, write it to the mbuf and return */
 		mbuf->hash.fdir.hi = mark_id;
-		mbuf->udata64 = (cfa_code & 0xffffffffull) << 32;
+		BNXT_CFA_CODE_DYNFIELD(mbuf) = cfa_code & 0xffffffffull;
 		mbuf->hash.fdir.id = rxcmp1->cfa_code;
 		mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
 		return mark_id;
drivers/net/bnxt/bnxt_rxr.h +5 -0
index b874e54a8c..2d16a551ce 100644
@@ -95,6 +95,11 @@ void bnxt_set_mark_in_mbuf(struct bnxt *bp,
 			   struct rx_pkt_cmpl_hi *rxcmp1,
 			   struct rte_mbuf *mbuf);
 
+typedef uint32_t bnxt_cfa_code_dynfield_t;
+extern int bnxt_cfa_code_dynfield_offset;
+#define BNXT_CFA_CODE_DYNFIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		bnxt_cfa_code_dynfield_offset, bnxt_cfa_code_dynfield_t *))
+
 #define BNXT_RX_META_CFA_CODE_SHIFT		19
 #define BNXT_CFA_CODE_META_SHIFT		16
 #define BNXT_RX_META_CFA_CODE_INT_ACT_REC_BIT	0x8000000
drivers/net/bnxt/rte_pmd_bnxt.h +3 -0
index 81d0d0e032..f538b6550e 100644
@@ -9,6 +9,9 @@
 #include <rte_ethdev.h>
 #include <rte_ether.h>
 
+/** mbuf dynamic field where CFA code is stored */
+#define RTE_PMD_BNXT_CFA_CODE_DYNFIELD_NAME "rte_net_bnxt_dynfield_cfa_code"
+
 /*
  * Response sent back to the caller after callback
  */
Signature · 1 line
2.28.0
#120 lore raw

PATCH v4 9/15 net/vmxnet3: switch MSS hint to dynamic mbuf field

In reply to Thomas Monjalon

The segment count, used for MSS guess,
was stored in the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 drivers/net/vmxnet3/vmxnet3_ethdev.c | 15 +++++++++++++++
 drivers/net/vmxnet3/vmxnet3_ethdev.h |  6 ++++++
 drivers/net/vmxnet3/vmxnet3_rxtx.c   |  9 +++++----
 3 files changed, 26 insertions(+), 4 deletions(-)
drivers/net/vmxnet3/vmxnet3_ethdev.c +15 -0
index 6920ab568c..23a2ebbefa 100644
@@ -59,6 +59,8 @@
 	 DEV_RX_OFFLOAD_JUMBO_FRAME |   \
 	 DEV_RX_OFFLOAD_RSS_HASH)
 
+int vmxnet3_segs_dynfield_offset = -1;
+
 static int eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev);
 static int eth_vmxnet3_dev_uninit(struct rte_eth_dev *eth_dev);
 static int vmxnet3_dev_configure(struct rte_eth_dev *dev);
@@ -233,6 +235,11 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	struct vmxnet3_hw *hw = eth_dev->data->dev_private;
 	uint32_t mac_hi, mac_lo, ver;
 	struct rte_eth_link link;
+	static const struct rte_mbuf_dynfield vmxnet3_segs_dynfield_desc = {
+		.name = VMXNET3_SEGS_DYNFIELD_NAME,
+		.size = sizeof(vmxnet3_segs_dynfield_t),
+		.align = __alignof__(vmxnet3_segs_dynfield_t),
+	};
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -242,6 +249,14 @@ eth_vmxnet3_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->tx_pkt_prepare = vmxnet3_prep_pkts;
 	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 
+	/* extra mbuf field is required to guess MSS */
+	vmxnet3_segs_dynfield_offset =
+		rte_mbuf_dynfield_register(&vmxnet3_segs_dynfield_desc);
+	if (vmxnet3_segs_dynfield_offset < 0) {
+		PMD_INIT_LOG(ERR, "Cannot register mbuf field.");
+		return -rte_errno;
+	}
+
 	/*
 	 * for secondary processes, we don't initialize any further as primary
 	 * has already done this work.
drivers/net/vmxnet3/vmxnet3_ethdev.h +6 -0
index dd685b02b7..e19718ce64 100644
@@ -193,4 +193,10 @@ uint16_t vmxnet3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 uint16_t vmxnet3_prep_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 			uint16_t nb_pkts);
 
+#define VMXNET3_SEGS_DYNFIELD_NAME "rte_net_vmxnet3_dynfield_segs"
+typedef uint8_t vmxnet3_segs_dynfield_t;
+extern int vmxnet3_segs_dynfield_offset;
+#define VMXNET3_SEGS_DYNFIELD(mbuf) (*RTE_MBUF_DYNFIELD(rxm, \
+		vmxnet3_segs_dynfield_offset, vmxnet3_segs_dynfield_t *))
+
 #endif /* _VMXNET3_ETHDEV_H_ */
drivers/net/vmxnet3/vmxnet3_rxtx.c +5 -4
index e10f9ee870..2b0e2e6f19 100644
@@ -674,6 +674,7 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	struct rte_ipv6_hdr *ipv6_hdr;
 	struct rte_tcp_hdr *tcp_hdr;
 	char *ptr;
+	uint8_t segs;
 
 	RTE_ASSERT(rcd->tcp);
 
@@ -710,9 +711,9 @@ vmxnet3_guess_mss(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 	tcp_hdr = (struct rte_tcp_hdr *)(ptr + hlen);
 	hlen += (tcp_hdr->data_off & 0xf0) >> 2;
 
-	if (rxm->udata64 > 1)
-		return (rte_pktmbuf_pkt_len(rxm) - hlen +
-				rxm->udata64 - 1) / rxm->udata64;
+	segs = VMXNET3_SEGS_DYNFIELD(rxm);
+	if (segs > 1)
+		return (rte_pktmbuf_pkt_len(rxm) - hlen + segs - 1) / segs;
 	else
 		return hw->mtu - hlen + sizeof(struct rte_ether_hdr);
 }
@@ -737,7 +738,7 @@ vmxnet3_rx_offload(struct vmxnet3_hw *hw, const Vmxnet3_RxCompDesc *rcd,
 					(const Vmxnet3_RxCompDescExt *)rcd;
 
 			rxm->tso_segsz = rcde->mss;
-			rxm->udata64 = rcde->segCnt;
+			VMXNET3_SEGS_DYNFIELD(rxm) = rcde->segCnt;
 			ol_flags |= PKT_RX_LRO;
 		}
 	} else { /* Offloads set in eop */
Signature · 1 line
2.28.0
#121 lore raw

PATCH v4 10/15 test/distributor: switch sequence to dynamic mbuf field

In reply to Thomas Monjalon

The test used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 app/test/test_distributor.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
app/test/test_distributor.c +23 -5
index eb889b91d1..24ee824eef 100644
@@ -10,6 +10,7 @@
 #include <rte_errno.h>
 #include <rte_mempool.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_distributor.h>
 #include <rte_string_fns.h>
 
@@ -17,6 +18,11 @@
 #define BURST 32
 #define BIG_BATCH 1024
 
+typedef uint32_t seq_dynfield_t;
+static int seq_dynfield_offset = -1;
+#define SEQ_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		seq_dynfield_offset, seq_dynfield_t *))
+
 struct worker_params {
 	char name[64];
 	struct rte_distributor *dist;
@@ -578,7 +584,7 @@ handle_and_mark_work(void *arg)
 		__atomic_fetch_add(&worker_stats[id].handled_packets, num,
 				__ATOMIC_RELAXED);
 		for (i = 0; i < num; i++)
-			buf[i]->udata64 += id + 1;
+			SEQ_FIELD(buf[i]) += id + 1;
 		num = rte_distributor_get_pkt(db, id,
 				buf, buf, num);
 	}
@@ -631,10 +637,10 @@ sanity_mark_test(struct worker_params *wp, struct rte_mempool *p)
 			<< shift;
 	}
 	/* Assign a sequence number to each packet. The sequence is shifted,
-	 * so that lower bits of the udate64 will hold mark from worker.
+	 * so that lower bits will hold mark from worker.
 	 */
 	for (i = 0; i < buf_count; i++)
-		bufs[i]->udata64 = i << seq_shift;
+		SEQ_FIELD(bufs[i]) = i << seq_shift;
 
 	count = 0;
 	for (i = 0; i < buf_count/burst; i++) {
@@ -660,8 +666,8 @@ sanity_mark_test(struct worker_params *wp, struct rte_mempool *p)
 
 	/* Sort returned packets by sent order (sequence numbers). */
 	for (i = 0; i < buf_count; i++) {
-		seq = returns[i]->udata64 >> seq_shift;
-		id = returns[i]->udata64 - (seq << seq_shift);
+		seq = SEQ_FIELD(returns[i]) >> seq_shift;
+		id = SEQ_FIELD(returns[i]) - (seq << seq_shift);
 		sorted[seq] = id;
 	}
 
@@ -805,6 +811,18 @@ test_distributor(void)
 	static struct rte_mempool *p;
 	int i;
 
+	static const struct rte_mbuf_dynfield seq_dynfield_desc = {
+		.name = "test_distributor_dynfield_seq",
+		.size = sizeof(seq_dynfield_t),
+		.align = __alignof__(seq_dynfield_t),
+	};
+	seq_dynfield_offset =
+		rte_mbuf_dynfield_register(&seq_dynfield_desc);
+	if (seq_dynfield_offset < 0) {
+		printf("Error registering mbuf field\n");
+		return TEST_FAILED;
+	}
+
 	if (rte_lcore_count() < 2) {
 		printf("Not enough cores for distributor_autotest, expecting at least 2\n");
 		return TEST_SKIPPED;
Signature · 1 line
2.28.0
#122 lore raw

PATCH v4 11/15 test/graph: switch user data to dynamic mbuf field

In reply to Thomas Monjalon

The test used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 app/test/test_graph.c | 94 ++++++++++++++++++++++++++-----------------
 1 file changed, 56 insertions(+), 38 deletions(-)
app/test/test_graph.c +56 -38
index ed69eda997..164486911f 100644
@@ -12,6 +12,7 @@
 #include <rte_graph.h>
 #include <rte_graph_worker.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_random.h>
 
 #include "test.h"
@@ -39,6 +40,11 @@ static uint16_t test_node3_worker(struct rte_graph *graph,
 #define MBUFF_SIZE 512
 #define MAX_NODES  4
 
+typedef uint64_t graph_dynfield_t;
+static int graph_dynfield_offset = -1;
+#define GRAPH_FIELD(mbuf) (*RTE_MBUF_DYNFIELD(mbuf, \
+		graph_dynfield_offset, graph_dynfield_t *))
+
 static struct rte_mbuf mbuf[MAX_NODES + 1][MBUFF_SIZE];
 static void *mbuf_p[MAX_NODES + 1][MBUFF_SIZE];
 static rte_graph_t graph_id;
@@ -162,9 +168,9 @@ test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
 	next_stream = rte_node_next_stream_get(graph, node, next, obj_node0);
 	for (i = 0; i < obj_node0; i++) {
 		data = &mbuf[0][i];
-		data->udata64 = ((uint64_t)tm->test_node[0].idx << 32) | i;
+		GRAPH_FIELD(data) = ((uint64_t)tm->test_node[0].idx << 32) | i;
 		if ((i + 1) == obj_node0)
-			data->udata64 |= (1 << 16);
+			GRAPH_FIELD(data) |= (1 << 16);
 		next_stream[i] = &mbuf[0][i];
 	}
 	rte_node_next_stream_put(graph, node, next, obj_node0);
@@ -175,9 +181,9 @@ test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
 	next_stream = rte_node_next_stream_get(graph, node, next, obj_node1);
 	for (i = 0; i < obj_node1; i++) {
 		data = &mbuf[0][obj_node0 + i];
-		data->udata64 = ((uint64_t)tm->test_node[1].idx << 32) | i;
+		GRAPH_FIELD(data) = ((uint64_t)tm->test_node[1].idx << 32) | i;
 		if ((i + 1) == obj_node1)
-			data->udata64 |= (1 << 16);
+			GRAPH_FIELD(data) |= (1 << 16);
 		next_stream[i] = &mbuf[0][obj_node0 + i];
 	}
 
@@ -205,23 +211,23 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 
 		for (i = 0; i < nb_objs; i++) {
 			data = (struct rte_mbuf *)objs[i];
-			if ((data->udata64 >> 32) != tm->test_node[0].idx) {
+			if ((GRAPH_FIELD(data) >> 32) != tm->test_node[0].idx) {
 				printf("Data idx miss match at node 0, expected"
 				       " = %u got = %u\n",
 				       tm->test_node[0].idx,
-				       (uint32_t)(data->udata64 >> 32));
+				       (uint32_t)(GRAPH_FIELD(data) >> 32));
 				goto end;
 			}
 
-			if ((data->udata64 & 0xffff) != (i - count)) {
+			if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 				printf("Expected buff count miss match at "
 				       "node 0\n");
 				goto end;
 			}
 
-			if (data->udata64 & (0x1 << 16))
+			if (GRAPH_FIELD(data) & (0x1 << 16))
 				count = i + 1;
-			if (data->udata64 & (0x1 << 17))
+			if (GRAPH_FIELD(data) & (0x1 << 17))
 				second_pass = 1;
 		}
 
@@ -233,12 +239,12 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node0 = nb_objs * obj_node0 * 0.01;
 		for (i = 0; i < obj_node0; i++) {
 			data = &mbuf[1][i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[1].idx << 32) | i;
 			if ((i + 1) == obj_node0)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 			if (second_pass)
-				data->udata64 |= (1 << 17);
+				GRAPH_FIELD(data) |= (1 << 17);
 		}
 		rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[1][0],
 				 obj_node0);
@@ -246,12 +252,12 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node1 = nb_objs - obj_node0;
 		for (i = 0; i < obj_node1; i++) {
 			data = &mbuf[1][obj_node0 + i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[2].idx << 32) | i;
 			if ((i + 1) == obj_node1)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 			if (second_pass)
-				data->udata64 |= (1 << 17);
+				GRAPH_FIELD(data) |= (1 << 17);
 		}
 		rte_node_enqueue(graph, node, 1, (void **)&mbuf_p[1][obj_node0],
 				 obj_node1);
@@ -285,22 +291,22 @@ test_node1_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	fn_calls[2] += 1;
 	for (i = 0; i < nb_objs; i++) {
 		data = (struct rte_mbuf *)objs[i];
-		if ((data->udata64 >> 32) != tm->test_node[1].idx) {
+		if ((GRAPH_FIELD(data) >> 32) != tm->test_node[1].idx) {
 			printf("Data idx miss match at node 1, expected = %u"
 			       " got = %u\n",
 			       tm->test_node[1].idx,
-			       (uint32_t)(data->udata64 >> 32));
+			       (uint32_t)(GRAPH_FIELD(data) >> 32));
 			goto end;
 		}
 
-		if ((data->udata64 & 0xffff) != (i - count)) {
+		if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 			printf("Expected buff count miss match at node 1\n");
 			goto end;
 		}
 
-		if (data->udata64 & (0x1 << 16))
+		if (GRAPH_FIELD(data) & (0x1 << 16))
 			count = i + 1;
-		if (data->udata64 & (0x1 << 17))
+		if (GRAPH_FIELD(data) & (0x1 << 17))
 			second_pass = 1;
 	}
 
@@ -312,11 +318,11 @@ test_node1_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	obj_node0 = nb_objs;
 	for (i = 0; i < obj_node0; i++) {
 		data = &mbuf[2][i];
-		data->udata64 = ((uint64_t)tm->test_node[2].idx << 32) | i;
+		GRAPH_FIELD(data) = ((uint64_t)tm->test_node[2].idx << 32) | i;
 		if ((i + 1) == obj_node0)
-			data->udata64 |= (1 << 16);
+			GRAPH_FIELD(data) |= (1 << 16);
 		if (second_pass)
-			data->udata64 |= (1 << 17);
+			GRAPH_FIELD(data) |= (1 << 17);
 	}
 	rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[2][0], obj_node0);
 
@@ -339,22 +345,22 @@ test_node2_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	fn_calls[3] += 1;
 	for (i = 0; i < nb_objs; i++) {
 		data = (struct rte_mbuf *)objs[i];
-		if ((data->udata64 >> 32) != tm->test_node[2].idx) {
+		if ((GRAPH_FIELD(data) >> 32) != tm->test_node[2].idx) {
 			printf("Data idx miss match at node 2, expected = %u"
 			       " got = %u\n",
 			       tm->test_node[2].idx,
-			       (uint32_t)(data->udata64 >> 32));
+			       (uint32_t)(GRAPH_FIELD(data) >> 32));
 			goto end;
 		}
 
-		if ((data->udata64 & 0xffff) != (i - count)) {
+		if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 			printf("Expected buff count miss match at node 2\n");
 			goto end;
 		}
 
-		if (data->udata64 & (0x1 << 16))
+		if (GRAPH_FIELD(data) & (0x1 << 16))
 			count = i + 1;
-		if (data->udata64 & (0x1 << 17))
+		if (GRAPH_FIELD(data) & (0x1 << 17))
 			second_pass = 1;
 	}
 
@@ -367,10 +373,10 @@ test_node2_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node0 = nb_objs;
 		for (i = 0; i < obj_node0; i++) {
 			data = &mbuf[3][i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[3].idx << 32) | i;
 			if ((i + 1) == obj_node0)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 		}
 		rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[3][0],
 				 obj_node0);
@@ -395,22 +401,22 @@ test_node3_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 	fn_calls[4] += 1;
 	for (i = 0; i < nb_objs; i++) {
 		data = (struct rte_mbuf *)objs[i];
-		if ((data->udata64 >> 32) != tm->test_node[3].idx) {
+		if ((GRAPH_FIELD(data) >> 32) != tm->test_node[3].idx) {
 			printf("Data idx miss match at node 3, expected = %u"
 			       " got = %u\n",
 			       tm->test_node[3].idx,
-			       (uint32_t)(data->udata64 >> 32));
+			       (uint32_t)(GRAPH_FIELD(data) >> 32));
 			goto end;
 		}
 
-		if ((data->udata64 & 0xffff) != (i - count)) {
+		if ((GRAPH_FIELD(data) & 0xffff) != (i - count)) {
 			printf("Expected buff count miss match at node 3\n");
 			goto end;
 		}
 
-		if (data->udata64 & (0x1 << 16))
+		if (GRAPH_FIELD(data) & (0x1 << 16))
 			count = i + 1;
-		if (data->udata64 & (0x1 << 17))
+		if (GRAPH_FIELD(data) & (0x1 << 17))
 			second_pass = 1;
 	}
 
@@ -426,11 +432,11 @@ test_node3_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 		obj_node0 = nb_objs * 2;
 		for (i = 0; i < obj_node0; i++) {
 			data = &mbuf[4][i];
-			data->udata64 =
+			GRAPH_FIELD(data) =
 				((uint64_t)tm->test_node[0].idx << 32) | i;
-			data->udata64 |= (1 << 17);
+			GRAPH_FIELD(data) |= (1 << 17);
 			if ((i + 1) == obj_node0)
-				data->udata64 |= (1 << 16);
+				GRAPH_FIELD(data) |= (1 << 16);
 		}
 		rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[4][0],
 				 obj_node0);
@@ -765,6 +771,18 @@ graph_setup(void)
 {
 	int i, j;
 
+	static const struct rte_mbuf_dynfield graph_dynfield_desc = {
+		.name = "test_graph_dynfield",
+		.size = sizeof(graph_dynfield_t),
+		.align = __alignof__(graph_dynfield_t),
+	};
+	graph_dynfield_offset =
+		rte_mbuf_dynfield_register(&graph_dynfield_desc);
+	if (graph_dynfield_offset < 0) {
+		printf("Cannot register mbuf field\n");
+		return TEST_FAILED;
+	}
+
 	for (i = 0; i <= MAX_NODES; i++) {
 		for (j = 0; j < MBUFF_SIZE; j++)
 			mbuf_p[i][j] = &mbuf[i][j];
Signature · 1 line
2.28.0
#123 lore raw

PATCH v4 12/15 app/eventdev: switch flow ID to dynamic mbuf field

In reply to Thomas Monjalon

The order test stored the flow ID in the deprecated mbuf field udata64. It is moved to a dynamic field in order to allow removal of udata64.

---
 app/test-eventdev/test_order_atq.c    |  4 ++--
 app/test-eventdev/test_order_common.c | 21 +++++++++++++++------
 app/test-eventdev/test_order_common.h | 21 +++++++++++++++++++++
 app/test-eventdev/test_order_queue.c  |  4 ++--
 4 files changed, 40 insertions(+), 10 deletions(-)
app/test-eventdev/test_order_atq.c +2 -2
index cfcb1dc4e9..71215a07b6 100644
@@ -35,7 +35,7 @@ order_atq_worker(void *arg, const bool flow_id_cap)
 		}
 
 		if (!flow_id_cap)
-			ev.flow_id = ev.mbuf->udata64;
+			order_flow_id_copy_from_mbuf(t, &ev);
 
 		if (ev.sub_event_type == 0) { /* stage 0 from producer */
 			order_atq_process_stage_0(&ev);
@@ -72,7 +72,7 @@ order_atq_worker_burst(void *arg, const bool flow_id_cap)
 
 		for (i = 0; i < nb_rx; i++) {
 			if (!flow_id_cap)
-				ev[i].flow_id = ev[i].mbuf->udata64;
+				order_flow_id_copy_from_mbuf(t, &ev[i]);
 
 			if (ev[i].sub_event_type == 0) { /*stage 0 */
 				order_atq_process_stage_0(&ev[i]);
app/test-eventdev/test_order_common.c +15 -6
index dc55d93921..01a44bcd75 100644
@@ -46,13 +46,10 @@ order_producer(void *arg)
 		if (m == NULL)
 			continue;
 
-		const uint32_t flow = (uintptr_t)m % nb_flows;
+		const flow_id_t flow = (uintptr_t)m % nb_flows;
 		/* Maintain seq number per flow */
 		m->seqn = producer_flow_seq[flow]++;
-		m->udata64 = flow;
-
-		ev.flow_id = flow;
-		ev.mbuf = m;
+		order_flow_id_save(t, flow, m, &ev);
 
 		while (rte_event_enqueue_burst(dev_id, port, &ev, 1) != 1) {
 			if (t->err)
@@ -138,6 +135,12 @@ int
 order_test_setup(struct evt_test *test, struct evt_options *opt)
 {
 	void *test_order;
+	struct test_order *t;
+	static const struct rte_mbuf_dynfield flow_id_dynfield_desc = {
+		.name = "test_event_dynfield_flow_id",
+		.size = sizeof(flow_id_t),
+		.align = __alignof__(flow_id_t),
+	};
 
 	test_order = rte_zmalloc_socket(test->name, sizeof(struct test_order),
 				RTE_CACHE_LINE_SIZE, opt->socket_id);
@@ -146,8 +149,14 @@ order_test_setup(struct evt_test *test, struct evt_options *opt)
 		goto nomem;
 	}
 	test->test_priv = test_order;
+	t = evt_test_priv(test);
 
-	struct test_order *t = evt_test_priv(test);
+	t->flow_id_dynfield_offset =
+		rte_mbuf_dynfield_register(&flow_id_dynfield_desc);
+	if (t->flow_id_dynfield_offset < 0) {
+		evt_err("failed to register mbuf field");
+		return -rte_errno;
+	}
 
 	t->producer_flow_seq = rte_zmalloc_socket("test_producer_flow_seq",
 				 sizeof(*t->producer_flow_seq) * opt->nb_flows,
app/test-eventdev/test_order_common.h +21 -0
index e0fe9c968a..90eac96fc8 100644
@@ -13,6 +13,7 @@
 #include <rte_lcore.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 
 #include "evt_common.h"
 #include "evt_options.h"
@@ -20,6 +21,8 @@
 
 #define BURST_SIZE 16
 
+typedef uint32_t flow_id_t;
+
 struct test_order;
 
 struct worker_data {
@@ -49,6 +52,7 @@ struct test_order {
 	uint32_t nb_flows;
 	uint64_t nb_pkts;
 	struct rte_mempool *pool;
+	int flow_id_dynfield_offset;
 	struct prod_data prod;
 	struct worker_data worker[EVT_MAX_PORTS];
 	uint32_t *producer_flow_seq;
@@ -56,6 +60,23 @@ struct test_order {
 	struct evt_options *opt;
 } __rte_cache_aligned;
 
+static inline void
+order_flow_id_copy_from_mbuf(struct test_order *t, struct rte_event *event)
+{
+	event->flow_id = *RTE_MBUF_DYNFIELD(event->mbuf,
+			t->flow_id_dynfield_offset, flow_id_t *);
+}
+
+static inline void
+order_flow_id_save(struct test_order *t, flow_id_t flow_id,
+		struct rte_mbuf *mbuf, struct rte_event *event)
+{
+	*RTE_MBUF_DYNFIELD(mbuf,
+			t->flow_id_dynfield_offset, flow_id_t *) = flow_id;
+	event->flow_id = flow_id;
+	event->mbuf = mbuf;
+}
+
 static inline int
 order_nb_event_ports(struct evt_options *opt)
 {
app/test-eventdev/test_order_queue.c +2 -2
index 1511c0092d..621367805a 100644
@@ -35,7 +35,7 @@ order_queue_worker(void *arg, const bool flow_id_cap)
 		}
 
 		if (!flow_id_cap)
-			ev.flow_id = ev.mbuf->udata64;
+			order_flow_id_copy_from_mbuf(t, &ev);
 
 		if (ev.queue_id == 0) { /* from ordered queue */
 			order_queue_process_stage_0(&ev);
@@ -73,7 +73,7 @@ order_queue_worker_burst(void *arg, const bool flow_id_cap)
 		for (i = 0; i < nb_rx; i++) {
 
 			if (!flow_id_cap)
-				ev[i].flow_id = ev[i].mbuf->udata64;
+				order_flow_id_copy_from_mbuf(t, &ev[i]);
 
 			if (ev[i].queue_id == 0) { /* from ordered queue */
 				order_queue_process_stage_0(&ev[i]);
Signature · 1 line
2.28.0
#124 lore raw

PATCH v4 13/15 examples/bbdev: switch to dynamic mbuf field

In reply to Thomas Monjalon

The example used the deprecated mbuf field udata64 as input mbuf pointer. It is moved to a dynamic field in order to allow removal of udata64.

---
 examples/bbdev_app/main.c | 49 +++++++++++++++++++++++++++++++--------
 1 file changed, 39 insertions(+), 10 deletions(-)
examples/bbdev_app/main.c +39 -10
index e512c807cd..63e8b18e44 100644
@@ -28,6 +28,7 @@
 #include <rte_lcore.h>
 #include <rte_malloc.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_memory.h>
 #include <rte_mempool.h>
 #include <rte_log.h>
@@ -59,6 +60,22 @@
 	} \
 } while (0)
 
+static int input_dynfield_offset = -1;
+
+static inline struct rte_mbuf *
+get_mbuf_input(struct rte_mbuf *mbuf)
+{
+	return *RTE_MBUF_DYNFIELD(mbuf,
+			input_dynfield_offset, struct rte_mbuf **);
+}
+
+static inline void
+set_mbuf_input(struct rte_mbuf *mbuf, struct rte_mbuf *input)
+{
+	*RTE_MBUF_DYNFIELD(mbuf,
+			input_dynfield_offset, struct rte_mbuf **) = input;
+}
+
 static const struct rte_eth_conf port_conf = {
 	.rxmode = {
 		.mq_mode = ETH_MQ_RX_NONE,
@@ -294,11 +311,11 @@ pktmbuf_free_bulk(struct rte_mbuf **mbufs, unsigned int nb_to_free)
 }
 
 static inline void
-pktmbuf_userdata_free_bulk(struct rte_mbuf **mbufs, unsigned int nb_to_free)
+pktmbuf_input_free_bulk(struct rte_mbuf **mbufs, unsigned int nb_to_free)
 {
 	unsigned int i;
 	for (i = 0; i < nb_to_free; ++i) {
-		struct rte_mbuf *rx_pkt = mbufs[i]->userdata;
+		struct rte_mbuf *rx_pkt = get_mbuf_input(mbufs[i]);
 		rte_pktmbuf_free(rx_pkt);
 		rte_pktmbuf_free(mbufs[i]);
 	}
@@ -429,7 +446,7 @@ verify_data(struct rte_mbuf **mbufs, uint16_t num_pkts)
 	uint16_t i;
 	for (i = 0; i < num_pkts; ++i) {
 		struct rte_mbuf *out = mbufs[i];
-		struct rte_mbuf *in = out->userdata;
+		struct rte_mbuf *in = get_mbuf_input(out);
 
 		if (memcmp(rte_pktmbuf_mtod_offset(in, uint8_t *,
 				sizeof(struct rte_ether_hdr)),
@@ -731,7 +748,7 @@ run_encoding(struct lcore_conf *lcore_conf)
 				rte_pktmbuf_data_len(rx_pkts_burst[i]) -
 				sizeof(struct rte_ether_hdr);
 		/* save input mbuf pointer for later comparison */
-		enc_out_pkts[i]->userdata = rx_pkts_burst[i];
+		set_mbuf_input(enc_out_pkts[i], rx_pkts_burst[i]);
 
 		/* copy ethernet header */
 		rte_pktmbuf_reset(enc_out_pkts[i]);
@@ -775,7 +792,7 @@ run_encoding(struct lcore_conf *lcore_conf)
 	nb_enq = rte_bbdev_enqueue_enc_ops(bbdev_id, enc_queue_id,
 			bbdev_ops_burst, nb_rx);
 	if (unlikely(nb_enq < nb_rx)) {
-		pktmbuf_userdata_free_bulk(&enc_out_pkts[nb_enq],
+		pktmbuf_input_free_bulk(&enc_out_pkts[nb_enq],
 				nb_rx - nb_enq);
 		rte_bbdev_enc_op_free_bulk(&bbdev_ops_burst[nb_enq],
 				nb_rx - nb_enq);
@@ -805,7 +822,7 @@ run_encoding(struct lcore_conf *lcore_conf)
 	nb_sent = rte_ring_enqueue_burst(enc_to_dec_ring, (void **)enc_out_pkts,
 			nb_deq, NULL);
 	if (unlikely(nb_sent < nb_deq)) {
-		pktmbuf_userdata_free_bulk(&enc_out_pkts[nb_sent],
+		pktmbuf_input_free_bulk(&enc_out_pkts[nb_sent],
 				nb_deq - nb_sent);
 		lcore_stats->enc_to_dec_lost_packets += nb_deq - nb_sent;
 	}
@@ -842,7 +859,7 @@ run_decoding(struct lcore_conf *lcore_conf)
 
 	if (unlikely(rte_bbdev_dec_op_alloc_bulk(bbdev_op_pool, bbdev_ops_burst,
 			nb_recv) != 0)) {
-		pktmbuf_userdata_free_bulk(recv_pkts_burst, nb_recv);
+		pktmbuf_input_free_bulk(recv_pkts_burst, nb_recv);
 		lcore_stats->rx_lost_packets += nb_recv;
 		return;
 	}
@@ -871,7 +888,7 @@ run_decoding(struct lcore_conf *lcore_conf)
 	nb_enq = rte_bbdev_enqueue_dec_ops(bbdev_id, bbdev_queue_id,
 			bbdev_ops_burst, nb_recv);
 	if (unlikely(nb_enq < nb_recv)) {
-		pktmbuf_userdata_free_bulk(&recv_pkts_burst[nb_enq],
+		pktmbuf_input_free_bulk(&recv_pkts_burst[nb_enq],
 				nb_recv - nb_enq);
 		rte_bbdev_dec_op_free_bulk(&bbdev_ops_burst[nb_enq],
 				nb_recv - nb_enq);
@@ -898,12 +915,12 @@ run_decoding(struct lcore_conf *lcore_conf)
 
 	/* Free the RX mbufs after verification */
 	for (i = 0; i < nb_deq; ++i)
-		rte_pktmbuf_free(recv_pkts_burst[i]->userdata);
+		rte_pktmbuf_free(get_mbuf_input(recv_pkts_burst[i]));
 
 	/* Transmit the packets */
 	nb_tx = rte_eth_tx_burst(port_id, tx_queue_id, recv_pkts_burst, nb_deq);
 	if (unlikely(nb_tx < nb_deq)) {
-		pktmbuf_userdata_free_bulk(&recv_pkts_burst[nb_tx],
+		pktmbuf_input_free_bulk(&recv_pkts_burst[nb_tx],
 				nb_deq - nb_tx);
 		lcore_stats->tx_lost_packets += nb_deq - nb_tx;
 	}
@@ -1046,6 +1063,12 @@ main(int argc, char **argv)
 	bool stats_thread_started = false;
 	unsigned int main_lcore_id = rte_get_main_lcore();
 
+	static const struct rte_mbuf_dynfield input_dynfield_desc = {
+		.name = "example_bbdev_dynfield_input",
+		.size = sizeof(struct rte_mbuf *),
+		.align = __alignof__(struct rte_mbuf *),
+	};
+
 	rte_atomic16_init(&global_exit_flag);
 
 	sigret = signal(SIGTERM, signal_handler);
@@ -1115,6 +1138,12 @@ main(int argc, char **argv)
 	if (bbdev_mbuf_mempool == NULL)
 		rte_exit(EXIT_FAILURE, "Cannot create ethdev mbuf mempool\n");
 
+	/* register mbuf field to store input pointer */
+	input_dynfield_offset =
+		rte_mbuf_dynfield_register(&input_dynfield_desc);
+	if (input_dynfield_offset < 0)
+		rte_exit(EXIT_FAILURE, "Cannot register mbuf field\n");
+
 	/* initialize ports */
 	ret = initialize_ports(&app_params, ethdev_mbuf_mempool);
 
Signature · 1 line
2.28.0
Reviewed-by on v4 13/15
#125 lore raw

Re: [dpdk-dev] [PATCH v4 13/15] examples/bbdev: switch to dynamic mbuf field

Quoted 4 lines · Thomas Monjalon

The example used the deprecated mbuf field udata64 as input mbuf pointer. It is moved to a dynamic field in order to allow removal of udata64.

I like the approach with inline function(s) more than approach with macros. Not sure that get/set is needed. Approach in David's patches looks a bit simpler to me - less duplicated code (i.e. just one function which returns pointer of correct type to a dynamic field and allow to get and set it).

#126 lore raw

Re: [dpdk-dev] [PATCH v4 13/15] examples/bbdev: switch to dynamic mbuf field

28/10/2020 12:51, Andrew Rybchenko:

Quoted 6 lines · Thomas Monjalon
Quoted 4 lines

The example used the deprecated mbuf field udata64 as input mbuf pointer. It is moved to a dynamic field in order to allow removal of udata64.

Quoted 7 lines

I like the approach with inline function(s) more than approach with macros. Not sure that get/set is needed. Approach in David's patches looks a bit simpler to me - less duplicated code (i.e. just one function which returns pointer of correct type to a dynamic field and allow to get and set it).

Yes I tend to agree with you.
Olivier was asking for more functions,
especially if it has a semantic meaning.
Here get/set has no real added value but I don't have strong opinion, and I don't think it deserves a respin :)

#127 lore raw

Re: [dpdk-dev] [PATCH v4 13/15] examples/bbdev: switch to dynamic mbuf field

Quoted 15 lines · Thomas Monjalon

28/10/2020 12:51, Andrew Rybchenko:

Quoted 6 lines · Thomas Monjalon
Quoted 4 lines

The example used the deprecated mbuf field udata64 as input mbuf pointer. It is moved to a dynamic field in order to allow removal of udata64.

Quoted 7 lines

I like the approach with inline function(s) more than approach with macros. Not sure that get/set is needed. Approach in David's patches looks a bit simpler to me - less duplicated code (i.e. just one function which returns pointer of correct type to a dynamic field and allow to get and set it).

Quoted 6 lines

Yes I tend to agree with you.
Olivier was asking for more functions,
especially if it has a semantic meaning.
Here get/set has no real added value but I don't have strong opinion, and I don't think it deserves a respin :)

Agreed.

#128 lore raw

PATCH v4 14/15 examples/rxtx_callbacks: switch to dynamic mbuf field

In reply to Thomas Monjalon

The example used the deprecated mbuf field udata64.
It is moved to a dynamic field in order to allow removal of udata64.

---
 doc/guides/sample_app_ug/rxtx_callbacks.rst |  4 ++--
 examples/rxtx_callbacks/main.c              | 20 ++++++++++++++++++--
 2 files changed, 20 insertions(+), 4 deletions(-)
doc/guides/sample_app_ug/rxtx_callbacks.rst +2 -2
index 62d1f39d7e..56c4293a1a 100644
@@ -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;
examples/rxtx_callbacks/main.c +18 -2
index 6fe39546dd..b9a98ceddc 100644
@@ -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)
Signature · 1 line
2.28.0
#129 lore raw

PATCH v4 15/15 mbuf: remove userdata field

In reply to Thomas Monjalon

As announced in the deprecation note, the field userdata / udata64 is removed to give more space to the dynamic fields.

This is how the mbuf layout looks like (pahole-style):

word  type                              name                byte  size
 0    void *                            buf_addr;         /*   0 +  8 */
 1    rte_iova_t                        buf_iova          /*   8 +  8 */
      /* --- RTE_MARKER64               rearm_data;                   */
 2    uint16_t                          data_off;         /*  16 +  2 */
      uint16_t                          refcnt;           /*  18 +  2 */
      uint16_t                          nb_segs;          /*  20 +  2 */
      uint16_t                          port;             /*  22 +  2 */
 3    uint64_t                          ol_flags;         /*  24 +  8 */
      /* --- RTE_MARKER                 rx_descriptor_fields1;        */
 4    uint32_t             union        packet_type;      /*  32 +  4 */
      uint32_t                          pkt_len;          /*  36 +  4 */
 5    uint16_t                          data_len;         /*  40 +  2 */
      uint16_t                          vlan_tci;         /*  42 +  2 */
 5.5  uint64_t             union        hash;             /*  44 +  8 */
 6.5  uint16_t                          vlan_tci_outer;   /*  52 +  2 */
      uint16_t                          buf_len;          /*  54 +  2 */
 7    uint64_t                          timestamp;        /*  56 +  8 */
      /* --- RTE_MARKER                 cacheline1;                   */
 8    struct rte_mempool *              pool;             /*  64 +  8 */
 9    struct rte_mbuf *                 next;             /*  72 +  8 */
10    uint64_t             union        tx_offload;       /*  80 +  8 */
11    uint16_t                          priv_size;        /*  88 +  2 */
      uint16_t                          timesync;         /*  90 +  2 */
      uint32_t                          seqn;             /*  92 +  4 */
12    struct rte_mbuf_ext_shared_info * shinfo;           /*  96 +  8 */
13    uint64_t                          dynfield1[3];     /* 104 + 24 */
16    /* --- END                                             128      */
---
 doc/guides/rel_notes/deprecation.rst   | 1 -
 doc/guides/rel_notes/release_20_11.rst | 3 +++
 lib/librte_kni/rte_kni_common.h        | 3 +--
 lib/librte_mbuf/rte_mbuf_core.h        | 8 +-------
 4 files changed, 5 insertions(+), 10 deletions(-)
doc/guides/rel_notes/deprecation.rst +0 -1
index 2e082499b8..0f6f1df12a 100644
@@ -87,7 +87,6 @@ Deprecation Notices
   The following static fields will be moved as dynamic:
 
   - ``timestamp``
-  - ``userdata`` / ``udata64``
   - ``seqn``
 
   As a consequence, the layout of the ``struct rte_mbuf`` will be re-arranged,
doc/guides/rel_notes/release_20_11.rst +3 -0
index d8ac359e51..3cec526b6a 100644
@@ -426,6 +426,9 @@ API Changes
   the structures ``rte_mbuf`` and ``rte_mbuf_ext_shared_info``.
   The field ``refcnt`` is remaining from the old unions.
 
+* mbuf: Removed the unioned fields ``userdata`` and ``udata64``
+  from the structure ``rte_mbuf``. It is replaced with dynamic fields.
+
 * pci: Removed the ``rte_kernel_driver`` enum defined in rte_dev.h and
   replaced with a private enum in the PCI subsystem.
 
lib/librte_kni/rte_kni_common.h +1 -2
index 21b477f0aa..0db45e6a24 100644
@@ -86,8 +86,7 @@ struct rte_kni_mbuf {
 	uint16_t data_len;      /**< Amount of data in segment buffer. */
 
 	/* fields on second cache line */
-	char pad3[8] __attribute__((__aligned__(RTE_CACHE_LINE_MIN_SIZE)));
-	void *pool;
+	void *pool __attribute__((__aligned__(RTE_CACHE_LINE_MIN_SIZE)));
 	void *next;             /**< Physical address of next mbuf in kernel. */
 };
 
lib/librte_mbuf/rte_mbuf_core.h +1 -7
index 065d87d28a..a65eaaf692 100644
@@ -599,12 +599,6 @@ struct rte_mbuf {
 	/* second cache line - fields only used in slow path or on TX */
 	RTE_MARKER cacheline1 __rte_cache_min_aligned;
 
-	RTE_STD_C11
-	union {
-		void *userdata;   /**< Can be used for external metadata */
-		uint64_t udata64; /**< Allow 8-byte userdata on 32-bit */
-	};
-
 	struct rte_mempool *pool; /**< Pool from which mbuf was allocated. */
 	struct rte_mbuf *next;    /**< Next segment of scattered packet. */
 
@@ -662,7 +656,7 @@ struct rte_mbuf {
 	 */
 	struct rte_mbuf_ext_shared_info *shinfo;
 
-	uint64_t dynfield1[2]; /**< Reserved for dynamic fields. */
+	uint64_t dynfield1[3]; /**< Reserved for dynamic fields. */
 } __rte_cache_aligned;
 
 /**
Signature · 1 line
2.28.0
#130 lore raw

v5 cover remove mbuf userdata

In reply to Thomas Monjalon

The mbuf field userdata (aliased as udata64)
was announced to be removed for two reasons:
- applications, libraries and drivers used the same field for different purposes, with a risk of usage conflict.
- this field always used 8 bytes even if unneeded

Some dynamic fields are created when needed to replace the big static userdata field.
As a consequence, 8 bytes can be re-allocated to dynamic fields.

This mbuf layout change is important to allow adding more features (consuming more dynamic fields) during the next year.

v5:
- ARK field types different for Rx and Tx
- replace macros with inline functions

v4 (thanks Jerin, Nithin and Ed):
- move rte_node dynfield offset to hotter context in cache
- move test-eventdev dynfield offset to hotter context in cache
- split ARK user data for Rx and Tx + more ARK fixes

v3 (thanks Olivier):
- use typedef for new field types
- fix node field type
- initialize offsets to -1
- add more inline functions
- inline rte_security_dynfield_is_registered
- add PMD-specific userdata field for ARK

v2 (thanks David & Andrew):
- fix some indentations
- return -rte_errno consistently
- make some type casts more precise
- define dynfield types in macros
- hide field description in rte_security
- do not lookup security dynfield in ipsec-secgw
- do not use the existing timestamp field for other purpose

Thomas Monjalon (15):
eventdev: remove software Rx timestamp
mbuf: add Rx timestamp dynamic flag
ethdev: register mbuf field and flags for timestamp
latency: switch timestamp to dynamic mbuf field net/ark: switch timestamp to dynamic mbuf field net/dpaa2: switch timestamp to dynamic mbuf field net/mlx5: fix dynamic mbuf offset lookup check net/mlx5: switch timestamp to dynamic mbuf field net/nfb: switch timestamp to dynamic mbuf field net/octeontx2: switch timestamp to dynamic mbuf field net/pcap: switch timestamp to dynamic mbuf field app/testpmd: switch timestamp to dynamic mbuf field examples/rxtx_callbacks: switch timestamp to dynamic field
mbuf: remove deprecated timestamp field
mbuf: move pool pointer in hotter first half

 app/test-pmd/config.c                         | 38 ----------
 app/test-pmd/util.c                           | 39 ++++++++++-
 app/test/test_mbuf.c                          |  1 -
 doc/guides/nics/mlx5.rst                      |  5 +-
 .../prog_guide/event_ethernet_rx_adapter.rst  |  6 +-
 doc/guides/rel_notes/deprecation.rst          |  6 --
 doc/guides/rel_notes/release_20_11.rst        |  4 ++
 drivers/net/ark/ark_ethdev.c                  | 23 ++++++
 drivers/net/ark/ark_ethdev_rx.c               | 10 ++-
 drivers/net/dpaa2/dpaa2_ethdev.c              | 20 ++++++
 drivers/net/dpaa2/dpaa2_ethdev.h              |  2 +
 drivers/net/dpaa2/dpaa2_rxtx.c                | 25 +++++--
 drivers/net/mlx5/mlx5_rxq.c                   | 36 ++++++++++
 drivers/net/mlx5/mlx5_rxtx.c                  |  8 +--
 drivers/net/mlx5/mlx5_rxtx.h                  | 19 +++++
 drivers/net/mlx5/mlx5_rxtx_vec_altivec.h      | 41 +++++------
 drivers/net/mlx5/mlx5_rxtx_vec_neon.h         | 43 ++++++------
 drivers/net/mlx5/mlx5_rxtx_vec_sse.h          | 35 +++++-----
 drivers/net/mlx5/mlx5_trigger.c               |  2 +-
 drivers/net/mlx5/mlx5_txq.c                   |  2 +-
 drivers/net/nfb/nfb_rx.c                      | 23 +++++-
 drivers/net/nfb/nfb_rx.h                      | 18 +++--
 drivers/net/octeontx2/otx2_ethdev.c           | 33 +++++++++
 drivers/net/octeontx2/otx2_rx.h               | 19 ++++-
 drivers/net/octeontx2/version.map             |  7 ++
 drivers/net/pcap/rte_eth_pcap.c               | 29 +++++++-
 examples/rxtx_callbacks/main.c                | 17 ++++-
 lib/librte_ethdev/rte_ethdev.c                | 70 +++++++++++++++++++
 lib/librte_ethdev/rte_ethdev.h                | 13 +++-
 .../rte_event_eth_rx_adapter.c                | 11 ---
 .../rte_event_eth_rx_adapter.h                |  6 +-
 lib/librte_kni/rte_kni_common.h               |  3 +-
 lib/librte_latencystats/rte_latencystats.c    | 48 +++++++++++--
 lib/librte_mbuf/rte_mbuf.c                    |  2 -
 lib/librte_mbuf/rte_mbuf.h                    |  1 -
 lib/librte_mbuf/rte_mbuf_core.h               | 15 +---
 lib/librte_mbuf/rte_mbuf_dyn.h                | 11 +--
 37 files changed, 507 insertions(+), 184 deletions(-)
Signature · 1 line
2.28.0
#131 lore raw

PATCH v5 1/15 eventdev: remove software Rx timestamp

This a revert of the commit 569758758dcd ("eventdev: add Rx timestamp"). If the Rx timestamp is not configured on the ethdev port, there is no reason to set one.
Also the accuracy of the timestamp was bad because set at a late stage. Anyway there is no trace of the usage of this timestamp.

---
 doc/guides/prog_guide/event_ethernet_rx_adapter.rst |  6 +-----
 lib/librte_eventdev/rte_event_eth_rx_adapter.c      | 11 -----------
 lib/librte_eventdev/rte_event_eth_rx_adapter.h      |  6 +-----
 3 files changed, 2 insertions(+), 21 deletions(-)
doc/guides/prog_guide/event_ethernet_rx_adapter.rst +1 -5
index 236f43f455..cb44ce0e47 100644
@@ -12,11 +12,7 @@ be supported in hardware or require a software thread to receive packets from
 the ethdev port using ethdev poll mode APIs and enqueue these as events to the
 event device using the eventdev API. Both transfer mechanisms may be present on
 the same platform depending on the particular combination of the ethdev and
-the event device. For SW based packet transfer, if the mbuf does not have a
-timestamp set, the adapter adds a timestamp to the mbuf using
-rte_get_tsc_cycles(), this provides a more accurate timestamp as compared to
-if the application were to set the timestamp since it avoids event device
-schedule latency.
+the event device.
 
 The Event Ethernet Rx Adapter library is intended for the application code to
 configure both transfer mechanisms using a common API. A capability API allows
lib/librte_eventdev/rte_event_eth_rx_adapter.c +0 -11
index f0000d1ede..3c73046551 100644
@@ -763,7 +763,6 @@ rxa_buffer_mbufs(struct rte_event_eth_rx_adapter *rx_adapter,
 	uint32_t rss_mask;
 	uint32_t rss;
 	int do_rss;
-	uint64_t ts;
 	uint16_t nb_cb;
 	uint16_t dropped;
 
@@ -771,16 +770,6 @@ rxa_buffer_mbufs(struct rte_event_eth_rx_adapter *rx_adapter,
 	rss_mask = ~(((m->ol_flags & PKT_RX_RSS_HASH) != 0) - 1);
 	do_rss = !rss_mask && !eth_rx_queue_info->flow_id_mask;
 
-	if ((m->ol_flags & PKT_RX_TIMESTAMP) == 0) {
-		ts = rte_get_tsc_cycles();
-		for (i = 0; i < num; i++) {
-			m = mbufs[i];
-
-			m->timestamp = ts;
-			m->ol_flags |= PKT_RX_TIMESTAMP;
-		}
-	}
-
 	for (i = 0; i < num; i++) {
 		m = mbufs[i];
 
lib/librte_eventdev/rte_event_eth_rx_adapter.h +1 -5
index 2dd259c279..21bb1e54c8 100644
@@ -21,11 +21,7 @@
  *
  * The adapter uses a EAL service core function for SW based packet transfer
  * and uses the eventdev PMD functions to configure HW based packet transfer
- * between the ethernet device and the event device. For SW based packet
- * transfer, if the mbuf does not have a timestamp set, the adapter adds a
- * timestamp to the mbuf using rte_get_tsc_cycles(), this provides a more
- * accurate timestamp as compared to if the application were to set the time
- * stamp since it avoids event device schedule latency.
+ * between the ethernet device and the event device.
  *
  * The ethernet Rx event adapter's functions are:
  *  - rte_event_eth_rx_adapter_create_ext()
Signature · 1 line
2.28.0
#132 lore raw

PATCH v5 2/15 mbuf: add Rx timestamp dynamic flag

In reply to Thomas Monjalon

There is already a dynamic field for timestamp,
used only for Tx scheduling, thanks to the dedicated flag. The same field can be used for Rx timestamp filled by drivers. The only missing part to get rid of the static timestamp field was to declare a new dynamic flag for Rx usage.

After migrating all Rx timestamp usages, it will be possible to remove the deprecated timestamp field.

---
 lib/librte_mbuf/rte_mbuf_dyn.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/librte_mbuf/rte_mbuf_dyn.h +5 -5
index 0ebac88b83..5fb85c0610 100644
@@ -258,14 +258,14 @@ void rte_mbuf_dyn_dump(FILE *out);
  * timestamp. The dynamic Tx timestamp flag tells whether the field contains
  * actual timestamp value for the packets being sent, this value can be
  * used by PMD to schedule packet sending.
- *
- * After PKT_RX_TIMESTAMP flag and fixed timestamp field deprecation
- * and obsoleting, the dedicated Rx timestamp flag is supposed to be
- * introduced and the shared dynamic timestamp field will be used
- * to handle the timestamps on receiving datapath as well.
  */
 #define RTE_MBUF_DYNFIELD_TIMESTAMP_NAME "rte_dynfield_timestamp"
 
+/**
+ * Indicate that the timestamp field in the mbuf was filled by the driver.
+ */
+#define RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME "rte_dynflag_rx_timestamp"
+
 /**
  * When PMD sees the RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME flag set on the
  * packet being sent it tries to synchronize the time of packet appearing
Signature · 1 line
2.28.0
Acked-by on v5 2/15
#133 lore raw

Re: [dpdk-dev] [PATCH v5 02/15] mbuf: add Rx timestamp dynamic flag

Quoted 10 lines · Thomas Monjalon

There is already a dynamic field for timestamp,
used only for Tx scheduling, thanks to the dedicated flag. The same field can be used for Rx timestamp filled by drivers. The only missing part to get rid of the static timestamp field was to declare a new dynamic flag for Rx usage.

After migrating all Rx timestamp usages, it will be possible to remove the deprecated timestamp field.

#134 lore raw

PATCH v5 3/15 ethdev: register mbuf field and flags for timestamp

In reply to Thomas Monjalon

During port configure or queue setup, the offload flags DEV_RX_OFFLOAD_TIMESTAMP and DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP trigger the registration of the related mbuf field and flags.

Previously, the Tx timestamp field and flag were registered in testpmd, as described in mlx5 guide.
For the general usage of Rx and Tx timestamps,
managing registrations inside ethdev is simpler and properly documented.

---
 app/test-pmd/config.c          | 38 ------------------
 doc/guides/nics/mlx5.rst       |  5 +--
 lib/librte_ethdev/rte_ethdev.c | 70 ++++++++++++++++++++++++++++++++++
 lib/librte_ethdev/rte_ethdev.h |  9 ++++-
 lib/librte_mbuf/rte_mbuf_dyn.h |  1 +
 5 files changed, 81 insertions(+), 42 deletions(-)
app/test-pmd/config.c +0 -38
index 1668ae3238..9a2baf16fe 100644
@@ -3955,44 +3955,6 @@ show_tx_pkt_times(void)
 void
 set_tx_pkt_times(unsigned int *tx_times)
 {
-	uint16_t port_id;
-	int offload_found = 0;
-	int offset;
-	int flag;
-
-	static const struct rte_mbuf_dynfield desc_offs = {
-		.name = RTE_MBUF_DYNFIELD_TIMESTAMP_NAME,
-		.size = sizeof(uint64_t),
-		.align = __alignof__(uint64_t),
-	};
-	static const struct rte_mbuf_dynflag desc_flag = {
-		.name = RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME,
-	};
-
-	RTE_ETH_FOREACH_DEV(port_id) {
-		struct rte_eth_dev_info dev_info = { 0 };
-		int ret;
-
-		ret = rte_eth_dev_info_get(port_id, &dev_info);
-		if (ret == 0 && dev_info.tx_offload_capa &
-				DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP) {
-			offload_found = 1;
-			break;
-		}
-	}
-	if (!offload_found) {
-		printf("No device supporting Tx timestamp scheduling found, "
-		       "dynamic flag and field not registered\n");
-		return;
-	}
-	offset = rte_mbuf_dynfield_register(&desc_offs);
-	if (offset < 0 && rte_errno != EEXIST)
-		printf("Dynamic timestamp field registration error: %d",
-		       rte_errno);
-	flag = rte_mbuf_dynflag_register(&desc_flag);
-	if (flag < 0 && rte_errno != EEXIST)
-		printf("Dynamic timestamp flag registration error: %d",
-		       rte_errno);
 	tx_pkt_times_inter = tx_times[0];
 	tx_pkt_times_intra = tx_times[1];
 }
doc/guides/nics/mlx5.rst +2 -3
index afa65a1379..fa8b13dd1b 100644
@@ -237,9 +237,8 @@ Limitations
   ``txq_inline_max`` and ``txq_inline_mpw`` devargs keys.
 
 - To provide the packet send scheduling on mbuf timestamps the ``tx_pp``
-  parameter should be specified, RTE_MBUF_DYNFIELD_TIMESTAMP_NAME and
-  RTE_MBUF_DYNFLAG_TIMESTAMP_NAME should be registered by application.
-  When PMD sees the RTE_MBUF_DYNFLAG_TIMESTAMP_NAME set on the packet
+  parameter should be specified.
+  When PMD sees the RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME set on the packet
   being sent it tries to synchronize the time of packet appearing on
   the wire with the specified packet timestamp. It the specified one
   is in the past it should be ignored, if one is in the distant future
lib/librte_ethdev/rte_ethdev.c +70 -0

100 lines not on this page · raw message

lib/librte_ethdev/rte_ethdev.h +8 -1
index ba997f16ce..3be0050592 100644
@@ -1344,6 +1344,9 @@ struct rte_eth_conf {
 #define DEV_RX_OFFLOAD_VLAN_EXTEND	0x00000400
 #define DEV_RX_OFFLOAD_JUMBO_FRAME	0x00000800
 #define DEV_RX_OFFLOAD_SCATTER		0x00002000
+/**
+ * The mbuf field and flag are registered when the offload is configured.
+ */
 #define DEV_RX_OFFLOAD_TIMESTAMP	0x00004000
 #define DEV_RX_OFFLOAD_SECURITY         0x00008000
 #define DEV_RX_OFFLOAD_KEEP_CRC		0x00010000
@@ -1408,7 +1411,11 @@ struct rte_eth_conf {
 #define DEV_TX_OFFLOAD_IP_TNL_TSO       0x00080000
 /** Device supports outer UDP checksum */
 #define DEV_TX_OFFLOAD_OUTER_UDP_CKSUM  0x00100000
-/** Device supports send on timestamp */
+/**
+ * Device sends on time read from RTE_MBUF_DYNFIELD_TIMESTAMP_NAME
+ * if RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME is set in ol_flags.
+ * The mbuf field and flag are registered when the offload is configured.
+ */
 #define DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP 0x00200000
 /*
  * If new Tx offload capabilities are defined, they also must be
lib/librte_mbuf/rte_mbuf_dyn.h +1 -0
index 5fb85c0610..d4d8f66f77 100644
@@ -260,6 +260,7 @@ void rte_mbuf_dyn_dump(FILE *out);
  * used by PMD to schedule packet sending.
  */
 #define RTE_MBUF_DYNFIELD_TIMESTAMP_NAME "rte_dynfield_timestamp"
+typedef uint64_t rte_mbuf_timestamp_t;
 
 /**
  * Indicate that the timestamp field in the mbuf was filled by the driver.
Signature · 1 line
2.28.0
Acked-by on v5 3/15
#135 lore raw

Re: [dpdk-dev] [PATCH v5 03/15] ethdev: register mbuf field and flags for timestamp

Quoted 10 lines · Thomas Monjalon

During port configure or queue setup, the offload flags DEV_RX_OFFLOAD_TIMESTAMP and DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP trigger the registration of the related mbuf field and flags.

Previously, the Tx timestamp field and flag were registered in testpmd, as described in mlx5 guide.
For the general usage of Rx and Tx timestamps,
managing registrations inside ethdev is simpler and properly documented.

A nit below, but regardless of outcome:

[snip]

Quoted 21 lines
lib/librte_ethdev/rte_ethdev.c +6 -0
index b12bb3854d..7c9aadb461 100644
@@ -31,6 +31,7 @@
  #include <rte_mempool.h>
  #include <rte_malloc.h>
  #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
  #include <rte_errno.h>
  #include <rte_spinlock.h>
  #include <rte_string_fns.h>
@@ -1232,6 +1233,59 @@ eth_dev_check_lro_pkt_size(uint16_t port_id, uint32_t config_size,
  	return ret;
  }
 
+static inline int
+eth_dev_timestamp_mbuf_register(uint64_t rx_offloads, uint64_t tx_offloads)
+{
+	static const struct rte_mbuf_dynfield field_desc = {
+		.name = RTE_MBUF_DYNFIELD_TIMESTAMP_NAME,

lib/librte_ethdev/rte_ethdev.c eth_dev_check_lro_pkt_size(uint16_t port_id, uint32_t config_size, · line 1250

Quoted 10 lines
lib/librte_ethdev/rte_ethdev.c +10 -0
+		.size = sizeof(rte_mbuf_timestamp_t),
+		.align = __alignof__(rte_mbuf_timestamp_t),
+	};
+	static const struct rte_mbuf_dynflag rx_flag_desc = {
+		.name = RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME,
+	};
+	static const struct rte_mbuf_dynflag tx_flag_desc = {
+		.name = RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME,
+	};
+	static bool done_rx, done_tx;

Are these static fields remain by intention? May be I misunderstand the summary of the previous discussion.

Quoted 41 lines
lib/librte_ethdev/rte_ethdev.c +38 -0
+	bool todo_rx, todo_tx;
+	int offset;
+
+	todo_rx = (rx_offloads & DEV_RX_OFFLOAD_TIMESTAMP) != 0
+		&& !done_rx;
+	todo_tx = (tx_offloads & DEV_TX_OFFLOAD_SEND_ON_TIMESTAMP) != 0
+		&& !done_tx;
+
+	if (todo_rx || todo_tx) {
+		offset = rte_mbuf_dynfield_register(&field_desc);
+		if (offset < 0) {
+			RTE_ETHDEV_LOG(ERR,
+					"Failed to register mbuf field for timestamp\n");
+			return -rte_errno;
+		}
+	}
+	if (todo_rx) {
+		offset = rte_mbuf_dynflag_register(&rx_flag_desc);
+		if (offset < 0) {
+			RTE_ETHDEV_LOG(ERR,
+					"Failed to register mbuf flag for Rx timestamp\n");
+			return -rte_errno;
+		}
+		done_rx = true;
+	}
+	if (todo_tx) {
+		offset = rte_mbuf_dynflag_register(&tx_flag_desc);
+		if (offset < 0) {
+			RTE_ETHDEV_LOG(ERR,
+					"Failed to register mbuf flag for Tx timestamp\n");
+			return -rte_errno;
+		}
+		done_tx = true;
+	}
+
+	return 0;
+}
+
  /*
   * Validate offloads that are requested through rte_eth_dev_configure against
   * the offloads successfully set by the ethernet device.

[snip]

#136 lore raw

Re: [dpdk-dev] [PATCH v5 03/15] ethdev: register mbuf field and flags for timestamp

01/11/2020 21:10, Andrew Rybchenko:

Quoted 5 lines · Thomas Monjalon

lib/librte_ethdev/rte_ethdev.c eth_dev_check_lro_pkt_size(uint16_t port_id, uint32_t config_size, · line 1250

Quoted 1 line
lib/librte_ethdev/rte_ethdev.c +1 -0
+	static bool done_rx, done_tx;

Are these static fields remain by intention? May be I misunderstand the summary of the previous discussion.

Andrew, you are reading the wrong thread.
The timestamp series has been sent by mistake as v5 of the userdata series. Please read v6 of userdata (merged) and v2 of timestamp series. All your comments have been addressed.

#137 lore raw

PATCH v5 4/15 latency: switch timestamp to dynamic mbuf field

In reply to Thomas Monjalon

The mbuf timestamp is moved to a dynamic field
in order to allow removal of the deprecated static field. The related mbuf flag is also replaced with the dynamic one.

---
 lib/librte_latencystats/rte_latencystats.c | 48 +++++++++++++++++++---
 1 file changed, 43 insertions(+), 5 deletions(-)
lib/librte_latencystats/rte_latencystats.c +43 -5
index ba2fff3bcb..a21f6239d9 100644
@@ -8,7 +8,9 @@
 #include <math.h>
 
 #include <rte_string_fns.h>
+#include <rte_bitops.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
 #include <rte_log.h>
 #include <rte_cycles.h>
 #include <rte_ethdev.h>
@@ -31,6 +33,16 @@ latencystat_cycles_per_ns(void)
 /* Macros for printing using RTE_LOG */
 #define RTE_LOGTYPE_LATENCY_STATS RTE_LOGTYPE_USER1
 
+static uint64_t timestamp_dynflag;
+static int timestamp_dynfield_offset = -1;
+
+static inline rte_mbuf_timestamp_t *
+timestamp_dynfield(struct rte_mbuf *mbuf)
+{
+	return RTE_MBUF_DYNFIELD(mbuf,
+			timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
+}
+
 static const char *MZ_RTE_LATENCY_STATS = "rte_latencystats";
 static int latency_stats_index;
 static uint64_t samp_intvl;
@@ -128,10 +140,10 @@ add_time_stamps(uint16_t pid __rte_unused,
 		diff_tsc = now - prev_tsc;
 		timer_tsc += diff_tsc;
 
-		if ((pkts[i]->ol_flags & PKT_RX_TIMESTAMP) == 0
+		if ((pkts[i]->ol_flags & timestamp_dynflag) == 0
 				&& (timer_tsc >= samp_intvl)) {
-			pkts[i]->timestamp = now;
-			pkts[i]->ol_flags |= PKT_RX_TIMESTAMP;
+			*timestamp_dynfield(pkts[i]) = now;
+			pkts[i]->ol_flags |= timestamp_dynflag;
 			timer_tsc = 0;
 		}
 		prev_tsc = now;
@@ -161,8 +173,8 @@ calc_latency(uint16_t pid __rte_unused,
 
 	now = rte_rdtsc();
 	for (i = 0; i < nb_pkts; i++) {
-		if (pkts[i]->ol_flags & PKT_RX_TIMESTAMP)
-			latency[cnt++] = now - pkts[i]->timestamp;
+		if (pkts[i]->ol_flags & timestamp_dynflag)
+			latency[cnt++] = now - *timestamp_dynfield(pkts[i]);
 	}
 
 	rte_spinlock_lock(&glob_stats->lock);
@@ -204,6 +216,14 @@ int
 rte_latencystats_init(uint64_t app_samp_intvl,
 		rte_latency_stats_flow_type_fn user_cb)
 {
+	static const struct rte_mbuf_dynfield timestamp_dynfield_desc = {
+		.name = RTE_MBUF_DYNFIELD_TIMESTAMP_NAME,
+		.size = sizeof(rte_mbuf_timestamp_t),
+		.align = __alignof__(rte_mbuf_timestamp_t),
+	};
+	static const struct rte_mbuf_dynflag timestamp_dynflag_desc = {
+		.name = RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME,
+	};
 	unsigned int i;
 	uint16_t pid;
 	uint16_t qid;
@@ -211,6 +231,7 @@ rte_latencystats_init(uint64_t app_samp_intvl,
 	const char *ptr_strings[NUM_LATENCY_STATS] = {0};
 	const struct rte_memzone *mz = NULL;
 	const unsigned int flags = 0;
+	int timestamp_dynflag_offset;
 	int ret;
 
 	if (rte_memzone_lookup(MZ_RTE_LATENCY_STATS))
@@ -241,6 +262,23 @@ rte_latencystats_init(uint64_t app_samp_intvl,
 		return -1;
 	}
 
+	/* Register mbuf field and flag for Rx timestamp */
+	timestamp_dynfield_offset =
+			rte_mbuf_dynfield_register(&timestamp_dynfield_desc);
+	if (timestamp_dynfield_offset < 0) {
+		RTE_LOG(ERR, LATENCY_STATS,
+				"Cannot register mbuf field for timestamp\n");
+		return -rte_errno;
+	}
+	timestamp_dynflag_offset =
+			rte_mbuf_dynflag_register(&timestamp_dynflag_desc);
+	if (timestamp_dynflag_offset < 0) {
+		RTE_LOG(ERR, LATENCY_STATS,
+				"Cannot register mbuf field for timestamp\n");
+		return -rte_errno;
+	}
+	timestamp_dynflag = RTE_BIT64(timestamp_dynflag_offset);
+
 	/** Register Rx/Tx callbacks */
 	RTE_ETH_FOREACH_DEV(pid) {
 		struct rte_eth_dev_info dev_info;
Signature · 1 line
2.28.0
#138 lore raw

PATCH v5 5/15 net/ark: switch timestamp to dynamic mbuf field

In reply to Thomas Monjalon

The mbuf timestamp is moved to a dynamic field
in order to allow removal of the deprecated static field. The related dynamic mbuf flag is set, although was missing previously.

The timestamp is set if configured for at least one device.

---
 drivers/net/ark/ark_ethdev.c    | 23 +++++++++++++++++++++++
 drivers/net/ark/ark_ethdev_rx.c | 10 +++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)
drivers/net/ark/ark_ethdev.c +23 -0
index fa343999a1..629f825019 100644
@@ -9,6 +9,7 @@
 #include <rte_bus_pci.h>
 #include <rte_ethdev_pci.h>
 #include <rte_kvargs.h>
+#include <rte_bitops.h>
 
 #include "rte_pmd_ark.h"
 #include "ark_global.h"
@@ -79,6 +80,8 @@ static int  eth_ark_set_mtu(struct rte_eth_dev *dev, uint16_t size);
 #define ARK_TX_MAX_QUEUE (4096 * 4)
 #define ARK_TX_MIN_QUEUE (256)
 
+uint64_t ark_timestamp_rx_dynflag;
+int ark_timestamp_dynfield_offset = -1;
 int rte_pmd_ark_rx_userdata_dynfield_offset = -1;
 int rte_pmd_ark_tx_userdata_dynfield_offset = -1;
 
@@ -552,6 +555,24 @@ static int
 eth_ark_dev_configure(struct rte_eth_dev *dev)
 {
 	struct ark_adapter *ark = dev->data->dev_private;
+	int ark_timestamp_rx_dynflag_offset;
+
+	if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_TIMESTAMP) {
+		ark_timestamp_dynfield_offset = rte_mbuf_dynfield_lookup(
+				RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL);
+		if (ark_timestamp_dynfield_offset < 0) {
+			ARK_PMD_LOG(ERR, "Failed to lookup timestamp field\n");
+			return -rte_errno;
+		}
+		ark_timestamp_rx_dynflag_offset = rte_mbuf_dynflag_lookup(
+				RTE_MBUF_DYNFLAG_RX_TIMESTAMP_NAME, NULL);
+		if (ark_timestamp_rx_dynflag_offset < 0) {
+			ARK_PMD_LOG(ERR, "Failed to lookup Rx timestamp flag\n");
+			return -rte_errno;
+		}
+		ark_timestamp_rx_dynflag =
+				RTE_BIT64(ark_timestamp_rx_dynflag_offset);
+	}
 
 	eth_ark_dev_set_link_up(dev);
 	if (ark->user_ext.dev_configure)
@@ -782,6 +803,8 @@ eth_ark_dev_info_get(struct rte_eth_dev *dev,
 				ETH_LINK_SPEED_50G |
 				ETH_LINK_SPEED_100G);
 
+	dev_info->rx_offload_capa = DEV_RX_OFFLOAD_TIMESTAMP;
+
 	return 0;
 }
 
drivers/net/ark/ark_ethdev_rx.c +9 -1
index 825b4791be..dda796da0d 100644
@@ -15,6 +15,9 @@
 #define ARK_RX_META_OFFSET (RTE_PKTMBUF_HEADROOM - ARK_RX_META_SIZE)
 #define ARK_RX_MAX_NOCHAIN (RTE_MBUF_DEFAULT_DATAROOM)
 
+extern uint64_t ark_timestamp_rx_dynflag;
+extern int ark_timestamp_dynfield_offset;
+
 /* Forward declarations */
 struct ark_rx_queue;
 struct ark_rx_meta;
@@ -272,7 +275,12 @@ eth_ark_recv_pkts(void *rx_queue,
 		mbuf->port = meta->port;
 		mbuf->pkt_len = meta->pkt_len;
 		mbuf->data_len = meta->pkt_len;
-		mbuf->timestamp = meta->timestamp;
+		/* set timestamp if enabled at least on one device */
+		if (ark_timestamp_rx_dynflag > 0) {
+			*RTE_MBUF_DYNFIELD(mbuf, ark_timestamp_dynfield_offset,
+				rte_mbuf_timestamp_t *) = meta->timestamp;
+			mbuf->ol_flags |= ark_timestamp_rx_dynflag;
+		}
 		rte_pmd_ark_mbuf_rx_userdata_set(mbuf, meta->user_data);
 
 		if (ARK_DEBUG_CORE) {	/* debug sanity checks */
Signature · 1 line
2.28.0