Configuration¶
Every aspect of the simulated machine is set through the Config class.
Its parameters are flat keywords; caches, predictors, backends, memory
controllers and the coherence fabric are small builder classes passed to
them. The Rust core checks each Config as a whole as it is constructed:
a value it cannot read, or a combination no machine can have (for example
a BTB whose set count is not a power of two, or an exclusive L1/L2 with
more than one core), raises rvsim.ConfigError, a ValueError, naming
the field before anything runs.
Basic Usage¶
from rvsim import Config, Cache, Backend, BranchPredictor, MemDepPredictor
config = Config(
width=4,
backend=Backend.OutOfOrder(rob_size=128),
branch_predictor=BranchPredictor.Tage(),
l1d=Cache("32KB", ways=8, latency=1, mshr_count=8),
l2=Cache("256KB", ways=8, latency=10),
)
Use replace() to derive new configs from a base; every Config keeps
its own copies of its components, so changing one never changes another:
base = Config(width=4, branch_predictor=BranchPredictor.Tage())
narrow = base.replace(width=2)
wide = base.replace(width=8)
Config() is a complete machine, a desktop out-of-order core of the
mid-2020s with three cache levels, every prefetcher and DDR5-5600: the
defaults below describe it, so a configuration changes only what it
names. rvsim.presets holds the others: basic(), which is Config();
fast(); rocket() and boom() for Chipyard's Rocket and Medium BOOM as
their RTL builds them (Error against Rocket,
Error against BOOM); and linux() for a system that boots
the bundled Linux image. See Benchmark Configs.
Pipeline¶
| Parameter | Type | Default | Description |
|---|---|---|---|
width |
int |
6 |
Instructions per cycle for every stage that has no width of its own |
fetch_width, decode_width, rename_width, issue_width, commit_width |
int |
width |
Per-stage widths |
fetch_block_bytes |
int or None |
None |
Bytes fetch reads a cycle: an aligned block of the I-cache line, at least 4 bytes and a power of two, ending the cycle's fetch at its end; None reads up to the end of the line |
writeback_width |
int |
width |
Results the out-of-order backend writes back per cycle; the rest wait for later cycles |
trap_latency |
int |
2 |
Cycles from commit detecting a trap or interrupt to the squash into its handler; an interrupt is taken on the instruction at the ROB head, unless that is an atomic or a device read already under way, and flushes what follows it |
redirect_latency |
int |
1 |
Cycles from execute resolving a misprediction, CSR write, fault or ordering violation to the squash into the redirect; commit retires nothing the pending squash will remove |
fetch_decode_latency |
int |
1 |
Cycles from fetch2 writing a bundle to decode reading it: one stage boundary, two for a front end with a stage between its cache response and decode (BOOM's F3); at least 1 |
decode_rename_latency |
int |
1 |
Cycles from decode to rename; 0 runs both in one stage, as Rocket's ID decodes and reads the registers together |
rename_issue_latency |
int |
2 |
Cycles from rename writing a bundle to the backend issuing from it: gem5's two from rename to IEW, Rocket's one from ID to EX; at least 1 on the in-order backend and 2 on the out-of-order one, whose dispatch takes a stage of its own |
csr_squash |
str |
"EveryAccess" (in-order), "Never" (O3) |
Which CSR accesses squash the instructions fetched behind them and refetch: "EveryAccess" (gem5's MinorCPU; BOOM, whose decoder flushes after every CSR instruction), "AffectingWrites" (Rocket: a write to any CSR but the scratch, epc, cause and tval ones, never a read) or "Never" (gem5's O3, which holds rename after one instead; the out-of-order backend only). The refetch is taken when the access commits, as Rocket's and BOOM's are |
fence_squash |
bool |
False |
Whether a FENCE squashes the instructions fetched behind it when it commits, as BOOM's does |
store_forward_latency |
int |
L1D hit latency | Cycles from a load matching a store in the store buffer to its data reaching writeback, where a load the L1D answers takes the L1D hit latency; 0 writes the load back in the cycle it matches (a forwarded vector span takes at least one cycle) |
backend |
Backend.* |
OutOfOrder() |
Backend.OutOfOrder(...) or Backend.InOrder() |
branch_predictor |
BranchPredictor.* |
ScLTage() |
Direction predictor, with ITTAGE for indirect targets (see below) |
btb_size |
int |
8192 |
Branch target buffer entries |
btb_ways |
int |
8 |
BTB associativity; btb_size / btb_ways must be a power of two |
btb_taken_bubbles |
int |
0 |
Cycles fetch idles after a taken branch the BTB predicts, before it fetches the target |
micro_btb |
MicroBtb or None |
None |
A smaller BTB looked up alongside the main one: MicroBtb(size=..., ways=..., taken_bubbles=...). It holds the branches most recently retired taken, and a taken branch it predicts costs its taken_bubbles instead of btb_taken_bubbles |
ras_size |
int |
32 |
Return address stack depth |
mem_dep_predictor |
MemDepPredictor.* |
StoreSet() |
Memory dependence predictor (see below) |
Backend: Out-of-Order¶
Backend.OutOfOrder(
rob_size=320, # Reorder buffer entries
issue_queue_size=128, # Unified issue queue entries (CAM wakeup/select)
store_buffer_size=72, # Store buffer entries
load_queue_size=128, # Load queue entries
load_ports=3, # Loads issued per cycle
store_ports=2, # Stores issued per cycle
prf_gpr_size=224, # Physical integer registers
prf_fpr_size=192, # Physical floating-point registers
fu_config=Fu([...]), # Functional unit pool (see below); Fu() by default
checkpoint_count=32, # Rename-map checkpoints for branch recovery (0: walk the ROB)
squash_width=8, # ROB entries a squash without a checkpoint walks per cycle
prf_vpr_size=96, # Physical vector registers
vec_chaining=True, # Let a dependent vector op start on the first element group
vec_store_buffer_size=8, # In-flight vector stores
vec_store_forwarding="ByteMask", # Vector store-to-load forwarding: "ByteMask", "Stall" or "Off"
)
- Register files. The integer and floating-point registers are two
files of
prf_gpr_sizeandprf_fpr_size, each with 32 holding the architectural registers, and rename stalls an instruction once the rest of its destination's file are destinations of instructions in flight, whatever the other file has free. The default's 192 integer and 160 FP rename registers are fewer than its 320-entry ROB, so a run of either kind can stall before the ROB fills. - Squash recovery. A mispredicted branch with a checkpoint restores the
rename map from it at once, and a squash whose branch has already retired,
or a trap, copies back the committed map at once. Any other squash (a
branch without a checkpoint, an ordering violation) walks the ROB back
squash_widthentries per cycle, and rename waits until it has finished. Rename stalls on a branch while every checkpoint is in use. - Stores issue in two halves when their data is not ready: the address as soon as the base register is, the data when the value is (see Pipeline).
- Vector store forwarding.
ByteMaskforwards any bytes a vector store holds, as most out-of-order cores do;Stallmakes an overlapping load wait for the store to be written, as Saturn does;Offtreats every overlap as a stall.
Backend: In-Order¶
Backend.InOrder(
fu_config=None, # Functional unit pool (see below); a dual-issue core's by default
rob_size=64, # Instructions in flight from issue to commit
store_buffer_size=16, # Committed stores waiting to drain
load_ports=1, # Loads reaching memory per cycle
store_ports=1, # Stores reaching memory per cycle
vec_store_buffer_size=8, # In-flight vector stores
vec_store_forwarding="ByteMask", # As for the out-of-order backend
)
The in-order backend issues in program order, up to issue_width per
cycle, with a scoreboard tracking operands. fu_config is its functional
unit pool, described under Functional Units below: when None, a
dual-issue core's, with two integer ALUs and one of every other unit at
the default machine's latencies.
Functional Units¶
from rvsim import Fu
fu = Fu([
Fu.IntAlu(count=4, latency=1), # add, sub, logic, shift, compare
Fu.IntMul(count=1, latency=3), # multiply (pipelined)
Fu.IntDiv(count=1, latency=14), # divide and remainder (not pipelined)
Fu.FpAdd(count=2, latency=3), # FP add, subtract, compare, convert
Fu.FpMul(count=2, latency=4), # FP multiply
Fu.FpFma(count=2, latency=4), # FP fused multiply-add
Fu.FpDivSqrt(count=1, latency=13), # FP divide and square root (not pipelined)
Fu.Branch(count=2, latency=1), # branch and jump resolution
Fu.Mem(count=3, latency=1), # load and store address generation
Fu.VecIntAlu(count=2, latency=1), # vector integer arithmetic and logic
Fu.VecIntMul(count=1, latency=3), # vector integer multiply
Fu.VecIntDiv(count=1, latency=14), # vector integer divide (not pipelined)
Fu.VecFpAlu(count=2, latency=3), # vector FP add, compare, convert
Fu.VecFpFma(count=2, latency=4), # vector FP multiply and fused multiply-add
Fu.VecFpDivSqrt(count=1, latency=13), # vector FP divide and square root (not pipelined)
Fu.VecMem(count=2, latency=1), # vector load and store address generation
Fu.VecPermute(count=1, latency=1), # slides, gathers, compress, moves
])
The list above is Fu(), the default machine's pool, and each unit's
count and latency default to its entry there. A scalar unit type left out of a
Fu list has no units, so an instruction that needs one never issues:
include every scalar type your workload uses. A vector unit type left out
gets one unit with the default latency. A vector instruction's time on its
unit also scales with vl over the number of lanes (num_vec_lanes,
below).
Branch Prediction¶
BranchPredictor.Static() # Always predicts not-taken
BranchPredictor.GShare() # PC XOR global history, 2-bit counters
BranchPredictor.Bht( # Rocket's BHT: counters indexed by the PC, hashed history above the PC bits
entries=512,
counter_bits=1,
history_length=8,
history_bits=3,
)
BranchPredictor.Tournament( # gem5's TournamentBP (Alpha 21264): local, global, choice
global_size_bits=12,
local_hist_bits=10,
local_pred_bits=10,
)
BranchPredictor.Perceptron( # Perceptron predictor
history_length=32,
table_bits=10,
)
BranchPredictor.Tage( # TAGEBase-style TAGE (defaults shown)
num_banks=8,
table_size=2048,
reset_interval=256_000,
history_lengths=[5, 11, 22, 44, 89, 178, 356, 712],
tag_widths=[8, 8, 9, 9, 10, 10, 11, 11],
)
BranchPredictor.ScLTage() # 64KB TAGE-SC-L with ITTAGE (Seznec's CBP-5 configuration)
Tage and ScLTage take further keywords for every structure of the
predictor (allocation and update rules, history kind, hashing, banking,
the bimodal table, USE_ALT_ON_NA counters); ScLTage adds the loop
predictor (loop_*), the statistical corrector (sc_*, with
BranchPredictor.ScGehl and BranchPredictor.ScLocalGehl components) and
ITTAGE (ittage_*). Their defaults reproduce Seznec's 64KB TAGE-SC-L.
Branch Prediction describes each
parameter.
Memory Dependence Prediction¶
Controls how a load decides whether it may issue ahead of older stores whose addresses are not known yet.
MemDepPredictor.Blind() # Loads wait for every older store's address
MemDepPredictor.StoreSet( # Store-set predictor (Chrysos & Emer 1998), the default
ssit_size=1024, # Store Set ID Table entries (PC -> store set)
lfst_size=1024, # Last Fetched Store Table entries (store set -> last store)
)
The store-set predictor learns from ordering violations and wipes both tables every 250,000 memory instructions.
Caches¶
Each level is configured independently. The builder's own defaults (a
4 KiB direct-mapped cache) are shown; Config's default levels are in the
table below.
Cache(
size="4KB", # "4KB", "32KB", "1MB", or bytes
line="64B", # Line size; at least the 64-byte block CBOs act on
ways=1, # Associativity
latency=1, # Tag and data access latency in cycles
response_latency=1, # Cycles from a fill arriving to answering its requests
mshr_count=None, # Lines fetched at once (None = the default, 8)
write_buffers=None, # Evicted lines in flight to the next level (None = the default, 8)
targets_per_mshr=None, # Requests one MSHR can hold (None = the default, 20)
policy=None, # Eviction policy; ReplacementPolicy.Lru() when None
prefetcher=None, # Hardware prefetcher; Prefetcher.Off() when None
)
| Parameter | Type | Default | Description |
|---|---|---|---|
l1i |
Cache or None |
32 KiB, 8-way, PLRU, 1 cycle, next-line prefetch, 8 MSHRs | L1 instruction cache |
l1d |
Cache or None |
48 KiB, 12-way, PLRU, latency=4 (5-cycle load-to-use), next-line prefetch, 16 MSHRs |
L1 data cache |
l2 |
Cache or None |
1 MiB, 8-way, PLRU, latency=8 (14-cycle load-to-use), stream prefetch (degree 4), 32 MSHRs |
Private L2 |
l3 |
Cache or None |
32 MiB, 16-way, PLRU, latency=35 (50-cycle load-to-use), 64 MSHRs |
Shared last-level cache |
inclusion_policy |
Cache.* |
Cache.Nine() |
Relationship between L1 and L2 |
wcb_entries |
int |
16 |
Write-combining buffer entries between the store buffer and the L1D: 0 for none, otherwise at least 2, since a store across two lines takes an entry for each |
wcb_idle_cycles |
int |
16 |
Cycles a partly written WCB line waits for another store before it is written. No core documents its value; this default is not fitted to a measurement |
load_prefetcher |
LoadPrefetcher.Stride or None |
64 entries, 4 lines ahead in the L1D and 16 in the L2, crossing pages through the TLB | The load/store unit's load prefetcher (see below) |
store_prefetcher |
StorePrefetcher.Stream or None |
4 streams, 8 lines ahead | The L1D's store-miss prefetcher, which fills the L2 (see below) |
write_streaming |
WriteStreaming or None |
None |
When a run of whole-line writes stops allocating (see below) |
A load that hits takes one cycle of address generation plus the L1D's
latency to reach its dependents, so latency=3 models a 4-cycle
load-to-use. None disables a level. The default machine's load-to-use
figures are each level's own: a dependent pointer chase over a footprint
that level holds, with the levels above it shrunk to a few KiB at their
own latencies and a TLB large enough that no step walks.
MSHRs and writeback buffers
Every level fetches at most mshr_count lines at a time and keeps at
most write_buffers evicted lines in flight to the next level; while
either is exhausted, or one MSHR holds targets_per_mshr requests, the
cache blocks and later requests queue. None leaves the simulator
default in place (8, 8 and 20); mshr_count=1 gives a blocking cache
that serialises its misses. Each must be at least 1: a Config or
config dict holding 0 is refused.
Replacement Policies¶
ReplacementPolicy.Lru() # Least recently used (default)
ReplacementPolicy.Plru() # Bit pseudo-LRU: one bit per way
ReplacementPolicy.Fifo() # First in, first out
ReplacementPolicy.Random() # Random eviction
ReplacementPolicy.Mru() # Most recently used
Prefetchers¶
Prefetcher.Off() # None (the default for Cache())
Prefetcher.NextLine(degree=1) # The next `degree` lines on every access
Prefetcher.Stride(degree=1, table_size=64) # PC-indexed constant-stride detection
Prefetcher.Stream(degree=1) # Ascending or descending streams
Prefetcher.Tagged(degree=1) # Next lines on a miss or a first use of a prefetched line
A prefetch is a real fetch: it takes an MSHR (never the last free one) and travels down the hierarchy like a demand miss. A cache sees physical addresses only, so its prefetcher never crosses the 4 KiB page of the access that triggered it.
Load and store prefetchers¶
The L1D's prefetching on a real core lives in the load/store unit, where each load's PC, virtual address and translation are known. These follow the Cortex-A72's documented prefetcher; the memory hierarchy page gives the design and its sources.
LoadPrefetcher.Stride(
table_size=64, # PC-indexed entries, a power of two
l1_lines=4, # Lines kept ahead in the L1D
l2_lines=0, # Lines kept ahead in the L2 alone (the A72 keeps 22)
page_boundary=None, # PageBoundary.Stop() (when None) or PageBoundary.CrossWithTlb()
)
StorePrefetcher.Stream(
streams=4, # Runs of store misses tracked at once
l2_lines=8, # Lines kept ahead in the L2, with write permission
)
PageBoundary.Stop() keeps a stream inside the page of the load that
trained it, at that page's size; PageBoundary.CrossWithTlb() continues
into the next page when the data TLB holds its translation and drops the
prefetch when it does not. Both are passed to Config:
Config(
load_prefetcher=LoadPrefetcher.Stride(l1_lines=1, l2_lines=22,
page_boundary=PageBoundary.CrossWithTlb()),
store_prefetcher=StorePrefetcher.Stream(),
)
Write streaming¶
A copy or a fill writes whole lines it never reads, and a cache that
fetches each line before overwriting it moves twice the data. Some cores
stop allocating such a run: the Cortex-A72's load/store unit, at its reset
settings (CPUACTLR_EL1[28:25]), stops filling the L1D from the 4th
consecutive whole-line write and the L2 as well from the 12th.
Config(
wcb_entries=4, # whole lines come from the write-combining buffer
write_streaming=WriteStreaming(skip_l1_from=4, skip_l2_from=12),
)
A run is whole-line writes to adjacent lines in one direction; a write to
part of a line ends it, and loads do not. From skip_l1_from, a
whole-line write that misses the L1D is performed and acknowledged without
fetching the line, and goes to the L2, which keeps it without reading
memory. From skip_l2_from the L2 passes it on too, and memory takes it
as it takes a writeback. With several harts, an L2 that passes a line on
sends the home a WriteUniqueFull, which invalidates every other copy; one
asked to keep a line it does not hold fetches ownership first, where a CHI
system would send a dataless MakeUnique. skip_l2_from must be at least
skip_l1_from.
Inclusion Policies¶
Cache.Nine() # Neither inclusive nor exclusive (default)
Cache.Inclusive() # An L2 eviction back-invalidates the L1 copies
Cache.Exclusive() # L1 victims go to the L2; an L1 fill takes the L2's copy
Memory and Translation¶
| Parameter | Type | Default | Description |
|---|---|---|---|
ram_size |
str or int |
"256MB" |
Main memory size |
memory_controller |
MemoryController.* |
Ddr5(speed_bin="Ddr5_5600B"), two channels (324-cycle, 81 ns load-to-use) |
Memory controller (see below) |
tlb_size |
int |
64 |
Entries in each of the instruction and data L1 TLBs |
tlb_ways |
int |
0 |
L1 TLB associativity; 0 is fully associative |
l2_tlb_size |
int |
2048 |
Entries in the shared L2 TLB; 0 disables it |
l2_tlb_ways |
int |
8 |
L2 TLB associativity |
l2_tlb_latency |
int |
7 |
L2 TLB lookup latency in cycles: a hit proceeds, and a miss starts its walk, this long after the L1 TLB missed |
walk_cache_entries |
int |
0 |
Pointer PTEs the page-table walker caches, so a walk can start below the root (at most 256); 0 for none |
walker_port |
str |
"L1D" |
The cache the page-table walker reads PTEs from: "L1D", or "L2" as on the Cortex-A72 (needs an L2) |
page_walkers |
int |
1 |
Page-table walks the core runs at once (at least 1); a TLB miss beyond them waits for a walker |
walker_sharing |
str |
"Shared" |
"Shared": fetch and data walks share the page_walkers, as on Rocket and BOOM; "PerSide": each has page_walkers of its own, as gem5's instruction and data TLBs each have a walker |
paging_mode_max |
str |
"Sv57" |
Strongest paging mode satp accepts ("Bare", "Sv39", "Sv48", "Sv57"); a stronger mode written to satp reads back as Bare, which makes a kernel fall back |
misaligned_access_trap |
bool |
False |
Raise address-misaligned exceptions instead of performing misaligned accesses in hardware |
isa |
str or None |
None |
The ISA the hart implements, as the compiler's -march, spike's --isa and /proc/cpuinfo spell it: the single letters (G is IMAFD, B is Zba, Zbb and Zbs together), then every multi-letter extension, such as "rv64gcv_zba_zbb_zbs_zicbom_zicboz"; the vector crypto groups zvkn, zvknc, zvkng, zvks, zvksc and zvksg stand for their members. It sets misa, what the decoder accepts (an instruction of an extension left out raises an illegal-instruction exception) and what the device tree advertises. None is everything the simulator implements; Config().isa_string() shows the resolved string. Zicsr, Zifencei, Zicntr, Zihintpause, Zihpm and Sstc are always implemented, and an unknown name is refused. Without C every instruction is 32 bits: fetch steps a word at a time and a word whose low bits are not 11 is illegal |
svadu |
bool |
False |
Implement Svadu: with menvcfg.ADUE set the page-table walker sets A and D bits itself; otherwise a missing A or D bit faults (Svade) |
Memory Controllers¶
MemoryController.Simple( # Fixed latency, serialised on a bandwidth:
latency=120, # Core cycles from the controller starting a request to its data
bandwidth_gib_s=12.8, # each request busies the controller for its bytes' time
)
MemoryController.Dram( # Row-buffer DRAM: per-bank open rows and refresh
t_cas=14, # Column access, cycles
t_ras=14, # Row activate, cycles
t_pre=14, # Precharge, cycles
)
# Simple and Dram post a cache's writeback: it is acknowledged as the
# controller takes it in (Simple waits for its bandwidth), and Dram still
# opens its row. Other requests are answered after their access.
MemoryController.Ddr5( # Command-level JEDEC DDR5 (see Memory Hierarchy); the
# default machine's is Ddr5(speed_bin="Ddr5_5600B")
speed_bin="Ddr5_4800B", # "Ddr5_4800B" or "Ddr5_5600B"
channels=2, # Channels; each has two 32-bit sub-channels
subchannels_per_channel=2,
ranks_per_channel=2,
bank_groups_per_rank=8,
banks_per_group=4,
row_bits=16,
column_bits=6, # Rows of 64 << column_bits bytes
read_queue_entries=64,
write_queue_entries=64,
write_high_watermark=54, # Start draining writes at this depth
write_low_watermark=32, # Return to reads at this depth
min_writes_per_switch=16,
frontend_latency_ns=10, # Controller pipeline
backend_latency_ns=10,
scheduler="FrFcfs", # or "Fcfs"
refresh="AllBank", # or "SameBank"
address_mapping="RoRaBaChCo", # or "RoRaBaCoCh", "RoCoRaBaCh"
power_down_idle_ns=None, # e.g. 200 to enable rank power-down
ecc="None", # "SecDed" or "ChipKill"
patrol_scrub_ns=None, # e.g. 100_000 to enable patrol scrubbing
timing=None, # Per-field overrides in DRAM command clocks, e.g. {"t_rcd": 40}
)
MemoryController.Lpddr4( # Command-level JEDEC LPDDR4 on the same controller
speed_bin="Lpddr4_3200",
density="Gb16", # Per-channel die: "Gb4", "Gb8" or "Gb16"
channels=2, # 16-bit channels; an x32 package has two
ranks_per_channel=1,
read_queue_entries=64, # Queues, latencies and policies as for Ddr5
write_queue_entries=64,
write_high_watermark=54,
write_low_watermark=32,
min_writes_per_switch=16,
frontend_latency_ns=10,
backend_latency_ns=10,
scheduler="FrFcfs",
refresh="AllBank", # or "PerBank" (REFpb, one bank every tREFI / 8)
address_mapping="RoRaBaChCo",
power_down_idle_ns=None,
timing=None,
)
On the DRAM controller a row hit costs t_cas and a row miss
t_pre + t_ras + t_cas. The DDR5 and LPDDR4 controllers run at the DRAM command clock
(half the data rate) and convert to and from the core clock through cpu_clock_mhz; their statistics appear under
memctrl0.ch<C>.sc<S>.*. Every controller sits behind the system bus, so a
miss to memory also pays bus_latency each way.
Vector Extension¶
| Parameter | Type | Default | Description |
|---|---|---|---|
vlen |
int |
256 |
Vector register length in bits, a power of two from 128 to 2048 |
num_vec_lanes |
int |
vlen / 64, at least 1 |
64-bit lanes the vector units process per cycle |
vector_mem_width |
int |
vlen / 8, at most 64 |
Bytes one unit-stride vector memory access moves (the vector load-store datapath), a power of two from 8 to 64 |
ELEN is 64 and Zvfh is implemented.
System¶
These parameters set the SoC's memory map, clocks and devices. You
normally need to change only cpu_clock_mhz, hart_count and the
console.
| Parameter | Type | Default | Description |
|---|---|---|---|
cpu_clock_mhz |
int |
4000 |
Core clock: converts between cycles and time for SE mode's time syscalls, the DDR5 and LPDDR4 controllers, device latencies, the RTC and a real-time timer |
hart_count |
int |
1 |
Harts in the system, one per core (see Multi-core) |
bus_width |
int |
8 |
System bus width in bytes |
bus_latency |
int |
1 |
System bus latency in cycles, each way |
bus_clock_divider |
int |
1 |
Core cycles per bus clock: each bus_width-byte beat takes this many cycles |
bus_channels |
str |
"RequestResponse" |
"RequestResponse": one channel out (address and write data) and one back (read data or acknowledgement), as TileLink and gem5's crossbar; "Axi": AXI's five channels |
device_latency_ns |
int |
100 |
Time every device takes to answer a register access |
device_latency_ns_overrides |
dict |
None |
Per-device access latency by name (UART0, CLINT, PLIC, VirtIO-Blk, SysCon, GoldfishRTC, HTIF) |
timer |
str |
"RealTime" |
How mtime advances: "RealTime" at timebase_hz, so guest time keeps pace with the core clock, or "EveryCycle", every cycle, so guest time runs cpu_clock_mhz * 10**6 / timebase_hz times fast |
timebase_hz |
int |
10_000_000 |
The timer frequency the device tree reports; for a "RealTime" timer it must divide the core clock |
rtc_epoch_seconds |
int |
1767225600 |
Wall-clock time the RTC reports at cycle zero (2026-01-01), advanced by simulated time so runs are reproducible |
ram_base |
int |
0x8000_0000 |
RAM base address |
uart_base |
int |
0x1000_0000 |
UART base address |
disk_base |
int |
0x9000_0000 |
VirtIO disk base address |
clint_base |
int |
0x0200_0000 |
CLINT base address |
syscon_base |
int |
0x0010_0000 |
SYSCON base address |
kernel_offset |
int |
0x0020_0000 |
Kernel load offset from ram_base |
Multi-core¶
hart_count=N builds N single-threaded cores, each with its own
pipeline, branch predictor, TLBs and private L1 and L2, sharing the LLC,
memory and devices. Every hart has its own CLINT timer and
software-interrupt registers and its own PLIC contexts, and the generated
device tree enumerates them. Bare-metal programs start every hart at the
entry point with a0 holding the hart id and a1 the hart count.
from rvsim import Config, Coherence, HomeAgent, Interconnect
config = Config(
width=4,
hart_count=4,
coherence=Coherence(
home_agent=HomeAgent.SnoopFilter(capacity_factor=1.5, ways=8),
interconnect=Interconnect.Mesh(hop_latency=2, bytes_per_cycle=32),
),
)
With more than one core the private L2s become requesting agents on a
coherence fabric: MESI states in every private cache, a home agent at the
LLC that serialises requests per line and decides who is snooped, and an
interconnect that carries request, snoop, response and data messages on
separate virtual channels. The L2 is made inclusive of its L1s so snoops
are answered from its tags; Cache.Exclusive() is therefore rejected
with hart_count > 1. A single core builds no fabric.
| Parameter | Type | Default | Description |
|---|---|---|---|
coherence.home_agent |
HomeAgent.* |
HomeAgent.SnoopFilter() |
Who must be snooped for a request |
coherence.interconnect |
Interconnect.* |
Interconnect.Crossbar() |
Message transport between the L2s and the home |
coherence.txn_entries |
int |
32 |
Transactions the home can have live at once |
Home agents¶
HomeAgent.SnoopFilter(capacity_factor=1.5, ways=8) # exact sharers and owner per tracked line (default)
HomeAgent.Broadcast() # track nothing; snoop every other core
The snoop filter tracks capacity_factor times the aggregate private L2
lines in a ways-way set-associative array. When a set is full, its least
recently used line is recalled (every holder invalidated) before a new
line is tracked, as Arm's snoop filter and AMD's probe filter do.
Interconnects¶
Interconnect.Crossbar(hop_latency=2, bytes_per_cycle=32) # any port to any port (default)
Interconnect.Ring(hop_latency=2, bytes_per_cycle=32) # bidirectional ring, shorter direction
Interconnect.Mesh(hop_latency=2, bytes_per_cycle=32) # square 2-D mesh, XY routing
Interconnect.Torus(hop_latency=2, bytes_per_cycle=32) # mesh with wraparound
Interconnect.Hypercube(hop_latency=2, bytes_per_cycle=32) # dimension-order routing
hop_latency is the cycles a message spends per hop and bytes_per_cycle
the width of a port or link; a 64-byte data message on a 32-byte link
occupies it for two cycles. The crossbar is one hop; the routed networks
place the cores and the home on their nodes and charge every hop.
The fabric reports under coherence.ha.* (requests by kind, snoops,
cache-to-cache transfers, recalls, transaction latency) and
coherence.interconnect.* (messages, bytes, busy and blocked cycles);
each private cache counts its snoops under
core<N>.cache.<level>.coherence.*. See Multi-core.
General¶
| Parameter | Type | Default | Description |
|---|---|---|---|
trace |
bool |
False |
Emit a trace event at every pipeline stage an instruction passes. RUST_LOG selects which are printed: rvsim=trace for all, or targets such as rvsim::commit=trace, rvsim::mem=trace and rvsim::fwd=trace |
console |
ConsoleMode or str |
"Stdout" |
Where the guest's console connects, for the UART, HTIF's console and a user program's stdin, stdout and stderr: ConsoleMode.STDOUT, STDERR, QUIET, or CAPTURED (kept in memory for read_console(), input given with write_console()), or the same names as strings: "Stdout", "Stderr", "Quiet", "Captured" |
What a configuration must satisfy¶
The core checks the whole configuration when a Config is constructed,
and again when a simulator is built from a Config or a config dict;
rvsim._core.check_config(config.to_dict()) runs the same checks on their
own. A configuration that breaks a rule raises rvsim.ConfigError (a
ValueError) naming the field, rather than hanging, crashing or quietly
building another machine:
- Room to work. Every width, the ROB, the issue queue, the load queue,
the store buffer, the load and store ports,
squash_width, the vector store buffer, the L1 TLB,hart_count,cpu_clock_mhz,timebase_hz, the coherence transaction entries and the interconnect'sbytes_per_cycleare at least 1. - Registers. On the out-of-order backend
prf_gpr_sizeandprf_fpr_sizeeach hold their 32 architectural registers and at least one more, andprf_vpr_sizeholds the 32 architectural vector registers and one eight-register group, at least 40. - Units. The unit pool has an integer ALU, a branch unit and a memory unit, a multiplier and a divider when the ISA has M, and every FP unit when it has F or D. A vector unit type left out gets one unit.
- Caches. An enabled level holds a whole number of sets; its lines are a power of two of at least 64 bytes, the same at every level; PLRU replacement tracks at most 63 ways; a stride prefetcher's table is a power of two and every prefetcher's degree at least 1.
- TLBs. A set-associative TLB fills a power-of-two number of sets;
0ways is fully associative. - Memory and the address map.
ram_sizeis a non-zero multiple of 4 KiB that holdskernel_offset, the bus is a power of two bytes wide, and a DRAM controller has banks and power-of-two rows. RAM and the devices' register windows do not overlap: the UART's 256 bytes atuart_base, VirtIO's 4 KiB atdisk_base, the CLINT's 64 KiB atclint_base, the system controller's 4 KiB atsyscon_base, the PLIC's 64 MiB at0x0c00_0000and the RTC's 4 KiB at0x10_1000. With the default map RAM ends wheredisk_basebegins, so more than 256 MB of RAM needsdisk_basemoved, aspresets.linux()does. - Predictors. The BTB has a power-of-two set count; TAGE and ITTAGE
tables are powers of two with one history length and one tag width per
bank. TAGE histories are at most 8192 bits and ITTAGE ones at most 1024,
the global history register's size. Tables stay small enough to allocate: perceptron
table_bitsat most 20 andhistory_lengthat most 63, tournament tables at most 24 bits, the loop predictor at most 2^20 entries and the write-combining buffer at most 1024 entries. - Names.
device_latency_ns_overridesnames devices the system has.
A BTB or return stack of size 0, zero-latency units or memory, an L2 smaller than the L1D and a cache with a set count that is not a power of two are allowed: they describe machines that work.
Example Configurations¶
Minimal embedded core¶
Config(
width=1,
backend=Backend.InOrder(),
branch_predictor=BranchPredictor.Static(),
l1d=Cache("4KB", ways=1, latency=1),
l1i=Cache("4KB", ways=1, latency=1),
l2=None,
)
High-performance out-of-order core¶
Config(
width=4,
backend=Backend.OutOfOrder(
rob_size=128,
issue_queue_size=48,
load_queue_size=32,
store_buffer_size=32,
prf_gpr_size=256,
prf_fpr_size=128,
checkpoint_count=32,
fu_config=Fu([
Fu.IntAlu(count=4, latency=1),
Fu.IntMul(count=1, latency=3),
Fu.IntDiv(count=1, latency=35),
Fu.FpAdd(count=2, latency=4),
Fu.FpMul(count=2, latency=5),
Fu.FpFma(count=2, latency=5),
Fu.FpDivSqrt(count=1, latency=21),
Fu.Branch(count=2, latency=1),
Fu.Mem(count=2, latency=1),
]),
),
branch_predictor=BranchPredictor.ScLTage(),
mem_dep_predictor=MemDepPredictor.StoreSet(),
l1d=Cache("32KB", ways=8, latency=3, mshr_count=8,
prefetcher=Prefetcher.Stride(degree=2, table_size=128)),
l1i=Cache("32KB", ways=8, latency=1,
prefetcher=Prefetcher.NextLine(degree=2)),
l2=Cache("256KB", ways=8, latency=12, mshr_count=16),
l3=Cache("4MB", ways=16, latency=30, mshr_count=32),
memory_controller=MemoryController.Ddr5(speed_bin="Ddr5_5600B"),
l2_tlb_size=1024,
)
Linux-capable system¶
presets.linux() places a core in a system that boots the bundled Linux
image; see Linux Boot.