Give two cores their own private L1 cache and a shared memory to work with, and you have created a problem neither core knows it has: each one can quietly hold a stale copy of data the other has already changed. Cache coherency is the hardware's promise that this never happens - that no matter which core reads a given address, it sees the most recently written value. Verifying that promise is one of the hardest jobs at the SoC level, because a coherency bug only shows up when two specific accesses land close enough together in time, on hardware that otherwise looks correct in every other test.
14 min read | Intermediate Level
What You'll Learn
- Why cache coherency has to be verified as a cross-core problem, not a per-cache one
- What the MESI states actually track, and how snooping keeps them consistent
- Where a design's coherency point is, and why verification aims tests there
- How to build a test that actually exercises a coherency race, instead of hoping one happens by accident
- How real coherency environments are structured - the agents, monitors, and scoreboard that actually implement snoop checking - and how that pairs with C-level litmus tests
Why Coherency Is a Verification Problem
A single-core cache is straightforward to reason about: a core writes a value, the cache holds it, and any later read from that same core sees it. The moment a second core gets its own cache and its own copy of the same memory location, that guarantee is no longer automatic. If core A writes to an address and core B has an old copy of that line sitting in its own cache, core B has to be told - somehow - that its copy is now wrong, or find the new value some other way. Coherency hardware exists entirely to make that handoff invisible to software.
This is different from the ordering and synchronization concerns covered when discussing shared memory between cores. A flag or semaphore controls when one core is allowed to read data another core produced. Coherency controls whether, once it does read, it actually sees the right value. A design can get the synchronization primitive exactly right and still have a coherency bug underneath it - the read happens at the correct time, but the cache serves stale data anyway.
The MESI States, From a Test-Writer's Perspective
Most coherent caches track each line's state using some variation of MESI - Modified, Exclusive, Shared, Invalid. The exact name matters less than what each state promises about who else might have a copy:
| State | Meaning | Can another cache hold this line? |
|---|---|---|
| Modified (M) | This cache has the only copy, and it differs from memory - the write hasn't been flushed back yet | No |
| Exclusive (E) | This cache has the only copy, and it matches memory | No |
| Shared (S) | This cache has a clean copy that matches memory | Yes, other caches may also hold it Shared |
| Invalid (I) | This cache's copy is stale or was never valid | Not applicable |
Many real SoCs extend this to MOESI, adding an Owned state that lets one cache hand a modified line directly to another cache without writing it back to memory first. From a test-writer's standpoint, the extra state matters because it opens another data path to verify: a cache-to-cache transfer that never touches the memory controller at all, and can just as easily be verified incorrectly.
A coverage model for coherency typically tracks state-transition coverage per cache: for every master, has its modeled cache line actually transitioned through every legal MESI/MOESI state, not just started or ended in each one. A cache that always goes straight from Invalid to Modified and back is technically passing every check while leaving entire transition paths, like Shared-to-Modified, completely unexercised.
Snooping: How a Cache Finds Out It's Wrong
The mechanism that keeps every cache's state accurate is snooping: every cache watches transactions on the shared interconnect, not just its own core's requests. When core B's cache sees a bus transaction indicating core A is about to write to an address B also has cached, B's snoop logic invalidates its own copy before A's write completes - or, in a MOESI-capable design, may supply the current value directly to A's cache instead of forcing a round trip to memory.
Verifying the snoop path means checking two things separately, because each can fail independently: that a snoop actually fires for every access that should trigger one, and that the snooping cache takes the correct action once it does - invalidate, supply data, or both. A snoop that fires but produces the wrong state transition is just as broken as one that never fires at all, and a scoreboard that only checks the final data value in memory can miss both kinds of bug if the wrong path happens to still land on the right answer.
How a Coherency Agent Actually Gets Built
None of this is checked by one component watching one wire - a coherency-aware UVM environment for a protocol like AMBA ACE or CHI is layered, because a single snoop can only be judged correct in the context of everything else happening around it at the same time. A coherent master agent sits on each core's (or core-cluster's) coherent interface: it drives that master's coherent read/write transactions and, just as importantly, responds to whatever snoop requests arrive back at it. Each master agent typically carries a lightweight built-in cache model with a backdoor API, so a test can force or query a specific line into a specific state before a scenario even starts, rather than driving a long setup sequence just to reach one interesting starting condition.
Sitting between the master agents, an interconnect environment - a bus functional model standing in for the real coherent interconnect during agent-level verification - receives each coherent transaction and works out which other masters need a snoop, based on which masters share that coherency domain and what state their cache models currently claim to hold. Passive port monitors on every master's coherent and snoop interfaces turn raw signal activity into transaction-level objects and forward them up to one system-level monitor, which is where the actual coherency checking lives: it correlates each coherent transaction with the snoop transactions it triggered, enforces structural invariants - a line can only be Unique or Dirty in one master's cache at a time, no two snoop responses may both claim ownership - and cross-checks the data every involved cache model and the memory model actually hold against each other.
This entire environment - master agents, interconnect environment, backdoor cache models, system monitor - is almost always built and owned at the coherent interconnect's own subsystem level, by the team verifying that fabric IP on its own, well before it is integrated into a full chip. It is not typically rebuilt from scratch at the SoC level. What carries forward to SoC-level verification is usually the same active-to-passive reuse pattern already used for other block-level UVCs: the coherent master agents run in passive mode, monitoring real core traffic instead of driving synthetic transactions, while the system monitor's checks keep running underneath. SoC-level work then adds what the subsystem environment couldn't - the C-level litmus tests below, I/O coherency scenarios involving real DMA engines, and any coherency behavior that only emerges once the actual cores, caches, and interconnect are all assembled together.
The Coherency Point: Where Verification Should Actually Aim
In many cluster designs, coherency is enforced in two places: a snoop control unit inside each cluster that keeps that cluster's cores consistent with each other, and a separate coherency interface where multiple clusters connect, keeping clusters consistent with each other. Together these form the design's coherency point - the piece of logic actually responsible for making the M/E/S/I promise hold.
Aiming tests directly at the coherency point, rather than only at full end-to-end software scenarios, is a deliberate industry practice: a focused property - "if core A holds this line Modified and core B issues a read, does the line correctly transition and does B get the right data" - is something a small, targeted test can exercise directly and repeat across every reachable state combination, without needing a full software stack to set up the same scenario indirectly. This kind of exhaustive state-combination testing is subsystem-level verification by nature - it belongs to the coherent interconnect or cluster IP itself, run long before that block is dropped into an SoC, in the same way the interconnect and address-map verification discussed elsewhere in this series happens at the fabric's own level first.
task test_coherency_race(bit[31:0] addr, int core_a, int core_b);
// Core A takes exclusive ownership by writing first
core_write(core_a, addr, 32'hDEAD_BEEF);
check_cache_state(core_a, addr, MESI_MODIFIED);
// Core B reads the same line while A still holds it Modified
fork
core_write(core_a, addr, 32'hCAFE_F00D);
core_read(core_b, addr);
join
// B must see the newer value, and A's line must have transitioned correctly
if (core_b.last_read_data !== 32'hCAFE_F00D)
`uvm_error("COHERENCY", "Core B read stale data during concurrent access")
check_cache_state(core_a, addr, MESI_MODIFIED);
check_cache_state(core_b, addr, MESI_SHARED);
endtask
The value in this test isn't the final read result by itself - it's that the read is deliberately timed to overlap the write, and both caches' resulting states are checked, not just the data.
Two Layers of Checking: SV Protocol Compliance, C-Level Memory Ordering
The system-level monitor described above checks that the coherency protocol is followed correctly at the bus - the right snoops fire, the right invariants hold, the right cache ends up with the right data. It says nothing on its own about whether that result would actually look correct to software running on the real cores. That second, complementary question is what C-level litmus tests are built to answer.
A litmus test is a small, deliberately adversarial C program split across two or more cores, written to probe one specific memory-ordering guarantee rather than to do any real work. A classic version is a message-passing test: one core writes a data value and then sets a flag; a second core spins on the flag and, once it observes the flag set, reads the data.
// Core 0
data = 0xCAFEBABE;
flag = 1;
// Core 1
while (flag == 0) { /* spin */ }
result = data;
// A coherency/ordering bug shows up as: flag observed 1, but result != 0xCAFEBABE
Correct coherency and ordering together guarantee that Core 1 can never observe the flag set without also observing the new data value. A single run of this on real hardware almost never fails, because the race window is narrow - which is exactly why coherency verification doesn't run it once. A small litmus-test library gets run many times concurrently, across randomized core-to-address assignments and randomized initial cache states, because finding a real bug means landing inside that narrow window often enough for it to show up. This C-level stimulus is typically driven through the same SoC-level C-test infrastructure used for other bring-up and directed testing, and it is often paired with an SV sequence that pre-loads specific cache states through the master agent's backdoor API before the C code even starts, so the litmus test begins from a deliberately interesting state rather than a random one.
I/O Coherency: When the Requester Isn't a CPU Core
Coherency isn't only a CPU-to-CPU concern. A DMA engine or another autonomous bus master writing to memory a CPU has cached runs into exactly the same problem a second core would - if that master's writes bypass the coherency point entirely, every CPU with a cached copy of that address is now silently wrong. Some interconnects extend coherency to these non-CPU agents directly; where they don't, software is responsible for explicit cache maintenance around any such transfer, and that handoff is exactly the kind of boundary a coherency-aware SoC test needs to exercise on purpose, not assume.
Common Mistakes
Testing coherency with accesses that never actually overlap in time.
Two cores accessing the same address one after another, with a comfortable gap in between, never stresses the snoop and state-transition logic the way a genuinely concurrent access does. The interesting bugs live in the overlap.
Checking only the final data value, not the cache state transitions that produced it.
A design can occasionally land on the correct data through the wrong sequence of snoop and state-transition behavior. A scoreboard that only compares final memory contents can pass on a design with a genuine coherency defect underneath.
Assuming a DMA engine's writes are automatically coherent with CPU caches.
Whether a non-CPU master's writes go through the coherency point at all is a property of that specific interconnect, not something to assume. A test needs to confirm it directly rather than trusting the address map alone.
Summary
In this article, you learned:
- Cache coherency is what guarantees every core sees the latest write to a shared address, independent of whatever software synchronization controls when that read happens
- MESI (or MOESI) states track, per cache line, whether a copy is unique, shared, stale, or modified relative to memory
- Snooping is how a cache learns another core is about to change data it has cached, and verification has to check both that a snoop fires and that it produces the correct state transition
- Tests aimed directly at the coherency point can exercise state-transition combinations far more efficiently than relying on end-to-end software scenarios alone
- Real coherency environments layer coherent master agents with backdoor cache models, an interconnect environment generating snoops, and a system-level monitor that correlates transactions and enforces state invariants
- SV/UVM checking verifies the coherency protocol itself is followed at the bus; C-level litmus tests, run in volume with randomized timing, verify the memory-ordering result software actually observes
- Non-CPU masters like DMA engines can violate coherency just as easily as a second core, and whether their writes are automatically coherent needs to be verified, not assumed