2009-07-20 23:46:52

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [patch 34/54] Staging: hv: remove STRUCT_PACKED and STRUCT_ALIGNED defines

On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> @@ -43,7 +43,7 @@ typedef struct _RING_BUFFER {
> // volatile u32 InterruptMask;
> // Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!!
> u8 Buffer[0];
> -} STRUCT_PACKED RING_BUFFER;
> +} __attribute__((packed)) RING_BUFFER;
>

The data structure is actually packed already, the attribute does not make it better
and could be removed. We also have __packed as a shortcut for __attribute__((packed)).

Arnd <><


2009-07-24 21:32:35

by Jörn Engel

[permalink] [raw]
Subject: Re: [patch 34/54] Staging: hv: remove STRUCT_PACKED and STRUCT_ALIGNED defines

On Tue, 21 July 2009 01:46:41 +0200, Arnd Bergmann wrote:
> On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> > @@ -43,7 +43,7 @@ typedef struct _RING_BUFFER {
> > // volatile u32 InterruptMask;
> > // Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!!
> > u8 Buffer[0];
> > -} STRUCT_PACKED RING_BUFFER;
> > +} __attribute__((packed)) RING_BUFFER;
> >
>
> The data structure is actually packed already, the attribute does not make it better
> and could be removed. We also have __packed as a shortcut for __attribute__((packed)).

Honestly, I don't know how useful __packed really is. In a shared
kernel/userspace header, it is only defined for the kernel.

Jörn

--
Do not stop an army on its way home.
-- Sun Tzu

2009-07-24 21:52:00

by Stephen Hemminger

[permalink] [raw]
Subject: Re: [patch 34/54] Staging: hv: remove STRUCT_PACKED and STRUCT_ALIGNED defines

On Fri, 24 Jul 2009 23:32:19 +0200
Jörn Engel <[email protected]> wrote:

> On Tue, 21 July 2009 01:46:41 +0200, Arnd Bergmann wrote:
> > On Friday 17 July 2009, Greg Kroah-Hartman wrote:
> > > @@ -43,7 +43,7 @@ typedef struct _RING_BUFFER {
> > > // volatile u32 InterruptMask;
> > > // Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!!
> > > u8 Buffer[0];
> > > -} STRUCT_PACKED RING_BUFFER;
> > > +} __attribute__((packed)) RING_BUFFER;
> > >
> >
> > The data structure is actually packed already, the attribute does not make it better
> > and could be removed. We also have __packed as a shortcut for __attribute__((packed)).
>
> Honestly, I don't know how useful __packed really is. In a shared
> kernel/userspace header, it is only defined for the kernel.
>

As I remember, gcc generates worse code for packed structures on many architectures
since it may have to do byte fetchs/recombining to avoid unaligned
accesses.

--

2009-07-24 23:06:37

by Jörn Engel

[permalink] [raw]
Subject: Re: [patch 34/54] Staging: hv: remove STRUCT_PACKED and STRUCT_ALIGNED defines

On Fri, 24 July 2009 14:50:25 -0700, Stephen Hemminger wrote:
> On Fri, 24 Jul 2009 23:32:19 +0200
> Jörn Engel <[email protected]> wrote:
>
> > On Tue, 21 July 2009 01:46:41 +0200, Arnd Bergmann wrote:
> > >
> > > The data structure is actually packed already, the attribute does not make it better
> > > and could be removed. We also have __packed as a shortcut for __attribute__((packed)).
> >
> > Honestly, I don't know how useful __packed really is. In a shared
> > kernel/userspace header, it is only defined for the kernel.
>
> As I remember, gcc generates worse code for packed structures on many architectures
> since it may have to do byte fetchs/recombining to avoid unaligned
> accesses.

I was talking about "__packed" vs. "__attribute__((packed))". But yes,
avoiding packed structures where possible is a good idea.

Jörn

--
"[One] doesn't need to know [...] how to cause a headache in order
to take an aspirin."
-- Scott Culp, Manager of the Microsoft Security Response Center, 2001