netdev
[Top] [All Lists]

Re: [RFC][PATCH] net drivers and cache alignment

To: Andrew Morton <akpm@xxxxxxxxx>
Subject: Re: [RFC][PATCH] net drivers and cache alignment
From: Daniel Jacobowitz <dan@xxxxxxxxxx>
Date: Sat, 7 Dec 2002 20:14:03 -0500
Cc: Jeff Garzik <jgarzik@xxxxxxxxx>, "David S. Miller" <davem@xxxxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx, netdev@xxxxxxxxxxx
In-reply-to: <3DF2844C.F9216283@xxxxxxxxx>
Mail-followup-to: Andrew Morton <akpm@xxxxxxxxx>, Jeff Garzik <jgarzik@xxxxxxxxx>, "David S. Miller" <davem@xxxxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx, netdev@xxxxxxxxxxx
References: <3DF2781D.3030209@xxxxxxxxx> <20021207.144004.45605764.davem@xxxxxxxxxx> <3DF27EE7.4010508@xxxxxxxxx> <3DF2844C.F9216283@xxxxxxxxx>
Sender: netdev-bounce@xxxxxxxxxxx
User-agent: Mutt/1.5.1i
On Sat, Dec 07, 2002 at 03:29:16PM -0800, Andrew Morton wrote:
> Jeff Garzik wrote:
> > 
> > David S. Miller wrote:
> > > Can't the cacheline_aligned attribute be applied to individual
> > > struct members?  I remember doing this for thread_struct on
> > > sparc ages ago.
> > 
> > Looks like it from the 2.4 processor.h code.
> > 
> > Attached is cut #2.  Thanks for all the near-instant feedback so far :)
> >   Andrew, does the attached still need padding on SMP?
> 
> It needs padding _only_ on SMP.  ____cacheline_aligned_in_smp.
> 
> #define offsetof(t, m)  ((int)(&((t *)0)->m))
> 
> struct foo {
>         int a;
>         int b __attribute__((__aligned__(1024)));
>         int c;
> } foo;
> 
> main()
> {
>         printf("%d\n", sizeof(struct foo));
>         printf("%d\n", offsetof(struct foo, a));
>         printf("%d\n", offsetof(struct foo, b));
>         printf("%d\n", offsetof(struct foo, c));
> }
> 
> ./a.out
> 2048
> 0
> 1024
> 1028
> 
> So your patch will do what you want it to do.  You should just tag the
> first member of a group with ____cacheline_aligned_in_smp, and keep an
> eye on things with offsetof().
> 
> Not sure why sizeof() returned 2048 though.

The structure contains an __aligned__(1024) item.  Think about an array
of 'struct foo' items.  They have to be 2048 bytes or you won't align
correctly.

C allows for empty space in structure padding, but not in arrays,
AFAIK.


-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


<Prev in Thread] Current Thread [Next in Thread>