Skip to content

Commit

Permalink
ip_frag: use C11 alignas
Browse files Browse the repository at this point in the history
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>
Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
  • Loading branch information
Tyler Retzlaff authored and ovsrobot committed Mar 4, 2024
1 parent 5a1650b commit 8520ff3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/ip_frag/ip_reassembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,28 @@ 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 */
uint32_t total_size; /* expected reassembled size */
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 {
Expand Down

0 comments on commit 8520ff3

Please sign in to comment.