Skip to content

gem5 backend

Injects into microarchitectural state: caches, ECC check bits, DRAM, non-volatile memory, pipeline structures and coherence, in addition to registers and memory. RISC-V, in syscall-emulation mode or, for the Allwinner D1, in full system (below). 10 to 60 seconds per injection.

The SimObject tree of each configuration (classic, DRAMsim3, NVMain, Ruby) is drawn in gem5 diagrams.

How a fault is injected

flowchart LR
  ctrl["FIM controller<br/>compiled into gem5"]
  subgraph gem5["gem5 process, one per injection"]
    cpu["CPU model<br/>registers, ROB, LSQ, rename, TLB, branch predictor"]
    l1["L1D, L1I<br/>data, tags, check bits"]
    l2["L2, or Ruby controllers"]
    mem["memory controller<br/>gem5 DDR3, DRAMsim3, NVMain"]
  end
  out["injection_report.json<br/>state_dump.json"]
  cpu -- "committed instruction count" --> ctrl
  ctrl -- "register, phys_reg, rename_map, rob, lsq, branch_pred, tlb" --> cpu
  ctrl -- "cache_l1d, cache_l1i, cache_tag, cache_tag_parity, ecc_parity_l1d, ecc_parity_l1i, coherence" --> l1
  ctrl -- "cache_l2, ecc_parity_l2, ruby_mshr, ruby_tbe, ruby_directory, ruby_message_buffer" --> l2
  ctrl -- "memory, dram, nvm_tags" --> mem
  cpu -- "fetches, loads, stores" --> l1
  l1 -- "misses, writebacks" --> l2
  l2 -- "misses, writebacks" --> mem
  ctrl -- "fault and observable values" --> out

The FIM controller counts committed instructions and fires at the drawn count. Each arrow into a structure is labelled with the fault values that reach it. At fim_exit the controller writes the observable variables to state_dump.json, each one whole, at the size its symbol has in the ELF's symbol table; the classifier compares them with the golden run.

Setup

The Nezha C906 template pins hfim-sim-gem5@23.2.0.

hfim init nezha-c906-gem5 my-campaigns
cd my-campaigns                     # hfim init built the Docker image hfim-sim-gem5:23.2.0, once per machine
hfim run campaigns/fibonacci/register.yaml

A campaign of a QEMU template cannot switch to gem5: its boot code is built for QEMU (Another backend). Outside a template, hfim sim install gem5 installs the newest release of the package (hfim-sim-gem5, by its full name) and hfim doctor checks it.

When the release names a prebuilt image, hfim setup and hfim sim install gem5 download it (downloading prebuilt image ... done) and check its digest, which takes minutes instead of hours. --from-source builds the image on this machine (hfim setup --from-source, hfim sim install gem5 --from-source); so does an install whose download fails, after a line that says why. Prebuilt images describes the download and its check.

A build compiles gem5 twice, once per memory system. Measured with no Docker cache: 2 hours 25 minutes on an Apple Silicon laptop, where the image is linux/amd64 and runs emulated, and 15 minutes on a 64-core Linux server with DOCKER_BUILD_ARGS="--build-arg JOBS=48" (8 compile jobs without it). Keep the same JOBS on later installs of that machine: another value compiles gem5 again instead of reusing the cache. The image also carries the compiler of gem5 benchmarks, riscv64-linux-gnu-gcc, and hfim run builds a benchmark inside it.

The package holds two gem5 binaries, because a gem5 binary carries one coherence protocol:

simulator_backend Binary Memory system
gem5 build/RISCV/gem5.opt classic caches
gem5-ruby build/RISCV_MESI_Two_Level/gem5.opt Ruby, MESI_Two_Level protocol

A campaign names the backend and the package:

simulator_backend: gem5
simulator: hfim-sim-gem5@23.2.0

A fault value starting with ruby_ selects the Ruby binary also when simulator_backend is gem5. The SDK builds a separate gem5 ELF of the benchmark (<benchmark>_<arch>_gem5.elf), and a gem5 campaign runs that ELF even when a bare-metal one lies beside it.

Without Docker
cd hfim-sim-gem5
./install.sh                 # builds both binaries and DRAMsim3
export HFIM_SIM_GEM5=$PWD
The package manifest sets `LD_LIBRARY_PATH` to the DRAMsim3 library and `FIM_GEM5_CONFIGS` to gem5's configuration scripts. A rebuild by hand needs the scons flag `bitflip=1`; without it the build fails at `src/mem/mem_ctrl.cc` with `no field named tracer`.

What the board sets

The template's board.yaml sets the machine gem5 builds, as it sets the CPU QEMU runs:

board.yaml Setting gem5 option
cpu.model cpu_model --cpu-type
cpu.clock cpu_clock --cpu-clock
memory.size memory_size --mem-size
cache.line_size cache_config.line_size --cacheline-size
cache.l1i.size, cache.l1i.assoc cache_config.l1i_size, l1i_assoc --l1i-size, --l1i-assoc
cache.l1d.size, cache.l1d.assoc cache_config.l1d_size, l1d_assoc --l1d-size, --l1d-assoc
cache.l2.size, cache.l2.assoc cache_config.l2_size, l2_assoc --l2-size, --l2-assoc
no cache.l2, or l2: {enabled: false} cache_config.l2_enabled: false --no-l2

A campaign's own value wins over the board, and the board wins over the package default. For cache_config the campaign wins field by field: a campaign that states l2_size gets an L2 on a board without one. hfim run prints the machine before it starts, each part followed by who set it:

machine: cpu MinorCPU at 1GHz, L1I 32kB 2-way, L1D 32kB 4-way, no L2, 64 B lines, 512MB memory (board.yaml)

The Provenance of the campaign records the same values and who set each. The board's emulation: section is QEMU's; gem5 reads none of it.

A board-driven run needs hfim-sim-gem5 23.0.3 or later. Version 23.0.2 rejects --cpu-clock, --cacheline-size and --no-l2 and the run stops; before 23.0.3 every timing CPU had a 256 kB L2, whatever the board said.

Full-system D1 platform

By default gem5 runs a benchmark in syscall-emulation mode: a static Linux ELF built for gem5, in user mode. gem5_platform: d1 runs a bare-metal image built for the Allwinner D1 board (the XuanTie C906 of the Nezha) instead, unmodified, in full system, with the T-Head instructions the C906 adds. The package's golden_d1 and inject_d1 scripts replace the SE ones; hfim-sim-gem5 23.1.0 and later ship them.

The golden boots the image and takes a checkpoint at the first instruction of a symbol you name. The golden and every injection start from that checkpoint, so a run does not repeat the boot, and the injection instant counts from there. A campaign whose golden left no checkpoint stops before the first injection and asks you to measure the golden again.

A board image usually has no fim_init and fim_exit and loops over its work. gem5_args passes the run controls the D1 scripts take, each one string:

Argument What it does
--checkpoint-symbol=SYM the golden checkpoints at the first commit of SYM; every run starts there
--window-start=SYM, --window-end=SYM the first commit of each symbol after the checkpoint opens and closes the injection window
--poke=VAR=VALUE@PC[:SIZE] every commit of PC writes VALUE to VAR (symbols or numbers), for example to end the image's loop early
--stop-after-lines=N the run stops after N UART lines, counted from the checkpoint
--uart-drop-column=N leaves the 0-based tab-separated column N out of the compared output, for example a cycle count
benchmark: mmult_TMR
elf_path: benchmarks/mmult_TMR/build/mmult_TMR_riscv64.elf   # the board image, as built for the board
simulator_backend: gem5
gem5_platform: d1
gem5_args:
  - --checkpoint-symbol=bench_run
  - --window-start=start_timer
  - --window-end=stop_timer
  - --poke=run_counter=10000@start_timer
  - --stop-after-lines=3
  - --uart-drop-column=2
fault: cache_l1i
fault_model: single_bit_flip
num_injections: 2000

The output the classifier compares is the UART text of the image, without the dropped columns. The machine is the board's, as for SE: the Nezha C906 board gives MinorCPU at 1 GHz, a 32 kB 2-way L1I, a 32 kB 4-way L1D and no L2.

Parameters

The keys below are read only by the gem5 backend. Keys common to every backend: Campaign configuration. All keys: Configuration keys.

Simulator and CPU

Key Values Default
simulator_backend gem5, gem5-ruby qemu
simulator hfim-sim-gem5@<version>, or the short gem5@<version>
gem5_binary path to a gem5.opt, used without a package
cpu_model AtomicSimpleCPU, TimingSimpleCPU, MinorCPU, DerivO3CPU the board's cpu.model, else AtomicSimpleCPU
cpu_clock frequency of the CPU and its L1 caches, e.g. 1GHz the board's cpu.clock, else 1GHz
memory_size guest memory, e.g. 256MB the board's memory.size, else 256MB
max_ticks simulation tick limit, 0 for none 0
warmup_instructions committed instructions before the injection window opens 0
fault_persistence transient: written once; permanent: re-applied every cycle transient
gem5_platform se, or a platform the package ships scripts for: d1 se
gem5_args list of strings appended last to every golden and injection command none
timeout wall-clock seconds per injection, or auto: timeout_factor (1.5) times the golden run's wall time, at least timeout_floor (30 s) required

The golden run stops after the campaign's timeout when it is a number, and after 900 seconds when it is auto. Its wall time is recorded in trace.json, so timeout: auto scales from it as on QEMU.

AtomicSimpleCPU has no caches. A cache, ECC check-bit, coherence or Ruby campaign whose CPU is AtomicSimpleCPU, from the campaign or the board, runs on TimingSimpleCPU, with a log line saying so. The Ruby binary accepts TimingSimpleCPU, MinorCPU and DerivO3CPU. fault_persistence: permanent is rejected on QEMU.

cpu_model Pipeline Caches Targets it adds
AtomicSimpleCPU none none
TimingSimpleCPU none L1I, L1D, L2 cache targets
MinorCPU in-order L1I, L1D, L2 cache targets
DerivO3CPU out-of-order L1I, L1D, L2 phys_reg, rename_map, rob, lsq, branch_pred

Caches

Key Values Default
cache_config map with line_size, l1i_size, l1i_assoc, l1d_size, l1d_assoc, l2_enabled, l2_size, l2_assoc the board's cache section, else 32kB/2, 32kB/2, 256kB/8, 64-byte lines
cache_lines valid: the line is drawn among those holding data at the injection; all: set, way and byte are drawn over the whole array (Cache data) valid
cache_set set index; checked against the hierarchy gem5 is given drawn as cache_lines says
cache_way way index; checked the same way drawn as cache_lines says
cache_level_sweep list of l1d, l1i, l2: injections cycle through the levels unset
fault: cache_l2
cpu_model: TimingSimpleCPU
cache_config: {l1i_size: 32kB, l1i_assoc: 2, l1d_size: 32kB, l1d_assoc: 2, l2_size: 256kB, l2_assoc: 8}
cache_set: 17

cache_set, cache_way and fault: cache_l2 are checked against the caches gem5 builds: the campaign's cache_config over the board's. A cache_l2 campaign on a board without L2 stops before it starts unless it states an L2, as above.

ECC

Key Values Default
cache_ecc_enabled true: SECDED decode on the cache read path false
cache_ecc_scope data; tag and both are accepted but do not enable tag ECC data
cache_ecc_policy_l1d, cache_ecc_policy_l1i, cache_ecc_policy_l2 parity, secded, none inherit cache_ecc_enabled
dram_ecc_enabled true: SECDED over DRAM; needs a dram_error_model other than none false

fim/configs/ecc_policies/c906.yaml holds the C906 per-level policy. Cache ECC is single-core: cache_ecc_enabled: true with num_cores above 1 is rejected. What each verdict means: Cache ECC check bits.

DRAM fault model

Key Values Default
dram_error_model none, single_bit, multi_bit, row, retention none
dram_multi_bit_count bits flipped by multi_bit 2
dram_row_size row size in bytes for row 8192
memory_random_fallback true: a memory fault picks any DRAM byte false

Memory backend

Key Values Default
mem_backend gem5_builtin (DDR3_1600_8x8), dramsim3, nvmain gem5_builtin
dramsim3_ini DRAMsim3 .ini file; required with dramsim3
nvmain_config NVMain .config file; required with nvmain
mem_backend: dramsim3
dramsim3_ini: /path/to/DDR4_8Gb_x8_2400.ini

Use an absolute path to the device configuration on the machine running the campaign.

dramsim3 adds DRAM timing and per-access energy (dram_energy_J). The shipped files are DDR3 and DDR4 devices under fim/configs/dramsim3/.

nvmain adds non-volatile memory with per-cell write endurance. A cell written past its endurance limit fails, and the row's outcome becomes stuck_after_wear. The limit per cell is drawn from a normal distribution set in the .config file (EnduranceDistMean, EnduranceDistVariance). Shipped files under fim/configs/nvmain/:

File Technology Endurance model
PCM_ISSCC_2012_4GB_BitModel.config PCM per bit
PCM_ISSCC_2012_4GB_ByteModel.config PCM per byte
PCM_ISSCC_2012_4GB_WordModel.config PCM per 4-byte word
PCM_ISSCC_2012_4GB_RowModel.config PCM per row
PCM_ISSCC_2012_4GB_BitModel_ECP.config PCM with error-correcting pointers per bit
PCM_MLC_example_BitModel.config multi-level-cell PCM per bit
STTRAM_Everspin_4GB_BitModel.config STT-MRAM per bit
RRAM_ISSCC_2012_4GB.config RRAM none

A configuration without an endurance model counts no wear. Both binaries load any of these files.

Ruby

Key Values Default
num_cores CPUs in the Ruby system 1
ruby_target_symbol data symbol whose line the ruby_* fault corrupts pingpong_var
ruby_target_addr address of that line; replaces ruby_target_symbol unset
simulator_backend: gem5-ruby
simulator: hfim-sim-gem5@23.2.0
fault: ruby_tbe
cpu_model: TimingSimpleCPU
num_cores: 2
ruby_target_symbol: pingpong_var

The symbol resolves from the ELF; HFIM translates it to a physical address. A symbol absent from the ELF stops the injection. With num_cores above 1, register faults go to CPU 0. Multicore rules: Multicore.

Power (McPAT)

Key Values Default
mcpat true: run McPAT on each injection's statistics false
mcpat_template McPAT XML template, e.g. fim/configs/mcpat/c906.xml
mcpat_binary McPAT executable mcpat
mcpat_translator script that turns gem5 statistics into McPAT input scripts/gem5_to_mcpat.py

Set mcpat_binary and mcpat_translator to the tools available on the machine running the analysis.

McPAT fills the power columns of injections.csv. power_model names the model behind the numbers and power_model_note states its known bias against silicon.

Fault targets

Target fault values Needs
registers register any CPU model except DerivO3CPU
memory memory
cache data cache_l1d, cache_l1i, cache_l2 a CPU model with caches
cache tags cache_tag, cache_tag_parity a CPU model with caches
ECC check bits ecc_parity_l1d, ecc_parity_l1i, ecc_parity_l2 cache_ecc_enabled: true
DRAM and NVM dram, nvm_tags nvm_tags: gem5-ruby with mem_backend: nvmain
pipeline phys_reg, rename_map, rob, lsq, branch_pred DerivO3CPU
TLB tlb a workload that fills the TLB (see Limitations)
coherence coherence classic caches
Ruby coherence ruby_mshr, ruby_tbe, ruby_directory, ruby_message_buffer gem5-ruby

Important

Memory and cache-data faults are byte-granular on gem5: one byte is read, modified and written, so only bits 0 to 7 flip.

What each target corrupts, its keys and the bits that can flip: Fault targets.

Results

Same layout as QEMU. Each injection directory adds:

File Content
injection_report.json the target, original and faulty value, written by the FIM controller
state_dump.json observable variables at fim_exit
gem5_stdout.log, gem5_stderr.log gem5 console output
stats.txt, config.json gem5 statistics and the simulated system
dramsim3.json DRAMsim3 statistics, with mem_backend: dramsim3

gem5 fills these injections.csv columns:

Columns Filled when
cache_level, set, way, block_offset cache targets
cache_ecc_engaged, cache_ecc_corrected, cache_ecc_detected_bits, cache_evicted_unread, ecc_false_correct cache_ecc_enabled: true
tag_fault_engaged cache_tag_parity
dram_energy_J mem_backend: dramsim3
dram_writes_per_cell_max, endurance_failed, ecp_corrected_count mem_backend: nvmain
core_power_W, l1d_power_W, l2_power_W, total_power_W, total_area_mm2, power_model, power_model_note, total_power_W_silicon_typ mcpat: true

Outcome values beyond the five common ones:

Outcome Target
latent_clean, latent_dirty, ecc_false_correct cache with ECC
tag_false_hit, tag_false_miss, tag_latent cache_tag_parity
stuck_after_wear mem_backend: nvmain

Definitions: Cache ECC check bits. Every column: Output files.

A register fault on DerivO3CPU ends with gem5's message Program aborted at tick; the classifier records it as crash.

Limitations

  • RISC-V only.
  • In syscall-emulation mode the program runs in user mode, with no CSRs and no mhartid. The TLB is not filled, so a tlb fault injects nothing. The one full-system platform is the single-core Allwinner D1.
  • The classic backend is single-core. Multicore needs gem5-ruby, with the MESI_Two_Level protocol only.
  • Cache ECC is single-core. There is no DRAM check-bit target: ecc_parity_dram is refused at load.
  • A register fault on DerivO3CPU aborts gem5; use phys_reg.
  • No interconnect model: router buffers and network-on-chip state are out of reach.
  • One fault per run. multi_bit_count flips several bits in one word, not two separate events.
  • SDC rates describe the simulated workload and machine. Estimating a silicon error rate requires calibration against physical measurements.
  • The server's distributed workers run QEMU only; a gem5 campaign runs on one machine. num_workers above 1 runs several gem5 processes at once on that machine.