Skip to contentSkip to conversation

riscv: tarce: Implement riscv trace pmu driver and perf support

RFC PATCH In review [email protected] 5 participants 11 messages Sep 11, 2025 – Oct 14, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover riscv: tarce: Implement riscv trace pmu driver and perf support

From: Chen Pei <[email protected]>

The RISC-V Trace Specification defines a standardized framework for capturing and analyzing the execution of RISC-V processors. Its main uses include: instruction and data tracing, real-time debugging, etc. Similar to Intel-PT and ARM-CoreSight.

According to the RISC-V Trace Control Interface specification [1]. There are two standard RISC-V trace protocols which will utilize this RISC-V Trace Control Interface:
- RISC-V N-Trace (Nexus-based Trace) Specification
- Efficient Trace for RISC-V Specification
So, this is a complete guideline for any standard RISC-V trace implementation.

This series of patches is mainly used to start related work and communication. It completes the following tasks:
1. dt-bindings completes the basic definition of riscv trace component properties, but is still incomplete.
2. Implemented the basic RISC-V Trace PMU driver, including support for the aux buffer.
3. Implemented basic support for AUXTRACE integration with perf tools.

There's still more work to be done, such as:
1. Complete RISC-V Trace PMU implementation.
2. The perf.data generation and parsing including AUXTRACE events.
3. Taking RISC-V N-Trace as an example, implement the parsing of Nexus Trace data format, including support for perf report and perf script commands.
We are still sorting out.

Any comments or suggestions are welcome.

[1] https://github.com/riscv-non-isa/tg-nexus-trace.git

Chen Pei (4):
dt-bindings: riscv: Add trace components description
riscv: event: Initial riscv trace driver support
tools: perf: Support perf record with aux buffer for riscv trace
riscv: trace: Support sink using dma buffer

 .../riscv/trace/riscv,trace,encoder.yaml      |  41 +++
 .../riscv/trace/riscv,trace,funnel.yaml       |  46 ++++
 .../riscv/trace/riscv,trace,sink.yaml         |  37 +++
 arch/riscv/Kbuild                             |   1 +
 arch/riscv/Kconfig                            |   2 +
 arch/riscv/events/Kconfig                     |  11 +
 arch/riscv/events/Makefile                    |   3 +
 arch/riscv/events/riscv_trace.c               | 253 ++++++++++++++++++
 arch/riscv/events/riscv_trace.h               | 133 +++++++++
 arch/riscv/events/riscv_trace_encoder.c       | 109 ++++++++
 arch/riscv/events/riscv_trace_funnel.c        | 160 +++++++++++
 arch/riscv/events/riscv_trace_sink.c          | 100 +++++++
 tools/perf/arch/riscv/util/Build              |   3 +
 tools/perf/arch/riscv/util/auxtrace.c         |  33 +++
 tools/perf/arch/riscv/util/pmu.c              |  18 ++
 tools/perf/arch/riscv/util/riscv-trace.c      | 183 +++++++++++++
 tools/perf/arch/riscv/util/tsc.c              |  15 ++
 tools/perf/util/Build                         |   1 +
 tools/perf/util/auxtrace.c                    |   4 +
 tools/perf/util/auxtrace.h                    |   1 +
 tools/perf/util/riscv-trace.c                 | 162 +++++++++++
 tools/perf/util/riscv-trace.h                 |  18 ++
 22 files changed, 1334 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,encoder.yaml
 create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,funnel.yaml
 create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,sink.yaml
 create mode 100644 arch/riscv/events/Kconfig
 create mode 100644 arch/riscv/events/Makefile
 create mode 100644 arch/riscv/events/riscv_trace.c
 create mode 100644 arch/riscv/events/riscv_trace.h
 create mode 100644 arch/riscv/events/riscv_trace_encoder.c
 create mode 100644 arch/riscv/events/riscv_trace_funnel.c
 create mode 100644 arch/riscv/events/riscv_trace_sink.c
 create mode 100644 tools/perf/arch/riscv/util/auxtrace.c
 create mode 100644 tools/perf/arch/riscv/util/pmu.c
 create mode 100644 tools/perf/arch/riscv/util/riscv-trace.c
 create mode 100644 tools/perf/arch/riscv/util/tsc.c
 create mode 100644 tools/perf/util/riscv-trace.c
 create mode 100644 tools/perf/util/riscv-trace.h
Signature · 1 line
2.49.0
#1 lore raw

RFC PATCH 1/4 dt-bindings: riscv: Add trace components description

From: Chen Pei <[email protected]>

This patch has added property definitions related to the riscv trace component, providing a foundation for subsequent driver implementations.

The RISC-V Trace Control Interface can be found in [1]. Some principles are as follows:
1. Trace has three types of components:
1.1 Encoder: Collects CPU execution information through the
Ingress Port and generates Trace Messages.
1.2 Funnel: Used to integrate multiple trace sources. 1.3 Sink: Used to store trace data.
2. Each hart requires one trace encoder.
3. When there are multiple trace sources, a trace funnel component is needed to integrate them. One trace funnel is required for each cluster.
4. When multiple trace funnels are fed into a single trace sink, multiple levels of trace funnels are required.
5. If there is only one cluster, the trace funnel (Level 0) can be connected directly to the trace sink.

Taking [cpu0]-->[encoder0]-->[funnel0]-->[sink0] as an example, the DTS configuration is as follows:

    encoder0: trace_encoder@26001000 {
        compatible = "riscv_trace,encoder-controller";
        reg = <0x0 0x26001000 0x0 0x1000>;
        cpu = <&cpu0>;
        output_port {
            port0 {
                endpoint = <&funnel0>;
            };
        };
    };

    funnel0: trace_funnel@26404000 {
        compatible = "riscv_trace,funnel-controller";
        reg = <0x0 0x26404000 0x0 0x1000>;
        level = <1>;
        input_port {
            port0 {
                endpoint = <&encoder0>;
            };
        };
        output_port {
            port0 {
                endpoint = <&sink0>;
            };
        };
    };

    sink0: trace_sink@26401000 {
        compatible = "riscv_trace,sink-controller";
        reg = <0x0 0x26401000 0x0 0x1000>;
        input_port {
            port0 {
                endpoint = <&funnel0>;
            };
        };
    };

Note: The detailed property definition of each component will be provided in the subsequent series of patches.

[1] https://github.com/riscv-non-isa/tg-nexus-trace.git

---
 .../riscv/trace/riscv,trace,encoder.yaml      | 41 +++++++++++++++++
 .../riscv/trace/riscv,trace,funnel.yaml       | 46 +++++++++++++++++++
 .../riscv/trace/riscv,trace,sink.yaml         | 37 +++++++++++++++
 3 files changed, 124 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,encoder.yaml
 create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,funnel.yaml
 create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,sink.yaml
Documentation/devicetree/bindings/riscv/trace/riscv,trace,encoder.yaml new file +41 -0
new file mode 100644
index 000000000000..e2ec3ce514b2
@@ -0,0 +1,41 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/riscv/trace/riscv,trace,encoder.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RISC-V Trace Encoder Controller
+
+description: |
+  riscv trace encoder controller description.
+
+maintainers:
+  - Chen Pei <[email protected]>
+
+properties:
+  compatible:
+    items:
+      - const: riscv_trace,encoder-controller
+  reg:
+    description: A memory region containing registers for encoder controller
+
+  cpu:
+    description: CPU identifier associated with this encoder
+
+  ports:
+    description: Output port definitions
+
+additionalProperties: true
+
+examples:
+  - |
+    encoder0: trace_encoder@26001000 {
+        compatible = "riscv_trace,encoder-controller";
+        reg = <0x0 0x26001000 0x0 0x1000>;
+        cpu = <&cpu0>;
+        output_port {
+            port0 {
+                endpoint = <&funnel0>;
+            };
+        };
+    };
Documentation/devicetree/bindings/riscv/trace/riscv,trace,funnel.yaml new file +46 -0

46 lines not on this page · raw message

Documentation/devicetree/bindings/riscv/trace/riscv,trace,sink.yaml new file +37 -0
new file mode 100644
index 000000000000..b42e65988f31
@@ -0,0 +1,37 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/riscv/trace/riscv,trace,sink.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: RISC-V Trace Sink Controller
+
+description: |
+  riscv trace sink controller description.
+
+maintainers:
+  - Chen Pei <[email protected]>
+
+properties:
+  compatible:
+    items:
+      - const: riscv_trace,sink-controller
+  reg:
+    description: A memory region containing registers for sink controller
+
+  ports:
+    description: Input port definitions
+
+additionalProperties: true
+
+examples:
+  - |
+    sink0: trace_sink@26401000 {
+        compatible = "riscv_trace,sink-controller";
+        reg = <0x0 0x26401000 0x0 0x1000>;
+        input_port {
+            port0 {
+                endpoint = <&funnel0>;
+            };
+        };
+    };
Signature · 1 line
2.49.0
#2 lore raw

Re: [RFC PATCH 1/4] dt-bindings: riscv: Add trace components description

Quoted 3 lines · On 11/09/2025 14:44, [email protected] wrote:

From: Chen Pei <[email protected]>

This patch has added property definitions related to the riscv

Please do not use "This commit/patch/change", but imperative mood. See longer explanation here:
https://elixir.bootlin.com/linux/v6.16/source/Documentation/process/submitting-patches.rst#L94

<form letter>
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.

Tools like b4 or scripts/get_maintainer.pl provide you proper list of people, so fix your workflow. Tools might also fail if you work on some ancient tree (don't, instead use mainline) or work on fork of kernel (don't, instead use mainline). Just use b4 and everything should be fine, although remember about b4 prep --auto-to-cc if you added new patches to the patchset.

You missed at least devicetree list (maybe more), so this won't be tested by automated tooling. Performing review on untested code might be a waste of time.

Please kindly resend and include all necessary To/Cc entries. </form letter>

Quoted 3 lines

trace component, providing a foundation for subsequent driver implementations.

...

Quoted 5 lines

+$id: http://devicetree.org/schemas/riscv/trace/riscv,trace,funnel.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

Documentation/devicetree/bindings/riscv/trace/riscv,trace,funnel.yaml new file +3 -0
+
+title: RISC-V Trace Funnel Controller
+

Documentation/devicetree/bindings/riscv/trace/riscv,trace,funnel.yaml line 18

Quoted 10 lines
Documentation/devicetree/bindings/riscv/trace/riscv,trace,funnel.yaml new file +10 -0
+description: |
+  riscv trace funnel controller description.
+
+maintainers:
+  - Chen Pei <[email protected]>
+
+properties:
+  compatible:
+    items:
+      - const: riscv_trace,funnel-controller

You need to start following DTS coding style.

Documentation/devicetree/bindings/riscv/trace/riscv,trace,funnel.yaml line 28

Quoted 10 lines
Documentation/devicetree/bindings/riscv/trace/riscv,trace,funnel.yaml new file +10 -0
+  reg:
+    description: A memory region containing registers for funnel controller
+
+  ports:
+    description: Input/Output port definitions
+
+  level:
+    description: Level of the funnel (e.g., 1 means close to the encoder)
+
+additionalProperties: true

No clue from where you got this, but that's not how DT bindings are written. Maybe you used some AI tools for that - in that case, it would be strong grumpy NAK. :( You just waste community time with such approach.

Please start from scratch from example-schema or known good bindings.

Best regards,
Krzysztof

#3 lore raw

Re: [RFC PATCH 1/4] dt-bindings: riscv: Add trace components description

Quoted 19 lines · On Thu, 11 Sep 2025 19:24:39 +0200, [email protected] wrote:
Quoted 1 line

This patch has added property definitions related to the riscv>

Please do not use "This commit/patch/change", but imperative mood. See longer explanation here:
https://elixir.bootlin.com/linux/v6.16/source/Documentation/process/submitting-patches.rst#L94>

<form letter>
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.>

Tools like b4 or scripts/get_maintainer.pl provide you proper list of people, so fix your workflow. Tools might also fail if you work on some ancient tree (don't, instead use mainline) or work on fork of kernel (don't, instead use mainline). Just use b4 and everything should be fine, although remember about b4 prep --auto-to-cc if you added new patches to the patchset.>

Quoted 10 lines

You missed at least devicetree list (maybe more), so this won't be tested by automated tooling. Performing review on untested code might be a waste of time.>

Please kindly resend and include all necessary To/Cc entries. </form letter>>

Quoted 2 lines

trace component, providing a foundation for subsequent driver implementations.

Thank you very much for your review.
My next resend will include all necessary To/Cc entries.

Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+    items:
+      - const: riscv_trace,funnel-controller>

You need to start following DTS coding style.>

Quoted 2 lines
Documentation/devicetree/bindings/riscv/trace/riscv,trace,funnel.yaml new file +2 -0
+  reg:
+    description: A memory region containing registers for funnel controller

Indeed, the current dt-bindings are very primitive and may contain some errors. I should improve and check them before sending them out. I will pay attention to it next time.

Thank you,
Pei

#4 lore raw

RFC PATCH 2/4 riscv: event: Initial riscv trace driver support

In reply to [email protected]

From: Chen Pei <[email protected]>

This patch implements the riscv trace perf driver. It's suitable for RISC-V processors that implement the trace specification (N-Trace or E-Trace). Users can specify the riscv_trace driver through the perf program.

The driver adds two format attributes, start_addr and stop_addr, to specify the valid instruction range for tracing. It also supports specifying the priv_mode (user and kernel) to specify the valid privilege mode for tracing.

The reference commands are as follows:

cat /sys/bus/event_source/devices/riscv_trace/format/* perf record -e riscv_trace// ls
perf record -e riscv_trace/start_addr=0x1234,stop_addr=0x5678/ ls perf record -e riscv_trace/start_addr=0x1234,stop_addr=0x5678/k ls perf report -D

---
 arch/riscv/Kbuild                       |   1 +
 arch/riscv/Kconfig                      |   2 +
 arch/riscv/events/Kconfig               |  11 ++
 arch/riscv/events/Makefile              |   3 +
 arch/riscv/events/riscv_trace.c         | 145 +++++++++++++++++++++
 arch/riscv/events/riscv_trace.h         | 123 ++++++++++++++++++
 arch/riscv/events/riscv_trace_encoder.c | 109 ++++++++++++++++
 arch/riscv/events/riscv_trace_funnel.c  | 160 ++++++++++++++++++++++++
 arch/riscv/events/riscv_trace_sink.c    | 100 +++++++++++++++
 9 files changed, 654 insertions(+)
 create mode 100644 arch/riscv/events/Kconfig
 create mode 100644 arch/riscv/events/Makefile
 create mode 100644 arch/riscv/events/riscv_trace.c
 create mode 100644 arch/riscv/events/riscv_trace.h
 create mode 100644 arch/riscv/events/riscv_trace_encoder.c
 create mode 100644 arch/riscv/events/riscv_trace_funnel.c
 create mode 100644 arch/riscv/events/riscv_trace_sink.c
arch/riscv/Kbuild +1 -0
index 126fb738fc44..8107a614c428 100644
@@ -4,6 +4,7 @@ obj-y += kernel/ mm/ net/
 obj-$(CONFIG_CRYPTO) += crypto/
 obj-y += errata/
 obj-$(CONFIG_KVM) += kvm/
+obj-$(CONFIG_PERF_EVENTS) += events/
 
 obj-$(CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY) += purgatory/
 
arch/riscv/Kconfig +2 -0
index 51dcd8eaa243..145d3424651b 100644
@@ -1374,3 +1374,5 @@ endmenu # "CPU Power Management"
 source "arch/riscv/kvm/Kconfig"
 
 source "drivers/acpi/Kconfig"
+
+source "arch/riscv/events/Kconfig"
arch/riscv/events/Kconfig new file +11 -0
new file mode 100644
index 000000000000..c6fb073b29b1
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0
+menu "Performance monitoring"
+
+config PERF_EVENTS_RISCV_TRACE
+	tristate "RISCV TRACE events"
+	depends on PERF_EVENTS && RISCV
+	default m
+	help
+	  Include support for riscv trace events.
+
+endmenu
arch/riscv/events/Makefile new file +3 -0
new file mode 100644
index 000000000000..5014de2847df
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_PERF_EVENTS_RISCV_TRACE) += riscv_trace_pmu.o
+riscv_trace_pmu-objs := riscv_trace.o riscv_trace_encoder.o riscv_trace_funnel.o riscv_trace_sink.o
arch/riscv/events/riscv_trace.c new file +145 -0

145 lines not on this page · raw message

arch/riscv/events/riscv_trace.h new file +123 -0

123 lines not on this page · raw message

arch/riscv/events/riscv_trace_encoder.c new file +109 -0

109 lines not on this page · raw message

arch/riscv/events/riscv_trace_funnel.c new file +160 -0

160 lines not on this page · raw message

arch/riscv/events/riscv_trace_sink.c new file +100 -0

100 lines not on this page · raw message

Signature · 1 line
2.49.0
#5 lore raw

RFC PATCH 3/4 tools: perf: Support perf record with aux buffer for riscv trace

In reply to [email protected]

From: Chen Pei <[email protected]>

This patch implements AUXTRACE support for RISC-V Trace. The corresponding driver needs to implement the setup_aux and free_aux PMU driver ops.

The aux buffer is a type of ring buffer used in trace scenarios, and RISC-V Trace should also reuse this capability.

---
 arch/riscv/events/riscv_trace.c          |  61 ++++++++
 arch/riscv/events/riscv_trace.h          |   8 +
 tools/perf/arch/riscv/util/Build         |   3 +
 tools/perf/arch/riscv/util/auxtrace.c    |  33 ++++
 tools/perf/arch/riscv/util/pmu.c         |  18 +++
 tools/perf/arch/riscv/util/riscv-trace.c | 183 +++++++++++++++++++++++
 tools/perf/arch/riscv/util/tsc.c         |  15 ++
 tools/perf/util/Build                    |   1 +
 tools/perf/util/auxtrace.c               |   4 +
 tools/perf/util/auxtrace.h               |   1 +
 tools/perf/util/riscv-trace.c            | 162 ++++++++++++++++++++
 tools/perf/util/riscv-trace.h            |  18 +++
 12 files changed, 507 insertions(+)
 create mode 100644 tools/perf/arch/riscv/util/auxtrace.c
 create mode 100644 tools/perf/arch/riscv/util/pmu.c
 create mode 100644 tools/perf/arch/riscv/util/riscv-trace.c
 create mode 100644 tools/perf/arch/riscv/util/tsc.c
 create mode 100644 tools/perf/util/riscv-trace.c
 create mode 100644 tools/perf/util/riscv-trace.h
arch/riscv/events/riscv_trace.c +61 -0
index e408d9a4034a..3ac4a3be5d3e 100644
@@ -8,6 +8,7 @@
 #include <linux/slab.h>
 #include <linux/device.h>
 #include <linux/perf_event.h>
+#include <linux/vmalloc.h>
 
 #include "riscv_trace.h"
 
@@ -81,6 +82,9 @@ static void riscv_trace_event_start(struct perf_event *event, int flags)
 {
 	pr_info("%s:%d on_cpu=%d cpu=%d\n", __func__, __LINE__,
 		event->oncpu, event->cpu);
+	// TODO: Begin aux buffer
+	// struct xuantie_ntrace_aux_buf *buf;
+	// buf = perf_aux_output_begin(&riscv_trace_pmu.handle, event);
 	// TODO: Enable the trace component
 }
 
@@ -89,6 +93,61 @@ static void riscv_trace_event_stop(struct perf_event *event, int flags)
 	pr_info("%s:%d on_cpu=%d cpu=%d\n", __func__, __LINE__,
 		event->oncpu, event->cpu);
 	// TODO: Disable the trace component
+	// TODO: End aux buffer
+	// struct xuantie_ntrace_aux_buf *buf;
+	// buf = perf_get_aux(&riscv_trace_pmu.handle);
+	// Fill aux buffer
+	// perf_aux_output_end(&riscv_trace_pmu.handle, size);
+}
+
+static void *riscv_trace_buffer_setup_aux(struct perf_event *event, void **pages,
+					 int nr_pages, bool overwrite)
+{
+	struct riscv_trace_aux_buf *buf;
+	struct page **pagelist;
+	int i;
+
+	if (overwrite) {
+		pr_warn("Overwrite mode is not supported\n");
+		return NULL;
+	}
+
+	buf = kzalloc(sizeof(*buf), GFP_KERNEL);
+	if (!buf)
+		return NULL;
+
+	pagelist = kcalloc(nr_pages, sizeof(*pagelist), GFP_KERNEL);
+	if (!pagelist)
+		goto err;
+
+	for (i = 0; i < nr_pages; i++)
+		pagelist[i] = virt_to_page(pages[i]);
+
+	buf->base = vmap(pagelist, nr_pages, VM_MAP, PAGE_KERNEL);
+	if (!buf->base) {
+		kfree(pagelist);
+		goto err;
+	}
+
+	buf->nr_pages = nr_pages;
+	buf->length = nr_pages * PAGE_SIZE;
+	buf->pos = 0;
+
+	pr_info("nr_pages=%d length=%d\n", buf->nr_pages, buf->length);
+
+	kfree(pagelist);
+	return buf;
+err:
+	kfree(buf);
+	return NULL;
+}
+
+static void riscv_trace_buffer_free_aux(void *aux)
+{
+	struct riscv_trace_aux_buf *buf = aux;
+
+	vunmap(buf->base);
+	kfree(buf);
 }
 
 static int __init riscv_trace_init(void)
@@ -128,6 +187,8 @@ static int __init riscv_trace_init(void)
 	riscv_trace_pmu.pmu.del          = riscv_trace_event_del;
 	riscv_trace_pmu.pmu.start        = riscv_trace_event_start;
 	riscv_trace_pmu.pmu.stop         = riscv_trace_event_stop;
+	riscv_trace_pmu.pmu.setup_aux    = riscv_trace_buffer_setup_aux;
+	riscv_trace_pmu.pmu.free_aux     = riscv_trace_buffer_free_aux;
 
 	return perf_pmu_register(&riscv_trace_pmu.pmu, "riscv_trace", -1);
 }
arch/riscv/events/riscv_trace.h +8 -0
index ef0af0d0b2ee..c28216227006 100644
@@ -75,6 +75,14 @@ extern struct list_head riscv_trace_controllers;
 struct riscv_trace_pmu {
 	struct pmu pmu;
 	struct riscv_trace_filter_attr filter_attr;
+	struct perf_output_handle handle;
+};
+
+struct riscv_trace_aux_buf {
+	u32 length;
+	u32 nr_pages;
+	void *base;
+	u32 pos;
 };
 
 static inline const char *riscv_trace_type2str(enum RISCV_TRACE_COMPONENT_TYPE
tools/perf/arch/riscv/util/Build +3 -0
index 58a672246024..d1599b70ef2f 100644
@@ -1,5 +1,8 @@
 perf-util-y += perf_regs.o
 perf-util-y += header.o
+perf-util-y += tsc.o
 
 perf-util-$(CONFIG_LIBTRACEEVENT) += kvm-stat.o
 perf-util-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
+
+perf-util-$(CONFIG_AUXTRACE) += pmu.o auxtrace.o riscv-trace.o
tools/perf/arch/riscv/util/auxtrace.c new file +33 -0
new file mode 100644
index 000000000000..51c8dac5ff61
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <dirent.h>
+#include <stdbool.h>
+#include <linux/zalloc.h>
+#include <api/fs/fs.h>
+
+#include "../../../util/auxtrace.h"
+#include "../../../util/debug.h"
+#include "../../../util/evlist.h"
+#include "../../../util/pmu.h"
+#include "../../../util/pmus.h"
+#include "riscv-trace.h"
+
+struct auxtrace_record
+*auxtrace_record__init(struct evlist *evlist, int *err)
+{
+	struct perf_pmu	*riscv_trace_pmu = NULL;
+	struct evsel *evsel;
+	bool found_riscv_trace = false;
+
+	riscv_trace_pmu = perf_pmus__find(RISCV_TRACE_PMU_NAME);
+
+	evlist__for_each_entry(evlist, evsel) {
+		if (riscv_trace_pmu && evsel->core.attr.type == riscv_trace_pmu->type)
+			found_riscv_trace = true;
+	}
+
+	if (found_riscv_trace)
+		return riscv_trace_recording_init(err, riscv_trace_pmu);
+
+	return NULL;
+}
tools/perf/arch/riscv/util/pmu.c new file +18 -0
new file mode 100644
index 000000000000..921b083c4f6b
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <string.h>
+#include <linux/perf_event.h>
+#include <linux/string.h>
+
+#include "riscv-trace.h"
+#include "../../../util/pmu.h"
+
+void perf_pmu__arch_init(struct perf_pmu *pmu)
+{
+#ifdef HAVE_AUXTRACE_SUPPORT
+	if (!strcmp(pmu->name, RISCV_TRACE_PMU_NAME)) {
+		pmu->auxtrace = true;
+		pmu->selectable = true;
+	}
+#endif
+}
tools/perf/arch/riscv/util/riscv-trace.c new file +183 -0

183 lines not on this page · raw message

tools/perf/arch/riscv/util/tsc.c new file +15 -0
new file mode 100644
index 000000000000..cf021e423f79
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/types.h>
+
+#include "../../../util/tsc.h"
+
+u64 rdtsc(void)
+{
+	u64 val;
+
+	// https://lore.kernel.org/all/[email protected]/T/
+	asm volatile("rdtime %0" : "=r"(val));
+
+	return val;
+}
tools/perf/util/Build +1 -0
index 4959e7a990e4..4726a100a156 100644
@@ -136,6 +136,7 @@ perf-util-$(CONFIG_AUXTRACE) += arm-spe-decoder/
 perf-util-$(CONFIG_AUXTRACE) += hisi-ptt.o
 perf-util-$(CONFIG_AUXTRACE) += hisi-ptt-decoder/
 perf-util-$(CONFIG_AUXTRACE) += s390-cpumsf.o
+perf-util-$(CONFIG_AUXTRACE) += riscv-trace.o
 
 ifdef CONFIG_LIBOPENCSD
 perf-util-$(CONFIG_AUXTRACE) += cs-etm.o
tools/perf/util/auxtrace.c +4 -0
index ebd32f1b8f12..b4d8f3c5ebb1 100644
@@ -54,6 +54,7 @@
 #include "arm-spe.h"
 #include "hisi-ptt.h"
 #include "s390-cpumsf.h"
+#include "riscv-trace.h"
 #include "util/mmap.h"
 
 #include <linux/ctype.h>
@@ -1393,6 +1394,9 @@ int perf_event__process_auxtrace_info(struct perf_session *session,
 	case PERF_AUXTRACE_HISI_PTT:
 		err = hisi_ptt_process_auxtrace_info(event, session);
 		break;
+	case PERF_AUXTRACE_RISCV_TRACE:
+		err = riscv_trace_process_auxtrace_info(event, session);
+		break;
 	case PERF_AUXTRACE_UNKNOWN:
 	default:
 		return -EINVAL;
tools/perf/util/auxtrace.h +1 -0
index f001cbb68f8e..5b7ce4a99709 100644
@@ -50,6 +50,7 @@ enum auxtrace_type {
 	PERF_AUXTRACE_ARM_SPE,
 	PERF_AUXTRACE_S390_CPUMSF,
 	PERF_AUXTRACE_HISI_PTT,
+	PERF_AUXTRACE_RISCV_TRACE,
 };
 
 enum itrace_period_type {
tools/perf/util/riscv-trace.c new file +162 -0

162 lines not on this page · raw message

tools/perf/util/riscv-trace.h new file +18 -0
new file mode 100644
index 000000000000..4901ea323b77
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef INCLUDE__PERF_RISCV_TRACE_H__
+#define INCLUDE__PERF_RISCV_TRACE_H__
+
+#define RISCV_TRACE_PMU_NAME		"riscv_trace"
+#define RISCV_TRACE_AUXTRACE_PRIV_SIZE	sizeof(u64)
+
+union perf_event;
+struct perf_session;
+struct perf_pmu;
+
+struct auxtrace_record *riscv_trace_recording_init(int *err,
+						struct perf_pmu *riscv_ntrace_pmu);
+
+int riscv_trace_process_auxtrace_info(union perf_event *event,
+				   struct perf_session *session);
+
+#endif
Signature · 1 line
2.49.0
#6 lore raw

RFC PATCH 4/4 riscv: trace: Support sink using dma buffer

In reply to [email protected]

From: Chen Pei <[email protected]>

In common SoC systems, the trace data by the sink is usually written to the memory, and the memory needs to be a large block.

We have two methods to achieve this. One is based on reserved memory. This method requires pre-isolation of memory and is not flexible enough. Therefore, we chose the second method, which is based on IOMMU to map non-contiguous memory to continuous. When implementing the driver, only the DMA alloc related APIs are needed.

---
 arch/riscv/events/riscv_trace.c | 49 ++++++++++++++++++++++++++++++++-
 arch/riscv/events/riscv_trace.h |  4 ++-
 2 files changed, 51 insertions(+), 2 deletions(-)
arch/riscv/events/riscv_trace.c +48 -1
index 3ac4a3be5d3e..e8deaefa0180 100644
@@ -9,6 +9,7 @@
 #include <linux/device.h>
 #include <linux/perf_event.h>
 #include <linux/vmalloc.h>
+#include <linux/dma-mapping.h>
 
 #include "riscv_trace.h"
 
@@ -55,6 +56,44 @@ static void riscv_trace_init_filter_attrs(struct perf_event *event)
 		riscv_trace_pmu.filter_attr.priv_mode);
 }
 
+static int riscv_trace_sink_dma_alloc(unsigned long size)
+{
+	struct riscv_trace_component *component;
+	dma_addr_t dma_addr;
+
+	list_for_each_entry(component, &riscv_trace_controllers, list) {
+		if (component->type == RISCV_TRACE_SINK) {
+			component->sink.vaddr =
+			    dma_alloc_coherent(riscv_trace_pmu.pmu.dev, size,
+					       &dma_addr, GFP_KERNEL);
+			if (component->sink.vaddr) {
+				component->sink.start_addr = dma_addr;
+				component->sink.limit_addr = dma_addr + size;
+				continue;
+			} else {
+				pr_err("dma_alloc_coherent failed\n");
+				return -ENOMEM;
+			}
+		}
+	}
+
+	return 0;
+}
+
+static void riscv_trace_sink_dma_free(void)
+{
+	struct riscv_trace_component *component;
+
+	list_for_each_entry(component, &riscv_trace_controllers, list) {
+		if (component->type == RISCV_TRACE_SINK) {
+			if (component->sink.vaddr)
+				dma_free_coherent(riscv_trace_pmu.pmu.dev,
+					component->sink.limit_addr - component->sink.start_addr,
+					component->sink.vaddr, component->sink.start_addr);
+		}
+	}
+}
+
 static int riscv_trace_event_init(struct perf_event *event)
 {
 	if (event->attr.type != riscv_trace_pmu.pmu.type)
@@ -105,7 +144,7 @@ static void *riscv_trace_buffer_setup_aux(struct perf_event *event, void **pages
 {
 	struct riscv_trace_aux_buf *buf;
 	struct page **pagelist;
-	int i;
+	int i, ret;
 
 	if (overwrite) {
 		pr_warn("Overwrite mode is not supported\n");
@@ -135,6 +174,12 @@ static void *riscv_trace_buffer_setup_aux(struct perf_event *event, void **pages
 
 	pr_info("nr_pages=%d length=%d\n", buf->nr_pages, buf->length);
 
+	ret = riscv_trace_sink_dma_alloc(buf->length);
+	if (ret) {
+		kfree(pagelist);
+		goto err;
+	}
+
 	kfree(pagelist);
 	return buf;
 err:
@@ -148,6 +193,8 @@ static void riscv_trace_buffer_free_aux(void *aux)
 
 	vunmap(buf->base);
 	kfree(buf);
+
+	riscv_trace_sink_dma_free();
 }
 
 static int __init riscv_trace_init(void)
arch/riscv/events/riscv_trace.h +3 -1
index c28216227006..7819fbeace1f 100644
@@ -49,7 +49,9 @@ struct riscv_trace_funnel {
 };
 
 struct riscv_trace_sink {
-	;
+	u64 start_addr;
+	u64 limit_addr;
+	void __iomem *vaddr;
 };
 
 struct riscv_trace_component {
Signature · 1 line
2.49.0
#7 lore raw
In reply to [email protected]
Quoted 32 lines · On 9/11/25 05:44, [email protected] wrote:

From: Chen Pei <[email protected]>

The RISC-V Trace Specification defines a standardized framework for capturing and analyzing the execution of RISC-V processors. Its main uses include: instruction and data tracing, real-time debugging, etc. Similar to Intel-PT and ARM-CoreSight.

According to the RISC-V Trace Control Interface specification [1]. There are two standard RISC-V trace protocols which will utilize this RISC-V Trace Control Interface:
- RISC-V N-Trace (Nexus-based Trace) Specification
- Efficient Trace for RISC-V Specification
So, this is a complete guideline for any standard RISC-V trace implementation.

This series of patches is mainly used to start related work and communication. It completes the following tasks:
1. dt-bindings completes the basic definition of riscv trace component properties, but is still incomplete.
2. Implemented the basic RISC-V Trace PMU driver, including support for the aux buffer.
3. Implemented basic support for AUXTRACE integration with perf tools.

There's still more work to be done, such as:
1. Complete RISC-V Trace PMU implementation.
2. The perf.data generation and parsing including AUXTRACE events.
3. Taking RISC-V N-Trace as an example, implement the parsing of Nexus Trace data format, including support for perf report and perf script commands.
We are still sorting out.

Quoted 4 lines

Any comments or suggestions are welcome.

[1] https://github.com/riscv-non-isa/tg-nexus-trace.git

Hi Chen, thanks for starting this series. I have done a N-trace driver in user space: https://github.com/ganboing/riscv-trace-umd, and I'd love to see someone finally taking the effort to try a proper kernel driver.

My overall suggestions:

1. We need a way to expose proper topology to user-space like coresight. Thus, I'm thinking of using similar logic in coresight to export the topology through sysfs. Potentially we can abstract some logic out of coresight and make it a common core path that can be reused by riscv trace driver. Thus, we don't reinvent the wheel. This also helps debugging trace driver issues if anything goes wrong.

2. IMO, The driver should be moved to drivers/hwtracing/. It's not tightly coupled with arch, and there are many platform related logic where it doesn't belong to arch/riscv/. Having said that, I do believe we'll need something in arch/riscv/ eventually for trace once the self-hosted trace spec is finalized. Self-hosted trace behaves more like Intel PT, where the control will be done through some CSR(s), and it doesn't need those funnel/sink topology, and can emit trace stream to virtual memory directly. It's a per-hart thing with LAMBI and all that. I'd imagine that eventually riscv trace will be two parts. One is more coresight-alike, where you have encoders/funnel/sink/bridge that are described through DT and controlled by MMIO. The other part is more PT-alike, where the feature is described by ISA-string (I guess?), and it's much easier to program. For the time being, IMO, a coresight-alike driver, e.g., drivers/hwtracing/rvtrace, is more suited for existing platforms implementing N-trace or E-trace. Also, don't assume the memory sink is available. People using this "coresight-alike" driver can very-well be HW engineers who's collecting traces using external probes, so again I think we may want to abstract out part of coresight's logic and reuse then in riscv.

3. I've already implemented a N-trace decoder:
https://github.com/ganboing/libnexus-rv
It can decode N-trace on real HW (ESWIN EIC7700/Sifive P550). I'll try to see if I have the time to code up N-trace decoding in perf tool, once the driver and the perf trace collection part is stabilized. If not, I will be happy to review yours. Please include me in future series.

BTW, perhaps you want to also CC riscv Task Groups such as
- Sig-Debug-Trace-Perf-Mon (DTPM)
- Tech-Self-Hosted-Trace

to keep people like Beeman/Robert/Bruce/Iain/Greg posted. Robert mentioned they tried to contact Sifive to see if they had similar driver upstreaming effort just like yours, but there were no reply. Keep them posted anyway to avoid duplicate work. We should also discuss this during riscv NA summit if you or Guo's attending.

Quoted 29 lines

Chen Pei (4):
dt-bindings: riscv: Add trace components description
riscv: event: Initial riscv trace driver support
tools: perf: Support perf record with aux buffer for riscv trace
riscv: trace: Support sink using dma buffer

  .../riscv/trace/riscv,trace,encoder.yaml      |  41 +++
  .../riscv/trace/riscv,trace,funnel.yaml       |  46 ++++
  .../riscv/trace/riscv,trace,sink.yaml         |  37 +++
  arch/riscv/Kbuild                             |   1 +
  arch/riscv/Kconfig                            |   2 +
  arch/riscv/events/Kconfig                     |  11 +
  arch/riscv/events/Makefile                    |   3 +
  arch/riscv/events/riscv_trace.c               | 253 ++++++++++++++++++
  arch/riscv/events/riscv_trace.h               | 133 +++++++++
  arch/riscv/events/riscv_trace_encoder.c       | 109 ++++++++
  arch/riscv/events/riscv_trace_funnel.c        | 160 +++++++++++
  arch/riscv/events/riscv_trace_sink.c          | 100 +++++++
  tools/perf/arch/riscv/util/Build              |   3 +
  tools/perf/arch/riscv/util/auxtrace.c         |  33 +++
  tools/perf/arch/riscv/util/pmu.c              |  18 ++
  tools/perf/arch/riscv/util/riscv-trace.c      | 183 +++++++++++++
  tools/perf/arch/riscv/util/tsc.c              |  15 ++
  tools/perf/util/Build                         |   1 +
  tools/perf/util/auxtrace.c                    |   4 +
  tools/perf/util/auxtrace.h                    |   1 +
  tools/perf/util/riscv-trace.c                 | 162 +++++++++++
  tools/perf/util/riscv-trace.h                 |  18 ++
  22 files changed, 1334 insertions(+)
Quoted 17 lines

create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,encoder.yaml create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,funnel.yaml create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,sink.yaml create mode 100644 arch/riscv/events/Kconfig
create mode 100644 arch/riscv/events/Makefile
create mode 100644 arch/riscv/events/riscv_trace.c
create mode 100644 arch/riscv/events/riscv_trace.h
create mode 100644 arch/riscv/events/riscv_trace_encoder.c
create mode 100644 arch/riscv/events/riscv_trace_funnel.c
create mode 100644 arch/riscv/events/riscv_trace_sink.c
create mode 100644 tools/perf/arch/riscv/util/auxtrace.c
create mode 100644 tools/perf/arch/riscv/util/pmu.c
create mode 100644 tools/perf/arch/riscv/util/riscv-trace.c
create mode 100644 tools/perf/arch/riscv/util/tsc.c
create mode 100644 tools/perf/util/riscv-trace.c
create mode 100644 tools/perf/util/riscv-trace.h

Bo

#8 lore raw

On Wed, 17 Sep 2025 00:27:43 -0700, [email protected]:

Quoted 48 lines
Quoted 4 lines

Any comments or suggestions are welcome.

[1] https://github.com/riscv-non-isa/tg-nexus-trace.git

Quoted 1 line

Hi Chen, thanks for starting this series. I have done a N-trace driver in user space: https://github.com/ganboing/riscv-trace-umd, and I'd love to see someone finally taking the effort to try a proper kernel driver.>

My overall suggestions:>

1. We need a way to expose proper topology to user-space like coresight. Thus, I'm thinking of using similar logic in coresight to export the topology through sysfs. Potentially we can abstract some logic out of coresight and make it a common core path that can be reused by riscv trace driver. Thus, we don't reinvent the wheel. This also helps debugging trace driver issues if anything goes wrong.>

2. IMO, The driver should be moved to drivers/hwtracing/. It's not tightly coupled with arch, and there are many platform related logic where it doesn't belong to arch/riscv/. Having said that, I do believe we'll need something in arch/riscv/ eventually for trace once the self-hosted trace spec is finalized. Self-hosted trace behaves more like Intel PT, where the control will be done through some CSR(s), and it doesn't need those funnel/sink topology, and can emit trace stream to virtual memory directly. It's a per-hart thing with LAMBI and all that. I'd imagine that eventually riscv trace will be two parts. One is more coresight-alike, where you have encoders/funnel/sink/bridge that are described through DT and controlled by MMIO. The other part is more PT-alike, where the feature is described by ISA-string (I guess?), and it's much easier to program. For the time being, IMO, a coresight-alike driver, e.g., drivers/hwtracing/rvtrace, is more suited for existing platforms implementing N-trace or E-trace. Also, don't assume the memory sink is available. People using this "coresight-alike" driver can very-well be HW engineers who's collecting traces using external probes, so again I think we may want to abstract out part of coresight's logic and reuse then in riscv.>

3. I've already implemented a N-trace decoder:
https://github.com/ganboing/libnexus-rv
It can decode N-trace on real HW (ESWIN EIC7700/Sifive P550). I'll try to see if I have the time to code up N-trace decoding in perf tool, once the driver and the perf trace collection part is stabilized. If not, I will be happy to review yours. Please include me in future series.>

BTW, perhaps you want to also CC riscv Task Groups such as
- Sig-Debug-Trace-Perf-Mon (DTPM)
- Tech-Self-Hosted-Trace>

Quoted 11 lines

to keep people like Beeman/Robert/Bruce/Iain/Greg posted. Robert mentioned they tried to contact Sifive to see if they had similar driver upstreaming effort just like yours, but there were no reply. Keep them posted anyway to avoid duplicate work. We should also discuss this during riscv NA summit if you or Guo's attending.>

Quoted 5 lines

Chen Pei (4):
dt-bindings: riscv: Add trace components description
riscv: event: Initial riscv trace driver support
tools: perf: Support perf record with aux buffer for riscv trace
riscv: trace: Support sink using dma buffer

Thank you very much for your review. Every suggestion and existing work is valuable, and I will carefully evaluate it.

1. I will further investigate the technical details you mentioned in CoreSight, reusing existing design and code as much as possible.

2. Moving the driver to drivers/hwtracing/ is a good suggestion, and I've considered it before.

3. We've noticed that there are many types of sinks, such as the Lauterbach's Debug Probe, as you mentioned. The current code does not reflect this, I will consider compatibility later.

4. Your implementation of the N-trace decoder is very useful as a reference. I will study it carefully. We also have an internal implementation, which I will compare and provide feedback to you later.

5. The RISC-V Task Groups should indeed be cc'd. Thanks for the reminder.

Thank you,
Pei

#9 lore raw
In reply to [email protected]

Hi Guo,

Quoted 83 lines · On Thu, Sep 11, 2025 at 6:15 PM <[email protected]> wrote:

From: Chen Pei <[email protected]>

The RISC-V Trace Specification defines a standardized framework for capturing and analyzing the execution of RISC-V processors. Its main uses include: instruction and data tracing, real-time debugging, etc. Similar to Intel-PT and ARM-CoreSight.

According to the RISC-V Trace Control Interface specification [1]. There are two standard RISC-V trace protocols which will utilize this RISC-V Trace Control Interface:
- RISC-V N-Trace (Nexus-based Trace) Specification
- Efficient Trace for RISC-V Specification
So, this is a complete guideline for any standard RISC-V trace implementation.

This series of patches is mainly used to start related work and communication. It completes the following tasks:
1. dt-bindings completes the basic definition of riscv trace component properties, but is still incomplete.
2. Implemented the basic RISC-V Trace PMU driver, including support for the aux buffer.
3. Implemented basic support for AUXTRACE integration with perf tools.

There's still more work to be done, such as:
1. Complete RISC-V Trace PMU implementation.
2. The perf.data generation and parsing including AUXTRACE events.
3. Taking RISC-V N-Trace as an example, implement the parsing of Nexus Trace data format, including support for perf report and perf script commands.
We are still sorting out.

Any comments or suggestions are welcome.

[1] https://github.com/riscv-non-isa/tg-nexus-trace.git

Chen Pei (4):
dt-bindings: riscv: Add trace components description
riscv: event: Initial riscv trace driver support
tools: perf: Support perf record with aux buffer for riscv trace
riscv: trace: Support sink using dma buffer

 .../riscv/trace/riscv,trace,encoder.yaml      |  41 +++
 .../riscv/trace/riscv,trace,funnel.yaml       |  46 ++++
 .../riscv/trace/riscv,trace,sink.yaml         |  37 +++
 arch/riscv/Kbuild                             |   1 +
 arch/riscv/Kconfig                            |   2 +
 arch/riscv/events/Kconfig                     |  11 +
 arch/riscv/events/Makefile                    |   3 +
 arch/riscv/events/riscv_trace.c               | 253 ++++++++++++++++++
 arch/riscv/events/riscv_trace.h               | 133 +++++++++
 arch/riscv/events/riscv_trace_encoder.c       | 109 ++++++++
 arch/riscv/events/riscv_trace_funnel.c        | 160 +++++++++++
 arch/riscv/events/riscv_trace_sink.c          | 100 +++++++
 tools/perf/arch/riscv/util/Build              |   3 +
 tools/perf/arch/riscv/util/auxtrace.c         |  33 +++
 tools/perf/arch/riscv/util/pmu.c              |  18 ++
 tools/perf/arch/riscv/util/riscv-trace.c      | 183 +++++++++++++
 tools/perf/arch/riscv/util/tsc.c              |  15 ++
 tools/perf/util/Build                         |   1 +
 tools/perf/util/auxtrace.c                    |   4 +
 tools/perf/util/auxtrace.h                    |   1 +
 tools/perf/util/riscv-trace.c                 | 162 +++++++++++
 tools/perf/util/riscv-trace.h                 |  18 ++
 22 files changed, 1334 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,encoder.yaml
 create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,funnel.yaml
 create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,sink.yaml
 create mode 100644 arch/riscv/events/Kconfig
 create mode 100644 arch/riscv/events/Makefile
 create mode 100644 arch/riscv/events/riscv_trace.c
 create mode 100644 arch/riscv/events/riscv_trace.h
 create mode 100644 arch/riscv/events/riscv_trace_encoder.c
 create mode 100644 arch/riscv/events/riscv_trace_funnel.c
 create mode 100644 arch/riscv/events/riscv_trace_sink.c
 create mode 100644 tools/perf/arch/riscv/util/auxtrace.c
 create mode 100644 tools/perf/arch/riscv/util/pmu.c
 create mode 100644 tools/perf/arch/riscv/util/riscv-trace.c
 create mode 100644 tools/perf/arch/riscv/util/tsc.c
 create mode 100644 tools/perf/util/riscv-trace.c
 create mode 100644 tools/perf/util/riscv-trace.h
Quoted 1 line

--

Few months back we (Ventana) had informed everyone within RVI (particularly self-hosted trace TG) that we are working on Linux trace framework and drivers for the RISC-V community [1]. There are also publicly accessible RISE project pages already available for the trace efforts [2].

This is yet another instance where ongoing efforts were totally ignored.

--
Anup

[1] https://lists.riscv.org/g/sig-hypervisors/message/648
[2] https://lf-rise.atlassian.net/wiki/spaces/HOME/pages/8591251/2025+-+Kernel+and+Virtualization+Priorities

#10 lore raw
Quoted 87 lines · Anup Patel

Hi Guo,

Quoted 83 lines · On Thu, Sep 11, 2025 at 6:15 PM <[email protected]> wrote:

From: Chen Pei <[email protected]>

The RISC-V Trace Specification defines a standardized framework for capturing and analyzing the execution of RISC-V processors. Its main uses include: instruction and data tracing, real-time debugging, etc. Similar to Intel-PT and ARM-CoreSight.

According to the RISC-V Trace Control Interface specification [1]. There are two standard RISC-V trace protocols which will utilize this RISC-V Trace Control Interface:
- RISC-V N-Trace (Nexus-based Trace) Specification
- Efficient Trace for RISC-V Specification
So, this is a complete guideline for any standard RISC-V trace implementation.

This series of patches is mainly used to start related work and communication. It completes the following tasks:
1. dt-bindings completes the basic definition of riscv trace component properties, but is still incomplete.
2. Implemented the basic RISC-V Trace PMU driver, including support for the aux buffer.
3. Implemented basic support for AUXTRACE integration with perf tools.

There's still more work to be done, such as:
1. Complete RISC-V Trace PMU implementation.
2. The perf.data generation and parsing including AUXTRACE events.
3. Taking RISC-V N-Trace as an example, implement the parsing of Nexus Trace data format, including support for perf report and perf script commands.
We are still sorting out.

Any comments or suggestions are welcome.

[1] https://github.com/riscv-non-isa/tg-nexus-trace.git

Chen Pei (4):
dt-bindings: riscv: Add trace components description
riscv: event: Initial riscv trace driver support
tools: perf: Support perf record with aux buffer for riscv trace
riscv: trace: Support sink using dma buffer

 .../riscv/trace/riscv,trace,encoder.yaml      |  41 +++
 .../riscv/trace/riscv,trace,funnel.yaml       |  46 ++++
 .../riscv/trace/riscv,trace,sink.yaml         |  37 +++
 arch/riscv/Kbuild                             |   1 +
 arch/riscv/Kconfig                            |   2 +
 arch/riscv/events/Kconfig                     |  11 +
 arch/riscv/events/Makefile                    |   3 +
 arch/riscv/events/riscv_trace.c               | 253 ++++++++++++++++++
 arch/riscv/events/riscv_trace.h               | 133 +++++++++
 arch/riscv/events/riscv_trace_encoder.c       | 109 ++++++++
 arch/riscv/events/riscv_trace_funnel.c        | 160 +++++++++++
 arch/riscv/events/riscv_trace_sink.c          | 100 +++++++
 tools/perf/arch/riscv/util/Build              |   3 +
 tools/perf/arch/riscv/util/auxtrace.c         |  33 +++
 tools/perf/arch/riscv/util/pmu.c              |  18 ++
 tools/perf/arch/riscv/util/riscv-trace.c      | 183 +++++++++++++
 tools/perf/arch/riscv/util/tsc.c              |  15 ++
 tools/perf/util/Build                         |   1 +
 tools/perf/util/auxtrace.c                    |   4 +
 tools/perf/util/auxtrace.h                    |   1 +
 tools/perf/util/riscv-trace.c                 | 162 +++++++++++
 tools/perf/util/riscv-trace.h                 |  18 ++
 22 files changed, 1334 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,encoder.yaml
 create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,funnel.yaml
 create mode 100644 Documentation/devicetree/bindings/riscv/trace/riscv,trace,sink.yaml
 create mode 100644 arch/riscv/events/Kconfig
 create mode 100644 arch/riscv/events/Makefile
 create mode 100644 arch/riscv/events/riscv_trace.c
 create mode 100644 arch/riscv/events/riscv_trace.h
 create mode 100644 arch/riscv/events/riscv_trace_encoder.c
 create mode 100644 arch/riscv/events/riscv_trace_funnel.c
 create mode 100644 arch/riscv/events/riscv_trace_sink.c
 create mode 100644 tools/perf/arch/riscv/util/auxtrace.c
 create mode 100644 tools/perf/arch/riscv/util/pmu.c
 create mode 100644 tools/perf/arch/riscv/util/riscv-trace.c
 create mode 100644 tools/perf/arch/riscv/util/tsc.c
 create mode 100644 tools/perf/util/riscv-trace.c
 create mode 100644 tools/perf/util/riscv-trace.h
Quoted 7 lines
Quoted 1 line

--

Few months back we (Ventana) had informed everyone within RVI (particularly self-hosted trace TG) that we are working on Linux trace framework and drivers for the RISC-V community [1]. There are also publicly accessible RISE project pages already available for the trace efforts [2].\

Thx for reminding, I would reply on [1].

Quoted 9 lines

This is yet another instance where ongoing efforts were totally ignored.

--
Anup

[1] https://lists.riscv.org/g/sig-hypervisors/message/648
[2] https://lf-rise.atlassian.net/wiki/spaces/HOME/pages/8591251/2025+-+Kernel+and+Virtualization+Priorities

Signature · 2 lines
Best Regards
 Guo Ren