[v7,08/39] mbuf: use C11 alignas
Checks
Commit Message
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>
---
lib/mbuf/rte_mbuf_core.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Comments
On Mon, Mar 4, 2024 at 6:54 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> 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 <roretzla@linux.microsoft.com>
> Acked-by: Morten Brørup <mb@smartsharesystems.com>
> Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
> ---
> lib/mbuf/rte_mbuf_core.h | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/lib/mbuf/rte_mbuf_core.h b/lib/mbuf/rte_mbuf_core.h
> index 5688683..917a811 100644
> --- a/lib/mbuf/rte_mbuf_core.h
> +++ b/lib/mbuf/rte_mbuf_core.h
> @@ -463,7 +463,7 @@ enum {
> /**
> * The generic rte_mbuf, containing a packet mbuf.
> */
> -struct rte_mbuf {
> +struct __rte_cache_aligned rte_mbuf {
> RTE_MARKER cacheline0;
>
> void *buf_addr; /**< Virtual address of segment buffer. */
> @@ -476,7 +476,7 @@ struct rte_mbuf {
> * same mbuf cacheline0 layout for 32-bit and 64-bit. This makes
> * working on vector drivers easier.
> */
> - rte_iova_t buf_iova __rte_aligned(sizeof(rte_iova_t));
> + alignas(sizeof(rte_iova_t)) rte_iova_t buf_iova;
> #else
> /**
> * Next segment of scattered packet.
> @@ -662,7 +662,7 @@ struct rte_mbuf {
> uint16_t timesync;
>
> uint32_t dynfield1[9]; /**< Reserved for dynamic fields. */
> -} __rte_cache_aligned;
> +};
I probably missed the discussion, but why is cacheline1 not handled in
this patch?
I was expecting a:
- RTE_MARKER cacheline1 __rte_cache_min_aligned;
+ alignas(RTE_CACHE_LINE_MIN_SIZE) RTE_MARKER cacheline1;
On Tue, Mar 05, 2024 at 03:30:49PM +0100, David Marchand wrote:
> On Mon, Mar 4, 2024 at 6:54 PM Tyler Retzlaff
> <roretzla@linux.microsoft.com> 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 <roretzla@linux.microsoft.com>
> > Acked-by: Morten Brørup <mb@smartsharesystems.com>
> > Acked-by: Konstantin Ananyev <konstantin.ananyev@huawei.com>
> > ---
> > lib/mbuf/rte_mbuf_core.h | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/lib/mbuf/rte_mbuf_core.h b/lib/mbuf/rte_mbuf_core.h
> > index 5688683..917a811 100644
> > --- a/lib/mbuf/rte_mbuf_core.h
> > +++ b/lib/mbuf/rte_mbuf_core.h
> > @@ -463,7 +463,7 @@ enum {
> > /**
> > * The generic rte_mbuf, containing a packet mbuf.
> > */
> > -struct rte_mbuf {
> > +struct __rte_cache_aligned rte_mbuf {
> > RTE_MARKER cacheline0;
> >
> > void *buf_addr; /**< Virtual address of segment buffer. */
> > @@ -476,7 +476,7 @@ struct rte_mbuf {
> > * same mbuf cacheline0 layout for 32-bit and 64-bit. This makes
> > * working on vector drivers easier.
> > */
> > - rte_iova_t buf_iova __rte_aligned(sizeof(rte_iova_t));
> > + alignas(sizeof(rte_iova_t)) rte_iova_t buf_iova;
> > #else
> > /**
> > * Next segment of scattered packet.
> > @@ -662,7 +662,7 @@ struct rte_mbuf {
> > uint16_t timesync;
> >
> > uint32_t dynfield1[9]; /**< Reserved for dynamic fields. */
> > -} __rte_cache_aligned;
> > +};
>
> I probably missed the discussion, but why is cacheline1 not handled in
> this patch?
> I was expecting a:
> - RTE_MARKER cacheline1 __rte_cache_min_aligned;
> + alignas(RTE_CACHE_LINE_MIN_SIZE) RTE_MARKER cacheline1;
I should have replaced it I just missed it. Could I get you to fix it up?
We have 2 options.
1. You can leave it as is, eventually the other series I have dealing
with the markers I will probably remove the cacheline1 marker anyway.
2. You could adjust it as you've identified above, just move alignas
before the field type and name.
If you want me to submit a v8 for this let me know I'll do it right
away.
Thanks!
>
>
> --
> David Marchand
On Tue, Mar 5, 2024 at 6:37 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
> > > diff --git a/lib/mbuf/rte_mbuf_core.h b/lib/mbuf/rte_mbuf_core.h
> > > index 5688683..917a811 100644
> > > --- a/lib/mbuf/rte_mbuf_core.h
> > > +++ b/lib/mbuf/rte_mbuf_core.h
> > > @@ -463,7 +463,7 @@ enum {
> > > /**
> > > * The generic rte_mbuf, containing a packet mbuf.
> > > */
> > > -struct rte_mbuf {
> > > +struct __rte_cache_aligned rte_mbuf {
> > > RTE_MARKER cacheline0;
> > >
> > > void *buf_addr; /**< Virtual address of segment buffer. */
> > > @@ -476,7 +476,7 @@ struct rte_mbuf {
> > > * same mbuf cacheline0 layout for 32-bit and 64-bit. This makes
> > > * working on vector drivers easier.
> > > */
> > > - rte_iova_t buf_iova __rte_aligned(sizeof(rte_iova_t));
> > > + alignas(sizeof(rte_iova_t)) rte_iova_t buf_iova;
> > > #else
> > > /**
> > > * Next segment of scattered packet.
> > > @@ -662,7 +662,7 @@ struct rte_mbuf {
> > > uint16_t timesync;
> > >
> > > uint32_t dynfield1[9]; /**< Reserved for dynamic fields. */
> > > -} __rte_cache_aligned;
> > > +};
> >
> > I probably missed the discussion, but why is cacheline1 not handled in
> > this patch?
> > I was expecting a:
> > - RTE_MARKER cacheline1 __rte_cache_min_aligned;
> > + alignas(RTE_CACHE_LINE_MIN_SIZE) RTE_MARKER cacheline1;
>
> I should have replaced it I just missed it. Could I get you to fix it up?
> We have 2 options.
>
> 1. You can leave it as is, eventually the other series I have dealing
> with the markers I will probably remove the cacheline1 marker anyway.
>
> 2. You could adjust it as you've identified above, just move alignas
> before the field type and name.
I like consistency, let's go with option 2.
I'll adjust as I mentionned, no need for a v8.
I already tested it in my builds.
Thanks.
@@ -463,7 +463,7 @@ enum {
/**
* The generic rte_mbuf, containing a packet mbuf.
*/
-struct rte_mbuf {
+struct __rte_cache_aligned rte_mbuf {
RTE_MARKER cacheline0;
void *buf_addr; /**< Virtual address of segment buffer. */
@@ -476,7 +476,7 @@ struct rte_mbuf {
* same mbuf cacheline0 layout for 32-bit and 64-bit. This makes
* working on vector drivers easier.
*/
- rte_iova_t buf_iova __rte_aligned(sizeof(rte_iova_t));
+ alignas(sizeof(rte_iova_t)) rte_iova_t buf_iova;
#else
/**
* Next segment of scattered packet.
@@ -662,7 +662,7 @@ struct rte_mbuf {
uint16_t timesync;
uint32_t dynfield1[9]; /**< Reserved for dynamic fields. */
-} __rte_cache_aligned;
+};
/**
* Function typedef of callback to free externally attached buffer.