Cache data (L1D, L1I, L2)¶
gem5 only. Fault models: single-bit flip, multi-bit, stuck-at. fault: cache_l1d, cache_l1i, cache_l2.
A cache keeps copies of the memory lines the program is using close to the CPU, in a small array of static RAM cells. A particle strike on one of those cells changes a byte of a line without the program writing it. This target corrupts one byte of one line in the data array of the L1 data cache (L1D), the L1 instruction cache (L1I) or the level-2 cache (L2), at an instant drawn from the campaign seed. By default the line is one that holds data at that instant. 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.
A cache fault is different from a memory fault because the byte lives in a copy. If the program never reads the byte and the line leaves the cache clean, the fault disappears with the line. If the line leaves dirty, the corrupted byte is written back and the fault moves to the next level.
How HFIM applies the fault¶
Before the campaign starts, HFIM draws four things per injection from the seed: the instant, as an instruction count inside the benchmark's computation window (between its calls to fim_init and fim_exit, the two markers that bracket the work HFIM measures), the bit or bits to change, between 0 and 7, the line, and the byte of the line the bits are in. A cache line is made of bytes, so the fault always stays inside one byte. Everything random about a cache fault comes from the campaign seed, so running the same campaign again hits the same cells.
gem5 then runs the benchmark and stops at that instruction. How the line is chosen depends on cache_lines:
valid, the default. The campaign draws a number, and the injector inside gem5 collects every line of the cache you named whose valid bit is set and takes the one at that number modulo their count. Lines whose valid bit is clear hold nothing and are never picked. Which line that is depends on what the cache holds at that instant, which only gem5 knows, so the injection report names it.all. The campaign draws the set and the way over the whole array, as a particle strike would. A cell whose line is invalid at that instant holds nothing the program can read: the fault has no effect, and the report saysinvalid.
The byte inside the line is the one the campaign drew, from 0 to 63 for 64-byte lines.
The injector changes the byte in the line's data array itself and lets the program continue. From then on the cache behaves as it would after a real upset:
- A read of that byte returns the corrupted value.
- A write to that byte replaces it, and the fault is gone. A write to another byte of the line leaves it in place.
- A clean eviction drops the line, and the next fill brings the correct byte back from the next level.
- A dirty eviction writes the line back, so the next level now holds the corrupted byte.
The three levels differ in who reads the byte and whether the line can become dirty:
fault |
Who reads the corrupted byte | Can the line be dirty | Sets in the default geometry |
|---|---|---|---|
cache_l1d |
the program's loads | yes, after a store | 32 kB, 2-way: 256 sets |
cache_l1i |
instruction fetch: the byte is part of an instruction | no, the CPU never writes through it | 32 kB, 2-way: 256 sets |
cache_l2 |
an L1 that misses and refills the line from the L2 | yes | 256 kB, 8-way: 512 sets |
The default geometry applies when neither the board nor the campaign describes the caches. A board's cache: section replaces it. The nezha-c906-gem5 template's board gives the L1D 32 kB in 4 ways (128 sets), the L1I 32 kB in 2 ways (256 sets), and no L2.
To aim at one slot instead of a drawn line, set both cache_set and cache_way; only the byte is drawn. HFIM checks both against the cache geometry before the first run. With cache_lines: all, a stated cache_set or cache_way is kept and the other one is drawn. cache_lines: valid stated together with cache_set or cache_way is refused, since the two name the line in different ways.
Valid lines or the whole array¶
The two values answer different questions. all measures what an upset anywhere in the array does. On a small program most lines of an instruction cache are empty: a 32 kB L1I has 512 lines, and a benchmark whose code fits in 2 kB keeps about 32 of them valid, so about 94 % of the faults land on empty lines and few runs tell you anything about the code. valid measures what an upset does once it has hit a line that holds data. It is a conditional rate: to compare it with an all campaign, multiply it by the fraction of valid lines at the injection, which every report states.
valid needs hfim-sim-gem5 23.2.0 or newer, the first release whose injection script takes the campaign's pick. With an older package, a campaign that draws the pick stops before its first injection and names the installed version. Run hfim sim install gem5 to update the package, or set cache_lines: all. A stated cache_set and cache_way, an ultra target and a Ruby run draw no pick and run on any release.
A campaign¶
This campaign comes from the nezha-c906-gem5 template, campaigns/fibonacci/cache_l1d.yaml. It flips one bit of the L1D in each of 10 runs of the Fibonacci benchmark. The included fibonacci.yaml names the benchmark and its observable, the result array.
include: fibonacci.yaml
campaign_name: fibonacci-cache_l1d
simulator_backend: gem5
seed: 7
num_injections: 10
num_workers: 1
target_types: [cache_l1d]
fault_model: single_bit_flip
timeout: 120
output_dir: results
target_types: [cache_l1d] is the list form of fault: cache_l1d, and either works. The template's cache_l1i.yaml is the same file with cache_l1i. To spread one campaign over several levels, list them all: target_types: [cache_l1d, cache_l1i] makes the runs take turns between the two caches.
Run it from the template directory:
hfim run campaigns/fibonacci/cache_l1d.yaml
Before it builds anything, hfim run prints the machine gem5 will build and who chose each part. For this campaign the board chose everything:
machine: cpu MinorCPU at 1GHz, L1I 32kB 2-way, L1D 32kB 4-way, no L2, 64 B lines, 256MB memory (board.yaml)
Check this line when you change caches: cache_l2 needs an L2 in it. If the board names no CPU, a cache target runs on TimingSimpleCPU, because gem5 builds no caches for AtomicSimpleCPU.
What you see in the results¶
Each run adds one row to injections.csv. For this target the columns that matter are these:
| Column | What it holds |
|---|---|
target_type |
the fault value, for example cache_l1d |
target_name, cache_level |
the level that took the fault: l1d, l1i or l2. With several levels listed, this tells you which one each run used |
original_value, faulty_value |
the byte before and after the fault, as gem5 read and wrote it |
bit_position, bit_positions |
the bit that changed, or the ;-separated bits of a multi-bit fault |
set, way |
the values of cache_set and cache_way when you set them, empty otherwise |
outcome |
what the run ended as |
The line and byte gem5 picked are recorded in the run's own folder, injection_NNNN/injection_report.json. Its target field reads cache[set=S,way=W,off=B]: the set, the way and the byte offset of the fault. With cache_lines: valid it ends ,valid=K/LINES, the number of valid lines at the injection out of all the lines of the cache. With cache_lines: all a fault in an invalid line ends ,invalid. The block_offset column is not filled for this target, so read the offset there.
A cache data fault often ends masked. Many valid lines are never read again before the run ends or before they are evicted clean, and a store to the faulted byte also erases it. An L1D fault becomes sdc (silent data corruption) when the program loads the byte and the wrong value reaches an observable such as result. An L1I fault changes an instruction, so the next fetch of that byte runs a different instruction or an illegal one: the run can end crash, timeout or sdc. An L2 fault matters only if an L1 refills the line from the L2, or if the line is written back to memory and read again. The outcome follows the same rules as any other target; see Fault classification for the full decision order.
Keys¶
| Key | Values | Default |
|---|---|---|
fault or target_types |
cache_l1d, cache_l1i, cache_l2; target_types also takes a list of them |
required |
fault_model |
single_bit_flip, stuck_at_0, stuck_at_1 |
required |
multi_bit_count |
1 to 8 distinct bits in the byte | 1 |
cache_lines |
valid, all |
valid |
cache_set |
set index, below the number of sets | drawn as cache_lines says |
cache_way |
way index, below the associativity | drawn as cache_lines says |
cache_level_sweep |
list of l1d, l1i, l2: runs take turns between the levels |
unset |
cache_config |
line_size, l1i_size, l1i_assoc, l1d_size, l1d_assoc, l2_enabled, l2_size, l2_assoc |
the board's cache:, else the default geometry above |
cpu_model |
TimingSimpleCPU, MinorCPU, DerivO3CPU (AtomicSimpleCPU is refused) |
the board's cpu.model, else TimingSimpleCPU |
cache_lines, cache_set, cache_way, cache_level_sweep and the ECC keys belong to the cache family. A register or memory campaign that sets them is rejected before anything runs.
Limits¶
- gem5 only. QEMU has no cache state to corrupt. A QEMU campaign stops with
fault_target: 'cache_l1d' is not supported on the QEMU backend (QEMU does not expose cache state). Set simulator_backend: gem5 to use cache injection. - No caches on the atomic CPU. A campaign that states
cpu_model: AtomicSimpleCPUis refused withcpu_model: AtomicSimpleCPU cannot reach target 'cache_l1d': gem5 builds no caches for an Atomic CPU and Atomic never touches Ruby state.Leavecpu_modelunset or name a timing CPU. cache_l2needs an L2. On a machine without one, the campaign stops withfault_target: 'cache_l2' rejected: the machine gem5 builds has no L2 cache (chosen by board.yaml (cache)). Use cache_l1d or cache_l1i, or select a board with L2.Give the campaign an L2 throughcache_config(l2_sizeandl2_assocare enough), or use a board that has one.- Out-of-range slots are refused. For example
cache_set=200 out of range for l1d as gem5 builds it, from board.yaml (cache) (n_sets=128). - Set both
cache_setandcache_way. gem5 aims at a slot only when it has both. With only one of them, it still picks a random valid line, while the CSV'ssetorwaycolumn repeats the value you set. - An aimed slot may be empty. If the line at
cache_setandcache_wayis not valid at the instant, the fault is recorded with,invalidat the end oftargetininjection_report.jsonand has no effect, because nothing reads an invalid line and the next fill overwrites it. - No fault, no verdict. If the cache holds no valid line at the instant, or a stuck-at fault finds its bits already at the stuck value, gem5 writes no fault. The run is then
infrastructure_failure, notmasked. A stuck-at campaign on a byte that is often zero therefore shows many such rows forstuck_at_0. - Applied once.
fault_persistence: permanentis accepted but has no effect here: gem5 re-applies a permanent fault only to registers, so a cache fault is written once and the program may overwrite it. - ECC changes the path. With
cache_ecc_enabled: true, the fault is not written into the line. The ECC model decodes it on the next read instead, and adds outcomes such aslatent_cleanandlatent_dirty. This page describes the default, with ECC off, which matches a cache without ECC such as the XuanTie C906 L1. - Tags are a separate target. This target never touches the tag, valid or dirty bits of a line. To fault the tag, see Cache tags.
See also: gem5 backend · Single-bit flip · Cache ECC · Configuration keys