[04/15] node: switch IPv4 metadata to dynamic mbuf field

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

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Thomas Monjalon Oct. 26, 2020, 5:20 a.m. UTC
  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.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 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(-)
  

Comments

David Marchand Oct. 26, 2020, 10:40 a.m. UTC | #1
On Mon, Oct 26, 2020 at 6:21 AM Thomas Monjalon <thomas@monjalon.net> wrote:
>
> 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.
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
>  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(-)
>
> diff --git a/lib/librte_node/ip4_lookup.c b/lib/librte_node/ip4_lookup.c
> index 8835aab9dd..2cc91c0c67 100644
> --- a/lib/librte_node/ip4_lookup.c
> +++ b/lib/librte_node/ip4_lookup.c
> @@ -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;

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


> +
>                 /* Setup LPM tables for all sockets */
>                 RTE_LCORE_FOREACH(lcore_id)
>                 {

[snip]

> diff --git a/lib/librte_node/node_private.h b/lib/librte_node/node_private.h
> index ab7941c12b..bafea3704d 100644
> --- a/lib/librte_node/node_private.h
> +++ b/lib/librte_node/node_private.h
> @@ -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),

s/uint64_t/struct node_mbuf_priv1/g ?


> +};
> +extern int node_mbuf_priv1_dynfield_offset;
> +
>  /**
>   * Node mbuf private area 2.
>   */
  
Thomas Monjalon Oct. 26, 2020, 2:29 p.m. UTC | #2
26/10/2020 11:40, David Marchand:
> On Mon, Oct 26, 2020 at 6:21 AM Thomas Monjalon <thomas@monjalon.net> wrote:
> > +               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

[...]
> > +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
  
Andrew Rybchenko Oct. 26, 2020, 2:34 p.m. UTC | #3
On 10/26/20 5:29 PM, Thomas Monjalon wrote:
> 26/10/2020 11:40, David Marchand:
>> On Mon, Oct 26, 2020 at 6:21 AM Thomas Monjalon <thomas@monjalon.net> wrote:
>>> +               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
> 
> [...]
>>> +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 *"
  
Thomas Monjalon Oct. 26, 2020, 2:39 p.m. UTC | #4
26/10/2020 15:34, Andrew Rybchenko:
> On 10/26/20 5:29 PM, Thomas Monjalon wrote:
> > 26/10/2020 11:40, David Marchand:
> >> On Mon, Oct 26, 2020 at 6:21 AM Thomas Monjalon <thomas@monjalon.net> wrote:
> >>> +               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
> > 
> > [...]
> >>> +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 *"

Yes, pointer to node_mbuf_priv1.
  

Patch

diff --git a/lib/librte_node/ip4_lookup.c b/lib/librte_node/ip4_lookup.c
index 8835aab9dd..2cc91c0c67 100644
--- a/lib/librte_node/ip4_lookup.c
+++ b/lib/librte_node/ip4_lookup.c
@@ -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)
 		{
diff --git a/lib/librte_node/ip4_rewrite.c b/lib/librte_node/ip4_rewrite.c
index bb7f671b5c..2ffb3f4340 100644
--- a/lib/librte_node/ip4_rewrite.c
+++ b/lib/librte_node/ip4_rewrite.c
@@ -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;
diff --git a/lib/librte_node/node_private.h b/lib/librte_node/node_private.h
index ab7941c12b..bafea3704d 100644
--- a/lib/librte_node/node_private.h
+++ b/lib/librte_node/node_private.h
@@ -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 *);
 }
 
 /**