MESI
Every core sees every write, and the bus bills you for it
Each core has a private cache, kept coherent by messages on a shared bus. Core 0 holds line L in the Exclusive state: no other cache has a copy. It writes one byte of L. What goes on the bus?
Each core has a private cache. When one core writes, the others must not keep reading their old copy, so the caches talk over a bus. MESI tags every cache line as Modified, Exclusive, Shared or Invalid. A read miss asks the bus; a write to a Shared line first invalidates every other copy; a Modified line is flushed when someone else reads it. A line a core holds in Exclusive or Modified is written with no bus traffic at all. The bus does not know what a variable is. It knows lines: 64 bytes on most x86 and many ARM cores, 128 on Apple M-series.
MESI state transitions (PrRd/PrWr = this core; BusRd/BusRdX = snooped from the bus)
Invalid + PrRd → BusRd → Exclusive (no other copy)
→ Shared (another cache has it)
Invalid + PrWr → BusRdX → Modified (others invalidated)
Exclusive + PrRd → hit → Exclusive
Exclusive + PrWr → hit → Modified (SILENT: no bus traffic)
Exclusive + BusRd → supply → Shared
Exclusive + BusRdX → → Invalid
Shared + PrRd → hit → Shared
Shared + PrWr → BusUpgr → Modified (invalidate every other copy)
Shared + BusRd → → Shared
Shared + BusRdX → → Invalid
Modified + PrRd → hit → Modified
Modified + PrWr → hit → Modified
Modified + BusRd → flush → Shared (write back, then share)
Modified + BusRdX → flush → Invalid (write back, then drop)
Invariant: at most one cache holds a line in E or M, and then no other cache holds it at all. Watch the two invariants. WITHOUT COHERENCE breaks the single-owner invariant the moment Core 0 writes without invalidating, and the freshness invariant on Core 1’s next read. FALSE SHARING keeps both green while the bus counter climbs by one per write.
Core 0 only ever writes x. Core 1 only ever writes y. They never read each other's variable. Order the six writes so the bus carries at least 6 transactions.
GOAL: all six writes run and bus transactions >= 6
This transition table has two wrong rows. One is unsafe: a core can read a stale value. One is slow: it puts a transaction on the bus that the protocol does not need. Fix both. The grader runs two caches through five programs and checks every read against the newest write.
Per-thread counters packed in one array, a spinlock next to the data it protects, hot fields of two threads in one struct. Symptoms are scaling curves that bend the wrong way: more cores, less throughput, and a profiler that blames a plain store. Look for alignas(64), padding fields and @Contended.
“What is false sharing and how do you fix it?” Say that the cache line is the unit, that each write invalidates the other core's copy, and that padding hot variables onto separate lines removes the traffic. Then name the invariant MESI protects: at most one Modified copy, every other copy Invalid.