tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Is there a way to obtain a machine's cache line size?
Hello,
Is there a way to obtain the correct cache line size for the machine
code is running on, both in the kernel and at user level? I see
there is a compile time constant CACHE_LINE_SIZE in <sys/param.h>
which currently seems to be always be set to 64, but I'm pretty
certain that is not necessarily a correct value. For example, I'm
pretty sure that for the PowerPC 32 and 128 are possibilities, and
the same binary could run on machines with either line size so there
is no correct compile-time answer.
I have a data structure in which I'd like to get some of the data items
on cache lines by themselves to avoid false sharing. The bigger
structure is variably sized in any case, with its size being determined
at run time and the memory for it allocated dynamically, so there is
no particular value in having a one-size-fits-all compile time constant
for the cache line size. If I could obtain the actual size for the
machine the code is running on I could compute the appropriate amount
of space to tack onto the end of the allocation to get a separate
cache line for each of the items which requires one without having
to use a worst-case number.
Thanks,
Dennis Ferguson
Home |
Main Index |
Thread Index |
Old Index