4.1.27 · D3Computer Architecture (Deep)

Worked examples — Multicore coherence protocols

2,880 words13 min readBack to topic

This page is a drill through every case class that multicore coherence protocols can throw at you. We start from the parent note 4.1.27 and go deeper: not one or two happy-path traces, but every corner — every state a block can be in, every bus event that can hit it, the zero/degenerate cases (eviction, self-write), the limiting behaviour (N cores all reading), and the exam twists.

Before you read a single worked example, meet the vocabulary as verbs and nouns you can picture, so no symbol is ever used before it is earned.

Why do we even need three different shouts instead of one? Because the cost differs. A plain read must not kick everyone else out (that would be wasteful) — so BusRd. A write from nothing must both fetch the data and clear others — BusRdX. A write from a shared copy already has the data, so it only needs the clearing half — BusUpgr, the cheapest write shout. Matching the shout to the situation is the entire art.


The scenario matrix

Every worked example below is tagged with the cell of this matrix it exercises. Together they cover every cell.

# Case class The specific corner Example
A Cold read, sole owner I → load, nobody else has it Ex 1 (MESI E)
B Cold read, sharers exist I → load, someone already has it Ex 2
C Write from Shared S → M, must invalidate others Ex 2, Ex 3
D Write from Exclusive/Modified E → M or M → M, silent, zero traffic Ex 1
E Snoop while Modified another core reads my dirty line Ex 3 (MSI), Ex 6 (MOESI)
F Degenerate: eviction dirty line thrown out → write-back; clean → silent Ex 4
G Degenerate: false sharing two vars, one line, ping-pong Ex 5
H Limiting: N readers all cores read, all end in S Ex 7
I Real-world word problem producer/consumer flag Ex 8
J Exam twist: coherence ≠ correctness reordering across two locations Ex 9

Worked examples

Cell A + D — MESI: exclusive read, then a free write

Figure — Multicore coherence protocols

Cell B + C — MSI: two readers, then one writer


Cell C + E — MSI: writer meets a snoop on its dirty line


Cell F — Degenerate: eviction (dirty vs clean)


Cell G — Degenerate: false sharing

Figure — Multicore coherence protocols

Cell E — MOESI: the Owned state defers the write-back


Cell H — Limiting case: N cores all read


Cell I — Real-world word problem: producer/consumer flag


Cell J — Exam twist: coherence ≠ correctness


Recall Rapid self-test across the whole matrix

Which cell: a solely-owned clean line written with zero bus traffic? ::: Cell D — MESI E → M silent (Ex 1). Which cell: eviction that costs a DRAM write? ::: Cell F — evicting an M line (Ex 4a). Which cell: two independent variables killing performance? ::: Cell G — false sharing (Ex 5); fix with padding. Which cell: a coherent program that is still buggy? ::: Cell J — ordering across two locations needs a fence (Ex 9). In MOESI, what state lets a dirty owner feed sharers without a write-back? ::: O (Owned) — Cell E, Ex 6. When N cores all just read, what state do they all end in and how many invalidations occur? ::: All S, zero invalidations (Cell H, Ex 7).

Back to the parent: 4.1.27 Multicore coherence protocols · related: Cache memory hierarchy · Bus arbitration.