[PATCH v4 0/7] riscv: pmu: Add support for Control Transfer Records Ext.
From: Vikram Singh
Date: Fri Nov 06 2026 - 12:46:42 EST
This series enables Control Transfer Records extension support on riscv
architecture. This extension is similar to Arch LBR in x86 and BRBE in ARM.
The Extension has been ratified and latest release can be found here [0]
CTR extension depends on both the implementation of S-mode and Sscsrind
extension v1.0.0 [1]. CTR access ctrsource, ctrtartget and ctrdata CSRs
using sscsrind extension.
The series is based on Smcdeleg/Ssccfg counter delegation extension [2]
patches [3]. CTR itself doesn't depend on counter delegation support. This
rebase is basically to include the Smcsrind patches.
The last patch is in the perf tool to allow processing 256 entries. Without
this perf seems to consider that sample as corrupted and discards it.
Here is the link to a quick guide [4] to setup and run a basic perf demo on
Linux to use CTR Ext.
Qemu patches are merged upstream and is available with latest version
Opensbi patch is merged upstream and is available with latest version
[0]: https://github.com/riscv/riscv-control-transfer-records/releases/tag/v1.0
[1]: https://github.com/riscvarchive/riscv-indirect-csr-access/releases/tag/v1.0.0
[2]: https://github.com/riscvarchive/riscv-smcdeleg-ssccfg/releases/tag/v1.0.0
[3]: https://lore.kernel.org/lkml/20250114-counter_delegation-v2-0-8ba74cdb851b@xxxxxxxxxxxx/
[4]: https://github.com/rajnesh-kanwal/linux/wiki/Running-CTR-basic-demo-on-QEMU-RISC%E2%80%90V-Virt-machine
To: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
To: Ingo Molnar <mingo@xxxxxxxxxx>
To: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
To: Namhyung Kim <namhyung@xxxxxxxxxx>
To: Mark Rutland <mark.rutland@xxxxxxx>
To: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
To: Jiri Olsa <jolsa@xxxxxxxxxx>
To: Ian Rogers <irogers@xxxxxxxxxx>
To: Adrian Hunter <adrian.hunter@xxxxxxxxx>
To: Liang, Kan <kan.liang@xxxxxxxxxxxxxxx>
To: Paul Walmsley <paul.walmsley@xxxxxxxxxx>
To: Palmer Dabbelt <palmer@xxxxxxxxxxx>
To: Albert Ou <aou@xxxxxxxxxxxxxxxxx>
To: Alexandre Ghiti <alex@xxxxxxxx>
To: Atish Kumar Patra <atishp@xxxxxxxxxxxx>
To: Anup Patel <anup.patel@xxxxxxxxxxxxxxxx>
To: Will Deacon <will@xxxxxxxxxx>
To: Rob Herring <robh@xxxxxxxxxx>
To: Krzysztof Kozlowski <krzk+dt@xxxxxxxxxx>
To: Conor Dooley <conor+dt@xxxxxxxxxx>
To: Beeman Strong <beeman@xxxxxxxxxxxx>
Cc: linux-perf-users@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: linux-riscv@xxxxxxxxxxxxxxxxxxx
Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
Cc: Palmer Dabbelt <palmer@xxxxxxxxxx>
Cc: Conor Dooley <conor@xxxxxxxxxx>
Cc: devicetree@xxxxxxxxxxxxxxx
---
Changelog:
v4:
- Ported CTR driver and support files from kernel version 6.14 to kernel version 7.2
- Added CSR indirect access header file to be used by CTR driver
- Changes in sched_task call back signature to accomodate new kernel headers
- Minor clean up
v3:
- Added missing To/Cc, especially devicetree@xxxxxxxxxxxxxxx
- Changed the commit description to better describe the need of
perf tool change that increases max sample size processing
capacity of remove_loops function.
- Minor fixes found while doing a virtualization PoC.
- Added the missing commit and repository information to dt-bindings,
indicating where the extension was ratified.
v2
- Added context save/restore support for tasks using CTR feature.
- https://lore.kernel.org/lkml/20250116230955.867152-1-rkanwal@xxxxxxxxxxxx/
v1:
- https://lore.kernel.org/lkml/20240529185337.182722-1-rkanwal@xxxxxxxxxxxx/
---
Vikram Singh (7):
perf: Increase the maximum number of branches remove_loops() can
process.
riscv: pmu: Add Control transfer records CSR definations.
riscv: Add Control Transfer Records extension parsing
riscv: pmu: Add infrastructure for Control Transfer Record
riscv: pmu: Add driver for Control Transfer Records Ext
riscv: pmu: Integrate CTR Ext support in riscv_pmu_dev driver
dt-bindings: riscv: add Sxctr ISA extension description
.../devicetree/bindings/riscv/extensions.yaml | 29 +
MAINTAINERS | 4 +
arch/riscv/include/asm/csr.h | 85 +++
arch/riscv/include/asm/csr_indirect.h | 50 ++
arch/riscv/include/asm/hwcap.h | 9 +-
arch/riscv/kernel/cpufeature.c | 2 +
drivers/perf/Kconfig | 16 +
drivers/perf/Makefile | 1 +
drivers/perf/riscv_ctr.c | 609 ++++++++++++++++++
drivers/perf/riscv_pmu.c | 21 +-
drivers/perf/riscv_pmu_legacy.c | 2 +
drivers/perf/riscv_pmu_sbi.c | 85 +++
include/linux/perf/riscv_pmu.h | 55 +-
tools/perf/util/machine.c | 21 +-
14 files changed, 979 insertions(+), 10 deletions(-)
create mode 100644 arch/riscv/include/asm/csr_indirect.h
create mode 100644 drivers/perf/riscv_ctr.c
--
2.43.0