- 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> --- 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 0b474cd2bc..7e9d21a9c9 100644 --- a/lib/node/ip4_lookup.c +++ b/lib/node/ip4_lookup.c @@ -31,8 +31,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) \ @@ -180,17 +178,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) { @@ -208,7 +204,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 34a920df5e..b05decc1a3 100644 --- a/lib/node/ip4_rewrite.c +++ b/lib/node/ip4_rewrite.c @@ -258,19 +258,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 f378d2d064..c140aa9cf3 100644 --- a/lib/node/ip6_lookup.c +++ b/lib/node/ip6_lookup.c @@ -316,18 +316,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) { @@ -345,8 +343,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 198d8d8820..b9e223ab3a 100644 --- a/lib/node/ip6_rewrite.c +++ b/lib/node/ip6_rewrite.c @@ -242,19 +242,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 4293b3823d..8dd6cfc401 100644 --- a/lib/node/rte_node_mbuf_dynfield.h +++ b/lib/node/rte_node_mbuf_dynfield.h @@ -36,6 +36,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