[PATCH v6 39/39] ip_frag: use C11 alignas

Konstantin Ananyev konstantin.ananyev at huawei.com
Tue Feb 27 10:44:08 CET 2024



> Subject: [PATCH v6 39/39] ip_frag: 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/ip_frag/ip_reassembly.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/ip_frag/ip_reassembly.h b/lib/ip_frag/ip_reassembly.h
> index a9f97ae..5443c73 100644
> --- a/lib/ip_frag/ip_reassembly.h
> +++ b/lib/ip_frag/ip_reassembly.h
> @@ -47,7 +47,7 @@ struct ip_frag_key {
>   * Fragmented packet to reassemble.
>   * First two entries in the frags[] array are for the last and first fragments.
>   */
> -struct ip_frag_pkt {
> +struct __rte_cache_aligned ip_frag_pkt {
>  	RTE_TAILQ_ENTRY(ip_frag_pkt) lru;      /* LRU list */
>  	struct ip_frag_key key;                /* fragmentation key */
>  	uint64_t start;                        /* creation timestamp */
> @@ -55,20 +55,20 @@ struct ip_frag_pkt {
>  	uint32_t frag_size;                    /* size of fragments received */
>  	uint32_t last_idx;                     /* index of next entry to fill */
>  	struct ip_frag frags[IP_MAX_FRAG_NUM]; /* fragments */
> -} __rte_cache_aligned;
> +};
> 
>   /* fragments tailq */
>  RTE_TAILQ_HEAD(ip_pkt_list, ip_frag_pkt);
> 
>  /* fragmentation table statistics */
> -struct ip_frag_tbl_stat {
> +struct __rte_cache_aligned ip_frag_tbl_stat {
>  	uint64_t find_num;     /* total # of find/insert attempts. */
>  	uint64_t add_num;      /* # of add ops. */
>  	uint64_t del_num;      /* # of del ops. */
>  	uint64_t reuse_num;    /* # of reuse (del/add) ops. */
>  	uint64_t fail_total;   /* total # of add failures. */
>  	uint64_t fail_nospace; /* # of 'no space' add failures. */
> -} __rte_cache_aligned;
> +};
> 
>  /* fragmentation table */
>  struct rte_ip_frag_tbl {
> --

Acked-by: Konstantin Ananyev <konstantin.ananyev at huawei.com>
 

> 1.8.3.1



More information about the dev mailing list