[v4] graph: expose node context as pointers

Message ID 20240325163108.816996-3-rjarry@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v4] graph: expose node context as pointers |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation fail Compilation issues
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS

Commit Message

Robin Jarry March 25, 2024, 4:31 p.m. UTC
  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 helper
inline functions to cast the node context to opaque pointers.

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

Notes:
    v4:
    
    * Replaced the unnamed union with helper inline functions.
    
    v3:
    
    * Added __extension__ to the unnamed struct inside the union.
    * Fixed C++ header checks.
    * Replaced alignas() with an explicit static_assert.

 lib/graph/rte_graph_worker_common.h | 54 +++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
  

Comments

Jerin Jacob March 25, 2024, 4:50 p.m. UTC | #1
On Mon, Mar 25, 2024 at 10:11 PM Robin Jarry <rjarry@redhat.com> wrote:
>
> 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 helper
> inline functions to cast the node context to opaque pointers.
>
> Signed-off-by: Robin Jarry <rjarry@redhat.com>
> ---
>
> Notes:
>     v4:
>
>     * Replaced the unnamed union with helper inline functions.
>
>     v3:
>
>     * Added __extension__ to the unnamed struct inside the union.
>     * Fixed C++ header checks.
>     * Replaced alignas() with an explicit static_assert.
>
>  lib/graph/rte_graph_worker_common.h | 54 +++++++++++++++++++++++++++++
>  1 file changed, 54 insertions(+)
>
> diff --git a/lib/graph/rte_graph_worker_common.h b/lib/graph/rte_graph_worker_common.h
> index 36d864e2c14e..f54f65598193 100644
> --- a/lib/graph/rte_graph_worker_common.h
> +++ b/lib/graph/rte_graph_worker_common.h
> @@ -130,6 +130,60 @@ struct __rte_cache_aligned rte_node {
>         alignas(RTE_CACHE_LINE_MIN_SIZE) struct rte_node *nodes[]; /**< Next nodes. */
>  };
>
> +/**
> + * Cast the first 8 bytes of node context as an opaque pointer.
> + *
> + * @param node
> + *   Pointer to the node object.
> + *
> + * @return
> + *   The opaque pointer value.
> + */
> +static inline void *rte_node_ctx_ptr1_get(struct rte_node *node)

New line after void*. Same for all new functions.

With that change:

Acked-by: Jerin Jacob <jerinj@marvell.com>



> +{
> +       return ((void **)node->ctx)[0];
> +}
> +
> +/**
> + * Cast the last 8 bytes of node context as an opaque pointer.
> + *
> + * @param node
> + *   Pointer to the node object.
> + *
> + * @return
> + *   The opaque pointer value.
> + */
> +static inline void *rte_node_ctx_ptr2_get(struct rte_node *node)
> +{
> +       return ((void **)node->ctx)[1];
> +}
> +
> +/**
> + * Set the first 8 bytes of node context to an opaque pointer value.
> + *
> + * @param node
> + *   Pointer to the node object.
> + * @param ptr
> + *   The opaque pointer value.
> + */
> +static inline void rte_node_ctx_ptr1_set(struct rte_node *node, void *ptr)
> +{
> +       ((void **)node->ctx)[0] = ptr;
> +}
> +
> +/**
> + * Set the last 8 bytes of node context to an opaque pointer value.
> + *
> + * @param node
> + *   Pointer to the node object.
> + * @param ptr
> + *   The opaque pointer value.
> + */
> +static inline void rte_node_ctx_ptr2_set(struct rte_node *node, void *ptr)
> +{
> +       ((void **)node->ctx)[1] = ptr;
> +}
> +
>  /**
>   * @internal
>   *
> --
> 2.44.0
>
  

Patch

diff --git a/lib/graph/rte_graph_worker_common.h b/lib/graph/rte_graph_worker_common.h
index 36d864e2c14e..f54f65598193 100644
--- a/lib/graph/rte_graph_worker_common.h
+++ b/lib/graph/rte_graph_worker_common.h
@@ -130,6 +130,60 @@  struct __rte_cache_aligned rte_node {
 	alignas(RTE_CACHE_LINE_MIN_SIZE) struct rte_node *nodes[]; /**< Next nodes. */
 };
 
+/**
+ * Cast the first 8 bytes of node context as an opaque pointer.
+ *
+ * @param node
+ *   Pointer to the node object.
+ *
+ * @return
+ *   The opaque pointer value.
+ */
+static inline void *rte_node_ctx_ptr1_get(struct rte_node *node)
+{
+	return ((void **)node->ctx)[0];
+}
+
+/**
+ * Cast the last 8 bytes of node context as an opaque pointer.
+ *
+ * @param node
+ *   Pointer to the node object.
+ *
+ * @return
+ *   The opaque pointer value.
+ */
+static inline void *rte_node_ctx_ptr2_get(struct rte_node *node)
+{
+	return ((void **)node->ctx)[1];
+}
+
+/**
+ * Set the first 8 bytes of node context to an opaque pointer value.
+ *
+ * @param node
+ *   Pointer to the node object.
+ * @param ptr
+ *   The opaque pointer value.
+ */
+static inline void rte_node_ctx_ptr1_set(struct rte_node *node, void *ptr)
+{
+	((void **)node->ctx)[0] = ptr;
+}
+
+/**
+ * Set the last 8 bytes of node context to an opaque pointer value.
+ *
+ * @param node
+ *   Pointer to the node object.
+ * @param ptr
+ *   The opaque pointer value.
+ */
+static inline void rte_node_ctx_ptr2_set(struct rte_node *node, void *ptr)
+{
+	((void **)node->ctx)[1] = ptr;
+}
+
 /**
  * @internal
  *