0
  1. What are the major differences between _mm_clflush and _mm_clflushout ?
  2. Is flushing the invalidate pages in the CPU cache is thread-safe, given that each thread flushes different memory regions (can be originated from different CPU cores)?
  3. Just to be sure - these commands are synchronous? I.e., they return only after the cache page is being flushed to the memory (if it is an invalidated page)?
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
user3563894
  • 331
  • 3
  • 13
  • 1
    Did you read the manual? https://www.felixcloutier.com/x86/clflushopt pretty clearly says it *not* ordered wrt. a lot of things, and you'd have to use `sfence` or `mfence` if you want later stores (or all memory ops) to happen after `clflushopt`'s effects on memory happens. – Peter Cordes Nov 23 '21 at 03:01
  • (2) - flushing cache has no effect on correctness of multi-threaded code, even when it's dirty in another core. Cache is coherent at all times, and it doesn't introduce new memory reordering or break the illusion of a single thread's own operations all happening in program order. If you're using non-volatile DIMMs like Optane DC PM, you could make a store visible earlier than normal, but it's always possible for that to happen by chance anyway (e.g. an interrupt right after a store leads to its eviction before other stores to other lines even execute). – Peter Cordes Nov 23 '21 at 03:11

0 Answers0