Questions tagged [mesi]

The MESI protocol (known also as Illinois protocol) is a cache coherence and memory coherence protocol.

The MESI protocol (known also as Illinois protocol) is a cache coherence and memory coherence protocol. It or an extension like MESIF or MOESI is used nearly universally in multi-core CPUs and SMP systems.

http://en.wikipedia.org/wiki/MESI_protocol

MESI requires a core to take exclusive ownership of a cache line before writing to it, preventing multiple cores from storing conflicting values, or even from reading stale values.

(Cache itself is not the source of memory reordering: that's usually store buffers within individual cores. And on weakly-ordered ISAs, out-of-order execution of loads. See Does a memory barrier ensure that the cache coherence has been completed? no, cache is always coherent. A memory barrier waits for the store buffer to drain. It's a common misconception that stores make cache non-coherent and then barriers flush it manually.)

Relevant Q&As:

  • Can num++ be atomic for 'int num'? explains how atomic RMW operations are typically implemented in modern x86, by holding a cache line in Modified state between the load and store, not responding to Invalidate or RFOs until after the atomic transaction.
61 questions
22
votes
2 answers

Which cache-coherence-protocol does Intel and AMD use?

For my bachelor thesis I have to analyse the effecs of False Sharing on multicore systems. So looking for the different cache-coherence-protocol-types I have come across on Wikipedia that Intel has developed the MESIF cache-coherence-protocol, but…
mbed_dev
  • 1,450
  • 16
  • 33
15
votes
5 answers

Why is the standard C# event invocation pattern thread-safe without a memory barrier or cache invalidation? What about similar code?

In C#, this is the standard code for invoking an event in a thread-safe way: var handler = SomethingHappened; if(handler != null) handler(this, e); Where, potentially on another thread, the compiler-generated add method uses Delegate.Combine to…
Andrew Russell
  • 26,924
  • 7
  • 58
  • 104
12
votes
2 answers

LOCK prefix vs MESI protocol?

What is the purpose of the x86 LOCK prefix, if the MESI protocol prevents other cores from writing to "exclusive"-ly owned data anyway? I am getting a little confused between what LOCK provides and what MESI provides? I understand the MESI protocol…
user997112
  • 29,025
  • 43
  • 182
  • 361
10
votes
5 answers

MESI cache protocol

I was reading about the MESI snooping cache coherence protocol, which I guess is the protocol that is used in modern multicore x86 processors (please correct me if I'm wrong). Now that article says this at one place. A cache that holds a line in…
pythonic
  • 20,589
  • 43
  • 136
  • 219
9
votes
2 answers

What is the benefit of the MOESI cache coherency protocol over MESI?

I was wondering what benefits MOESI has over the MESI cache coherency protocol, and which protocol is currently favored for modern architectures. Oftentimes benefits don't translate to implementation if the costs don't allow it. Quantitative…
Nathan Doromal
  • 3,437
  • 2
  • 24
  • 25
8
votes
1 answer

What cache coherence solution do modern x86 CPUs use?

I am somewhat confused with what how cache coherence systems function in modern multi core CPU. I have seen that snooping based protocols like MESIF/MOESI snooping based protocols have been used in Intel and AMD processors, on the other hand…
7
votes
2 answers

Even faster inexpensive thread-safe counter?

I've read this topic: C# Thread safe fast(est) counter and have implemented this feature in my parallel code. As far as I can see it all works fine, however it has measurably increased the processing time, as in 10% or so. It's been bugging me a…
mmix
  • 6,057
  • 3
  • 39
  • 65
6
votes
1 answer

Cache coherency(MESI protocol) between different levels of cache namely L1, L2 and L3

This is about cache coherency protocol across different layers of cache. My understanding(X86_64) about L1 is that, it is owned exclusively by a core and L2 is between 2 cores and L3 for all the cores in a CPU socket. I have read the MESI protocol…
Franc
  • 319
  • 9
  • 28
6
votes
1 answer

Why can the MESI protocol not guarantee atomicity of CMPXCHG on x86 without the LOCK prefix?

I understand that the MESI protocol successfully guarantees the same view of memory (caches) for different cores. My question comes from the fact that during writing MESI guarantees that the cache is exclusively owned by a CPU and then atomic…
5
votes
2 answers

MESI Protocol & std::atomic - Does it ensure all writes are immediately visible to other threads?

In regards to std::atomic, the C++11 standard states that stores to an atomic variable will become visible to loads of that variable in a "reasonable amount of time". From 29.3p13: Implementations should make atomic stores visible to atomic loads…
yggdrasil
  • 737
  • 5
  • 14
5
votes
1 answer

performance for writing the same value again into cache line

I sometimes see optimized code like this: if (matrix[t] != 0) { matrix[t] = 0; } As opposed to just this code: matrix[t] = 0; I suppose this code is written this way to reduce memory bandwidth in the CPU. Is this a good optimization on a…
dinfuehr
  • 587
  • 6
  • 13
5
votes
1 answer

Why MESI protocol need the Exclusive state

I am learning cache coherency now, but I don't quite understand what's the function of Exclusive state in MESI protocol, as I think MSI is also work well.
Peter Hu
  • 51
  • 1
  • 2
4
votes
1 answer

How do modern Intel x86 CPUs implement the total order over stores

x86 guarantees a total order over all stores due to its TSO memory model. My question is if anyone has an idea how this is actually implemented. I have a good impression how all the 4 fences are implemented, so I can explain how local order is…
pveentjer
  • 10,545
  • 3
  • 23
  • 40
4
votes
2 answers

what's L3$ role part in MESI protocal

I like to know more details of MESI in intel broadwell . Suppose A cpu socket has 6 cores core 0 to core 5 , each of them has their own L1$ and L2$ and share L3$ , there are a var X in shared memory , x located in cache line called XCacheL , the…
barfatchen
  • 1,630
  • 2
  • 24
  • 48
4
votes
2 answers

Are cache operations atomic?

I'm learning about CPU cache and now I still have misunderstanding of cache coherence protocol (MESI). Imagine that we have 2 cores have a cache line in a shared state. And one of them performs read, another one performs write: ;mem is cached in…
1
2 3 4 5