From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0146E43BF1; Mon, 26 Feb 2024 18:29:57 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7DC19402B2; Mon, 26 Feb 2024 18:29:57 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id A0A3C40144 for ; Mon, 26 Feb 2024 18:29:55 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id C51B920B74C0; Mon, 26 Feb 2024 09:29:54 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C51B920B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1708968594; bh=9Aa8oNl6I9sKlv1Z+YH1YfmvbWDsItrb3DtYjbganno=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kuGaeTVhdH2JFFsrV4aH6CGNyS3YHShIjEH7usJir+PxFmZik73MJn4has5xO/pAO nf1goTGFaNGPHWFCxewja95KE5Hi1I5xI5xiT/qs/3ttgyutfXc3X0Gkm5T0EY3UIG glUwkgay3xw6Vc7iPuzYeT6xkbb7FhjETGzowPxk= Date: Mon, 26 Feb 2024 09:29:54 -0800 From: Tyler Retzlaff To: Konstantin Ananyev Cc: "dev@dpdk.org" , Andrew Rybchenko , Bruce Richardson , Fengchengwen , 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 Subject: Re: [PATCH v5 05/39] ring: use C11 alignas Message-ID: <20240226172954.GC20214@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1707873986-29352-1-git-send-email-roretzla@linux.microsoft.com> <1708715054-22386-1-git-send-email-roretzla@linux.microsoft.com> <1708715054-22386-6-git-send-email-roretzla@linux.microsoft.com> <7dda41098ac24f3a92b57f757c1686c8@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7dda41098ac24f3a92b57f757c1686c8@huawei.com> User-Agent: Mutt/1.5.21 (2010-09-15) 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 On Mon, Feb 26, 2024 at 01:23:35PM +0000, Konstantin Ananyev wrote: > > > > > > 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/ring/rte_ring_core.h | 16 +++++++++------- > > lib/ring/rte_ring_peek_zc.h | 4 ++-- > > 2 files changed, 11 insertions(+), 9 deletions(-) > > > > diff --git a/lib/ring/rte_ring_core.h b/lib/ring/rte_ring_core.h > > index b770873..497d535 100644 > > --- a/lib/ring/rte_ring_core.h > > +++ b/lib/ring/rte_ring_core.h > > @@ -19,6 +19,8 @@ > > * instead. > > */ > > > > +#include > > + > > #ifdef __cplusplus > > extern "C" { > > #endif > > @@ -78,7 +80,7 @@ struct rte_ring_headtail { > > > > union __rte_ring_rts_poscnt { > > /** raw 8B value to read/write *cnt* and *pos* as one atomic op */ > > - RTE_ATOMIC(uint64_t) raw __rte_aligned(8); > > + alignas(8) RTE_ATOMIC(uint64_t) raw; > > One small question - here and below, would it possible to do 'alignas(sizeof(uint64_t))' instead of 'alignas(8)? > Or MSVC has some restrictions here? it should be okay to use a constant expression with alignas(n) even with MSVC because it is conformant, if it isn't it would be a bug. it is one benefit over using __declspec(align(a)). i'll update the series to use sizeof. > > > > struct { > > uint32_t cnt; /**< head/tail reference counter */ > > uint32_t pos; /**< head/tail position */ > > @@ -94,7 +96,7 @@ struct rte_ring_rts_headtail { > >