Search code examples
clinuxmultithreadingx86cpu-cache

about _mm_clflush (void const* p)


I have 2 thread bonded to 2 cpu core separately.

thread A and thread B have the same cache line data.

If I modified the cache line data and call _mm_clflush (void const* p) in thread A.

The cache line (L1,L2,L3) in thread B will become invalid and only can be read from main memory again.

Is that right ?


Solution

  • The answer is yes.

    According to the Intel documentation, the CLFLUSH instruction invalidates the cache line in the entire "cache coherency domain". It is therefore not limited to the shared cache (normally Level 3 Cache), but also affects the dedicated cache of all other CPUs (i.e. their Level 1 and Level 2 Cache).

    So, the next time a read takes place from that cache line, it will have to be read from main memory again.