High-performance RISC-V cycle-accurate system simulator
Project description
rvsim
Cycle-accurate RISC-V 64-bit system simulator with a composable Python API for architecture research and design-space exploration.
Documentation · PyPI · Rust Core (crates.io) · Changelog
rvsim models a complete superscalar processor at cycle granularity. It implements two pluggable microarchitectural backends — out-of-order and in-order — sharing a common frontend, memory hierarchy, and SoC device layer. It boots Linux 6.6 through OpenSBI to a BusyBox shell and passes all 134/134 riscv-tests.
Install
pip install rvsim
Requires Python 3.10+. Ships pre-built wheels for Linux x86_64.
Quick Start
from rvsim import Config, BranchPredictor, Cache, Environment
config = Config(
width=4,
branch_predictor=BranchPredictor.TAGE(),
l1d=Cache("32KB", ways=8, latency=1, mshr_count=8),
l2=Cache("256KB", ways=8, latency=10),
)
result = Environment(binary="program.elf", config=config).run()
print(result.stats.query("ipc|branch|miss"))
ipc 0.9256
branch_accuracy_pct 83.3474
branch_mispredictions 497,026
dcache_misses 79,488
l2_misses 21,374
Features
Two Pipeline Backends
Out-of-order superscalar — Physical register file with dual rename maps (speculative + committed), CAM-style issue queue with wakeup/select and oldest-first priority, reorder buffer for in-order commit with precise exceptions, load queue for memory ordering violation detection, store buffer with forwarding, and a configurable functional unit pool (per-type counts and latencies).
In-order scalar — Scoreboard-based operand tracking, FIFO issue queue with head-of-queue blocking, backpressure gating. Shares the same frontend and commit/memory/writeback stages as the O3 backend, making both modes directly comparable on identical workloads.
Both backends enforce identical serialization semantics: system/CSR instructions wait for all older completions, FENCE respects predecessor/successor ordering bits, loads wait for older store address resolution.
Memory Hierarchy
- SV39 virtual memory — separate iTLB/dTLB, shared L2 TLB, full hardware page table walker with A/D bit management
- L1i / L1d / L2 / L3 caches — independently configurable size, associativity, latency, and replacement policy (LRU, PLRU, FIFO, Random, MRU)
- Non-blocking L1D via MSHRs with request coalescing
- Hardware prefetchers per cache level: next-line, stride, stream, tagged
- Inclusion policies: non-inclusive, inclusive (back-invalidation), exclusive (L1-L2 swap)
- DRAM controller — row-buffer aware timing (tCAS, tRAS, tPRE, row-miss, bank interleaving, refresh)
Branch Prediction
Five pluggable predictors with shared BTB, RAS, and global history register:
| Predictor | Description |
|---|---|
| Static | Always not-taken (baseline) |
| GShare | PC XOR global history, 2-bit counters |
| Tournament | Local + global two-level adaptive with meta-predictor |
| Perceptron | Neural predictor with weight vectors |
| TAGE | Tagged geometric history length with loop predictor |
RAS recognizes both x1 and x5 as link registers per RISC-V spec Table 2.1, including coroutine swap detection.
ISA & Privileged Architecture
RV64IMAFDC — base integer, multiply/divide, atomics (LR/SC + AMO), single/double float with IEEE 754 NaN-boxing, compressed instructions. M/S/U privilege modes, full CSR set, trap delegation, MRET/SRET, WFI, SFENCE.VMA, FENCE/FENCE.I, PMP (16 regions).
Passes all 134/134 tests in riscv-software-src/riscv-tests.
SoC Devices
CLINT timer, PLIC interrupt controller, 16550A UART, VirtIO MMIO block device, Goldfish RTC, SYSCON (poweroff/reboot), HTIF. Auto-generated device tree blob.
Python API
Comparing Configurations
from rvsim import BranchPredictor, Config, Environment, Stats
rows = {}
for name, bp in [("GShare", BranchPredictor.GShare()), ("TAGE", BranchPredictor.TAGE())]:
r = Environment("program.elf", Config(branch_predictor=bp)).run()
rows[name] = r.stats
print(Stats.tabulate(rows, title="Branch Predictor Comparison"))
Parallel Sweeps
Sweep distributes all (binary, config) combinations across CPU cores:
from rvsim import Sweep, Config, Cache
results = Sweep(
binaries=["qsort.elf", "mandelbrot.elf", "maze.elf"],
configs={
f"L1={s}": Config(l1d=Cache(s, ways=8, mshr_count=8), uart_quiet=True)
for s in ["8KB", "16KB", "32KB", "64KB"]
},
).run(parallel=True)
results.compare(metrics=["ipc", "dcache_misses"], baseline="L1=8KB")
Low-Level Control
from rvsim import Simulator, Config, reg, csr
cpu = Simulator().config(Config(width=4)).binary("program.elf").build()
for _ in range(1000):
cpu.tick()
cpu.pipeline_snapshot().visualize()
cpu.run_until(pc=0x80001234)
cpu.run_until(privilege="U")
print(hex(cpu.regs[reg.A0]))
print(hex(cpu.csrs[csr.MSTATUS]))
print(cpu.mem64[0x80001000])
cpu.save("checkpoint.bin")
Analysis Scripts
Ready-to-run design-space exploration in scripts/analysis/:
| Script | Description |
|---|---|
branch_predict.py |
Accuracy comparison across all 5 predictors |
cache_sweep.py |
L1D size vs miss rate and IPC impact |
design_space.py |
Multi-dimensional width x cache size sweep |
o3_inorder.py |
Out-of-order vs in-order backend comparison |
width_scaling.py |
IPC vs superscalar width |
stall_breakdown.py |
Stall cycle attribution (memory, control, data) |
top_down.py |
Top-down microarchitecture analysis |
inst_mix.py |
Instruction class breakdown |
rvsim scripts/analysis/branch_predict.py
rvsim scripts/analysis/cache_sweep.py --sizes 4KB 8KB 16KB 32KB 64KB
rvsim scripts/analysis/o3_inorder.py --widths 1 2 4
Building from Source
Requires Rust (2024 edition), Python 3.10+, and riscv64-unknown-elf-gcc.
git clone https://github.com/willmccallion/rvsim
cd rvsim
python3 -m venv .venv && source .venv/bin/activate
pip install maturin
maturin develop --release
make -C software
Linux Boot
Boots Linux 6.6 through OpenSBI to a BusyBox shell on both backends.
make -C software linux # Build kernel + rootfs via Buildroot
rvsim scripts/setup/boot_linux.py # Boot (login: root, no password)
Documentation
Full documentation including architecture deep-dives, API reference, and examples:
License
Licensed under either of MIT or Apache-2.0, at your option.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rvsim-1.2.2.tar.gz.
File metadata
- Download URL: rvsim-1.2.2.tar.gz
- Upload date:
- Size: 439.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ce7b5d25cefb529690be605259bfd27bd7b37648f2bb100cd1e24f81d2d4414
|
|
| MD5 |
ab227da18457e1c05db0f4345da43b8c
|
|
| BLAKE2b-256 |
30105d0be46832261ac76dba2ac19aa1c041b4eba13d515edd2909d12422dcf0
|
Provenance
The following attestation bundles were made for rvsim-1.2.2.tar.gz:
Publisher:
release.yml on willmccallion/rvsim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rvsim-1.2.2.tar.gz -
Subject digest:
9ce7b5d25cefb529690be605259bfd27bd7b37648f2bb100cd1e24f81d2d4414 - Sigstore transparency entry: 1155386985
- Sigstore integration time:
-
Permalink:
willmccallion/rvsim@ff82152c40b46a1b1648e4110c6fbd372188e4fe -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/willmccallion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ff82152c40b46a1b1648e4110c6fbd372188e4fe -
Trigger Event:
push
-
Statement type:
File details
Details for the file rvsim-1.2.2-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: rvsim-1.2.2-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 798.3 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86942b61d539bb8b6687c534aa2701ab7f4620063090fb0c69e9373a6ff0e818
|
|
| MD5 |
3a9ef71efa6101e9b9e4230baa8861c2
|
|
| BLAKE2b-256 |
705eed4a07878239215f33664e6698c182502dc725c7548a1d62d96331bc0150
|
Provenance
The following attestation bundles were made for rvsim-1.2.2-cp310-abi3-win_amd64.whl:
Publisher:
release.yml on willmccallion/rvsim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rvsim-1.2.2-cp310-abi3-win_amd64.whl -
Subject digest:
86942b61d539bb8b6687c534aa2701ab7f4620063090fb0c69e9373a6ff0e818 - Sigstore transparency entry: 1155386986
- Sigstore integration time:
-
Permalink:
willmccallion/rvsim@ff82152c40b46a1b1648e4110c6fbd372188e4fe -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/willmccallion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ff82152c40b46a1b1648e4110c6fbd372188e4fe -
Trigger Event:
push
-
Statement type:
File details
Details for the file rvsim-1.2.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: rvsim-1.2.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 930.0 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d35e19f04b16806c2e76e6166b68b4f5450d5cfff3ce1b4ff6eac436c867649
|
|
| MD5 |
eef3da85a34911e78077bdef3d339fd1
|
|
| BLAKE2b-256 |
5fc8ac1c524466317adc98dc08ad3c2e9e8348bdba0d667e56f9b02525a50d7f
|
Provenance
The following attestation bundles were made for rvsim-1.2.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on willmccallion/rvsim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rvsim-1.2.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
4d35e19f04b16806c2e76e6166b68b4f5450d5cfff3ce1b4ff6eac436c867649 - Sigstore transparency entry: 1155386995
- Sigstore integration time:
-
Permalink:
willmccallion/rvsim@ff82152c40b46a1b1648e4110c6fbd372188e4fe -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/willmccallion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ff82152c40b46a1b1648e4110c6fbd372188e4fe -
Trigger Event:
push
-
Statement type:
File details
Details for the file rvsim-1.2.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: rvsim-1.2.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 860.2 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f0f171ec8e2e1af3ae19921ceb30aa6958f6f087acfb4357685e78744333e38
|
|
| MD5 |
9f2e856040b2918a75948fc630ff8939
|
|
| BLAKE2b-256 |
7497437312e64b02dfd6c557b38f8acce1725e97c7a73bf40d39c61f2d1962a2
|
Provenance
The following attestation bundles were made for rvsim-1.2.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on willmccallion/rvsim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rvsim-1.2.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
0f0f171ec8e2e1af3ae19921ceb30aa6958f6f087acfb4357685e78744333e38 - Sigstore transparency entry: 1155386996
- Sigstore integration time:
-
Permalink:
willmccallion/rvsim@ff82152c40b46a1b1648e4110c6fbd372188e4fe -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/willmccallion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ff82152c40b46a1b1648e4110c6fbd372188e4fe -
Trigger Event:
push
-
Statement type:
File details
Details for the file rvsim-1.2.2-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: rvsim-1.2.2-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 808.6 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddd6e4b771d77862232fdc22870167b841e4a23c14420cda39b8a1e564621adb
|
|
| MD5 |
3222560bbb884c938ef873b418d56593
|
|
| BLAKE2b-256 |
2c01fd28c7aee0f2d9dd26a2f66ee35722cbe67e1778f2e8c694cac3f9da6839
|
Provenance
The following attestation bundles were made for rvsim-1.2.2-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on willmccallion/rvsim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rvsim-1.2.2-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
ddd6e4b771d77862232fdc22870167b841e4a23c14420cda39b8a1e564621adb - Sigstore transparency entry: 1155386989
- Sigstore integration time:
-
Permalink:
willmccallion/rvsim@ff82152c40b46a1b1648e4110c6fbd372188e4fe -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/willmccallion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ff82152c40b46a1b1648e4110c6fbd372188e4fe -
Trigger Event:
push
-
Statement type:
File details
Details for the file rvsim-1.2.2-cp310-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: rvsim-1.2.2-cp310-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 868.6 kB
- Tags: CPython 3.10+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e3a6b9a95f0d77280c313596acce13dc730fb1994cb4310af3fa3a6d240c26f
|
|
| MD5 |
a49bd821b98bf42a0556894268de81e1
|
|
| BLAKE2b-256 |
703bd8008b1a8fe5130c35a995b2707e55fb2ed5ed459a2e8938da55762f98f1
|
Provenance
The following attestation bundles were made for rvsim-1.2.2-cp310-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on willmccallion/rvsim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rvsim-1.2.2-cp310-abi3-macosx_10_12_x86_64.whl -
Subject digest:
5e3a6b9a95f0d77280c313596acce13dc730fb1994cb4310af3fa3a6d240c26f - Sigstore transparency entry: 1155386992
- Sigstore integration time:
-
Permalink:
willmccallion/rvsim@ff82152c40b46a1b1648e4110c6fbd372188e4fe -
Branch / Tag:
refs/tags/v1.2.2 - Owner: https://github.com/willmccallion
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@ff82152c40b46a1b1648e4110c6fbd372188e4fe -
Trigger Event:
push
-
Statement type: