[v5,25/39] node: use C11 alignas

Message ID 1708715054-22386-26-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Series use C11 alignas |


Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff Feb. 23, 2024, 7:04 p.m. UTC
  The current location used for __rte_aligned(a) for alignment of types
and variables is not compatible with MSVC. There is only a single
location accepted by both toolchains.

For variables standard C11 offers alignas(a) supported by conformant
compilers i.e. both MSVC and GCC.

For types the standard offers no alignment facility that compatibly
interoperates with C and C++ but may be achieved by relocating the
placement of __rte_aligned(a) to the aforementioned location accepted
by all currently supported toolchains.

To allow alignment for both compilers do the following:

* Move __rte_aligned from the end of {struct,union} definitions to
  be between {struct,union} and tag.

  The placement between {struct,union} and the tag allows the desired
  alignment to be imparted on the type regardless of the toolchain being
  used for all of GCC, LLVM, MSVC compilers building both C and C++.

* Replace use of __rte_aligned(a) on variables/fields with alignas(a).

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
 lib/node/node_private.h | 4 ++--
 lib/node/pkt_cls.c      | 4 +++-
 2 files changed, 5 insertions(+), 3 deletions(-)


diff --git a/lib/node/node_private.h b/lib/node/node_private.h
index 2b9bad1..ff04659 100644
--- a/lib/node/node_private.h
+++ b/lib/node/node_private.h
@@ -51,9 +51,9 @@  struct node_mbuf_priv1 {
  * Node mbuf private area 2.
-struct node_mbuf_priv2 {
+struct __rte_cache_aligned node_mbuf_priv2 {
 	uint64_t priv_data;
-} __rte_cache_aligned;
 #define NODE_MBUF_PRIV2_SIZE sizeof(struct node_mbuf_priv2)
diff --git a/lib/node/pkt_cls.c b/lib/node/pkt_cls.c
index a8302b8..9d21b7f 100644
--- a/lib/node/pkt_cls.c
+++ b/lib/node/pkt_cls.c
@@ -2,6 +2,8 @@ 
  * Copyright (C) 2020 Marvell.
+#include <stdalign.h>
 #include <rte_graph.h>
 #include <rte_graph_worker.h>
@@ -9,7 +11,7 @@ 
 #include "node_private.h"
 /* Next node for each ptype, default is '0' is "pkt_drop" */
-static const uint8_t p_nxt[256] __rte_cache_aligned = {
+static const alignas(RTE_CACHE_LINE_SIZE) uint8_t p_nxt[256] = {