On 2002.12.08 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?
>
What do you all think about this:
#include <stdio.h>
#define CACHE_LINE_SIZE 128
#define ____cacheline_aligned __attribute__((__aligned__(CACHE_LINE_SIZE)))
#define __cacheline_start struct { } ____cacheline_aligned;
#define offsetof(t, m) ((int)(&((t *)0)->m))
struct S {
__cacheline_start
int x;
__cacheline_start
int y;
int z;
};
int main()
{
struct S s;
printf("%d\n",sizeof(struct S));
printf("%d\n",offsetof(struct S,x));
printf("%d\n",offsetof(struct S,y));
printf("%d\n",offsetof(struct S,z));
}
werewolf:~> vi kk.c
werewolf:~> kk
256
0
128
132
So you don't have to modify any field, just put __cacheline_start where
needed ? (and does not add any extra sizeof(int) overhead).
-- J.A. Magallon <jamagallon@able.es> \ Software is like sex: werewolf.able.es \ It's better when it's free Mandrake Linux release 9.1 (Cooker) for i586 Linux 2.4.20-jam1 (gcc 3.2 (Mandrake Linux 9.1 3.2-4mdk)) - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Sat Dec 07 2002 - 22:00:31 EST