[PATCH v7 00/14] Linux RISC-V trace framework and drivers

From: Mayuresh Chitale

Date: Thu Nov 26 2026 - 04:56:02 EST


This series adds 'gtrace' which is an architecture-neutral hardware trace
framework with RISC-V E-trace as its first backend. The 'gtrace' core framework
has the minimal shared plumbing (component registration, path create/destroy,
path start/stop, etc) and the RISC-V trace drivers are its first consumer.
It should be possible for the required ARM components to be adapted to the same
framework in a future.

This series also adds initial support for RISC-V trace component drivers.
The RISC-V trace v1.0 specification is already ratified and can be found at:
https://github.com/riscv-non-isa/e-trace-encap/releases/tag/v1.0.0-ratified
https://github.com/riscv-non-isa/tg-nexus-trace/releases/tag/1.0_Ratified

The drivers use the common trace control interface. E-Trace remains the
preferred format for the generic RISC-V compatible string; the encoder now
reads back the accepted hardware format and updates the component's format.


In the future, there will be subsequent series adding:
1) Sysfs support
2) ACPI support
3) More trace drivers (such as funnel, ATB, etc)
4) Support for upcoming self-hosted trace specification
5) Arm component support under the gtrace framework
6) ... and more ...

These patches can also be found in the riscv_trace_support_v7 branch at:
https://github.com/mdchitale/linux.git

To test the patches, we need QEMU virt machine with RISC-V trace support
which can be found in rv-etrace_v4 branch at:
https://gitlab.com/danielhb/qemu.git

To capture gtrace data using perf on QEMU virt machine do the following:
1) Launch QEMU virt machine
$ qemu-system-riscv64 -nographic -M virt -smp 2 -bios fw_dynamic.bin \
-kernel Image -append "root=/dev/vda rw console=ttyS0 earlycon=sbi" \
-drive file=rootfs.img,id=disk1,if=none,format=raw \
-device virtio-blk-device,drive=disk1
2) Run perf record to capture gtrace data
$ perf record --all-cpus -e gtrace/event=0x1/ <command>
3) The step2 would create a perf.data file which has the gtrace data.
Now run perf report -D and look for PERF_RECORD_AUXTRACE event
section(s) which point(s) to the actual gtrace data offset.

Changes since v6:
- Rebased on latest upstream
- Add a gtrace component type of NONE version-zero components can match
- Hold gtrace component references for firmware-node and CPU-source lookups,
- Detach incoming/outgoing connection pointers before removing components
- Balance temporary OF node references and outgoing references on parser
and platform-probe failures; fix the CPU-node diagnostic lifetime and
the OF module device table declaration.
- Use a spinlock to guard trace-ID and component ready callbacks
- Probe SRCBITS using all possible allowed widths and select the final
allowed width
- Read back the trace format (e-trace/n-trace) supported by hardware and update
platform driver state accordingly
- Make ramsink register-pair helper functions generic to gtrace
- Copy AUX data from the actual path sink and not the first component that implemented
the aux copy callback.
- Pass the available AUX byte limit to the core and sink callbacks
whereas sink driver returns the actual byte count and AUX flags.
- Release AUX mappings data directly in free_aux() instead of deferring it via workqueue
- Set the AUX_OUTPUT_HW_ID to the encoder's hardware source ID
- Other fixes for issues reported by Sashiko bot

Changes since v5:
- Moved the DT connection parsing into the gtrace core as gtrace-of.c.
- Added start_count and a lock to the core's private component data
to serialize start/stop/copyto_auxbuf operations. Dropped
perf_buf_lock.
- Added handling of partially enabled path by disabling all enabled
components
- Added cycle detection when walking the trace component graph
- Added trace source ID configuration in the encoder driver
- Added trace format (E-Trace/N-Trace) selection via the platform driver
compatible string. It is used by encoder and perf drivers to set it
into hardware and perf data header respectively
- Modified the ramsink buffer setup to read back the trRamStart and
trRamLimit registers, and program the sync frequency, memory format
and stop-on-wrap settings at start time
- Improved error handling and added path owner in the perf driver
- Fixed several issues reported by sashiko-bot but some of its findings
are deferred to a later version.

Changes since v4:
- Introduced a new architecture-neutral 'gtrace' (Generic Trace) framework
and moved the RISC-V trace drivers on top of it instead of a RISC-V-only
'rvtrace' core.
- Added new PATCH3 "gtrace: Add RISC-V platform driver for the gtrace
framework" to split out the RISC-V platform/DT code from the core
framework patch.
- Moved all rvtrace driver sources from drivers/hwtracing/rvtrace/ to
drivers/hwtracing/gtrace/, with single Kconfig, Makefile using
- Made the perf driver (previously rvtrace-perf.c) architecture-neutral
and moved it into the gtrace framework as gtrace-perf.c; PMU name
changed from "rvtrace" to "gtrace"
- Added new PATCH8 "perf: Add gtrace AUX buffer trace format type" to
define PERF_AUX_FLAG_GTRACE_FORMAT_ETRACE which is used in later patches.
- copyto_auxbuf() and gtrace_path_copyto_auxbuf() now take an output
parameter so the AUX data format can be reported by the sink
driver by setting PERF_AUX_FLAG_GTRACE_FORMAT_ETRACE.
- Renamed the generic side of the perf tools support from rvtrace* to
gtrace*. perf.data ABI is unchanged.
- Fixed gtrace ramsink start/stop to call gtrace_enable_component()/
gtrace_disable_component() to remove duplication with code in
gtrace-core.c
- Updated the MAINTAINERS patch to refer to gtrace framework instead of
rvtrace

Changes since v3:
- Rebased on Linux-7.1-rc1
- Use kzalloc_obj() in-place of kzalloc() in PATCH2, PATCH3 and PATCH9
- Improved PATCH7 to save the previous WP value

Changes since v2:
- Rebased on Linux-7.0-rc1
- Addressed Rob's comments on DT bindings in PATCH1
- Addressed ref-count related issues in rvtrace_of_parse_outconns()
of PATCH2
- Made RVtrace framework more generic by avoiding implicit access
to component registers in PATCH2
- More improvements in trRamStart/Limit/WP programming and other
improvments in PATCH7
- Removed RVTRACE_BUF_LEN from PATCH9
- Removed redundant page_size from PATCH10
- Renamed found_etm in PATCH10
- Removed rvtrace_recording_init() declaration from header in PATCH11

Changes since v1:
- Rebased on Linux-6.18-rc3
- Addressed Rob's comments in dt-bindings added by PATCH1
- Get reference of conn->dest_fwnode and add missing break in
rvtrace_of_parse_outconns() of rvtrace-platform drivers added
by PATCH2
- Added new inline function rvtrace_comp_is_empty() in PATCH2
and used it in rvtrace_encoder_stop() added by PATCH5
- Fixed trRamWPLow usage in PATCH7
- Determine RAM sink buffer size based on component implementation
ID and reduce default RAM sink buffer size to 1MB
- Add new PATCH8 to enable DMA_RESTRICTED_POOL in RISC-V defconfig
so that implementations with RAM sink address restrictions can
be handled.

Anup Patel (7):
dt-bindings: Add RISC-V trace component bindings
hwtracing: gtrace: Initial implementation of gtrace framework
gtrace: Add RISC-V platform driver for the gtrace framework
gtrace: Add functions to create/destroy a trace component path
gtrace: Add function to copy into perf AUX buffer
riscv: Enable DMA_RESTRICTED_POOL in defconfig
MAINTAINERS: Add entry for RISC-V trace framework

Mayuresh Chitale (7):
gtrace: Add functions to start/stop tracing on a component path
gtrace: Add RISC-V Trace encoder driver
perf: Add gtrace AUX buffer trace format type
gtrace: Add RISC-V Trace ramsink driver
gtrace: Add perf driver for tracing using perf tool
perf tools: Add RISC-V trace PMU record capabilities
perf tools: Initial support for gtrace decoder

.../bindings/riscv/riscv,trace-component.yaml | 120 +++
MAINTAINERS | 11 +
arch/riscv/configs/defconfig | 1 +
drivers/Makefile | 1 +
drivers/hwtracing/Kconfig | 2 +
drivers/hwtracing/gtrace/Kconfig | 59 ++
drivers/hwtracing/gtrace/Makefile | 9 +
drivers/hwtracing/gtrace/gtrace-core.c | 962 ++++++++++++++++++
drivers/hwtracing/gtrace/gtrace-of.c | 133 +++
drivers/hwtracing/gtrace/gtrace-perf.c | 368 +++++++
drivers/hwtracing/gtrace/rvtrace-encoder.c | 274 +++++
drivers/hwtracing/gtrace/rvtrace-platform.c | 194 ++++
drivers/hwtracing/gtrace/rvtrace-ramsink.c | 366 +++++++
drivers/hwtracing/gtrace/rvtrace.h | 121 +++
include/linux/gtrace.h | 382 +++++++
include/uapi/linux/perf_event.h | 5 +
tools/include/uapi/linux/perf_event.h | 5 +
tools/perf/arch/riscv/util/Build | 1 +
tools/perf/arch/riscv/util/auxtrace.c | 220 ++++
tools/perf/util/Build | 1 +
tools/perf/util/auxtrace.c | 4 +
tools/perf/util/auxtrace.h | 1 +
tools/perf/util/gtrace-decoder.c | 99 ++
tools/perf/util/gtrace.h | 17 +
24 files changed, 3356 insertions(+)
create mode 100644 Documentation/devicetree/bindings/riscv/riscv,trace-component.yaml
create mode 100644 drivers/hwtracing/gtrace/Kconfig
create mode 100644 drivers/hwtracing/gtrace/Makefile
create mode 100644 drivers/hwtracing/gtrace/gtrace-core.c
create mode 100644 drivers/hwtracing/gtrace/gtrace-of.c
create mode 100644 drivers/hwtracing/gtrace/gtrace-perf.c
create mode 100644 drivers/hwtracing/gtrace/rvtrace-encoder.c
create mode 100644 drivers/hwtracing/gtrace/rvtrace-platform.c
create mode 100644 drivers/hwtracing/gtrace/rvtrace-ramsink.c
create mode 100644 drivers/hwtracing/gtrace/rvtrace.h
create mode 100644 include/linux/gtrace.h
create mode 100644 tools/perf/arch/riscv/util/auxtrace.c
create mode 100644 tools/perf/util/gtrace-decoder.c
create mode 100644 tools/perf/util/gtrace.h


base-commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
--
2.43.0