ISARef Multi-ISA & Silicon Reference
45,419 ISA items · 105,907 timings · 1,823 microarchs · 16,083 chips · 105 sources
Arch:
Tier:

Smctr

T1 riscv feature feature
Control Transfer Records
SourceRISC-V Official Unified Database (riscv-unified-db) (riscv_unified_db)
Reliability TierT1 — Official Specification
ISA / Silicon Scopev1.0.0 (ratified)
RV32 / RV64 (Ratified & Standard Extensions)
License & VersionApache-2.0 / CC-BY-4.0
main
Upstreamhttps://github.com/riscv/riscv-unified-db
Privilegeprivileged
ExtensionsS, Smcsrind, Ssctr

Summary

A method for recording control flow transfer history is valuable not only for performance profiling but also for debugging. Control flow transfers refer to jump instructions (including function calls and returns), taken branch instructions, traps, and trap returns. Profiling tools, such as Linux perf, collect control transfer history when sampling software execution, thereby enabling tools, like AutoFDO, to identify…

Syntax / Encoding

Smctr v1.0.0 (ratified)

Reference Notes

A method for recording control flow transfer history is valuable not only for performance
profiling but also for debugging.
Control flow transfers refer to jump instructions (including function calls and returns), taken
branch instructions, traps, and trap returns.
Profiling tools, such as Linux perf, collect control transfer history when sampling software
execution, thereby enabling tools, like AutoFDO, to identify hot paths for optimization.

Control flow trace capabilities offer very deep transfer history, but the volume of data produced
can result in significant performance overheads due to memory bandwidth consumption, buffer
management, and decoder overhead.
The Control Transfer Records (CTR) extension provides a method to record a limited history in
register-accessible internal chip storage, with the intent of dramatically reducing the
performance overhead and complexity of collecting transfer history.

CTR defines a circular (FIFO) buffer. Each buffer entry holds a record for a single recorded
control flow transfer.
The number of records that can be held in the buffer depends upon both the implementation (the
maximum supported depth) and the CTR configuration (the software selected depth).

Only qualified transfers are recorded.
Qualified transfers are those that meet the filtering criteria, which include the privilege mode
and the transfer type.

Recorded transfers are inserted at the write pointer, which is then incremented, while older
recorded transfers may be overwritten once the buffer is full.
Or the user can enable RAS (Return Address Stack) emulation mode, where only function calls are
recorded, and function returns pop the last call record.
The source PC, target PC, and some optional metadata (transfer type, elapsed cycles) are stored
for each recorded transfer.

The CTR buffer is accessible through an indirect CSR interface, such that software can specify
which logical entry in the buffer it wishes to read or write.
Logical entry 0 always corresponds to the youngest recorded transfer, followed by entry 1 as the
next youngest, and so on.