Cache ECC check bits¶
gem5 only, single core. Fault models: single-bit flip, multi-bit. fault: ecc_parity_l1d, ecc_parity_l1i, ecc_parity_l2, with cache_ecc_enabled: true.
A cache that is protected by an error-correcting code (ECC) stores extra check bits next to its data. On every read, a decoder recomputes the code from the data, compares it with the stored check bits, and fixes or flags any difference. HFIM models the common scheme, SECDED (single error correct, double error detect): one wrong bit is corrected, two are detected.
The check bits sit in the same kind of memory cell as the data, so a particle strike can flip them too. An ecc_parity_* fault does exactly that: it flips a check bit and leaves the data alone. The data is still right, but the decoder sees a mismatch and acts on it.
As with every HFIM target, a campaign runs the program many times with one fault per run. Each run is compared with a fault-free golden run of the same program.
How HFIM applies the fault¶
The campaign seed draws the instant, the bits to flip and the byte of the line, from 0 to the line size minus 1. Bits are drawn from 0 to 7, because HFIM keeps the check bits of one byte as an 8-bit mask. At the injection instant, gem5 picks a valid line in the target cache from a random stream seeded by the injection instant, so the same row always hits the same line. If you set cache_set and cache_way, that slot is used instead.
HFIM does not write anything into the line. It records next to the line that the check bits of byte N are wrong by mask M. The decoder then acts on the next read that covers byte N. Each fault value picks the cache:
fault |
Cache | Per-level policy key | Note |
|---|---|---|---|
ecc_parity_l1d |
level-1 data cache (L1D) | cache_ecc_policy_l1d |
loads and stores |
ecc_parity_l1i |
level-1 instruction cache (L1I) | cache_ecc_policy_l1i |
instruction fetches |
ecc_parity_l2 |
level-2 cache (L2) | cache_ecc_policy_l2 |
needs a board with an L2 |
HFIM does not model a particular Hamming code. The number of flipped check bits decides what the SECDED decoder does:
| Check bits flipped | Decoder action on read | gem5 log verdict | outcome |
|---|---|---|---|
1 (single_bit_flip) |
flips one correct data bit in the value it returns | false_correct |
ecc_false_correct |
2 (multi_bit_count: 2) |
reports an uncorrectable error; the access returns an error response | false_due |
see Limits |
| 3 or more | passes the data through unchanged | checkbit_silent |
from the golden comparison, normally masked |
With one flipped check bit, the data bit that the decoder flips is (byte offset + mask) mod 8. In the figure, offset 12 and mask 0x08 give data bit 4, so the CPU reads 0x10 where the golden run read 0x00. The figure uses the line and mask of the logged run in A campaign and shows what a read of byte 12 would return; in that run the program never read it. The change is made in the value delivered to the CPU, not in the cache line. The wrong check bits stay in the array, so every later read of that byte is miscorrected the same way.
The fault can also end without being read:
- A write to any byte of the line regenerates its check bits and erases the fault. The run is then compared with the golden run as usual.
- If the line is evicted before the byte is read, the row becomes
latent_dirtywhen the line was dirty (modified) at eviction, andlatent_cleanwhen it was not. - If the run ends with the fault still in the cache and unread, the row becomes
latent_dirtyorlatent_cleanin the same way, from the dirty bit the line had when the fault was injected.
A campaign¶
This campaign extends the fibonacci campaign of the nezha-c906-gem5 template. Save it as campaigns/fibonacci/ecc_parity_l1d.yaml:
include: fibonacci.yaml
campaign_name: fibonacci-ecc_parity_l1d
simulator_backend: gem5
seed: 7
num_injections: 20
target_types: [ecc_parity_l1d]
fault_model: single_bit_flip
cache_ecc_enabled: true
timeout: 120
output_dir: results
hfim run campaigns/fibonacci/ecc_parity_l1d.yaml
Each injection writes injection_NNNN/gem5_stderr.log. Two lines in it show where the fault went and how it ended. These are from a check-bit fault at instruction 2000 of fibonacci:
src/mem/cache/base.cc:2839: info: FIM-ECC registered blkAddr=0x6e740 offset=12 mask=0x08 is_check_bit=1 ecc_enabled=1
src/mem/cache/base.cc:3038: info: FIM-ECC latent_dirty at 0x6e740 offset=12 mask=0x08 (end-of-sim drain; never read, never evicted)
is_check_bit=1 confirms that the check bits were faulted, not the data. ecc_enabled=1 confirms that the decoder is active. The second line is the verdict. Here the program never read byte 12 again, so the fault was still in the cache when the run ended.
What you see in the results¶
Each run adds a row to injections.csv. In this row:
target_typeisecc_parity_l1dandcache_levelisl1d.setandwayare filled only when the campaign setscache_setandcache_way. The slot gem5 chose and the drawn byte are ininjection_report.json, for examplecache[set=29,way=0,off=12].bit_positionis the check bit that was flipped (0 to 7).original_valueis the data byte, andfaulty_valueis that byte XOR the mask. For a check-bit fault, the byte in the cache keepsoriginal_value.cache_ecc_engagedisTruewhen the decoder ran on the faulty byte andFalsewhen the fault left the cache unread. It stays empty when a write erased the fault first.ecc_false_correctisTruewhen the decoder flipped a correct data bit, andFalseafter any other check-bit verdict.cache_evicted_unreadisTruewhen the row endedlatent_cleanorlatent_dirty.
ecc_false_correct, latent_clean and latent_dirty are values of their own in the outcome column, next to the five standard outcomes (masked, sdc, detected, crash, timeout). ecc_false_correct means the protection itself corrupted data that was correct. The two latent values mean the program never read the fault. The outcome table in results.txt lists only the standard outcomes but counts these rows in its VALID total, so its percentages add up to less than 100. The standard outcomes are defined in Fault classification.
Most rows of a small benchmark end latent. In ten check-bit faults injected with gem5 into the fibonacci and mmult benchmarks of nezha-c906-gem5, at instants spread over each run, eight ended latent_dirty and two latent_clean, and none was read. A check bit matters only if the program reads that exact byte before it writes the line or the line leaves the cache. To raise the chance of a read, use a benchmark that keeps re-reading its data, or pin the fault with cache_set and cache_way to a line you know the program uses.
Keys¶
| Key | Values | Default |
|---|---|---|
fault or target_types |
ecc_parity_l1d, ecc_parity_l1i, ecc_parity_l2 |
required |
cache_ecc_enabled |
true turns the decoder on |
false |
cache_ecc_policy_l1d, cache_ecc_policy_l1i, cache_ecc_policy_l2 |
secded, parity, none |
inherit cache_ecc_enabled (SECDED) |
cache_ecc_scope |
data, tag, both |
data |
cache_set, cache_way |
integers inside the cache geometry | gem5 picks a valid line |
fault_model |
single_bit_flip |
required |
multi_bit_count |
2 to 8 flips that many distinct check bits |
1 |
check_bit_fault |
set to true automatically for these targets |
The per-level keys mix schemes in one machine. For example, parity on both L1 caches and SECDED on the L2:
cache_ecc_enabled: true
cache_ecc_policy_l1d: parity
cache_ecc_policy_l1i: parity
cache_ecc_policy_l2: secded
Limits¶
- Single core only.
cache_ecc_enabled: truewithnum_coresabove 1 is rejected at load:cache_ecc_enabled=true is single-core only (num_cores=2). On several cores the coherence paths bypass the decoder. - Without ECC, nothing happens. HFIM accepts an
ecc_parity_*campaign withcache_ecc_enabled: false. The check bits are then inert: gem5 logsecc_off_checkbit, the data reaches the CPU unchanged, and the run normally matches the golden run. A per-level policy other thannonenext tocache_ecc_enabled: falseis rejected:cache_ecc_policy_l1d='parity' requires cache_ecc_enabled=true. - A false double error is not reported as
detected. With two flipped check bits, the access returns an error response. On a load, MinorCPU (gem5's in-order CPU model, the onenezha-c906-gem5uses) stops the simulation withReceived error response packet for inst. The row'soutcomeis what HFIM's classifier makes of that stop. What an error response does to an instruction fetch onecc_parity_l1iis not documented here. Readgem5_stderr.logfor thefalse_dueline. - Parity verdicts are not in the ECC columns. Under a
paritypolicy, every read of the byte returns an error response, and gem5 logsparity_check_false_due. Thecache_ecc_*andecc_false_correctcolumns stay empty for that row. latent_dirtycarries nothing further. In a real chip the dirty line would be written back with its wrong check bits. gem5 writes back the unchanged data and models no check bits in the next level, so the fault ends there.- No tag ECC.
cache_ecc_scope: tagandbothare accepted but protect nothing beyond the data. Tag faults are on Cache tags. - Stuck-at is decided on the data byte. With
stuck_at_0orstuck_at_1, gem5 compares the stuck value with the data byte, not the check bits. When no bit would change, gem5 logsinjection NOT performed, writes noinjection_report.json, and the row becomesinfrastructure_failure. Usesingle_bit_flipormulti_bit_countfor check bits. - An empty slot gets no check-bit fault. If
cache_setandcache_wayname an invalid line, gem5 reports the fault against that empty line (invalidin theinjection_report.jsontarget), registers no check-bit fault and changes nothing the program can read. The run is classified by its output. ecc_parity_l2needs an L2. On a board without one, such asnezha-c906-gem5, gem5 stops at start withFIMController: cache injection requires target_cache.- No DRAM check bits.
ecc_parity_dramis refused at load: gem5 models no check bits for main memory. ECC on main memory (DRAM) is on DRAM.
See also: gem5 backend · Cache data · Multi-bit · Configuration keys