Skip to content

Nezha C906

Template hfim-template-nezha-c906-qemu. Allwinner Nezha board with the T-Head XuanTie C906 core: RISC-V RV64, one hart, bare metal, on QEMU. The template has one benchmark and two campaigns, and is the starting point for a first campaign.

hfim init nezha-c906-qemu my-campaigns
cd my-campaigns
hfim run campaigns/fibonacci/register.yaml

Board

Property Value
Core XuanTie C906, RV64IMAFDC(V), 5-stage in-order, single issue
Harts 1
Clusters 1
L1 instruction cache 32 kB, 2-way, 64-byte lines
L1 data cache 32 kB, 4-way, 64-byte lines
L2 cache none
QEMU machine virt, CPU c906fdv (the XuanTie fork's C906 with FPU and vector unit)
DRAM 0x80000000, 256 MB
UART0 (NS16550) 0x10000000
CLINT 0x02000000
PLIC 0x0C000000
Exit device sifive_test at 0x00100000

QEMU models no caches. The cache sizes in board.yaml describe the C906. For cache, coherence and non-volatile memory campaigns on the same core, use Nezha C906 on gem5.

The addresses are those of the QEMU virt machine, not of the Nezha board's silicon.

How a run ends

The machine has an exit device, so QEMU ends when the program calls fim_exit:

Call Value written to 0x100000 QEMU exit code Outcome
fim_exit(0) 0x5555 0 masked or sdc, decided by the observables
fim_exit(1) 0x3333 1 detected
CPU exception or other value above 1 crash

Requirements

Package Version Install
hfim >=1.14,<2 hfim update
hfim-sim-qemu-xuantie 9.0.2 hfim init or hfim run
hfim-sdk >=1.3,<2 hfim init or hfim run

hfim init installs the two packages, and hfim run installs one that is missing; hfim setup, run inside the campaign repository, checks both and repairs a failed install. hfim doctor reports what is still missing.

Contents

Path Contents
hfim.yaml template name, version pins, board, startup
board.yaml the C906 description: CPU, pipeline, caches, TLB, memory map, injection targets
startup/riscv64/ start.S, link.ld, and crt_shim_newlib.S with link_newlib.ld for benchmarks built with build_runtime: newlib
startup/aarch64/ start.S and link.ld for AArch64 builds
modules/ drivers a benchmark can include: uart, ccu (clocks), c906 (cache, CSR, delay, reset), riscv64, common, printf, simplecrc
benchmarks/fibonacci/ main.c, the benchmark's code
campaigns/fibonacci/ fibonacci.yaml, what both campaigns include (the benchmark and its observables), and the campaigns register.yaml and memory.yaml

In board.yaml, emulation: selects the virt machine, c906fdv CPU and 256 MB of RAM. See Template files.

Benchmark

fibonacci computes the first 64 Fibonacci numbers into volatile unsigned long result[64], between fim_init() and fim_exit(0). Each value depends on the previous two, so a flip in an intermediate value corrupts every later entry.

# campaigns/fibonacci/fibonacci.yaml
benchmark: fibonacci
observable_outputs:
  comparison: exact
  variables:
    - name: result

The type and size of result come from the ELF, so the comparison is element by element and sdc_details names the index that differs.

Campaigns

Campaign Target Injections Seed
fibonacci-register integer registers x10 to x15 10 7
fibonacci-memory section .bss, which holds result[] 20 7
# campaigns/fibonacci/memory.yaml
include: fibonacci.yaml          # benchmark: fibonacci and what counts as its answer
campaign_name: fibonacci-memory
simulator_backend: qemu
seed: 7
num_injections: 20
num_workers: 1
target_types: [memory]
memory_start: .bss
memory_end: .bss
fault_model: single_bit_flip
injection_mode: icount
timeout: auto
output_dir: results

memory_start and memory_end take a section name and resolve it from the built ELF, so the range follows the program when it changes. timeout: auto sets the limit to 1.5 times the golden run's duration, with a floor of 30 s.

Simulator

The template (version 1.1.2) pins hfim-sim-qemu-xuantie@9.0.2, the XuanTie fork of QEMU, and its board.yaml asks for CPU c906fdv (emulation.qemu_cpu). Upstream QEMU has no C906 model, so a campaign that pins upstream hfim-sim-qemu stops before boot and says so. Each run prints the package, the machine and the CPU, and who chose each.

The benchmark compiles with XuanTie's bare-metal toolchain (riscv64-unknown-elf-gcc, elf-newlib V3.0.1) inside the package's image. XuanTie publishes it for x86-64 Linux only, so the image is linux/amd64 on every host. An Apple Silicon Mac runs it emulated, slower, with XuanTie's own compiler: the same ELF and the same results as an x86-64 machine. A repository made from an earlier version of the template takes the new pin with hfim template update, then hfim setup.

Build the benchmark

hfim run builds a benchmark whose ELF is missing or whose sources changed. To build by hand:

hfim build benchmarks/fibonacci

The template's hfim.yaml names no build: command, so the SDK's build.sh compiles main.c, links it with startup/riscv64/, and writes the ELF under benchmarks/fibonacci/build/. It runs inside the hfim-sim-qemu-xuantie image, with XuanTie's compiler, so the machine needs no cross compiler of its own.

Add a benchmark

  1. Copy benchmarks/fibonacci to benchmarks/<name>.
  2. In main.c, call fim_init() where the measured work starts and fim_exit(0) where it ends. Declare every value to compare as a file-scope volatile variable.
  3. Copy campaigns/fibonacci/ to campaigns/<name>/ and rename fibonacci.yaml to <name>.yaml. In it, set benchmark: <name> and name those variables under observable_outputs.
  4. In the copied campaigns, include <name>.yaml and set a new campaign_name.

An array type such as uint64_t[64] is compared element by element. Details: Writing a benchmark.