PolarFire SoC, Zephyr SMP¶
Template hfim-template-polarfire-zephyr-qemu. Microchip PolarFire SoC Icicle Kit under QEMU, booted the way the silicon boots: the E51 runs Microchip's Hart Software Services (HSS), which reads a GPT partition table from an SD card image and starts Zephyr SMP on the four U54 cores. Faults land in a running operating system: a scheduler that moves threads across four cores, and shared kernel objects.
hfim init polarfire-zephyr-qemu ~/my-polarfire-campaigns
cd ~/my-polarfire-campaigns
hfim run campaigns/zephyr_pi_register_random.yaml --workers 2
The first hfim run builds the benchmark (Zephyr, the HSS and the SD card image), runs the golden run, then the injections. Later runs reuse all three.
Board¶
| Property | Value |
|---|---|
| SoC | Microchip MPFS250T, Icicle Kit |
| QEMU machine | microchip-icicle-kit |
| Harts | 5: hart 0 is the E51, harts 1 to 4 are U54_1 to U54_4 |
| Clusters | 2: cluster 0 is the E51, cluster 1 the four U54s |
| Firmware | patched HSS on the E51, linked at L2LIM 0x08000000 |
| Program | Zephyr SMP on the four U54s, linked at DDR 0x80000000 |
| HSS console | MMUART0 0x20000000 |
| Zephyr console | MMUART1 0x20100000 |
| Exit device | none |
| Caches | not modelled by QEMU |
Hart numbering¶
Harts are numbered within their cluster. A campaign selects the cluster with target_cluster and the hart in it with target_core.
| Core | Hart (TRM) | target_cluster |
target_core |
|---|---|---|---|
| E51 | 0 | 0 | 0 |
| U54_1 | 1 | 1 | 0 |
| U54_2 | 2 | 1 | 1 |
| U54_3 | 3 | 1 | 2 |
| U54_4 | 4 | 1 | 3 |
The target_core column of injections.csv uses the same numbering: 0 is U54_1 and 3 is U54_4.
How a run ends¶
The machine has no exit device, so fim_exit only loops. HFIM stops the run at a breakpoint on fim_exit, reads the observables, and takes the first argument register a0 as the exit code: fim_exit(1) is detected. Zephyr prints ZEPHYR FATAL ERROR on an unhandled exception; every campaign lists it under crash_patterns, so that line ends the run as crash.
Requirements¶
| Package | Version | Install |
|---|---|---|
| hfim | >=1.14,<2 |
hfim update |
hfim-sim-qemu |
9.2.4 (QEMU 9.2.4 with the SD fix) |
hfim init or hfim run |
| Docker | any | the distribution's package |
board.yaml requires the QEMU fix sdhci-v4-sdma: QEMU's SDHCI ignores the 64-bit SDMA address the HSS's SD driver programs, so without the fix the HSS never reads the card and every run times out. HFIM refuses to start on a simulator package whose manifest.yaml does not list the fix. 9.2.4 is the first release of hfim-sim-qemu that carries it: 9.2.3 installed from its release tag does not, and a rebuild reinstalls the same tag. A repository on the template's older pin moves to 9.2.4 with hfim template update and hfim setup.
A QEMU built by hand
Replace `simulator:` in the campaign with `qemu_path:` and `gdb_path:`. HFIM cannot check that QEMU for the fix and warns. `qemu-patch/` holds the fix for a QEMU 9.2.3 checkout and for the XuanTie fork (`xuantie-qemu-9.0`).Contents¶
| Path | Contents |
|---|---|
hfim.yaml |
pins, build: tools/build_all.sh, build_inputs, toolchain |
board.yaml |
harts and clusters, emulation:, the memory map from the PolarFire SoC TRM |
benchmarks/zephyr_pi/, benchmarks/zephyr_pktqueue/ |
the two benchmarks |
benchmarks/common/ |
fim_zephyr.c and fim_zephyr.h: fim_init, fim_exit, and the CPU-to-hart map fim_cpu_hart |
campaigns/ |
the campaigns below, and TEMPLATE.yaml.example for a new one |
tools/build_all.sh |
builds Zephyr, the HSS, the boot image and the SD image |
tools/Dockerfile.build |
the build image |
tools/make_gpt_image.py |
writes the GPT image the QEMU SD model and the HSS can read |
hss/ |
the HSS patch, hss.config, build-hss.sh, and PATCH_NOTES.md explaining each change |
qemu-patch/ |
the SDHCI fix for a QEMU checkout |
zephyr/ |
smp_4cpu.conf, which keeps 4 CPUs when an application's prj.conf asks for fewer |
board.yaml keys HFIM acts on¶
| Key | Value | Effect |
|---|---|---|
cpu.cores |
5 |
5 host threads per QEMU |
cpu.clusters |
2 |
the E51 and the U54s are separate GDB inferiors |
cpu.harts[].cluster |
0 for hart 0, 1 for harts 1 to 4 |
target_core: random draws among the U54s only |
emulation.exit_device |
none |
the run ends at the fim_exit breakpoint |
emulation.boot_seconds |
90 |
the HSS and SD boot, under GDB, on a loaded host |
emulation.requires_qemu_patches |
[sdhci-v4-sdma] |
refuses a simulator package without the fix |
emulation.timing: icount is left out on purpose, see A boot that hangs. Every key: Template files.
Benchmarks¶
Both are Zephyr's own SMP samples. They call fim_init() where the measured work starts and fim_exit(code) where it ends, and the template's own build (tools/build_all.sh) compiles them. campaigns/<benchmark>/<benchmark>.yaml names each one's build outputs and its results as observables; every campaign of the benchmark includes it, together with campaigns/shared/icicle.yaml (the U54 cluster, the guest console and the crash text).
| Benchmark | Zephyr sample | Work | Observables |
|---|---|---|---|
zephyr_pi |
samples/arch/smp/pi |
16 threads each compute 240 digits of pi, spread over the 4 U54s | th_buffer, uint8_t[3856]: the 16 results |
zephyr_pktqueue |
samples/arch/smp/pktqueue |
2 queues of 5000 packet headers, each checked with CRC16 and moved by 5 threads | the headers, and the count received per queue |
zephyr_pktqueue takes its headers from a fixed generator instead of the sample's random one, so every run processes the same packets. Its own CRC check ends the run with fim_exit(1), the detected outcome.
Campaigns¶
Every campaign uses injection_mode: breakpoint. Each injection stops at a point drawn from the golden run's [fim_init, fim_exit) window: an instruction weighted by how often it ran there, on any of the four U54s, and one of its executions (the hit instance). The icount plugin counts the hits inside QEMU. target_core decides only which hart's registers take the flip at that point.
| Campaign | Target |
|---|---|
zephyr_pi_buffer |
th_buffer, the 16 results |
zephyr_pi_counter |
th_counter, which main waits on |
zephyr_pi_threads |
tthread, the 16 k_thread objects |
zephyr_pi_register |
GPRs of U54_1 |
zephyr_pi_register_random |
GPRs of any U54, drawn per injection |
zephyr_pi_register_some |
GPRs of U54_1 or U54_3, drawn per injection |
zephyr_pi_register_harts |
batch: zephyr_pi_register on each U54 in turn, one result directory per hart |
zephyr_pi_isr_stacks |
each U54's interrupt stack z_interrupt_stacks, drawn per injection |
zephyr_pi_idle_threads |
each U54's idle thread (k_thread), drawn per injection |
zephyr_pktqueue_headers |
the 240000 header bytes |
zephyr_pktqueue_queues |
sender[]: head, tail and count of the queues |
zephyr_pktqueue_mutex |
sender_queue_mtx[], the queues' k_mutex objects |
zephyr_pktqueue_register |
GPRs of U54_1 |
# campaigns/zephyr_pi_register_random.yaml
campaign_name: "zephyr_pi_register_random"
benchmark: "zephyr_pi"
elf_path: "build/zephyr_pi/zephyr.elf" # symbols only
firmware_path: "build/zephyr_pi/hss-l2scratch.elf" # what every hart starts in
sd_image_path: "build/zephyr_pi/zephyr_sd.img" # what the HSS boots
guest_uart_serial: "results/guest_uart.log" # Zephyr's console, MMUART1
# The simulator comes from hfim.yaml; the machine, its 2G of memory and its
# 5 harts from board.yaml (emulation:, cpu.harts).
target_cluster: 1
target_core: random
seed: 1234
num_injections: 100
num_workers: 8
injection_mode: "breakpoint"
target_types: ["register"]
target_registers: ["x1", "x2", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15"]
fault_model: "single_bit_flip"
crash_patterns: ["ZEPHYR FATAL ERROR"]
timeout: 30
output_dir: "results/zephyr_pi_register_random"
Choosing the U54¶
target_core |
Each injection hits | Example |
|---|---|---|
0 |
U54_1, always | zephyr_pi_register |
[0, 2] |
U54_1 or U54_3, drawn with the seed | zephyr_pi_register_some |
random, or left out |
one of U54_1 to U54_4, drawn with the seed | zephyr_pi_register_random |
The E51 is drawn only by a campaign with target_cluster: 0. None of the template's campaigns sets it.
A memory fault lands in memory every hart shares, so target_core has no effect on it, except with memory_per_core: true. Then the target variable is split into one slice per Zephyr CPU, and the fault lands in the slice of the drawn U54. zephyr_pi_isr_stacks (2048 bytes per slice) and zephyr_pi_idle_threads use it. The benchmarks publish the CPU-to-hart map in fim_cpu_hart, so the slice follows the U54 even when Zephyr booted on another one.
Reference results¶
500 injections per campaign, seed 2026, --workers 24, on a 64-core server. Infrastructure failures are left out.
| Campaign | masked | sdc | detected | crash | timeout |
|---|---|---|---|---|---|
zephyr_pi_buffer |
257 | 241 | |||
zephyr_pi_counter |
2 | 496 | |||
zephyr_pi_threads |
496 | 3 | 1 | ||
zephyr_pi_register |
241 | 105 | 95 | 57 | |
zephyr_pktqueue_headers |
222 | 273 | |||
zephyr_pktqueue_queues |
290 | 7 | 72 | 126 | |
zephyr_pktqueue_mutex |
122 | 367 | |||
zephyr_pktqueue_register |
289 | 1 | 49 | 158 |
zephyr_pi_register_harts:
| Hart | masked | sdc | crash | timeout |
|---|---|---|---|---|
| U54_1 | 248 | 103 | 97 | 52 |
| U54_2 | 227 | 112 | 105 | 55 |
| U54_3 | 238 | 102 | 103 | 57 |
| U54_4 | 244 | 93 | 104 | 55 |
zephyr_pi_counteralmost always times out: nearly any change to the countermainwaits on keeps it from reaching 0.zephyr_pktqueue_headerssplits by timing: a header flipped before a worker checks it fails its CRC (detected); one flipped after reaches the receiver queue corrupted (sdc).- The four U54s give the same distribution for this workload.
Build the benchmarks¶
hfim.yaml names build: tools/build_all.sh, so hfim build and hfim run use it instead of the SDK. hfim run rebuilds a benchmark when a file its campaign boots is missing, or when its directory or a path in build_inputs changed.
hfim build benchmarks/zephyr_pi # into build/zephyr_pi/
./tools/build_all.sh # both benchmarks
For each benchmark the build writes into build/<benchmark>/: Zephyr forced to 4 CPUs, the patched HSS linked at L2LIM 0x08000000, the HSS boot image of the Zephyr ELF, and the GPT SD image.
tools/build_all.sh runs inside a Docker image it builds the first time from tools/Dockerfile.build: Zephyr d1978d9a35e without west modules, Zephyr SDK 0.16.8 riscv64 toolchain, xPack riscv-none-elf-gcc 12.1.0-2. The first build takes several minutes. The image is linux/amd64 on every host; on an arm64 host Docker emulates it, which is slower and gives the same compilers.
Build with a local toolchain instead of Docker
Set all of these. With `ZEPHYR_BASE` set, the build runs on the host toolchain and identifies it by its compiler binaries, the Zephyr commit and the west version.export ZEPHYR_BASE=/path/to/zephyr
export ZEPHYR_SDK_INSTALL_DIR=/path/to/zephyr-sdk
export ZEPHYR_PYTHON=/path/to/venv/bin/python3 # west, pyelftools, pyyaml
export XPACK_CC_DIR=/path/to/xpack-riscv-none-elf-gcc-12.x/bin
Add a benchmark¶
- Copy
benchmarks/zephyr_pi. Usefim_init()andfim_exit()frombenchmarks/common, keep the result in a global, and use a deterministic input. Copycampaigns/zephyr_pi/zephyr_pi.yamltocampaigns/<name>/<name>.yamland name the benchmark, its build outputs and that global underobservable_outputs. - Build it:
./tools/build_all.sh benchmarks/<name> build/<name>. - Copy
campaigns/TEMPLATE.yaml.exampleand fill every<FILL>. - Check every symbol the campaign names against the built ELF, not the source.
Caveats¶
A boot that hangs¶
The HSS can hang in its own start-up, before it reads the SD card, on a loaded host: measured at 1 in 500 runs on an idle 64-core server and up to 11 in 500 on a busy one. Such a run never reaches fim_init, so nothing was injected. HFIM boots the same injection again, up to twice; a run that fails three times is recorded as infrastructure_failure and left out of the rates. Each run that times out waiting for its injection point writes infra_diagnostics/injection_NNNN.txt: whether it reached fim_init, the PC of every hart, and the end of the consoles.
emulation.timing: icount in board.yaml avoids the hang, but QEMU then runs the harts one at a time and Zephyr places 8 to 11 of zephyr_pi's 16 threads on one U54, instead of 3 to 5 per U54. That is not the board's behaviour, so the template leaves it out.
Workers¶
Each QEMU runs the five harts as parallel host threads (MTTCG). Start with one worker. Increase --workers while monitoring boot timeouts; a busy host can stall the HSS before injection.
Warning
Runs are not bit-exact reproducible: QEMU runs the U54s as parallel threads, and HFIM warns about it on every multicore campaign. The faultlist and the observables are reproducible; the exact interleaving is not.