> -----Original Message-----
> From: Nitin Saxena <nsax...@marvell.com>
> Sent: Monday, April 28, 2025 4:07 PM
> To: Nithin Kumar Dabilpuram <ndabilpu...@marvell.com>; Pavan Nikhilesh
> Bhagavatula <pbhagavat...@marvell.com>; Robin Jarry
> <rja...@redhat.com>; Christophe Fontaine <cfont...@redhat.com>
> Cc: dev@dpdk.org; Jerin Jacob <jer...@marvell.com>; Nitin Saxena
> <nsaxen...@gmail.com>
> Subject: [PATCH v6 2/2] node: use node mbuf dynfield in ip4 nodes
>
> - Used global node mbuf in ip[4|6]_lookup/rewrite nodes
> - Redefine node_mbuf_priv1() to rte_node_mbuf_overload_fields_get()
>
> Signed-off-by: Nitin Saxena <nsax...@marvell.com>
Acked-by: Pavan Nikhilesh <pbhagavat...@marvell.com>
> ---
> lib/node/ip4_lookup.c | 14 ++++-------
> lib/node/ip4_rewrite.c | 15 +++++-------
> lib/node/ip6_lookup.c | 15 +++++-------
> lib/node/ip6_rewrite.c | 14 ++++-------
> lib/node/node_private.h | 40 +++----------------------------
> lib/node/rte_node_mbuf_dynfield.h | 9 +++++++
> 6 files changed, 34 insertions(+), 73 deletions(-)
>
> diff --git a/lib/node/ip4_lookup.c b/lib/node/ip4_lookup.c
> index 604fcb267a..f6db3219f0 100644
> --- a/lib/node/ip4_lookup.c
> +++ b/lib/node/ip4_lookup.c
> @@ -32,8 +32,6 @@ struct ip4_lookup_node_ctx {
> 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) \
> @@ -182,17 +180,15 @@ ip4_lookup_node_init(const struct rte_graph
> *graph, struct rte_node *node)
> {
> uint16_t socket, lcore_id;
> static uint8_t init_once;
> - int rc;
> + int rc, dyn;
>
> RTE_SET_USED(graph);
> RTE_BUILD_BUG_ON(sizeof(struct ip4_lookup_node_ctx) >
> RTE_NODE_CTX_SZ);
>
> + dyn = rte_node_mbuf_dynfield_register();
> + if (dyn < 0)
> + return -rte_errno;
> 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)
> {
> @@ -210,7 +206,7 @@ ip4_lookup_node_init(const struct rte_graph *graph,
> struct rte_node *node)
>
> /* 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;
> + IP4_LOOKUP_NODE_PRIV1_OFF(node->ctx) = dyn;
>
> #if defined(__ARM_NEON) || defined(RTE_ARCH_X86)
> if (rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128)
> diff --git a/lib/node/ip4_rewrite.c b/lib/node/ip4_rewrite.c
> index a9ab5eaa57..dfa4382350 100644
> --- a/lib/node/ip4_rewrite.c
> +++ b/lib/node/ip4_rewrite.c
> @@ -259,19 +259,16 @@ 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;
> + int dyn;
>
> RTE_SET_USED(graph);
> RTE_BUILD_BUG_ON(sizeof(struct ip4_rewrite_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;
> - init_once = true;
> - }
> - IP4_REWRITE_NODE_PRIV1_OFF(node->ctx) =
> node_mbuf_priv1_dynfield_offset;
> + dyn = rte_node_mbuf_dynfield_register();
> + if (dyn < 0)
> + return -rte_errno;
> +
> + IP4_REWRITE_NODE_PRIV1_OFF(node->ctx) = dyn;
>
> node_dbg("ip4_rewrite", "Initialized ip4_rewrite node initialized");
>
> diff --git a/lib/node/ip6_lookup.c b/lib/node/ip6_lookup.c
> index 827fc2f379..83c0500c76 100644
> --- a/lib/node/ip6_lookup.c
> +++ b/lib/node/ip6_lookup.c
> @@ -318,18 +318,16 @@ ip6_lookup_node_init(const struct rte_graph
> *graph, struct rte_node *node)
> {
> uint16_t socket, lcore_id;
> static uint8_t init_once;
> - int rc;
> + int rc, dyn;
>
> RTE_SET_USED(graph);
> RTE_BUILD_BUG_ON(sizeof(struct ip6_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;
> + dyn = rte_node_mbuf_dynfield_register();
> + if (dyn < 0)
> + return -rte_errno;
>
> + if (!init_once) {
> /* Setup LPM tables for all sockets */
> RTE_LCORE_FOREACH(lcore_id)
> {
> @@ -347,8 +345,7 @@ ip6_lookup_node_init(const struct rte_graph *graph,
> struct rte_node *node)
>
> /* Update socket's LPM and mbuf dyn priv1 offset in node ctx */
> IP6_LOOKUP_NODE_LPM(node->ctx) =
> ip6_lookup_nm.lpm_tbl[graph->socket];
> - IP6_LOOKUP_NODE_PRIV1_OFF(node->ctx) =
> - node_mbuf_priv1_dynfield_offset;
> + IP6_LOOKUP_NODE_PRIV1_OFF(node->ctx) = dyn;
>
> node_dbg("ip6_lookup", "Initialized ip6_lookup node");
>
> diff --git a/lib/node/ip6_rewrite.c b/lib/node/ip6_rewrite.c
> index e157964c6a..d5488e7fa3 100644
> --- a/lib/node/ip6_rewrite.c
> +++ b/lib/node/ip6_rewrite.c
> @@ -243,19 +243,15 @@ ip6_rewrite_node_process(struct rte_graph
> *graph, struct rte_node *node,
> static int
> ip6_rewrite_node_init(const struct rte_graph *graph, struct rte_node *node)
> {
> - static bool init_once;
> + int dyn;
>
> RTE_SET_USED(graph);
> RTE_BUILD_BUG_ON(sizeof(struct ip6_rewrite_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;
> - init_once = true;
> - }
> - IP6_REWRITE_NODE_PRIV1_OFF(node->ctx) =
> node_mbuf_priv1_dynfield_offset;
> + dyn = rte_node_mbuf_dynfield_register();
> + if (dyn < 0)
> + return -rte_errno;
> + IP6_REWRITE_NODE_PRIV1_OFF(node->ctx) = dyn;
>
> node_dbg("ip6_rewrite", "Initialized ip6_rewrite node");
>
> diff --git a/lib/node/node_private.h b/lib/node/node_private.h
> index 4fafab19be..7fb2aff0b8 100644
> --- a/lib/node/node_private.h
> +++ b/lib/node/node_private.h
> @@ -13,6 +13,7 @@
> #include <rte_mbuf_dyn.h>
>
> #include <rte_graph_worker_common.h>
> +#include <rte_node_mbuf_dynfield.h>
>
> extern int rte_node_logtype;
> #define RTE_LOGTYPE_NODE rte_node_logtype
> @@ -26,28 +27,8 @@ extern int rte_node_logtype;
> #define node_info(node_name, ...) NODE_LOG(INFO, node_name,
> __VA_ARGS__)
> #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 {
> - union {
> - /* IP4/IP6 rewrite */
> - struct {
> - uint16_t nh;
> - uint16_t ttl;
> - uint32_t cksum;
> - };
> -
> - uint64_t u;
> - };
> -};
> -
> -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;
> +/* define internal function used by nodes */
> +#define node_mbuf_priv1 rte_node_mbuf_overload_fields_get
>
> /**
> * Node mbuf private area 2.
> @@ -60,21 +41,6 @@ struct __rte_cache_aligned node_mbuf_priv2 {
>
> #define OBJS_PER_CLINE (RTE_CACHE_LINE_SIZE / sizeof(void *))
>
> -/**
> - * Get mbuf_priv1 pointer from rte_mbuf.
> - *
> - * @param
> - * Pointer to the rte_mbuf.
> - *
> - * @return
> - * Pointer to the mbuf_priv1.
> - */
> -static __rte_always_inline struct node_mbuf_priv1 *
> -node_mbuf_priv1(struct rte_mbuf *m, const int offset)
> -{
> - return RTE_MBUF_DYNFIELD(m, offset, struct node_mbuf_priv1 *);
> -}
> -
> /**
> * Get mbuf_priv2 pointer from rte_mbuf.
> *
> diff --git a/lib/node/rte_node_mbuf_dynfield.h
> b/lib/node/rte_node_mbuf_dynfield.h
> index 4db5382f91..0b22fbf718 100644
> --- a/lib/node/rte_node_mbuf_dynfield.h
> +++ b/lib/node/rte_node_mbuf_dynfield.h
> @@ -40,6 +40,15 @@ extern "C" {
> */
> typedef struct rte_node_mbuf_overload_fields {
> union {
> + /* Following fields used by ip[4|6]-lookup -> ip[4|6]-rewrite
> nodes */
> + union {
> + struct {
> + uint16_t nh;
> + uint16_t ttl;
> + uint32_t cksum;
> + };
> + uint64_t u;
> + };
> uint8_t
> data[RTE_NODE_MBUF_OVERLOADABLE_FIELDS_SIZE];
> };
> } rte_node_mbuf_overload_fields_t;
> --
> 2.43.0