Skip to main content

High-performance RISC-V cycle-accurate system simulator

Project description

RISC-V 64-bit System Simulator

A cycle-accurate system simulator for the RISC-V 64-bit architecture (RV64IMAFD). Features a 5-stage pipelined CPU, comprehensive memory hierarchy, and can boot Linux (experimental).

Technologies Used

  • Languages: Rust (Simulator), C (Libc/Software), RISC-V Assembly, Python (Analysis)
  • Concepts: Pipelining, Virtual Memory (SV39), Cache Coherence, Branch Prediction, OS Development
  • Tools: Make, GCC Cross-Compiler, Cargo

Key Implementation Details

CPU Core (Rust)

  • 5-Stage Pipeline: Implements Fetch, Decode, Execute, Memory, and Writeback stages with full data forwarding and hazard detection.
  • Branch Prediction: Multiple swappable predictors including Static, GShare, Tournament, Perceptron, and TAGE (Tagged Geometric History).
  • Floating Point: Support for single and double-precision floating-point arithmetic (F/D extensions).

Memory System

  • Memory Management Unit (MMU): Implements SV39 virtual addressing with translation lookaside buffers (iTLB and dTLB).
  • Cache Hierarchy: Configurable L1, L2, and L3 caches supporting LRU, PLRU, and Random replacement policies.
  • DRAM Controller: Simulates timing constraints including row-buffer conflicts, CAS/RAS latency, and precharge penalties.

Example Programs (C & Assembly)

  • Custom Libc: A minimal standard library written from scratch (includes printf, malloc, string manipulation).
  • Benchmarks: Complete programs including chess engine, raytracer, quicksort, and performance microbenchmarks.
  • User Programs: Various test applications (Game of Life, Mandelbrot, 2048, etc.).

Performance Analysis

  • Automated Benchmarking: Python scripts to sweep hardware parameters (e.g., cache size vs. IPC) and visualize bottlenecks.
  • Design Space Exploration: Hardware configuration comparison and performance analysis tools.

Project Structure

rvsim/
├── crates/              # Rust workspace
│   ├── hardware/        # CPU simulator core
│   └── bindings/        # Python bindings (PyO3)
├── rvsim/               # Python package for scripting
├── software/            # System software
│   ├── libc/            # Custom C standard library
│   └── linux/           # Linux boot configuration
├── examples/            # Example programs
│   ├── benchmarks/      # Performance benchmarks
│   └── programs/        # User applications
├── scripts/             # Analysis and utilities
│   ├── benchmarks/      # Performance analysis scripts
│   └── setup/           # Installation helpers
└── docs/                # Documentation

Installation

Python bindings (via pip):

pip install rvsim

Build from Source

Requirements:

  • Rust toolchain (1.70+)
  • riscv64-unknown-elf-gcc cross-compiler
  • Python 3.10+ with maturin (for Python bindings)

Quick Start

Build everything:

make build

Run a benchmark:

rvsim -f software/bin/benchmarks/qsort.bin

Run a Python script:

rvsim --script scripts/benchmarks/tests/smoke_test.py

Available Make Targets

make help           # Show all available targets
make python         # Build and install Python bindings (editable)
make software       # Build libc and example programs
make test           # Run Rust tests
make lint           # Format check + clippy
make run-example    # Quick test (quicksort benchmark)
make clean          # Remove all build artifacts

Python Scripting

The simulator supports Python scripting for hardware configuration and performance analysis:

from rvsim import SimConfig, Simulator

# Configure a machine model
config = SimConfig.default()
config.pipeline.width = 4
config.pipeline.branch_predictor = "TAGE"
config.cache.l1_i.enabled = True
config.cache.l1_i.size_bytes = 65536

# Run a binary
Simulator().with_config(config).binary("software/bin/benchmarks/qsort.bin").run()

See docs/ for full API documentation and architecture details.

Documentation

Linux Boot (Experimental)

⚠️ Experimental Feature — The simulator can boot Linux, though full boot is still in progress:

make linux          # Download and build Linux (takes time)
make run-linux      # Attempt to boot Linux

License

Licensed under either of the following, at your option:

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project shall be dual-licensed as above, without any additional terms or conditions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rvsim-0.10.2.tar.gz (280.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rvsim-0.10.2-cp310-abi3-win_amd64.whl (339.5 kB view details)

Uploaded CPython 3.10+Windows x86-64

rvsim-0.10.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (474.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

rvsim-0.10.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (461.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

rvsim-0.10.2-cp310-abi3-macosx_11_0_arm64.whl (423.1 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

rvsim-0.10.2-cp310-abi3-macosx_10_12_x86_64.whl (446.9 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file rvsim-0.10.2.tar.gz.

File metadata

  • Download URL: rvsim-0.10.2.tar.gz
  • Upload date:
  • Size: 280.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rvsim-0.10.2.tar.gz
Algorithm Hash digest
SHA256 caa25b620ccc4ece46eb35de78d6961d7f9735eabe92cb07f09e9335393ad2e9
MD5 1673b35a538cd92425d9fb08d70ebf85
BLAKE2b-256 1e2ae16ac93299aa6a8aad7b9a67e95832a4d548d52a6291c7b9e4f392b85dd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.2.tar.gz:

Publisher: release.yml on willmccallion/rvsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rvsim-0.10.2-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: rvsim-0.10.2-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 339.5 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

Hashes for rvsim-0.10.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c7eb2592093447c33b035dfab5aece2c77a9d56038cb2d1fa15bdbe8cff33e3c
MD5 85127e2b57769ba2232eb308e93027cb
BLAKE2b-256 dce7b28257394fd03a70241be4729c64f794e21b4c55731a51c7231591e504eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.2-cp310-abi3-win_amd64.whl:

Publisher: release.yml on willmccallion/rvsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rvsim-0.10.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rvsim-0.10.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 85efe2a2b29a36f31ad9822a0302f1e3ca7139721f61f51915020fad283c9b5f
MD5 d3e1e401aca63f46b3dbfb4918892c52
BLAKE2b-256 4e2a23ba9396c501e5bed6b6e82dee5b4632332244b459bf82003c49eb7a5390

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on willmccallion/rvsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rvsim-0.10.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rvsim-0.10.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2d665480ffc769c050a02ee8a78f932298bd0e090293da67cef8ef8ced90ede3
MD5 909226796170695a60407309721848a3
BLAKE2b-256 d6f61da3e690a6e9fb8af0dd62bae9ef234da11bc8509b65123f8819928a4ae9

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on willmccallion/rvsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rvsim-0.10.2-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rvsim-0.10.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 04dbf408d3a16b3d90ccbc72156fa5e9751d891369b14a999535ba6e740caec4
MD5 7b599a7f9faa4f01f5ff08fd8adcb230
BLAKE2b-256 be35db2fad21beada9ec134aa3af77465693b7f933d3411a999d002b5a64cb8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.2-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on willmccallion/rvsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rvsim-0.10.2-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for rvsim-0.10.2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b57c6aa322ea60a10991702e3cbbc0dc00e1f47a441413d15f31f7501cf14164
MD5 1c94669a0274ac0b09bb832f1f594c73
BLAKE2b-256 a7bf08bfbeab0418fbbf80c9dc682be0551c4348dccd8e41be33b5fc3f276c49

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.2-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on willmccallion/rvsim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page