[v5,06/39] pipeline: use C11 alignas
Checks
Commit Message
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/pipeline/rte_pipeline.c | 4 ++--
lib/pipeline/rte_port_in_action.c | 3 ++-
lib/pipeline/rte_swx_ipsec.c | 4 +++-
lib/pipeline/rte_table_action.c | 24 ++++++++++++------------
4 files changed, 19 insertions(+), 16 deletions(-)
@@ -104,7 +104,7 @@ struct rte_table {
#define RTE_PIPELINE_MAX_NAME_SZ 124
-struct rte_pipeline {
+struct __rte_cache_aligned rte_pipeline {
/* Input parameters */
char name[RTE_PIPELINE_MAX_NAME_SZ];
int socket_id;
@@ -132,7 +132,7 @@ struct rte_pipeline {
uint64_t pkts_mask;
uint64_t n_pkts_ah_drop;
uint64_t pkts_drop_mask;
-} __rte_cache_aligned;
+};
static inline uint32_t
rte_mask_get_next(uint64_t mask, uint32_t pos)
@@ -2,6 +2,7 @@
* Copyright(c) 2010-2018 Intel Corporation
*/
+#include <stdalign.h>
#include <stdlib.h>
#include <string.h>
@@ -282,7 +283,7 @@ struct rte_port_in_action_profile *
struct rte_port_in_action {
struct ap_config cfg;
struct ap_data data;
- uint8_t memory[0] __rte_cache_aligned;
+ alignas(RTE_CACHE_LINE_SIZE) uint8_t memory[0];
};
static __rte_always_inline void *
@@ -1,6 +1,8 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2022 Intel Corporation
*/
+
+#include <stdalign.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
@@ -154,7 +156,7 @@ struct rte_swx_ipsec {
/*
* Table memory.
*/
- uint8_t memory[] __rte_cache_aligned;
+ alignas(RTE_CACHE_LINE_SIZE) uint8_t memory[];
};
static inline struct ipsec_sa *
@@ -465,11 +465,11 @@ struct encap_qinq_data {
((((uint64_t)(s)) & 0x1LLU) << 8) | \
(((uint64_t)(ttl)) & 0xFFLLU)))
-struct encap_mpls_data {
+struct __rte_aligned(2) encap_mpls_data {
struct rte_ether_hdr ether;
uint32_t mpls[RTE_TABLE_ACTION_MPLS_LABELS_MAX];
uint32_t mpls_count;
-} __rte_packed __rte_aligned(2);
+} __rte_packed;
#define PPP_PROTOCOL_IP 0x0021
@@ -487,42 +487,42 @@ struct encap_pppoe_data {
#define IP_PROTO_UDP 17
-struct encap_vxlan_ipv4_data {
+struct __rte_aligned(2) encap_vxlan_ipv4_data {
struct rte_ether_hdr ether;
struct rte_ipv4_hdr ipv4;
struct rte_udp_hdr udp;
struct rte_vxlan_hdr vxlan;
-} __rte_packed __rte_aligned(2);
+} __rte_packed;
-struct encap_vxlan_ipv4_vlan_data {
+struct __rte_aligned(2) encap_vxlan_ipv4_vlan_data {
struct rte_ether_hdr ether;
struct rte_vlan_hdr vlan;
struct rte_ipv4_hdr ipv4;
struct rte_udp_hdr udp;
struct rte_vxlan_hdr vxlan;
-} __rte_packed __rte_aligned(2);
+} __rte_packed;
-struct encap_vxlan_ipv6_data {
+struct __rte_aligned(2) encap_vxlan_ipv6_data {
struct rte_ether_hdr ether;
struct rte_ipv6_hdr ipv6;
struct rte_udp_hdr udp;
struct rte_vxlan_hdr vxlan;
-} __rte_packed __rte_aligned(2);
+} __rte_packed;
-struct encap_vxlan_ipv6_vlan_data {
+struct __rte_aligned(2) encap_vxlan_ipv6_vlan_data {
struct rte_ether_hdr ether;
struct rte_vlan_hdr vlan;
struct rte_ipv6_hdr ipv6;
struct rte_udp_hdr udp;
struct rte_vxlan_hdr vxlan;
-} __rte_packed __rte_aligned(2);
+} __rte_packed;
-struct encap_qinq_pppoe_data {
+struct __rte_aligned(2) encap_qinq_pppoe_data {
struct rte_ether_hdr ether;
struct rte_vlan_hdr svlan;
struct rte_vlan_hdr cvlan;
struct pppoe_ppp_hdr pppoe_ppp;
-} __rte_packed __rte_aligned(2);
+} __rte_packed;
static size_t
encap_data_size(struct rte_table_action_encap_config *encap)