Home Knowledge Base Cache coherence

Cache coherence is the hardware protocol that ensures every CPU core in a multi-core processor sees a consistent view of shared memory — guaranteeing that when one core writes a value, all other cores that read the same address see the updated value, not a stale copy from their own cache. Without coherence, multi-threaded programs would silently produce wrong results because different cores would disagree on the contents of memory. Every multi-core chip from a phone SoC to a 100+ core server processor implements a coherence protocol in hardware, consuming 10–30% of on-chip interconnect bandwidth.

Why coherence is necessary. Each core has private L1/L2 caches for speed. When core 0 writes address X to its L1, core 1's L1 might still hold the old value of X. Without coherence, core 1 reads stale data — a silent data corruption. The coherence protocol ensures either: (1) core 1's copy is invalidated before core 0 writes, or (2) core 0's write is propagated to core 1's cache. This must happen automatically in hardware (software-managed coherence is too slow and error-prone for general-purpose code).

The two dominant protocol families:

ProtocolMechanismScalabilityBandwidthUsed in
Snoopy (bus-based)Every cache snoops a shared bus; broadcast invalidations2–8 coresHigh (every write broadcasts)Small multi-core (phone SoC, embedded)
Directory-basedA directory tracks which caches hold each line; point-to-point messages8–1000+ coresLower (unicast, not broadcast)Server CPUs, GPU, AI SoC

MESI — the classic snoopy protocol. Each cache line is in one of four states:

Variants: MOESI (adds Owned state — dirty shared), MESIF (adds Forward — one cache supplies data to requesters instead of memory).

Directory-based coherence — scaling to many cores. A snoopy protocol broadcasts every invalidation to all caches — O(N) traffic per write. At 64+ cores this saturates the interconnect. Directory protocols maintain a bit-vector (or pointer list) per cache line in a distributed directory, recording which cores hold copies. Invalidation messages are sent only to the sharers — O(1) messages per write, scaling to hundreds of cores. AMD's MOESI/Probe-Filter and Intel's MESIF/snoop-filter are production directory variants.

Coherence overhead and performance impact:

Coherence in AI chips — a design choice. AI accelerators face a coherence trade-off:

<svg viewBox="0 0 960 380" xmlns="http://www.w3.org/2000/svg" font-family="-apple-system,Segoe UI,Roboto,sans-serif">
<rect width="960" height="380" rx="12" fill="#1a1a17"/>
<text x="480" y="28" fill="#e5e7eb" font-size="16" font-weight="700" text-anchor="middle">Cache coherence — MESI protocol state machine</text>

<!-- Four MESI states as circles -->
<circle cx="200" cy="120" r="45" fill="#3a2a2a" stroke="#bf4040" stroke-width="2"/>
<text x="200" y="115" fill="#f0bfbf" font-size="14" text-anchor="middle" font-weight="700">M</text>
<text x="200" y="132" fill="#bf4040" font-size="8" text-anchor="middle">Modified</text>

<circle cx="480" cy="120" r="45" fill="#14312a" stroke="#2f6d55" stroke-width="2"/>
<text x="480" y="115" fill="#8fe3bd" font-size="14" text-anchor="middle" font-weight="700">E</text>
<text x="480" y="132" fill="#2f6d55" font-size="8" text-anchor="middle">Exclusive</text>

<circle cx="760" cy="120" r="45" fill="#2a2a3a" stroke="#6f6fbf" stroke-width="2"/>
<text x="760" y="115" fill="#c9c3f2" font-size="14" text-anchor="middle" font-weight="700">S</text>
<text x="760" y="132" fill="#6f6fbf" font-size="8" text-anchor="middle">Shared</text>

<circle cx="480" cy="280" r="45" fill="#2a2a28" stroke="#6f6f6a" stroke-width="2"/>
<text x="480" y="275" fill="#afafab" font-size="14" text-anchor="middle" font-weight="700">I</text>
<text x="480" y="292" fill="#6f6f6a" font-size="8" text-anchor="middle">Invalid</text>

<!-- Transitions -->
<!-- E → M (local write, silent) -->
<path d="M340 105 L250 105" fill="none" stroke="#e8d44d" stroke-width="1.2" marker-end="url(#ccarr)"/>
<text x="295" y="97" fill="#e8d44d" font-size="7" text-anchor="middle">local write</text>

<!-- M → I (remote read → writeback + invalidate) -->
<path d="M220 165 L460 255" fill="none" stroke="#bf4040" stroke-width="1.2" marker-end="url(#ccarr)"/>
<text x="320" y="220" fill="#bf4040" font-size="7">remote read (flush)</text>

<!-- E → S (remote read) -->
<path d="M525 120 L715 120" fill="none" stroke="#6fafaf" stroke-width="1.2" marker-end="url(#ccarr)"/>
<text x="620" y="112" fill="#6fafaf" font-size="7" text-anchor="middle">remote read</text>

<!-- S → I (remote write → invalidate) -->
<path d="M740 162 L500 262" fill="none" stroke="#bf4040" stroke-width="1.2" marker-end="url(#ccarr)"/>
<text x="640" y="225" fill="#bf4040" font-size="7">remote write (inv)</text>

<!-- I → E (local read miss, no sharers) -->
<path d="M440 270 L440 165" fill="none" stroke="#6fbf6f" stroke-width="1.2" marker-end="url(#ccarr)"/>
<text x="418" y="220" fill="#6fbf6f" font-size="7">read miss</text>
<text x="418" y="230" fill="#6fbf6f" font-size="6">(no sharers)</text>

<!-- I → S (local read miss, sharers exist) -->
<path d="M520 260 L740 145" fill="none" stroke="#6f6fbf" stroke-width="1.2" marker-end="url(#ccarr)"/>
<text x="650" y="190" fill="#6f6fbf" font-size="7">read miss (shared)</text>

<!-- S → M (local write → invalidate others) -->
<path d="M760 165 L760 250 L525 280" fill="none" stroke="#e0913a" stroke-width="1.2" marker-end="url(#ccarr)" stroke-dasharray="4,2"/>
<text x="820" y="210" fill="#e0913a" font-size="7">write (inv all)</text>

<!-- Legend -->
<rect x="50" y="330" width="860" height="35" rx="5" fill="#111318" stroke="#3a3a37" stroke-width="0.8"/>
<text x="100" y="352" fill="#bf4040" font-size="9">M = dirty, only copy</text>
<text x="290" y="352" fill="#8fe3bd" font-size="9">E = clean, only copy</text>
<text x="470" y="352" fill="#c9c3f2" font-size="9">S = clean, shared (read-only)</text>
<text x="700" y="352" fill="#afafab" font-size="9">I = not present</text>

<defs><marker id="ccarr" markerWidth="7" markerHeight="7" refX="6" refY="3.5" orient="auto"><path d="M0,0 L7,3.5 L0,7" fill="none" stroke="#8a8a86" stroke-width="1"/></marker></defs>
</svg>

Cache coherence and the CFS platform. Coherence is the hardware mechanism that makes multi-core programming possible — it's what lets two threads on different cores share a data structure without explicit message passing. The CFS NoC keyword covers the on-chip network that carries coherence messages. The memory-controller keyword covers the DRAM interface that coherence protocol ultimately reads from on a miss. The computer-architecture keyword covers the full system context where coherence operates.

cache coherencemesi protocolcoherence protocol

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.