Skip to content

Coherence state

gem5 only, classic caches, one core. Fault models: any; each run inverts one state bit whichever you pick. fault: coherence.

Besides its data and its tag, every cache line carries a few state bits. They say whether the cache may read the line, whether it may write it without asking the next level first, and whether the line is newer than memory (dirty). Coherence protocols name the combinations: MESI stands for Modified, Exclusive, Shared and Invalid, the four states most textbooks draw. The coherence target inverts one of these state bits on one line of a cache in gem5's classic memory system (its built-in cache model, as opposed to the Ruby protocol models), so the cache later takes the wrong action for that line: it drops data it should write back, or asks again for permission it already had. As in every HFIM campaign, each run applies one fault, and HFIM compares the result with a fault-free golden run of the same program.

Two panels. Golden: an L1D line holds result[5] = 0x05 in state M, with the writable, readable and dirty bits set, while memory still holds 0x00; when the line is evicted it is written back, memory gets 0x05 and the next load reads 0x05. With the dirty bit cleared by HFIM, gem5 reads the line as E; the eviction drops it without a write-back, memory keeps 0x00 and the next load reads 0x00: sdc. Two panels. Golden: an L1D line holds result[5] = 0x05 in state M, with the writable, readable and dirty bits set, while memory still holds 0x00; when the line is evicted it is written back, memory gets 0x05 and the next load reads 0x05. With the dirty bit cleared by HFIM, gem5 reads the line as E; the eviction drops it without a write-back, memory keeps 0x00 and the next load reads 0x00: sdc.

The figure is a worked example on the Fibonacci benchmark's result array in the L1 data cache (L1D), not a campaign row. The line, set 5 and way 1, is schematic.

How HFIM applies the fault

gem5's classic cache stores three state bits per line, beside the valid bit: WritableBit, ReadableBit and DirtyBit. gem5 reads the familiar state names from them:

State Writable Dirty Valid
M (Modified) 1 1 1
O (Owned) 0 1 1
E (Exclusive) 1 0 1
S (Shared) 0 0 1
I (Invalid) 0 0 0

The readable bit is normally set on every valid line. gem5 clears it only while a write to the line is pending.

The target cache is the L1 data cache (L1D). At the injection instant, a committed-instruction count drawn from the campaign seed, gem5 lists the dirty lines of the L1D and picks one at random. If no line is dirty, it picks among all valid lines. It then picks one of the three bits with equal chance and inverts it. On a dirty line all three bits are set, so the fault always clears one of them. What follows depends on the bit:

Bit cleared State gem5 now reads What happens next
DirtyBit M becomes E When the line is evicted, gem5 drops it without a write-back. Memory keeps its older bytes, and a later load of that address reads them.
WritableBit M becomes O, E becomes S The next store to the line misses and asks the next level for write permission again. The data does not change; only the timing does.
ReadableBit M or E with the line marked unreadable The next load of the line misses while the line is still valid. gem5 does not expect this and stops on an internal assertion.

When the picked line is clean, the same draw can set a bit instead. Setting DirtyBit makes gem5 write back bytes memory already holds. A clean line in a one-core system is normally E, so WritableBit is already set and inverting it clears it, as in the table.

Whether a dropped dirty line matters depends on eviction. HFIM reads the observable outputs at the end of the run through the CPU's view of memory, which includes the cache. A line that is still in the cache then reports its correct bytes, and the run ends masked. The data is lost only if the line leaves the cache first.

A campaign

The template ships no coherence campaign. This one is the template's cache_tag.yaml with only the target and the name changed. It applies one fault in each of 10 runs of the Fibonacci benchmark, whose 64-number result array is the output HFIM compares:

include: fibonacci.yaml

campaign_name: fibonacci-coherence

simulator_backend: gem5

seed: 7
num_injections: 10
num_workers: 1

target_types: [coherence]
fault_model: single_bit_flip

timeout: 120
output_dir: results

Run it from the template folder:

hfim run campaigns/fibonacci/coherence.yaml

What you see in the results

Each run writes one row of injections.csv, the comma-separated values (CSV) file of the campaign, and one folder, injection_NNNN/. In the row, target_type and target_name both read coherence. original_value and faulty_value hold the one bit before and after: 0x1 and 0x0 when the fault cleared it. The bit_position column holds the faultlist's draw, which this target does not use. The set and way columns stay empty, and injections.csv drops a column that is empty in every row.

The line and the bit are in the run's injection_report.json, in its target field. This report comes from a gem5 run of the injector with the L1D connected:

"fault_type": "coherence",
"target": "coherence[set=90,way=0].ReadableBit",
"original_value": "0x0000000000000001",
"faulty_value": "0x0000000000000000",

That run cleared ReadableBit, and gem5 stopped at the next load of the line with this line in its output:

gem5.opt: src/mem/cache/base.cc:391: void gem5::BaseCache::handleTimingReqMiss(gem5::PacketPtr, gem5::MSHR*, gem5::CacheBlk*, gem5::Tick, gem5::Tick): Assertion `(pkt->needsWritable() && !blk->isSet(CacheBlk::WritableBit)) || pkt->req->isCacheMaintenance()' failed.
Program aborted at tick 29063000

The outcomes follow the table above. A cleared ReadableBit ends in crash, because the simulator aborts. A cleared WritableBit changes only the timing, so the result matches golden: masked. A cleared DirtyBit ends masked when the line stays in the cache until the end, and in sdc (silent data corruption, a wrong result with no error reported) when the line is evicted and the program, or the final comparison, reads the older bytes from memory. A program whose data fits in the L1D, as Fibonacci's does, rarely evicts the line. Every outcome: Fault classification.

Keys

Key Values Default
fault (or target_types) coherence required
simulator_backend gem5 qemu
fault_model single_bit_flip, stuck_at_0, stuck_at_1; each inverts one bit here required
cpu_model TimingSimpleCPU, MinorCPU, DerivO3CPU; AtomicSimpleCPU is refused, because it runs without caches the board's cpu.model (MinorCPU in the template), else TimingSimpleCPU
num_cores 1 1

Limits

  • One core, one cache. Classic gem5 runs only one core in HFIM; num_cores above 1 is refused with a message that points to gem5-ruby. With no other core's cache holding the same data there is no peer to disagree with, so this target models the bookkeeping between one cache and memory, not a coherence conflict between cores. For faults in the protocol between cores, use the Ruby targets: Ruby controllers.
  • The fault model and its keys have no effect. multi_bit_count, stuck_at_0, stuck_at_1 and fault_persistence: permanent change nothing: each run inverts exactly one bit, once.
  • The line and the bit do not follow the campaign seed. Only the instant comes from the seed. gem5 draws the line and the bit from its own random generator, which starts from the same seed in every gem5 process, so the runs of one campaign can draw the same bit again and again.
  • cache_set and cache_way do not steer the fault. The injector picks its own line.
  • The ReadableBit crash is gem5's, not the chip's. It is an internal consistency check of the simulator. A real cache with that bit flipped would behave in a way gem5 does not model.
  • No named state in the results. The report names the bit, not the MESI state before and after; use the table above to translate.
  • An empty cache records no fault. If the cache holds no valid line at the injection instant, gem5 warns UltraInjector failed: No valid cache blocks for coherence corruption and writes no injection report.

See also: gem5 backend · Cache data · Ruby controllers · Configuration keys