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.1.tar.gz (275.2 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.1-cp310-abi3-win_amd64.whl (331.1 kB view details)

Uploaded CPython 3.10+Windows x86-64

rvsim-0.10.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (466.3 kB view details)

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

rvsim-0.10.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (452.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

rvsim-0.10.1-cp310-abi3-macosx_11_0_arm64.whl (414.0 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

rvsim-0.10.1-cp310-abi3-macosx_10_12_x86_64.whl (439.0 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: rvsim-0.10.1.tar.gz
  • Upload date:
  • Size: 275.2 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.1.tar.gz
Algorithm Hash digest
SHA256 272e7727f5134c754dbb41c68542d767f11ec25df975b762a3236b8b4dd05e9c
MD5 61a3968dfa26fe8152d15571ee2e5aea
BLAKE2b-256 204813d9035fcb34dc44eea2d304ca527fa117218f93edec51309f29b798ac55

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.1.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.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: rvsim-0.10.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 331.1 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.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 d37fa8f6fe6a6e81934d084a58a99a80fd6303d78a633706f5da02ec15625cd7
MD5 00379806202fa416504cd5d776640ff9
BLAKE2b-256 47c6787233f74b0638a821cacdda695dae224a3527bdf694c35d7dc0c9916f45

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.1-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.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rvsim-0.10.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 64e05074dbdeb8bc6a7610d4adf93a42fc756165b02f02471ae72e041e1217be
MD5 0ec798b2c64b1d2a5c5be07d03a5e297
BLAKE2b-256 cb5c0ec55062f4d628b5a0d994430abfbdc0d413b0b842e70518c88ab507eb92

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.1-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.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for rvsim-0.10.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f1eeb705e6dab8eca9b70eeb26642d88e4dbd9eaee9cac72c06506f09dac9854
MD5 b7d4b7e1228c6b7dc73c2ba50e5f3720
BLAKE2b-256 b9d77de7e463db46b41af33667b0f4d55350a9022c2cab265775c00975c53578

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.1-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.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rvsim-0.10.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c6b73610d4d91d6e0e7bbbc8fbd4a958fc4f89d55affc29afc190191259f125
MD5 f35d635d6871f718b38887b25d1df88b
BLAKE2b-256 3ea903f716f10087a64f7c36f746969a23b6c361a883bd90e03dcca58cb5530d

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.1-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.1-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for rvsim-0.10.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b07534334939ecf53fc41a0d225e66f8b2bb5363e9d2f2a58f3d8f246b87c64e
MD5 63e87ac538f9de75184ecf55b532582d
BLAKE2b-256 f58a7523cb6b3c4ed2325c76a39cc57bbd73ac2bb17c4bf7b8944245d777635a

See more details on using hashes here.

Provenance

The following attestation bundles were made for rvsim-0.10.1-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