From patchwork Mon Mar 4 17:52:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 137942 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7ECF043B9B; Mon, 4 Mar 2024 18:56:11 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6669B42E90; Mon, 4 Mar 2024 18:53:26 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id AEF9440695 for ; Mon, 4 Mar 2024 18:52:52 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id 0A01D20B74D1; Mon, 4 Mar 2024 09:52:50 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0A01D20B74D1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1709574771; bh=tY+ib1a5vBunUMctFokCefqzLnfhOlZ6yQPL6iSHQek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GgP5lmLXxN3SzNj/9VTk5fYoj20bHvQelzciWMsuvgGeXefe6n0dM/cdEpLHdqLQ8 0sGghBPJbCEnh/yw9tZxJ0VmuiVtRk3WQSakc/muOvLtidBOpEURO4IrpMoWrMS6nl Rbizc3rY1f0QGfwGhoy78v1oDx0S1oQByPTDo7T4= From: Tyler Retzlaff To: dev@dpdk.org Cc: Andrew Rybchenko , Bruce Richardson , Chengwen Feng , Cristian Dumitrescu , David Christensen , David Hunt , Ferruh Yigit , Honnappa Nagarahalli , Jasvinder Singh , Jerin Jacob , Kevin Laatz , Konstantin Ananyev , Min Zhou , Ruifeng Wang , Sameh Gobriel , Stanislaw Kardach , Thomas Monjalon , Vladimir Medvedkin , Yipeng Wang , Tyler Retzlaff Subject: [PATCH v7 17/39] table: use C11 alignas Date: Mon, 4 Mar 2024 09:52:22 -0800 Message-Id: <1709574764-9041-18-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1709574764-9041-1-git-send-email-roretzla@linux.microsoft.com> References: <1707873986-29352-1-git-send-email-roretzla@linux.microsoft.com> <1709574764-9041-1-git-send-email-roretzla@linux.microsoft.com> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 Acked-by: Morten Brørup --- lib/table/rte_swx_table_learner.c | 4 ++-- lib/table/rte_table_acl.c | 3 ++- lib/table/rte_table_array.c | 7 ++++--- lib/table/rte_table_hash_cuckoo.c | 4 +++- lib/table/rte_table_hash_ext.c | 3 ++- lib/table/rte_table_hash_key16.c | 4 +++- lib/table/rte_table_hash_key32.c | 4 +++- lib/table/rte_table_hash_key8.c | 4 +++- lib/table/rte_table_hash_lru.c | 3 ++- lib/table/rte_table_lpm.c | 3 ++- lib/table/rte_table_lpm_ipv6.c | 3 ++- 11 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/table/rte_swx_table_learner.c b/lib/table/rte_swx_table_learner.c index 2b5e6bd..55a3645 100644 --- a/lib/table/rte_swx_table_learner.c +++ b/lib/table/rte_swx_table_learner.c @@ -145,13 +145,13 @@ struct table_params { size_t total_size; }; -struct table { +struct __rte_cache_aligned table { /* Table parameters. */ struct table_params params; /* Table buckets. */ uint8_t buckets[]; -} __rte_cache_aligned; +}; /* The timeout (in cycles) is stored in the table as a 32-bit value by truncating its least * significant 32 bits. Therefore, to make sure the time is always advancing when adding the timeout diff --git a/lib/table/rte_table_acl.c b/lib/table/rte_table_acl.c index 83411d2..2764cda 100644 --- a/lib/table/rte_table_acl.c +++ b/lib/table/rte_table_acl.c @@ -2,6 +2,7 @@ * Copyright(c) 2010-2014 Intel Corporation */ +#include #include #include @@ -47,7 +48,7 @@ struct rte_table_acl { uint8_t *acl_rule_memory; /* Memory to store the rules */ /* Memory to store the action table and stack of free entries */ - uint8_t memory[0] __rte_cache_aligned; + alignas(RTE_CACHE_LINE_SIZE) uint8_t memory[0]; }; diff --git a/lib/table/rte_table_array.c b/lib/table/rte_table_array.c index 80bc2a7..31a17d5 100644 --- a/lib/table/rte_table_array.c +++ b/lib/table/rte_table_array.c @@ -2,6 +2,7 @@ * Copyright(c) 2010-2014 Intel Corporation */ +#include #include #include @@ -27,7 +28,7 @@ #endif -struct rte_table_array { +struct __rte_cache_aligned rte_table_array { struct rte_table_stats stats; /* Input parameters */ @@ -39,8 +40,8 @@ struct rte_table_array { uint32_t entry_pos_mask; /* Internal table */ - uint8_t array[0] __rte_cache_aligned; -} __rte_cache_aligned; + alignas(RTE_CACHE_LINE_SIZE) uint8_t array[0]; +}; static void * rte_table_array_create(void *params, int socket_id, uint32_t entry_size) diff --git a/lib/table/rte_table_hash_cuckoo.c b/lib/table/rte_table_hash_cuckoo.c index 0f4900c..d3b60f3 100644 --- a/lib/table/rte_table_hash_cuckoo.c +++ b/lib/table/rte_table_hash_cuckoo.c @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2010-2017 Intel Corporation */ + +#include #include #include @@ -42,7 +44,7 @@ struct rte_table_hash { struct rte_hash *h_table; /* Lookup table */ - uint8_t memory[0] __rte_cache_aligned; + alignas(RTE_CACHE_LINE_SIZE) uint8_t memory[0]; }; static int diff --git a/lib/table/rte_table_hash_ext.c b/lib/table/rte_table_hash_ext.c index 2148d83..61e3c79 100644 --- a/lib/table/rte_table_hash_ext.c +++ b/lib/table/rte_table_hash_ext.c @@ -2,6 +2,7 @@ * Copyright(c) 2010-2017 Intel Corporation */ +#include #include #include @@ -99,7 +100,7 @@ struct rte_table_hash { uint32_t *bkt_ext_stack; /* Table memory */ - uint8_t memory[0] __rte_cache_aligned; + alignas(RTE_CACHE_LINE_SIZE) uint8_t memory[0]; }; static int diff --git a/lib/table/rte_table_hash_key16.c b/lib/table/rte_table_hash_key16.c index 7734aef..2af34a5 100644 --- a/lib/table/rte_table_hash_key16.c +++ b/lib/table/rte_table_hash_key16.c @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2010-2017 Intel Corporation */ + +#include #include #include @@ -83,7 +85,7 @@ struct rte_table_hash { uint32_t *stack; /* Lookup table */ - uint8_t memory[0] __rte_cache_aligned; + alignas(RTE_CACHE_LINE_SIZE) uint8_t memory[0]; }; static int diff --git a/lib/table/rte_table_hash_key32.c b/lib/table/rte_table_hash_key32.c index fcb4348..06e5cf4 100644 --- a/lib/table/rte_table_hash_key32.c +++ b/lib/table/rte_table_hash_key32.c @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2010-2017 Intel Corporation */ + +#include #include #include @@ -83,7 +85,7 @@ struct rte_table_hash { uint32_t *stack; /* Lookup table */ - uint8_t memory[0] __rte_cache_aligned; + alignas(RTE_CACHE_LINE_SIZE) uint8_t memory[0]; }; static int diff --git a/lib/table/rte_table_hash_key8.c b/lib/table/rte_table_hash_key8.c index bbe6562..2ab8e1b 100644 --- a/lib/table/rte_table_hash_key8.c +++ b/lib/table/rte_table_hash_key8.c @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2010-2017 Intel Corporation */ + +#include #include #include @@ -79,7 +81,7 @@ struct rte_table_hash { uint32_t *stack; /* Lookup table */ - uint8_t memory[0] __rte_cache_aligned; + alignas(RTE_CACHE_LINE_SIZE) uint8_t memory[0]; }; static int diff --git a/lib/table/rte_table_hash_lru.c b/lib/table/rte_table_hash_lru.c index cb4f329..8604a64 100644 --- a/lib/table/rte_table_hash_lru.c +++ b/lib/table/rte_table_hash_lru.c @@ -2,6 +2,7 @@ * Copyright(c) 2010-2017 Intel Corporation */ +#include #include #include @@ -76,7 +77,7 @@ struct rte_table_hash { uint32_t *key_stack; /* Table memory */ - uint8_t memory[0] __rte_cache_aligned; + alignas(RTE_CACHE_LINE_SIZE) uint8_t memory[0]; }; static int diff --git a/lib/table/rte_table_lpm.c b/lib/table/rte_table_lpm.c index b9cff25..978d7e5 100644 --- a/lib/table/rte_table_lpm.c +++ b/lib/table/rte_table_lpm.c @@ -2,6 +2,7 @@ * Copyright(c) 2010-2014 Intel Corporation */ +#include #include #include @@ -47,7 +48,7 @@ struct rte_table_lpm { /* Next Hop Table (NHT) */ uint32_t nht_users[RTE_TABLE_LPM_MAX_NEXT_HOPS]; - uint8_t nht[0] __rte_cache_aligned; + alignas(RTE_CACHE_LINE_SIZE) uint8_t nht[0]; }; static void * diff --git a/lib/table/rte_table_lpm_ipv6.c b/lib/table/rte_table_lpm_ipv6.c index e4e823a..1d54f83 100644 --- a/lib/table/rte_table_lpm_ipv6.c +++ b/lib/table/rte_table_lpm_ipv6.c @@ -2,6 +2,7 @@ * Copyright(c) 2010-2014 Intel Corporation */ +#include #include #include @@ -44,7 +45,7 @@ struct rte_table_lpm_ipv6 { /* Next Hop Table (NHT) */ uint32_t nht_users[RTE_TABLE_LPM_MAX_NEXT_HOPS]; - uint8_t nht[0] __rte_cache_aligned; + alignas(RTE_CACHE_LINE_SIZE) uint8_t nht[0]; }; static void *