DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v3] graph: expose node context as pointers
@ 2024-03-25 10:05 Robin Jarry
  2024-03-25 10:59 ` Jerin Jacob
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Robin Jarry @ 2024-03-25 10:05 UTC (permalink / raw)
  To: dev, Jerin Jacob, Kiran Kumar K, Nithin Dabilpuram, Zhirun Yan
  Cc: Tyler Retzlaff

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.

Signed-off-by: Robin Jarry <rjarry@redhat.com>
---

Notes:
    v3:
    
    * Added __extension__ to the unnamed struct inside the union.
    * Fixed C++ header checks.
    * Replaced alignas() with an explicit static_assert.
    
    v2:
    
    * Added __extension__ (not sure where it is needed, I don't have access to windows).
    * It still fails the header check for C++. It seems not possible to align an unnamed union...
      Tyler, do you have an idea about how to fix that?
    * Added static_assert to ensure the anonymous union is not larger than RTE_NODE_CTX_SZ.

 lib/graph/rte_graph_worker_common.h | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/lib/graph/rte_graph_worker_common.h b/lib/graph/rte_graph_worker_common.h
index 36d864e2c14e..722e9dac0d36 100644
--- a/lib/graph/rte_graph_worker_common.h
+++ b/lib/graph/rte_graph_worker_common.h
@@ -12,7 +12,9 @@
  * process, enqueue and move streams of objects to the next nodes.
  */
 
+#include <assert.h>
 #include <stdalign.h>
+#include <stddef.h>
 
 #include <rte_common.h>
 #include <rte_cycles.h>
@@ -112,7 +114,19 @@ 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) cannot be used for ctx since it is part of an unnamed union.
+	 * The compiler shifts the next field on the next cache line which is not what we want.
+	 * The alignment is enforced via a explcicit static asserts below.
+	 */
+	union {
+		uint8_t ctx[RTE_NODE_CTX_SZ];
+		/* Convenience aliases to store pointers without complex casting. */
+		__extension__ 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. */
@@ -130,6 +144,11 @@ struct __rte_cache_aligned rte_node {
 	alignas(RTE_CACHE_LINE_MIN_SIZE) struct rte_node *nodes[]; /**< Next nodes. */
 };
 
+static_assert(offsetof(struct rte_node, ctx) % RTE_CACHE_LINE_SIZE == 0,
+	"rte_node ctx must be aligned on a cache line");
+static_assert(offsetof(struct rte_node, size) - offsetof(struct rte_node, ctx) == RTE_NODE_CTX_SZ,
+	"rte_node context union cannot be larger than RTE_NODE_CTX_SZ");
+
 /**
  * @internal
  *
-- 
2.44.0


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2024-06-26 11:48 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-25 10:05 [PATCH v3] graph: expose node context as pointers Robin Jarry
2024-03-25 10:59 ` Jerin Jacob
2024-03-25 11:02   ` Robin Jarry
2024-03-25 11:08     ` Jerin Jacob
2024-03-25 11:15       ` Robin Jarry
2024-03-25 11:35         ` Jerin Jacob
2024-03-25 12:07           ` Bruce Richardson
2024-03-25 12:08           ` David Marchand
2024-03-25 15:20           ` Robin Jarry
2024-03-25 15:47             ` Jerin Jacob
2024-03-25 15:51               ` Robin Jarry
2024-03-25 15:56                 ` Jerin Jacob
2024-03-25 16:31 ` [PATCH v4] " Robin Jarry
2024-03-25 16:50   ` Jerin Jacob
2024-03-27  9:14 ` [PATCH v5] " Robin Jarry
2024-05-29 17:54   ` Nithin Dabilpuram
2024-06-18 12:33   ` David Marchand
2024-06-25 15:22     ` Robin Jarry
2024-06-26 11:30       ` Jerin Jacob

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).