c - Aligning to cache line and knowing the cache line size -
To stop false sharing, I want to align each element of a cache line. So first I need to know the size of a cache line, so I give the amount of bytes to each element. Secondly, I want to start the array to combine with a cash line.
I am using Linux and 8-core X86 platforms. How do I get the first cache line size? Secondly, how do I align the cache line in C. I am using the GCC compiler.
Then the example of the structure will be, assuming the size of 64's cache line.
element [0] bytes captures the 0-63 element [1] captures the bytes 64 -127 element holds [2] bytes at 128-191 And so on, of course there is a coalition in the 0-63 cache line.
To know the size, you need to use it for the processor documentation, afaik do this There is no programming method for. On the plus side however, most cache lines are of a standard size, which is based on the inputs standards. However, there are 64 bytes on x86 cache lines, you have to follow the processor guidelines (Intel has some special notes on the NetBurst-based processor) to prevent false partnership, normally you need 64 bytes (for this). Intel says you should avoid crossing 16 byte boundaries).
To do this, it is necessary in C or C ++ that you specify the standard aligned_alloc function or one of the compiler specific specifiers, such as __ attribute (__ (align) (64)) Use or __discacks (align (64)) To split them on different cache lines, for a pad between members in a structure, next to you Must have enough members to align it up to 64 byte extent
Comments
Post a Comment