[PATCH 00/15] fix packing of structs when building with MSVC

Tyler Retzlaff roretzla at linux.microsoft.com
Thu Mar 21 16:46:42 CET 2024


On Thu, Mar 21, 2024 at 08:32:19AM -0700, Stephen Hemminger wrote:
> On Wed, 20 Mar 2024 14:05:56 -0700
> Tyler Retzlaff <roretzla at linux.microsoft.com> wrote:
> 
> > MSVC struct packing is not compatible with GCC provide a macro that can
> > be used to push existing pack value and sets packing to 1-byte. The
> > existing __rte_packed macro is then used to restore the pack value
> > prior to the push.
> > 
> > Instead of providing macros exclusively for MSVC and for GCC the
> > existing macro is deliberately utilized to trigger a warning if no
> > existing packing has been pushed allowing easy identification of
> > locations where the __rte_msvc_pack is missing.
> > 
> > I've decided to only add the macro to packed structs that are built
> > for Windows. It seems there is little value in adding the macro tree
> > wide and if new code arrives that is built on Windows the __rte_packed
> > will flag where the preamble macro is required.
> > 
> 
> Why is packed used so many places in DPDK?
> Packed should be reserved for things like network protocols
> with unaligned fields.

I made the same observation. Even network frame formats can be handled
without packing so long as you do some extra work to copy small units
of data out which is often worth doing manually and once only instead
of obfuscated behind codegen and direct field access.

> Many of these structure have no holes and are naturally packed.
> Adding packed attribute unnecessarily can generate poor code on
> architectures that do not support unaligned access.

For the specific case where their fields and alignments are naturally
packed I'm not entirely certain you get different codegen but I agree
it might and we'd like to avoid it if it does.

In a lot of the cases it seems to be drivers and often appears like it
is either structs that are used to hardware registers or firmware
protocol data units. Both of which may be need packing.

I will commit to removing packing in structs in this series iff
individual maintainers identify the specific structs in reply to the
series.  If there is no request I'll leave it to them to figure out.

Maintainers should review and request removal as appropriate.

Thanks!


More information about the dev mailing list