Skip to contentSkip to conversation

graph: expose node context as pointers

PATCH Superseded Robin Jarry 2 participants 2 messages Mar 20, 2024 – Mar 21, 2024

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 graph: expose node context as pointers

In some cases, the node context data is used to store two pointers because the data is larger than the reserved 16 bytes. Having to define intermediate structures just to be able to cast is tedious. Add two pointers that take the same space than ctx.

---
 lib/graph/rte_graph_worker_common.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
lib/graph/rte_graph_worker_common.h +8 -1
index 36d864e2c14e..a7fcdf4893ea 100644
@@ -112,7 +112,14 @@ struct __rte_cache_aligned rte_node {
 	};
 	/* Fast path area  */
 #define RTE_NODE_CTX_SZ 16
-	alignas(RTE_CACHE_LINE_SIZE) uint8_t ctx[RTE_NODE_CTX_SZ]; /**< Node Context. */
+	alignas(RTE_CACHE_LINE_SIZE) union {
+		uint8_t ctx[RTE_NODE_CTX_SZ];
+		/* Convenience aliases to store pointers without complex casting. */
+		struct {
+			void *ctx_ptr;
+			void *ctx_ptr2;
+		};
+	}; /**< Node Context. */
 	uint16_t size;		/**< Total number of objects available. */
 	uint16_t idx;		/**< Number of objects used. */
 	rte_graph_off_t off;	/**< Offset of node in the graph reel. */
Signature · 1 line
2.44.0
#1 lore raw
Quoted 16 lines · Robin Jarry

In some cases, the node context data is used to store two pointers because the data is larger than the reserved 16 bytes. Having to define intermediate structures just to be able to cast is tedious. Add two pointers that take the same space than ctx.

---
 lib/graph/rte_graph_worker_common.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
lib/graph/rte_graph_worker_common.h +0 -0
index 36d864e2c14e..a7fcdf4893ea 100644

lib/graph/rte_graph_worker_common.h struct __rte_cache_aligned rte_node { · line 117

Quoted 7 lines
lib/graph/rte_graph_worker_common.h +3 -1
@@ -112,7 +112,14 @@ struct __rte_cache_aligned rte_node {
        };
        /* Fast path area  */
 #define RTE_NODE_CTX_SZ 16
-       alignas(RTE_CACHE_LINE_SIZE) uint8_t ctx[RTE_NODE_CTX_SZ]; /**< Node Context. */
+       alignas(RTE_CACHE_LINE_SIZE) union {
+               uint8_t ctx[RTE_NODE_CTX_SZ];
+               /* Convenience aliases to store pointers without complex casting. */

1) Use _extension_ to not break this on windows build. See rte_mbuf.
2) Also add static assert to make sure the following struct is not greater than RTE_NODE_CTX_SZ. To avoid accidentally adding something in the future.

Quoted 11 lines
lib/graph/rte_graph_worker_common.h +5 -1
+               struct {
+                       void *ctx_ptr;
+                       void *ctx_ptr2;
+               };
+       }; /**< Node Context. */
        uint16_t size;          /**< Total number of objects available. */
        uint16_t idx;           /**< Number of objects used. */
        rte_graph_off_t off;    /**< Offset of node in the graph reel. */
--

2.44.0