[PATCH v6 32/39] bpf: use C11 alignas
Konstantin Ananyev
konstantin.ananyev at huawei.com
Tue Feb 27 10:43:25 CET 2024
> Subject: [PATCH v6 32/39] bpf: use C11 alignas
>
> 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 at linux.microsoft.com>
> Acked-by: Morten Brørup <mb at smartsharesystems.com>
> ---
> lib/bpf/bpf_pkt.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/bpf/bpf_pkt.c b/lib/bpf/bpf_pkt.c
> index 793a75d..aaca935 100644
> --- a/lib/bpf/bpf_pkt.c
> +++ b/lib/bpf/bpf_pkt.c
> @@ -23,7 +23,7 @@
> * information about installed BPF rx/tx callback
> */
>
> -struct bpf_eth_cbi {
> +struct __rte_cache_aligned bpf_eth_cbi {
> /* used by both data & control path */
> RTE_ATOMIC(uint32_t) use; /*usage counter */
> const struct rte_eth_rxtx_callback *cb; /* callback handle */
> @@ -33,7 +33,7 @@ struct bpf_eth_cbi {
> LIST_ENTRY(bpf_eth_cbi) link;
> uint16_t port;
> uint16_t queue;
> -} __rte_cache_aligned;
> +};
>
> /*
> * Odd number means that callback is used by datapath.
> --
Acked-by: Konstantin Ananyev <konstantin.ananyev at huawei.com>
> 1.8.3.1
More information about the dev
mailing list