[RFC PATCH v2 0/4] RISC-V Sspesa: Linux perf precise sample attribution

From: Mayuresh Chitale

Date: Thu Oct 29 2026 - 09:10:29 EST


This Linux series adds kernel support for the RISC-V Performance Event
Sampling extensions Sspesa (Precise Event Sample Attribution) and
Ssplcofi (Precise Local Counter Overflow Interrupt).

The first two patches add the DT binding and ISA-extension detection.
Sspesa depends on Sscofpmf, while Ssplcofi depends on Sspesa. The third
patch implements perf_arch_misc_flags callback for RISC-V. The last
patch uses Sspesa in the SBI PMU driver to build synthetic regs for the
perf framework and report exact-IP samples when Ssplcofi is available.

Note:

QEMU does not currently identify any event as supporting precise
attribution. The QEMU setup is intended to validate the end-to-end
Sspesa plumbing only. Similarly, the `pesa=1` raw-event format bit in
Linux is used to simulate an event that supports precise attribution.
Such events are expected to be defined in vendor/platform specific
JSON event files, but this series does not add such an event file
for the 'Virt' machine.

Reproducing the full setup:

Sspesa support requires Linux, QEMU and OpenSBI. The matching v2
branches are:

Linux: https://github.com/mdchitale/linux/tree/riscv_sspesa_rfc_v2
QEMU: https://github.com/mdchitale/qemu/tree/riscv_sspesa_rfc_v2

OpenSBI must be built with the following fix so that PMU overflow
interrupts work correctly:

https://lists.infradead.org/pipermail/opensbi/2026-October/010957.html

Build Linux and QEMU from the branches above, and build OpenSBI with
this fix applied. By default QEMU doesn't define a raw event that can be
mapped to programmable counters and hence a special test DTB is required
which includes the raw-event-to-counter mapping.

Build the test DTB:
- qemu-system-riscv64 -machine virt,dumpdtb=/tmp/virt-sspesa.dtb \
-cpu rv64,sspesa=true,ssplcofi=true,ssccfg=true,sscofpmf=true
- dtc -I dtb -O dts -o /tmp/virt-sspesa.dts /tmp/virt-sspesa.dtb
- Edit `/tmp/virt-sspesa.dts` and add the following property to the
`/pmu` node:
riscv,raw-event-to-mhpmcounters = <0x0 0x2 0x0 0xffffffffffff 0x7fff8>;
- dtc -I dts -O dtb -o /tmp/virt-sspesa-test.dtb /tmp/virt-sspesa.dts

Boot Linux with the test DTB:
- qemu-system-riscv64 -nographic -machine virt \
-cpu rv64,sspesa=true,ssplcofi=true,ssccfg=true,sscofpmf=true \
-bios /path/to/fw_dynamic.bin -kernel /path/to/Image \
-drive file=/path/to/rootfs.img,id=hd0,format=raw,if=none \
-device virtio-blk-device,drive=hd0 \
-append "root=/dev/vda rw console=ttyS0 earlycon=sbi" \
-dtb /tmp/virt-sspesa-test.dtb

Once Linux boots, use the PESA event modifier with a precise request:

- perf record -o /tmp/sspesa-perf.data -e 'cpu/event=2,pesa=1/ppp' <workload>
- perf record -o /tmp/non-sspesa-perf.data -e 'cpu/event=2/' <workload>

Check the resulting data with:

- perf report -D -i /tmp/sspesa-perf.data \
| grep 'PERF_RECORD_SAMPLE' | head
- perf report -D -i /tmp/non-sspesa-perf.data \
| grep 'PERF_RECORD_SAMPLE' | head

Samples in sspesa-perf.data should have the PERF_RECORD_MISC_EXACT_IP
bit (0x4000) set in the misc field, while samples in non-sspesa-perf.data
should not have that bit set. This verifies plumbing only regardless of
whether QEMU supports precise attribution.

Changes since v1:
- Use the new shpmsdata.PRIV field defined in the updated spec
to reconstruct the regs for perf:
https://github.com/riscv/riscv-performance-event-sampling/commit/3eff81a6161ffc7a74a57436132d0c15ab549e74
Fallback to interrupted registers if precise attribution is not
available.
- Add the required extension dependencies: Sspesa requires Sscofpmf,
and Ssplcofi requires Sspesa.
- Add the perf_arch_misc_flags callback to update the EXACT_IP and mode
in perf misc record.
- Add the `pesa` raw-event format bit and validate precise_ip requests
against the precision supported by each event.
- Clear shpmsdata before clearing the pending overflow interrupt.
- Use Sspesa in the SBI PMU driver only when Smcdeleg is available.

Mayuresh Chitale (4):
dt-bindings: riscv: Add Sspesa and Ssplcofi extensions
riscv: Add detection for Sspesa and Ssplcofi extensions
riscv: Add perf_arch_misc_flags callback
perf/riscv: Use Sspesa for precise sample attribution

.../devicetree/bindings/riscv/extensions.yaml | 26 +++
arch/riscv/include/asm/csr.h | 12 ++
arch/riscv/include/asm/hwcap.h | 2 +
arch/riscv/include/asm/perf_event.h | 8 +
arch/riscv/kernel/cpufeature.c | 21 +++
arch/riscv/kernel/perf_callchain.c | 15 ++
drivers/perf/riscv_pmu_sbi.c | 150 +++++++++++++++++-
7 files changed, 233 insertions(+), 1 deletion(-)

--
2.43.0