Add Linux RISC-V trace support via the gtrace framework
cover Add Linux RISC-V trace support via the gtrace framework
This series adds Linux RISC-V trace support via the generic hardware trace (gtrace) framework [1]. The RISC-V trace encoder, funnel, ATB bridge, and timestamp components are implemented as gtrace components, and the CoreSight funnel and TMC (ETB/ETF/ETR) are likewise re-implemented as gtrace components so that they can be composed with the RISC-V components into a single trace path.
This work supersedes the earlier CoreSight-based RFC [2]. Instead of forcing the RISC-V trace IP to conform to the CoreSight device, this series shifts the topology onto the gtrace framework to achieve cleaner architectural decoupling and shared data paths.
The series includes:
- gtrace sysfs support, exposing per-component attributes (control, features, and timestamp) for configuration and validation
- gtrace component drivers for the RISC-V trace encoder, funnel, ATB bridge, and timestamp components
- gtrace component drivers for the CoreSight dynamic funnel and TMC (ETB/ETF/ETR), built on top of the CoreSight platform core APIs (CLAIM/device registration) re-implemented as gtrace components
- perf PMU support: gtrace event format attributes, per-event configuration parsing, and an AUX flag marking CoreSight-formatted trace data
- perf tooling: a Nexus (N-Trace) decoder and a gtrace AUX decoder that synthesizes branch samples, including machine-mode instruction access
Verification on K3 SoC:
The device tree follows [1], with only the compatible properties changed for the gtrace components.
# perf list pmu gtrace// [Kernel PMU event]
# perf record -e gtrace// --per-thread uname [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 1.946 MB perf.data ]
# perf script uname 767863 1 branches: ffffffff80d18b04 gtrace_poll_bit+0x34 ([kernel.kallsyms]) => ffffffff80d18b12 gtrace_poll_bit+0x42 ([kernel.kallsyms]) uname 767863 1 branches: ffffffff80d18b4e gtrace_poll_bit+0x7e ([kernel.kallsyms]) => ffffffff80d18b6c gtrace_poll_bit+0x9c ([kernel.kallsyms]) uname 767863 1 branches: ffffffff80d1c17a rvtrace_encoder_start+0x112 ([kernel.kallsyms]) => ffffffff80d1c196 rvtrace_encoder_start+0x12e ([kernel.kallsyms]) uname 767863 1 branches: ffffffff80d18782 gtrace_path_start+0xbe ([kernel.kallsyms]) => ffffffff80d18702 gtrace_path_start+0x3e ([kernel.kallsyms]) uname 767863 1 branches: ffffffff80d18712 gtrace_path_start+0x4e ([kernel.kallsyms]) => ffffffff80d18724 gtrace_path_start+0x60 ([kernel.kallsyms]) ...
In per-cpu mode, correlating trace data with the running task requires the encoder to emit a context ID. This depends on writing the task PID to the RISC-V scontext CSR on context switch [3].
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
Zane Leung (24):
gtrace: Move connection release into component unregister
gtrace: Initial implementation of gtrace sysfs framework
gtrace: Drop trace format field and helper function
gtrace: Add RISC-V trace encoder sysfs support
gtrace: Introduce some PMU format attributes
gtrace: Replace owner PID with perf_event pointer in gtrace_path
gtrace: Parse RISC-V Trace encoder config from perf event
gtrace: add perf symlink support for gtrace components
gtrace: Add port-level start/stop driver callbacks
gtrace: Add RISC-V trace funnel driver
gtrace: Add RISC-V trace timestamp support
gtrace: Add RISC-V trace ATB bridge driver
gtrace: Add CoreSight platform core APIs
gtrace: Add CoreSight funnel driver
gtrace: Only copy AUX data from the path sink
perf: Flag whether gtrace AUX data carries CoreSight framing
gtrace: Unify default sink selection across CPUs in perf setup
gtrace: Add sink-specific buffer alloc/free callbacks
gtrace: Add setup_sysfs_buf callback to setup sysfs sink buffer
gtrace: Add CoreSight TMC driver support
perf tools: riscv: making gtrace PMU listable
perf tools: Add Nexus RISC-V Trace decoder
perf tools: gtrace: Record and parse trace encoder metadata perf tools: gtrace: Add AUX trace decoder and branch sample synthesis
.../hwtracing/coresight/coresight-tmc-etf.c | 1 -
drivers/hwtracing/gtrace/Kconfig | 70 +
drivers/hwtracing/gtrace/Makefile | 12 +-
drivers/hwtracing/gtrace/coresight-funnel.c | 430 ++++
drivers/hwtracing/gtrace/coresight-platform.c | 279 +++
drivers/hwtracing/gtrace/coresight-tmc-core.c | 1111 ++++++++++
drivers/hwtracing/gtrace/coresight-tmc-etf.c | 573 +++++
drivers/hwtracing/gtrace/coresight-tmc-etr.c | 1888 +++++++++++++++++
drivers/hwtracing/gtrace/coresight-tmc.h | 469 ++++
drivers/hwtracing/gtrace/coresight.h | 212 ++
drivers/hwtracing/gtrace/gtrace-core.c | 165 +-
drivers/hwtracing/gtrace/gtrace-perf.c | 122 +-
drivers/hwtracing/gtrace/gtrace-sysfs.c | 452 ++++
drivers/hwtracing/gtrace/rvtrace-atbbridge.c | 153 ++
...trace-encoder.c => rvtrace-encoder-core.c} | 182 +-
.../hwtracing/gtrace/rvtrace-encoder-sysfs.c | 323 +++
drivers/hwtracing/gtrace/rvtrace-encoder.h | 61 +
drivers/hwtracing/gtrace/rvtrace-funnel.c | 220 ++
drivers/hwtracing/gtrace/rvtrace-funnel.h | 29 +
drivers/hwtracing/gtrace/rvtrace-platform.c | 26 +-
drivers/hwtracing/gtrace/rvtrace-ramsink.c | 11 +-
drivers/hwtracing/gtrace/rvtrace-timestamp.c | 336 +++
drivers/hwtracing/gtrace/rvtrace-timestamp.h | 44 +
drivers/hwtracing/gtrace/rvtrace.h | 5 +
include/linux/gtrace.h | 161 +-
include/uapi/linux/perf_event.h | 1 +
tools/arch/riscv/include/asm/insn.h | 645 ++++++
tools/include/uapi/linux/perf_event.h | 1 +
tools/perf/arch/riscv/util/Build | 1 +
tools/perf/arch/riscv/util/auxtrace.c | 203 +-
tools/perf/arch/riscv/util/pmu.c | 19 +
tools/perf/builtin-script.c | 4 +
tools/perf/util/Build | 1 +
tools/perf/util/gtrace-decoder.c | 1283 ++++++++++-
tools/perf/util/gtrace.h | 30 +-
tools/perf/util/rvtrace-decoder/Build | 2 +
.../util/rvtrace-decoder/rvtrace-decoder.c | 423 ++++
.../util/rvtrace-decoder/rvtrace-decoder.h | 122 ++
.../rvtrace-decoder/rvtrace-ntrace-decoder.c | 910 ++++++++
.../rvtrace-decoder/rvtrace-ntrace-decoder.h | 124 ++
tools/perf/util/symbol_conf.h | 2 +
41 files changed, 10926 insertions(+), 180 deletions(-)
create mode 100644 drivers/hwtracing/gtrace/coresight-funnel.c
create mode 100644 drivers/hwtracing/gtrace/coresight-platform.c
create mode 100644 drivers/hwtracing/gtrace/coresight-tmc-core.c
create mode 100644 drivers/hwtracing/gtrace/coresight-tmc-etf.c
create mode 100644 drivers/hwtracing/gtrace/coresight-tmc-etr.c
create mode 100644 drivers/hwtracing/gtrace/coresight-tmc.h
create mode 100644 drivers/hwtracing/gtrace/coresight.h
create mode 100644 drivers/hwtracing/gtrace/gtrace-sysfs.c
create mode 100644 drivers/hwtracing/gtrace/rvtrace-atbbridge.c
rename drivers/hwtracing/gtrace/{rvtrace-encoder.c => rvtrace-encoder-core.c} (55%)
create mode 100644 drivers/hwtracing/gtrace/rvtrace-encoder-sysfs.c
create mode 100644 drivers/hwtracing/gtrace/rvtrace-encoder.h
create mode 100644 drivers/hwtracing/gtrace/rvtrace-funnel.c
create mode 100644 drivers/hwtracing/gtrace/rvtrace-funnel.h
create mode 100644 drivers/hwtracing/gtrace/rvtrace-timestamp.c
create mode 100644 drivers/hwtracing/gtrace/rvtrace-timestamp.h
create mode 100644 tools/arch/riscv/include/asm/insn.h
create mode 100644 tools/perf/arch/riscv/util/pmu.c
create mode 100644 tools/perf/util/rvtrace-decoder/Build
create mode 100644 tools/perf/util/rvtrace-decoder/rvtrace-decoder.c
create mode 100644 tools/perf/util/rvtrace-decoder/rvtrace-decoder.h
create mode 100644 tools/perf/util/rvtrace-decoder/rvtrace-ntrace-decoder.c
create mode 100644 tools/perf/util/rvtrace-decoder/rvtrace-ntrace-decoder.hSignature · 1 line
2.34.1
PATCH 1/24 gtrace: Move connection release into component unregister
Add gtrace_release_outconns() and call it from gtrace_unregister_component() so the output connection fwnode references are released in the core instead of being duplicated in every platform driver's remove callback.
--- drivers/hwtracing/gtrace/gtrace-core.c | 15 +++++++++++++++ drivers/hwtracing/gtrace/rvtrace-platform.c | 9 --------- 2 files changed, 15 insertions(+), 9 deletions(-)
drivers/hwtracing/gtrace/gtrace-core.c +15 -0
@@ -479,10 +479,25 @@ struct gtrace_component *gtrace_register_component(struct gtrace_component_id *i }EXPORT_SYMBOL_GPL (gtrace_register_component); +static void gtrace_release_outconns (struct gtrace_component *comp) +{ +struct gtrace_platform_data *pdata = comp->pdata; +struct gtrace_connection *conn; +int i; + +for (i =0 ; i < pdata->nr_outconns; i++) { + conn = pdata->outconns[i]; +if (conn && conn->dest_fwnode) +fwnode_handle_put (conn->dest_fwnode); + } +} +void gtrace_unregister_component (struct gtrace_component *comp) {struct gtrace_component *c; +gtrace_release_outconns (comp); +mutex_lock (>race_mutex);if (comp->pdata->bound_cpu >=0 ) {
drivers/hwtracing/gtrace/rvtrace-platform.c +0 -9
@@ -141,15 +141,6 @@ static int rvtrace_platform_probe(struct platform_device *pdev)static void rvtrace_platform_remove (struct platform_device *pdev) {struct gtrace_component *comp =platform_get_drvdata (pdev); -struct gtrace_platform_data *pdata = comp->pdata; -struct gtrace_connection *conn; -int i; - -for (i =0 ; i < pdata->nr_outconns; i++) { - conn = pdata->outconns[i]; -if (conn && conn->dest_fwnode) -fwnode_handle_put (conn->dest_fwnode); - }gtrace_unregister_component (comp); }
Signature · 1 line
2.34.1
PATCH 2/24 gtrace: Initial implementation of gtrace sysfs framework
In reply to Zane LeungAdd per-component sysfs attribute groups (enable_sink, enable_source, label) and a connections/ group with nr_links and bidirectional out:X / in:Y symlinks. Drivers can attach extra groups via pdata->groups; they are registered and cleaned up inside gtrace_sysfs_add/remove.
--- drivers/hwtracing/gtrace/Makefile | 2 +- drivers/hwtracing/gtrace/gtrace-core.c | 47 ++- drivers/hwtracing/gtrace/gtrace-sysfs.c | 440 ++++++++++++++++++++++++ include/linux/gtrace.h | 104 ++++++ 4 files changed, 583 insertions(+), 10 deletions(-) create mode 100644 drivers/hwtracing/gtrace/gtrace-sysfs.c
drivers/hwtracing/gtrace/Makefile +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_GTRACE) += gtrace.o -gtrace-y := gtrace-core.o gtrace-perf.o +gtrace-y := gtrace-core.o gtrace-perf.o gtrace-sysfs.o gtrace-$(CONFIG_OF) += gtrace-of.o obj-$(CONFIG_RVTRACE) += rvtrace-platform.o
drivers/hwtracing/gtrace/gtrace-core.c +38 -9
132 lines not on this page · raw message
drivers/hwtracing/gtrace/gtrace-sysfs.c new file +440 -0
440 lines not on this page · raw message
include/linux/gtrace.h +104 -0
155 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 3/24 gtrace: Drop trace format field and helper function
In reply to Zane LeungRemove the format field from struct gtrace_platform_data and drop the associated gtrace_path_aux_format() helper function.
--- drivers/hwtracing/gtrace/gtrace-perf.c | 15 -------- drivers/hwtracing/gtrace/rvtrace-encoder.c | 39 --------------------- drivers/hwtracing/gtrace/rvtrace-platform.c | 3 +- drivers/hwtracing/gtrace/rvtrace-ramsink.c | 1 - include/linux/gtrace.h | 3 -- 5 files changed, 1 insertion(+), 60 deletions(-)
drivers/hwtracing/gtrace/gtrace-perf.c +0 -15
@@ -167,20 +167,6 @@ static void *gtrace_setup_aux(struct perf_event *event, void **pages,return NULL ; } -static u64 gtrace_path_aux_format (struct gtrace_path *path) -{ -struct gtrace_component *src =gtrace_path_source (path); - -switch (src->pdata->format) { -case GTRACE_FORMAT_ETRACE : -return PERF_AUX_FLAG_GTRACE_FORMAT_ETRACE ; -case GTRACE_FORMAT_NTRACE : -return PERF_AUX_FLAG_GTRACE_FORMAT_NTRACE ; -default : -return PERF_AUX_FLAG_GTRACE_FORMAT_UNKNOWN ; - } -} -static void gtrace_event_read (struct perf_event *event) { }
@@ -295,7 +281,6 @@ static void gtrace_event_stop(struct perf_event *event, int mode)return ; ret =gtrace_path_copyto_auxbuf (path, &event_data->buf, &size, &format);WARN_ON_ONCE (ret); - format =gtrace_path_aux_format (path);if (READ_ONCE (handle->event)) {/* Tag the AUX data with the source's trace format. */ perf_aux_output_flag (handle, format);
drivers/hwtracing/gtrace/rvtrace-encoder.c +0 -39
@@ -53,38 +53,11 @@ static void rvtrace_encoder_set_srcid(struct gtrace_platform_data *pdata, u32 srgtrace_write32 (pdata, val,RVTRACE_COMPONENT_CTRL_OFFSET ); } -/* Set requested trace format and return 0 if hardware supports that format */ -static int rvtrace_encoder_set_format (struct gtrace_platform_data *pdata) -{ -u32 val, fmt; - -switch (pdata->format) { -case GTRACE_FORMAT_ETRACE : - fmt =RVTRACE_COMPONENT_CTRL_FORMAT_ETRACE ; -break ; -case GTRACE_FORMAT_NTRACE : - fmt =RVTRACE_COMPONENT_CTRL_FORMAT_NTRACE ; -break ; -default : -return -EINVAL ; - } - - val =gtrace_read32 (pdata,RVTRACE_COMPONENT_CTRL_OFFSET ); - val &= ~(RVTRACE_COMPONENT_CTRL_FORMAT_MASK <<RVTRACE_COMPONENT_CTRL_FORMAT_SHIFT ); - val |= fmt <<RVTRACE_COMPONENT_CTRL_FORMAT_SHIFT ; -gtrace_write32 (pdata, val,RVTRACE_COMPONENT_CTRL_OFFSET ); - - val =gtrace_read32 (pdata,RVTRACE_COMPONENT_CTRL_OFFSET ); - val = (val >>RVTRACE_COMPONENT_CTRL_FORMAT_SHIFT ) &RVTRACE_COMPONENT_CTRL_FORMAT_MASK ; -return val == fmt ?0 : -EOPNOTSUPP ; -} -static int rvtrace_encoder_probe (struct gtrace_component *comp) {struct gtrace_platform_data *pdata = comp->pdata;struct rvtrace_encoder_priv *priv;u32 val, hw_srcbits, srcbits; -int ret;if (pdata->bound_cpu <0 ) {dev_err (&comp->dev,"cpu property missing. Please fix firmware.\n" );
@@ -95,12 +68,6 @@ static int rvtrace_encoder_probe(struct gtrace_component *comp)if (!priv)return -ENOMEM ; - ret =rvtrace_encoder_set_format (pdata); -if (ret) { -dev_err (&comp->dev,"failed to set format %d\n" , pdata->format); -return ret; - } -/* Check if trTeInhibitSrc is hardwired to 1 */ val =gtrace_read32 (pdata,RVTRACE_COMPONENT_CTRL_OFFSET ); val &= ~BIT (RVTRACE_COMPONENT_CTRL_INHIBITSRC_SHIFT );
@@ -144,12 +111,6 @@ static int rvtrace_encoder_start(struct gtrace_component *comp)if (priv->srcbits)rvtrace_encoder_set_srcid (pdata, priv->srcbits); - ret =rvtrace_encoder_set_format (pdata); -if (ret) { -dev_err (&comp->dev,"failed to set format %d\n" , pdata->format); -return ret; - } - ret =gtrace_enable_component (comp);if (ret) {dev_err (&comp->dev,"failed to enable encoder.\n" );
drivers/hwtracing/gtrace/rvtrace-platform.c +1 -2
@@ -78,7 +78,6 @@ static int rvtrace_platform_probe(struct platform_device *pdev) pdata->dev = dev; pdata->impid =RVTRACE_COMPONENT_IMPID_UNKNOWN ; pdata->hw_ops = &rvtrace_hw_ops; - pdata->format = (uintptr_t )device_get_match_data (dev); res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res)
@@ -146,7 +145,7 @@ static void rvtrace_platform_remove(struct platform_device *pdev) }static const struct of_device_id rvtrace_platform_match[] = { - { .compatible ="riscv,trace-component" , .data = (void *)GTRACE_FORMAT_ETRACE }, + { .compatible ="riscv,trace-component" }, {} };
drivers/hwtracing/gtrace/rvtrace-ramsink.c +0 -1
@@ -161,7 +161,6 @@ static size_t rvtrace_ramsink_copyto_auxbuf(struct gtrace_component *comp, dst.cur = buf->pos; src.base = priv->va; src.len = priv->size; - *format =PERF_AUX_FLAG_GTRACE_FORMAT_ETRACE ; wp =rvtrace_ramsink_read_pair (comp->pdata,RVTRACE_RAMSINK_WPLOW_OFF ); wrap = wp &RVTRACE_RAMSINK_WPLOW_WRAP ; wp &= ~RVTRACE_RAMSINK_WPLOW_WRAP ;
include/linux/gtrace.h +0 -3
@@ -96,7 +96,6 @@ struct gtrace_hw_ops {* @bound_cpu: CPU to which the component is bound, or -1 if unbound. For a * source component bound to a CPU this must not be -1. * @control_poll_timeout_usecs: Delay in usecs when polling control bits. -* @format: Trace format selected by the platform driver. * @nr_inconns: Number of input connections. * @inconns: Array of pointers to input connections. * @nr_outconns: Number of output connections.
@@ -128,8 +127,6 @@ struct gtrace_platform_data {/* Delay in microseconds when polling control register bits */ int control_poll_timeout_usecs; -enum gtrace_format format; -/* * Platform driver must only populate empty pointer array without * any actual input connections.
Signature · 1 line
2.34.1
PATCH 4/24 gtrace: Add RISC-V trace encoder sysfs support
In reply to Zane LeungAdd sysfs attribute support for RISC-V trace encoder components in the platform driver. The encoder attribute groups are now assigned to pdata->groups based on component type during registration, enabling encoder configuration through sysfs interfaces.
---
drivers/hwtracing/gtrace/Makefile | 1 +
...trace-encoder.c => rvtrace-encoder-core.c} | 117 +++++--
.../hwtracing/gtrace/rvtrace-encoder-sysfs.c | 290 ++++++++++++++++++
drivers/hwtracing/gtrace/rvtrace-encoder.h | 53 ++++
drivers/hwtracing/gtrace/rvtrace-platform.c | 8 +
drivers/hwtracing/gtrace/rvtrace.h | 3 +
6 files changed, 438 insertions(+), 34 deletions(-)
rename drivers/hwtracing/gtrace/{rvtrace-encoder.c => rvtrace-encoder-core.c} (60%)
create mode 100644 drivers/hwtracing/gtrace/rvtrace-encoder-sysfs.c
create mode 100644 drivers/hwtracing/gtrace/rvtrace-encoder.hdrivers/hwtracing/gtrace/Makefile +1 -0
@@ -6,4 +6,5 @@ gtrace-$(CONFIG_OF) += gtrace-of.o obj-$(CONFIG_RVTRACE) += rvtrace-platform.o obj-$(CONFIG_RVTRACE_ENCODER) += rvtrace-encoder.o +rvtrace-encoder-y := rvtrace-encoder-core.o rvtrace-encoder-sysfs.o obj-$(CONFIG_RVTRACE_RAMSINK) += rvtrace-ramsink.o
drivers/hwtracing/gtrace/rvtrace-encoder-core.c renamed from drivers/hwtracing/gtrace/rvtrace-encoder.c +83 -34
168 lines not on this page · raw message
drivers/hwtracing/gtrace/rvtrace-encoder-sysfs.c new file +290 -0
290 lines not on this page · raw message
drivers/hwtracing/gtrace/rvtrace-encoder.h new file +53 -0
53 lines not on this page · raw message
drivers/hwtracing/gtrace/rvtrace-platform.c +8 -0
@@ -129,6 +129,14 @@ static int rvtrace_platform_probe(struct platform_device *pdev) id.type = gtype; id.version =rvtrace_component_mkversion (major, minor); +switch (gtype) { +case GTRACE_RVTRACE_ENCODER : + pdata->groups = rvtrace_encoder_groups; +break ; +default : + pdata->groups =NULL ; + } + comp =gtrace_register_component (&id,rvtrace_type_name (gtype), pdata);if (IS_ERR (comp))return PTR_ERR (comp);
drivers/hwtracing/gtrace/rvtrace.h +3 -0
@@ -118,4 +118,7 @@ static inline int rvtrace_comp_poll_empty(struct gtrace_component *comp)extern const struct gtrace_hw_ops rvtrace_hw_ops; +/* Sysfs attribute groups for RISC-V trace components */ +extern const struct attribute_group *rvtrace_encoder_groups[]; +#endif /* __LINUX_RVTRACE_H__ */
Signature · 1 line
2.34.1
PATCH 5/24 gtrace: Introduce some PMU format attributes
In reply to Zane LeungAdd new PMU format attributes to support timestamp, context, and synchronization controls. This allows userspace tools like perf to pass detailed hardware configurations down to the gtrace framework.
--- drivers/hwtracing/gtrace/gtrace-perf.c | 12 ++++++++++++ include/linux/gtrace.h | 7 +++++++ 2 files changed, 19 insertions(+)
drivers/hwtracing/gtrace/gtrace-perf.c +12 -0
@@ -323,9 +323,21 @@ static void gtrace_event_del(struct perf_event *event, int mode) }PMU_FORMAT_ATTR (event,"config:0-0" ); +PMU_FORMAT_ATTR (context,"config:1-1" ); +PMU_FORMAT_ATTR (syncmode,"config:2-3" ); +PMU_FORMAT_ATTR (syncmax,"config:4-7" ); +PMU_FORMAT_ATTR (timestamp,"config:8-8" ); +PMU_FORMAT_ATTR (tsmode,"config:9-11" ); +PMU_FORMAT_ATTR (tsprescale,"config:12-13" );static struct attribute *gtrace_pmu_formats_attr[] = { &format_attr_event.attr, + &format_attr_context.attr, + &format_attr_syncmode.attr, + &format_attr_syncmax.attr, + &format_attr_timestamp.attr, + &format_attr_tsmode.attr, + &format_attr_tsprescale.attr,NULL , };
include/linux/gtrace.h +7 -0
@@ -14,6 +14,13 @@#include <linux/property.h> #include <linux/types.h> +#define GTRACE_PMU_ATTR_CFG_CONTEXT_SHIFT 1 +#define GTRACE_PMU_ATTR_CFG_SYNCMODE_MASK GENMASK(3, 2) +#define GTRACE_PMU_ATTR_CFG_SYNCMAX_MASK GENMASK(7, 4) +#define GTRACE_PMU_ATTR_CFG_TIMESTAMP_SHIFT 8 +#define GTRACE_PMU_ATTR_CFG_TSMODE_MASK GENMASK(11, 9) +#define GTRACE_PMU_ATTR_CFG_TSPRESCALE_MASK GENMASK(13, 12) +extern struct mutex gtrace_mutex;/*
Signature · 1 line
2.34.1
PATCH 6/24 gtrace: Replace owner PID with perf_event pointer in gtrace_path
In reply to Zane LeungReplace 'pid_t owner' with 'struct perf_event *event' in struct gtrace_path. This allows component drivers to directly access the perf_event for PMU configuration.
--- drivers/hwtracing/gtrace/gtrace-core.c | 12 ++++++++++-- drivers/hwtracing/gtrace/gtrace-perf.c | 2 +- include/linux/gtrace.h | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-)
drivers/hwtracing/gtrace/gtrace-core.c +10 -2
@@ -13,6 +13,7 @@#include <linux/spinlock.h> #include <linux/xarray.h> #include <linux/gtrace.h> +#include <linux/perf_event.h> #define GTRACE_POLL_TIMEOUT_US_DEFAULT 10
@@ -665,10 +666,16 @@ static int __gtrace_comp_start(struct gtrace_component *comp,raw_spin_lock_irqsave (&cpriv->lock, flags);if (cpriv->start_count) { -if (cpriv->owner != path->owner || cpriv->mode != path->mode) { +if (cpriv->mode != path->mode) { ret = -EBUSY ; goto out; } +if (cpriv->mode ==GTRACE_COMPONENT_MODE_PERF ) { +if (cpriv->owner !=task_pid_nr (path->event->owner)) { + ret = -EBUSY ; + goto out; + } + } }else {if (gtdrv->start) { comp->path = path;
@@ -678,8 +685,9 @@ static int __gtrace_comp_start(struct gtrace_component *comp, goto out; } } - cpriv->owner = path->owner; cpriv->mode = path->mode; +if (cpriv->mode ==GTRACE_COMPONENT_MODE_PERF ) + cpriv->owner =task_pid_nr (path->event->owner); } cpriv->start_count++;
drivers/hwtracing/gtrace/gtrace-perf.c +1 -1
@@ -137,7 +137,7 @@ static void *gtrace_setup_aux(struct perf_event *event, void **pages,continue ; } - path->owner =task_pid_nr (event->owner); + path->event = event; *gtrace_event_cpu_path_ptr (event_data, cpu) = path; }
include/linux/gtrace.h +1 -1
@@ -325,7 +325,7 @@ struct gtrace_path {enum gtrace_component_mode mode;u32 trace_id;#define GTRACE_INVALID_TRACE_ID 0 -pid_t owner; +struct perf_event *event; };struct gtrace_component *gtrace_path_source (struct gtrace_path *path);
Signature · 1 line
2.34.1
PATCH 7/24 gtrace: Parse RISC-V Trace encoder config from perf event
In reply to Zane LeungParse the hardware trace encoder configurations (timestamp, context, syncmode, and syncmax) from perf event attributes when operating in GTRACE_COMPONENT_MODE_PERF.
--- .../hwtracing/gtrace/rvtrace-encoder-core.c | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/hwtracing/gtrace/rvtrace-encoder-core.c +20 -0
@@ -140,13 +140,33 @@ static int rvtrace_encoder_probe(struct gtrace_component *comp)return 0 ; } +static void rvtrace_encoder_parse_event_config (struct rvtrace_encoder_priv *priv, +struct perf_event *event) +{ +u64 config = event->attr.config; +enum rvtrace_encoder_syncmode syncmode; + +if (priv->has_context) + priv->context = config &BIT (GTRACE_PMU_ATTR_CFG_CONTEXT_SHIFT ); + + syncmode =FIELD_GET (GTRACE_PMU_ATTR_CFG_SYNCMODE_MASK , config); +if (priv->syncmode_hw[syncmode]) { + priv->syncmode = syncmode; + priv->syncmax =FIELD_GET (GTRACE_PMU_ATTR_CFG_SYNCMAX_MASK , config); + } +} +static int rvtrace_encoder_start (struct gtrace_component *comp) {struct rvtrace_encoder_priv *priv =dev_get_drvdata (&comp->dev);struct gtrace_platform_data *pdata = comp->pdata; +struct gtrace_path *path = comp->path;int ret;u32 val; +if (path->mode ==GTRACE_COMPONENT_MODE_PERF ) +rvtrace_encoder_parse_event_config (priv, path->event); +if (priv->srcbits)rvtrace_encoder_set_srcid (pdata, priv->srcbits);
Signature · 1 line
2.34.1
PATCH 8/24 gtrace: add perf symlink support for gtrace components
In reply to Zane LeungImplement gtrace_perf_symlink() to let RISC-V Trace encoder link themselves to the gtrace PMU directory as "cpuX" based on their bound CPU.
--- drivers/hwtracing/gtrace/gtrace-perf.c | 29 +++++++++++++++++-- .../hwtracing/gtrace/rvtrace-encoder-core.c | 10 +++++++ include/linux/gtrace.h | 2 ++ 3 files changed, 39 insertions(+), 2 deletions(-)
drivers/hwtracing/gtrace/gtrace-perf.c +27 -2
@@ -23,6 +23,7 @@#define GTRACE_PMU_NAME "gtrace"static struct pmu gtrace_pmu;static struct workqueue_struct *gtrace_wq; +static bool gtrace_perf_up;/** * struct gtrace_event_data - generic hardware trace perf event data
@@ -351,6 +352,27 @@ static const struct attribute_group *gtrace_pmu_attr_groups[] = { NULL, }; +int gtrace_perf_symlink (struct gtrace_component *comp,bool link) +{ +char entry[sizeof ("cpu9999999" )]; +int ret =0 , cpu = comp->pdata->bound_cpu; +struct device *pmu_dev = gtrace_pmu.dev; +struct device *comp_dev = &comp->dev; + +sprintf (entry,"cpu%d" , cpu); + +if (!gtrace_perf_up) +return -EPROBE_DEFER ; + +if (link) + ret =sysfs_create_link (&pmu_dev->kobj, &comp_dev->kobj, entry); +else +sysfs_remove_link (&pmu_dev->kobj, entry); + +return ret; +} +EXPORT_SYMBOL_GPL (gtrace_perf_symlink); +int __init gtrace_perf_init (void ) {int ret;
@@ -373,10 +395,13 @@ int __init gtrace_perf_init(void)return -ENOMEM ; ret =perf_pmu_register (>race_pmu,GTRACE_PMU_NAME ,-1 ); -if (ret) +if (ret) {destroy_workqueue (gtrace_wq); +return ret; + } -return ret; + gtrace_perf_up = true; +return 0 ; } void __exit gtrace_perf_exit(void)
drivers/hwtracing/gtrace/rvtrace-encoder-core.c +10 -0
@@ -129,6 +129,10 @@ static int rvtrace_encoder_probe(struct gtrace_component *comp) }dev_set_drvdata (&comp->dev, priv); + ret =gtrace_perf_symlink (comp, true); +if (ret) +return ret; +if (boot_enable) { ret =gtrace_enable_sysfs (comp);if (ret) {
@@ -140,6 +144,11 @@ static int rvtrace_encoder_probe(struct gtrace_component *comp)return 0 ; } +static void rvtrace_encoder_remove (struct gtrace_component *comp) +{ +gtrace_perf_symlink (comp, false); +} +static void rvtrace_encoder_parse_event_config (struct rvtrace_encoder_priv *priv,struct perf_event *event) {
@@ -240,6 +249,7 @@ static const struct gtrace_component_id rvtrace_encoder_ids[] = {static struct gtrace_driver rvtrace_encoder_driver = { .id_table = rvtrace_encoder_ids, .probe = rvtrace_encoder_probe, + .remove = rvtrace_encoder_remove, .start = rvtrace_encoder_start, .stop = rvtrace_encoder_stop, .driver = {
include/linux/gtrace.h +2 -0
@@ -437,4 +437,6 @@ int gtrace_disable_sysfs(struct gtrace_component *comp);int gtrace_sysfs_add (struct gtrace_component *comp);void gtrace_sysfs_remove (struct gtrace_component *comp); +int gtrace_perf_symlink (struct gtrace_component *comp,bool link); +#endif /* __LINUX_GTRACE_H__ */
Signature · 1 line
2.34.1
PATCH 9/24 gtrace: Add port-level start/stop driver callbacks
In reply to Zane LeungAdd start_port() and stop_port() callbacks to gtrace_driver so multi-port link components like funnel and replicator can enable a specific input/output port the first time a path uses it, tracked by the per-connection src_refcnt/dest_refcnt fields.
--- drivers/hwtracing/gtrace/gtrace-core.c | 66 ++++++++++++++++++++------ include/linux/gtrace.h | 12 +++++ 2 files changed, 64 insertions(+), 14 deletions(-)
drivers/hwtracing/gtrace/gtrace-core.c +52 -14
@@ -654,7 +654,9 @@ static void gtrace_release_path_nodes(struct gtrace_path *path) }static int __gtrace_comp_start (struct gtrace_component *comp, -struct gtrace_path *path) +struct gtrace_path *path, +struct gtrace_connection *inconn, +struct gtrace_connection *outconn) {struct gtrace_comp_priv *cpriv =to_gtrace_comp_priv (comp);const struct gtrace_driver *gtdrv =to_gtrace_driver (comp->dev.driver);
@@ -690,6 +692,12 @@ static int __gtrace_comp_start(struct gtrace_component *comp, cpriv->owner =task_pid_nr (path->event->owner); } +if (gtdrv->start_port) { + ret = gtdrv->start_port (comp, inconn, outconn); +if (ret) + goto out; + } + cpriv->start_count++; out:raw_spin_unlock_irqrestore (&cpriv->lock, flags);
@@ -697,7 +705,9 @@ static int __gtrace_comp_start(struct gtrace_component *comp, }static int __gtrace_comp_stop (struct gtrace_component *comp, -struct gtrace_path *path) +struct gtrace_path *path, +struct gtrace_connection *inconn, +struct gtrace_connection *outconn) {struct gtrace_comp_priv *cpriv =to_gtrace_comp_priv (comp);const struct gtrace_driver *gtdrv =to_gtrace_driver (comp->dev.driver);
@@ -715,13 +725,16 @@ static int __gtrace_comp_stop(struct gtrace_component *comp, goto out; } +if (!gtdrv) { + ret = -ENODEV ; + goto out; + } + +if (gtdrv->stop_port) + gtdrv->stop_port (comp, inconn, outconn); + cpriv->start_count--;if (!cpriv->start_count) { -if (!gtdrv) { - ret = -ENODEV ; - goto out; - } -if (gtdrv->stop) ret = gtdrv->stop (comp); comp->path =NULL ;
@@ -734,19 +747,36 @@ static int __gtrace_comp_stop(struct gtrace_component *comp,int gtrace_path_start (struct gtrace_path *path) { -struct gtrace_path_node *node; +struct gtrace_path_node *node, *prev; +struct gtrace_connection *inconn;int ret =0 ;list_for_each_entry_reverse (node, &path->comp_list, head) { - ret =__gtrace_comp_start (node->comp, path); +if (node->comp ==gtrace_path_source (path)) { + inconn =NULL ; + }else { + prev =list_prev_entry (node, head); + inconn = prev->conn; + } + + ret =__gtrace_comp_start (node->comp, path, inconn, node->conn);if (ret)break ; }/* If a component failed to start, stop all the components that were started before it */ -if (ret) -list_for_each_entry_continue (node, &path->comp_list, head) -__gtrace_comp_stop (node->comp, path); +if (ret) { +list_for_each_entry_continue (node, &path->comp_list, head) { +if (node->comp ==gtrace_path_source (path)) { + inconn =NULL ; + }else { + prev =list_prev_entry (node, head); + inconn = prev->conn; + } + +__gtrace_comp_stop (node->comp, path, inconn, node->conn); + } + }return ret; }
@@ -754,11 +784,19 @@ EXPORT_SYMBOL_GPL(gtrace_path_start);int gtrace_path_stop (struct gtrace_path *path) { -struct gtrace_path_node *node; +struct gtrace_path_node *node, *prev; +struct gtrace_connection *inconn;int ret =0 , err;list_for_each_entry (node, &path->comp_list, head) { - err =__gtrace_comp_stop (node->comp, path); +if (node->comp ==gtrace_path_source (path)) { + inconn =NULL ; + }else { + prev =list_prev_entry (node, head); + inconn = prev->conn; + } + + err =__gtrace_comp_stop (node->comp, path, inconn, node->conn);if (err && !ret) ret = err; }
include/linux/gtrace.h +12 -0
@@ -55,9 +55,11 @@ enum gtrace_format {* @src_port: A connection's source port number. * @src_fwnode: Source component's fwnode handle. * @src_comp: Source component's pointer. +* @src_refcnt: Number of paths currently using this connection's source port. * @dest_port: A connection's destination port number. * @dest_fwnode: Destination component's fwnode handle. * @dest_comp: Destination component's pointer. +* @dest_refcnt: Number of paths currently routing data into the destination port. */ struct gtrace_connection {int src_port;
@@ -66,6 +68,8 @@ struct gtrace_connection {struct fwnode_handle *dest_fwnode;struct gtrace_component *src_comp;struct gtrace_component *dest_comp; +u32 src_refcnt; +u32 dest_refcnt; };struct gtrace_platform_data ;
@@ -363,6 +367,8 @@ int gtrace_path_copyto_auxbuf(struct gtrace_path *path,* via @format (see PERF_AUX_FLAG_PMU_FORMAT_TYPE_MASK). * @start: Callback to start tracing. * @stop: Callback to stop tracing. +* @start_port: Callback to start a specific component port. +* @stop_port: Callback to stop a specific component port. * @probe: Driver probe() function. * @remove: Driver remove() function. * @get_trace_id: Get/allocate a trace ID.
@@ -376,6 +382,12 @@ struct gtrace_driver { u64 *format);int (*start)(struct gtrace_component *comp);int (*stop)(struct gtrace_component *comp); +int (*start_port)(struct gtrace_component *comp, +struct gtrace_connection *inconn, +struct gtrace_connection *outconn); +void (*stop_port)(struct gtrace_component *comp, +struct gtrace_connection *inconn, +struct gtrace_connection *outconn);int (*probe)(struct gtrace_component *comp);void (*remove)(struct gtrace_component *comp); int (*get_trace_id)(struct gtrace_component *comp,
Signature · 1 line
2.34.1
PATCH 10/24 gtrace: Add RISC-V trace funnel driver
In reply to Zane LeungAdd initial implementation of RISC-V Trace funnel driver. The funnel is defined in the RISC-V Trace Control Interface specification.
--- drivers/hwtracing/gtrace/Kconfig | 14 ++ drivers/hwtracing/gtrace/Makefile | 1 + drivers/hwtracing/gtrace/rvtrace-funnel.c | 165 ++++++++++++++++++++ drivers/hwtracing/gtrace/rvtrace-funnel.h | 21 +++ drivers/hwtracing/gtrace/rvtrace-platform.c | 3 + drivers/hwtracing/gtrace/rvtrace.h | 1 + 6 files changed, 205 insertions(+) create mode 100644 drivers/hwtracing/gtrace/rvtrace-funnel.c create mode 100644 drivers/hwtracing/gtrace/rvtrace-funnel.h
drivers/hwtracing/gtrace/Kconfig +14 -0
@@ -57,3 +57,17 @@ config RVTRACE_RAMSINK To compile this driver as a module, choose M here: the module will be called rvtrace-ramsink. + +config RVTRACE_FUNNEL + tristate "RISC-V Trace Funnel driver" + depends on RVTRACE + default y + help + This driver provides support for the RISC-V trace funnel component + which is defined by the RISC-V Trace Control Interface specification. + The funnel merges trace data from multiple input ports into a single + output stream. It is a link component in the trace path between + sources and sinks. + + To compile this driver as a module, choose M here: the module + will be called rvtrace-funnel.
drivers/hwtracing/gtrace/Makefile +1 -0
@@ -8,3 +8,4 @@ obj-$(CONFIG_RVTRACE) += rvtrace-platform.o obj-$(CONFIG_RVTRACE_ENCODER) += rvtrace-encoder.o rvtrace-encoder-y := rvtrace-encoder-core.o rvtrace-encoder-sysfs.o obj-$(CONFIG_RVTRACE_RAMSINK) += rvtrace-ramsink.o +obj-$(CONFIG_RVTRACE_FUNNEL) += rvtrace-funnel.o
drivers/hwtracing/gtrace/rvtrace-funnel.c new file +165 -0
165 lines not on this page · raw message
drivers/hwtracing/gtrace/rvtrace-funnel.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (c) 2026 Spacemit Technologies, Inc. +*/ + +#ifndef __RVTRACE_HENNEL_H__ +#define __RVTRACE_HENNEL_H__ + +#define RVTRACE_FUNNEL_DISINPUT_OFFSET 0x008 +#define RVTRACE_FUNNEL_DISINPUT_MASK 0xffff + +/** +* struct rvtrace_encoder_priv - Private driver data for the rvtrace funnel +* @disinput_mask: Bitmask of inputs supporting disable. +*/ + +struct rvtrace_funnel_priv { +u32 disinput_mask; +}; + +#endif /* __RVTRACE_ENCODER_H__ */
drivers/hwtracing/gtrace/rvtrace-platform.c +3 -0
@@ -133,6 +133,9 @@ static int rvtrace_platform_probe(struct platform_device *pdev)case GTRACE_RVTRACE_ENCODER : pdata->groups = rvtrace_encoder_groups;break ; +case GTRACE_RVTRACE_FUNNEL : + pdata->groups = rvtrace_funnel_groups; +break ;default : pdata->groups =NULL ; }
drivers/hwtracing/gtrace/rvtrace.h +1 -0
@@ -120,5 +120,6 @@ extern const struct gtrace_hw_ops rvtrace_hw_ops;/* Sysfs attribute groups for RISC-V trace components */ extern const struct attribute_group *rvtrace_encoder_groups[]; +extern const struct attribute_group *rvtrace_funnel_groups[];#endif /* __LINUX_RVTRACE_H__ */
Signature · 1 line
2.34.1
PATCH 11/24 gtrace: Add RISC-V trace timestamp support
In reply to Zane LeungAdd a shared timestamp component for the RISC-V trace encoder and funnel.
--- drivers/hwtracing/gtrace/Makefile | 3 +- .../hwtracing/gtrace/rvtrace-encoder-core.c | 16 +- .../hwtracing/gtrace/rvtrace-encoder-sysfs.c | 33 ++ drivers/hwtracing/gtrace/rvtrace-encoder.h | 8 + drivers/hwtracing/gtrace/rvtrace-funnel.c | 55 +++ drivers/hwtracing/gtrace/rvtrace-funnel.h | 8 + drivers/hwtracing/gtrace/rvtrace-timestamp.c | 336 ++++++++++++++++++ drivers/hwtracing/gtrace/rvtrace-timestamp.h | 44 +++ 8 files changed, 500 insertions(+), 3 deletions(-) create mode 100644 drivers/hwtracing/gtrace/rvtrace-timestamp.c create mode 100644 drivers/hwtracing/gtrace/rvtrace-timestamp.h
drivers/hwtracing/gtrace/Makefile +2 -1
@@ -4,7 +4,8 @@ obj-$(CONFIG_GTRACE) += gtrace.o gtrace-y := gtrace-core.o gtrace-perf.o gtrace-sysfs.o gtrace-$(CONFIG_OF) += gtrace-of.o -obj-$(CONFIG_RVTRACE) += rvtrace-platform.o +obj-$(CONFIG_RVTRACE) += rvtrace.o +rvtrace-y := rvtrace-platform.o rvtrace-timestamp.o obj-$(CONFIG_RVTRACE_ENCODER) += rvtrace-encoder.o rvtrace-encoder-y := rvtrace-encoder-core.o rvtrace-encoder-sysfs.o obj-$(CONFIG_RVTRACE_RAMSINK) += rvtrace-ramsink.o
drivers/hwtracing/gtrace/rvtrace-encoder-core.c +14 -2
@@ -127,6 +127,10 @@ static int rvtrace_encoder_probe(struct gtrace_component *comp) val |=BIT (RVTRACE_COMPONENT_CTRL_INHIBITSRC_SHIFT );gtrace_write32 (pdata, val,RVTRACE_COMPONENT_CTRL_OFFSET ); } + + priv->has_timestamp =rvtrace_timestamp_reset (pdata) ==0 ; +if (priv->has_timestamp) +rvtrace_timestamp_init (pdata, &priv->ts_priv);dev_set_drvdata (&comp->dev, priv); ret =gtrace_perf_symlink (comp, true);
@@ -155,6 +159,8 @@ static void rvtrace_encoder_parse_event_config(struct rvtrace_encoder_priv *privu64 config = event->attr.config;enum rvtrace_encoder_syncmode syncmode; +if (priv->has_timestamp) + priv->ts_ctrl = config &BIT (GTRACE_PMU_ATTR_CFG_TIMESTAMP_SHIFT );if (priv->has_context) priv->context = config &BIT (GTRACE_PMU_ATTR_CFG_CONTEXT_SHIFT );
@@ -170,11 +176,17 @@ static int rvtrace_encoder_start(struct gtrace_component *comp)struct rvtrace_encoder_priv *priv =dev_get_drvdata (&comp->dev);struct gtrace_platform_data *pdata = comp->pdata;struct gtrace_path *path = comp->path; +struct perf_event *event =NULL ;int ret;u32 val; -if (path->mode ==GTRACE_COMPONENT_MODE_PERF ) -rvtrace_encoder_parse_event_config (priv, path->event); +if (path->mode ==GTRACE_COMPONENT_MODE_PERF ) { + event = path->event; +rvtrace_encoder_parse_event_config (priv, event); + } + +if (priv->has_timestamp) +rvtrace_timestamp_setup (pdata, &priv->ts_priv, event, priv->ts_ctrl);if (priv->srcbits)rvtrace_encoder_set_srcid (pdata, priv->srcbits);
drivers/hwtracing/gtrace/rvtrace-encoder-sysfs.c +33 -0
@@ -84,8 +84,40 @@ static ssize_t cpu_show(struct device *dev, }static DEVICE_ATTR_RO (cpu); +static ssize_t ts_ctrl_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct gtrace_component *comp =to_gtrace_component (dev); +struct rvtrace_encoder_priv *priv =dev_get_drvdata (&comp->dev); + +return sysfs_emit (buf,"%u\n" , priv->ts_ctrl); +} + +static ssize_t ts_ctrl_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t size) +{ +int ret; +unsigned long val; +struct gtrace_component *comp =to_gtrace_component (dev); +struct rvtrace_encoder_priv *priv =dev_get_drvdata (&comp->dev); + +if (!priv->has_timestamp) +return -EINVAL ; + + ret =kstrtoul (buf,10 , &val); +if (ret) +return ret; + + priv->ts_ctrl = !!val; + +return size; +} +static DEVICE_ATTR_RW (ts_ctrl); +static struct attribute *rvtrace_encoder_attrs[] = { &dev_attr_cpu.attr, + &dev_attr_ts_ctrl.attr,NULL , };
@@ -285,6 +317,7 @@ const struct attribute_group *rvtrace_encoder_groups[] = { &rvtrace_encoder_mgmt_group, &rvtrace_encoder_control_group, &rvtrace_encoder_features_group, + &rvtrace_timestamp_group,NULL , };EXPORT_SYMBOL_GPL (rvtrace_encoder_groups);
drivers/hwtracing/gtrace/rvtrace-encoder.h +8 -0
@@ -3,6 +3,8 @@#ifndef __RVTRACE_ENCODER_H__#define __RVTRACE_ENCODER_H__ +#include "rvtrace-timestamp.h" +#define RVTRACE_COMPONENT_CTRL_ITRACE_SHIFT 2#define RVTRACE_COMPONENT_CTRL_INSTMODE_MASK GENMASK(6, 4)#define RVTRACE_COMPONENT_CTRL_INSTMODE_OPIT 0x6
@@ -38,6 +40,9 @@ enum rvtrace_encoder_syncmode {* @has_context: Hardware flag for scontext/mcontext and privilege tracking. * @context: Current configuration for scontext/mcontext and privilege tracking. * @boot_enable: Flag to automatically enable tracing on boot. +* @has_timestamp: Hardware flag indicating if timestamp generation is supported. +* @ts_ctrl: Current configuration state of timestamp control. +* @ts_priv: Private configuration data specific to the timestamp unit. */ struct rvtrace_encoder_priv {bool syncmode_hw[RVTRACE_ENCODER_SYNCMODE_MAX ];
@@ -48,6 +53,9 @@ struct rvtrace_encoder_priv {bool has_context;bool context;bool boot_enable; +bool has_timestamp; +bool ts_ctrl; + struct rvtrace_timestamp_priv ts_priv; };#endif /* __RVTRACE_ENCODER_H__ */
drivers/hwtracing/gtrace/rvtrace-funnel.c +55 -0
85 lines not on this page · raw message
drivers/hwtracing/gtrace/rvtrace-funnel.h +8 -0
@@ -6,16 +6,24 @@#ifndef __RVTRACE_HENNEL_H__#define __RVTRACE_HENNEL_H__ +#include "rvtrace-timestamp.h" +#define RVTRACE_FUNNEL_DISINPUT_OFFSET 0x008#define RVTRACE_FUNNEL_DISINPUT_MASK 0xffff/** * struct rvtrace_encoder_priv - Private driver data for the rvtrace funnel * @disinput_mask: Bitmask of inputs supporting disable. +* @has_timestamp: Hardware flag indicating if timestamp generation is supported. +* @ts_ctrl: Current configuration state of timestamp control. +* @ts_priv: Private configuration data specific to the timestamp unit. */ struct rvtrace_funnel_priv {u32 disinput_mask; +bool has_timestamp; +bool ts_ctrl; +struct rvtrace_timestamp_priv ts_priv; };#endif /* __RVTRACE_ENCODER_H__ */
drivers/hwtracing/gtrace/rvtrace-timestamp.c new file +336 -0
336 lines not on this page · raw message
drivers/hwtracing/gtrace/rvtrace-timestamp.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 12/24 gtrace: Add RISC-V trace ATB bridge driver
In reply to Zane LeungAdd initial implementation of RISC-V Trace atbbridge driver. The atbbridge is defined in the RISC-V Trace Control Interface specification.
--- drivers/hwtracing/gtrace/Kconfig | 15 ++ drivers/hwtracing/gtrace/Makefile | 1 + drivers/hwtracing/gtrace/rvtrace-atbbridge.c | 153 +++++++++++++++++++ drivers/hwtracing/gtrace/rvtrace-platform.c | 3 + drivers/hwtracing/gtrace/rvtrace.h | 1 + 5 files changed, 173 insertions(+) create mode 100644 drivers/hwtracing/gtrace/rvtrace-atbbridge.c
drivers/hwtracing/gtrace/Kconfig +15 -0
@@ -71,3 +71,18 @@ config RVTRACE_FUNNEL To compile this driver as a module, choose M here: the module will be called rvtrace-funnel. + +config RVTRACE_ATBBRIDGE + tristate "RISC-V Trace ATB Bridge driver" + depends on RVTRACE + default y + help + This driver provides support for the RISC-V trace ATB bridge + component which is defined by the RISC-V Trace Control Interface + specification. The ATB bridge converts the RISC-V trace stream + to the ARM Advanced Trace Bus (ATB) protocol, allowing RISC-V + trace sources to feed into ARM CoreSight trace components. It is + a link component in the trace path. + + To compile this driver as a module, choose M here: the module + will be called rvtrace-atbbridge.
drivers/hwtracing/gtrace/Makefile +1 -0
@@ -10,3 +10,4 @@ obj-$(CONFIG_RVTRACE_ENCODER) += rvtrace-encoder.o rvtrace-encoder-y := rvtrace-encoder-core.o rvtrace-encoder-sysfs.o obj-$(CONFIG_RVTRACE_RAMSINK) += rvtrace-ramsink.o obj-$(CONFIG_RVTRACE_FUNNEL) += rvtrace-funnel.o +obj-$(CONFIG_RVTRACE_ATBBRIDGE) += rvtrace-atbbridge.o
drivers/hwtracing/gtrace/rvtrace-atbbridge.c new file +153 -0
153 lines not on this page · raw message
drivers/hwtracing/gtrace/rvtrace-platform.c +3 -0
@@ -136,6 +136,9 @@ static int rvtrace_platform_probe(struct platform_device *pdev)case GTRACE_RVTRACE_FUNNEL : pdata->groups = rvtrace_funnel_groups;break ; +case GTRACE_RVTRACE_ATBBRIDGE : + pdata->groups = rvtrace_atbbridge_groups; +break ;default : pdata->groups =NULL ; }
drivers/hwtracing/gtrace/rvtrace.h +1 -0
@@ -121,5 +121,6 @@ extern const struct gtrace_hw_ops rvtrace_hw_ops;/* Sysfs attribute groups for RISC-V trace components */ extern const struct attribute_group *rvtrace_encoder_groups[];extern const struct attribute_group *rvtrace_funnel_groups[]; +extern const struct attribute_group *rvtrace_atbbridge_groups[];#endif /* __LINUX_RVTRACE_H__ */
Signature · 1 line
2.34.1
PATCH 13/24 gtrace: Add CoreSight platform core APIs
In reply to Zane LeungAdd CoreSight infrastructure for the gtrace framework, providing driver registration helper, clock management, and other core integration APIs.
--- drivers/hwtracing/gtrace/Kconfig | 15 + drivers/hwtracing/gtrace/Makefile | 1 + drivers/hwtracing/gtrace/coresight-platform.c | 279 ++++++++++++++++++ drivers/hwtracing/gtrace/coresight.h | 212 +++++++++++++ include/linux/gtrace.h | 7 + 5 files changed, 514 insertions(+) create mode 100644 drivers/hwtracing/gtrace/coresight-platform.c create mode 100644 drivers/hwtracing/gtrace/coresight.h
drivers/hwtracing/gtrace/Kconfig +15 -0
@@ -86,3 +86,18 @@ config RVTRACE_ATBBRIDGE To compile this driver as a module, choose M here: the module will be called rvtrace-atbbridge. + +config GTRACE_CORESIGHT + tristate "CoreSight Trace Support" + depends on RISCV + depends on GTRACE + select ARM_AMBA + help + This provides the CoreSight backend for the generic hardware trace + (gtrace) framework. It provides the CoreSight claim protocol, + component and driver registration helpers, and clock management + used by the individual CoreSight component drivers (TMC, funnel, + etc.) to register CoreSight hardware with the gtrace core. + + To compile this driver as a module, choose M here: the module + will be called coresight.
drivers/hwtracing/gtrace/Makefile +1 -0
@@ -11,3 +11,4 @@ rvtrace-encoder-y := rvtrace-encoder-core.o rvtrace-encoder-sysfs.o obj-$(CONFIG_RVTRACE_RAMSINK) += rvtrace-ramsink.o obj-$(CONFIG_RVTRACE_FUNNEL) += rvtrace-funnel.o obj-$(CONFIG_RVTRACE_ATBBRIDGE) += rvtrace-atbbridge.o +obj-$(CONFIG_GTRACE_CORESIGHT) += coresight-platform.o
drivers/hwtracing/gtrace/coresight-platform.c new file +279 -0
279 lines not on this page · raw message
drivers/hwtracing/gtrace/coresight.h new file +212 -0
212 lines not on this page · raw message
include/linux/gtrace.h +7 -0
@@ -33,6 +33,13 @@ enum gtrace_component_type {GTRACE_RVTRACE_RAMSINK ,GTRACE_RVTRACE_PIBSINK ,GTRACE_RVTRACE_ATBBRIDGE , +GTRACE_CORESIGHT_FUNNEL , +GTRACE_CORESIGHT_REPLICATOR , +GTRACE_CORESIGHT_TMC_ETB , +GTRACE_CORESIGHT_TMC_ETR , +GTRACE_CORESIGHT_TMC_ETF , +GTRACE_CORESIGHT_ETB , +GTRACE_CORESIGHT_TPIU ,GTRACE_COMPONENT_TYPE_MAX };
Signature · 1 line
2.34.1
PATCH 14/24 gtrace: Add CoreSight funnel driver
In reply to Zane LeungAdd a CoreSight funnel driver for the gtrace framework, derived from drivers/hwtracing/coresight/coresight-funnel.c.
--- drivers/hwtracing/gtrace/Kconfig | 13 + drivers/hwtracing/gtrace/Makefile | 1 + drivers/hwtracing/gtrace/coresight-funnel.c | 430 ++++++++++++++++++++ 3 files changed, 444 insertions(+) create mode 100644 drivers/hwtracing/gtrace/coresight-funnel.c
drivers/hwtracing/gtrace/Kconfig +13 -0
@@ -101,3 +101,16 @@ config GTRACE_CORESIGHT To compile this driver as a module, choose M here: the module will be called coresight. + +config CORESIGHT_FUNNEL + tristate "CoreSight Trace Funnel driver" + depends on GTRACE_CORESIGHT + default y + help + This driver provides support for the CoreSight funnel component. + The funnel merges trace data from multiple input ports into a single + output stream. It supports both static funnels (platform bus, + arm,coresight-static-funnel) and dynamic funnels (AMBA bus). + + To compile this driver as a module, choose M here: the module + will be called coresight-funnel.
drivers/hwtracing/gtrace/Makefile +1 -0
@@ -12,3 +12,4 @@ obj-$(CONFIG_RVTRACE_RAMSINK) += rvtrace-ramsink.o obj-$(CONFIG_RVTRACE_FUNNEL) += rvtrace-funnel.o obj-$(CONFIG_RVTRACE_ATBBRIDGE) += rvtrace-atbbridge.o obj-$(CONFIG_GTRACE_CORESIGHT) += coresight-platform.o +obj-$(CONFIG_CORESIGHT_FUNNEL) += coresight-funnel.o
drivers/hwtracing/gtrace/coresight-funnel.c new file +430 -0
430 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 15/24 gtrace: Only copy AUX data from the path sink
In reply to Zane Leunggtrace_path_copyto_auxbuf() walked the path and copied from the first component implementing copyto_auxbuf(). For a linksink like ETF used as a link, this picked the wrong component. Call the sink's callback directly via gtrace_path_sink() and pass the perf handle so the sink can set AUX flags itself.
--- drivers/hwtracing/gtrace/gtrace-core.c | 39 ++++++++++------------ drivers/hwtracing/gtrace/gtrace-perf.c | 13 ++------ drivers/hwtracing/gtrace/rvtrace-ramsink.c | 10 ++++-- include/linux/gtrace.h | 10 +++--- 4 files changed, 34 insertions(+), 38 deletions(-)
drivers/hwtracing/gtrace/gtrace-core.c +17 -22
@@ -806,14 +806,14 @@ int gtrace_path_stop(struct gtrace_path *path)EXPORT_SYMBOL_GPL (gtrace_path_stop);int gtrace_path_copyto_auxbuf (struct gtrace_path *path, +struct perf_output_handle *handle,struct gtrace_perf_auxbuf *buf, -size_t *bytes_copied,u64 *format) +size_t *bytes_copied) { -struct gtrace_comp_priv *sink =to_gtrace_comp_priv (gtrace_path_sink (path)); -const struct gtrace_driver *gtdrv; -struct gtrace_component *comp; -struct gtrace_path_node *node; -int ret = -EOPNOTSUPP ; +struct gtrace_component *sink =gtrace_path_sink (path); +struct gtrace_comp_priv *spriv =to_gtrace_comp_priv (sink); +const struct gtrace_driver *sinkdrv =to_gtrace_driver (sink->dev.driver); +int ret =0 ;unsigned long flags;/*
@@ -823,25 +823,20 @@ int gtrace_path_copyto_auxbuf(struct gtrace_path *path,* sink's lock also stops another path from starting the sink before copy * completes. */ -raw_spin_lock_irqsave (&sink->lock, flags); -if (sink->start_count) { - *bytes_copied =0 ; - ret =0 ; - goto out; - } - -list_for_each_entry (node, &path->comp_list, head) { - comp = node->comp; - gtdrv =to_gtrace_driver (comp->dev.driver); -if (!gtdrv || !gtdrv->copyto_auxbuf) -continue ; +raw_spin_lock_irqsave (&spriv->lock, flags); +if (!spriv->start_count) { +if (!sinkdrv) { + ret = -ENODEV ; + goto out; + } - *bytes_copied = gtdrv->copyto_auxbuf (comp, buf, format); - ret =0 ; -break ; +if (sinkdrv->copyto_auxbuf) { + *bytes_copied = sinkdrv->copyto_auxbuf (sink, handle, buf); + ret =0 ; + } } out: -raw_spin_unlock_irqrestore (&sink->lock, flags); +raw_spin_unlock_irqrestore (&spriv->lock, flags);return ret; }EXPORT_SYMBOL_GPL (gtrace_path_copyto_auxbuf);
drivers/hwtracing/gtrace/gtrace-perf.c +3 -10
@@ -243,7 +243,6 @@ static void gtrace_event_stop(struct perf_event *event, int mode) {struct gtrace_ctxt *ctxt =this_cpu_ptr (>race_ctxt);struct perf_output_handle *handle = &ctxt->handle; -u64 format =PERF_AUX_FLAG_GTRACE_FORMAT_UNKNOWN ;struct gtrace_event_data *event_data;int ret, cpu =smp_processor_id ();struct gtrace_path *path;
@@ -280,17 +279,11 @@ static void gtrace_event_stop(struct perf_event *event, int mode)if (handle->event && (mode &PERF_EF_UPDATE )) {if (WARN_ON_ONCE (handle->event != event))return ; - ret =gtrace_path_copyto_auxbuf (path, &event_data->buf, &size, &format); + ret =gtrace_path_copyto_auxbuf (path, handle, &event_data->buf, &size);WARN_ON_ONCE (ret); -if (READ_ONCE (handle->event)) { -/* Tag the AUX data with the source's trace format. */ -perf_aux_output_flag (handle, format); -if (size > handle->size) { - size = handle->size; -perf_aux_output_flag (handle,PERF_AUX_FLAG_TRUNCATED ); - } +if (READ_ONCE (handle->event))perf_aux_output_end (handle, size); - }else +else WARN_ON (size); }
drivers/hwtracing/gtrace/rvtrace-ramsink.c +8 -2
@@ -11,6 +11,7 @@#include <linux/minmax.h> #include <linux/types.h> #include <linux/sizes.h> +#include <linux/perf_event.h> #include <uapi/linux/perf_event.h> #include "rvtrace.h"
@@ -147,8 +148,8 @@ static void tbuf_to_pbuf_copy(struct trace_buf *src, struct trace_buf *dst, size }static size_t rvtrace_ramsink_copyto_auxbuf (struct gtrace_component *comp, -struct gtrace_perf_auxbuf *buf, -u64 *format) +struct perf_output_handle *handle, +struct gtrace_perf_auxbuf *buf) {struct rvtrace_ramsink_priv *priv =dev_get_drvdata (&comp->dev);struct trace_buf src, dst;
@@ -181,6 +182,11 @@ static size_t rvtrace_ramsink_copyto_auxbuf(struct gtrace_component *comp, priv->prev_wp = wp; } +if (bytes > handle->size) { + bytes = handle->size; +perf_aux_output_flag (handle,PERF_AUX_FLAG_TRUNCATED ); + } +tbuf_to_pbuf_copy (&src, &dst, bytes);dev_dbg (&comp->dev,"Copied %zu bytes\n" , bytes);return bytes;
include/linux/gtrace.h +6 -4
@@ -13,6 +13,7 @@#include <linux/platform_device.h> #include <linux/property.h> #include <linux/types.h> +#include <linux/perf_event.h> #define GTRACE_PMU_ATTR_CFG_CONTEXT_SHIFT 1#define GTRACE_PMU_ATTR_CFG_SYNCMODE_MASK GENMASK(3, 2)
@@ -363,15 +364,16 @@ struct gtrace_perf_auxbuf { };int gtrace_path_copyto_auxbuf (struct gtrace_path *path, +struct perf_output_handle *handle,struct gtrace_perf_auxbuf *buf, -size_t *bytes_copied,u64 *format); +size_t *bytes_copied);/** * struct gtrace_driver - Representation of a trace driver. * @id_table: Table to match components handled by the driver. * @copyto_auxbuf: Callback to copy data into perf AUX buffer. The driver * reports the PMU specific trace format of the copied data -* via @format (see PERF_AUX_FLAG_PMU_FORMAT_TYPE_MASK). +* via @handle (see PERF_AUX_FLAG_PMU_FORMAT_TYPE_MASK). * @start: Callback to start tracing. * @stop: Callback to stop tracing. * @start_port: Callback to start a specific component port.
@@ -385,8 +387,8 @@ int gtrace_path_copyto_auxbuf(struct gtrace_path *path,struct gtrace_driver {const struct gtrace_component_id *id_table;size_t (*copyto_auxbuf)(struct gtrace_component *comp, -struct gtrace_perf_auxbuf *buf, -u64 *format); +struct perf_output_handle *handle, +struct gtrace_perf_auxbuf *buf);int (*start)(struct gtrace_component *comp);int (*stop)(struct gtrace_component *comp); int (*start_port)(struct gtrace_component *comp,
Signature · 1 line
2.34.1
PATCH 16/24 perf: Flag whether gtrace AUX data carries CoreSight framing
In reply to Zane LeungDefine PERF_AUX_FLAG_GTRACE_FORMAT_CORESIGHT for the gtrace format which reports whether the data has been wrapped in CoreSight frame formatting by a CoreSight sink.
--- include/uapi/linux/perf_event.h | 1 + tools/include/uapi/linux/perf_event.h | 1 + 2 files changed, 2 insertions(+)
include/uapi/linux/perf_event.h +1 -0
@@ -1315,6 +1315,7 @@ enum perf_callchain_context {#define PERF_AUX_FLAG_GTRACE_FORMAT_UNKNOWN 0x0000#define PERF_AUX_FLAG_GTRACE_FORMAT_ETRACE 0x0100/* RISC-V E-trace format */ #define PERF_AUX_FLAG_GTRACE_FORMAT_NTRACE 0x0200/* RISC-V N-Trace format */ +#define PERF_AUX_FLAG_GTRACE_FORMAT_CORESIGHT 0x0300/* Trace with CoreSight formatted frames */ #define PERF_FLAG_FD_NO_GROUP (1UL << 0)#define PERF_FLAG_FD_OUTPUT (1UL << 1)
tools/include/uapi/linux/perf_event.h +1 -0
@@ -1315,6 +1315,7 @@ enum perf_callchain_context {#define PERF_AUX_FLAG_GTRACE_FORMAT_UNKNOWN 0x0000#define PERF_AUX_FLAG_GTRACE_FORMAT_ETRACE 0x0100/* RISC-V E-trace format */ #define PERF_AUX_FLAG_GTRACE_FORMAT_NTRACE 0x0200/* RISC-V N-Trace format */ +#define PERF_AUX_FLAG_GTRACE_FORMAT_CORESIGHT 0x0300/* Trace with CoreSight formatted frames */ #define PERF_FLAG_FD_NO_GROUP (1UL << 0)#define PERF_FLAG_FD_OUTPUT (1UL << 1)
Signature · 1 line
2.34.1
PATCH 17/24 gtrace: Unify default sink selection across CPUs in perf setup
In reply to Zane LeungIn gtrace_setup_aux(), remember the sink found for the first CPU and pass it to gtrace_create_path() for the remaining CPUs so they share a compatible default sink. Clear a CPU from the mask when no path can be built for it and abort when no sink is reachable at all.
--- drivers/hwtracing/gtrace/gtrace-perf.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/hwtracing/gtrace/gtrace-perf.c +15 -2
@@ -109,6 +109,7 @@ static void *gtrace_setup_aux(struct perf_event *event, void **pages, int nr_pages, bool overwrite) {struct gtrace_event_data *event_data =NULL ; +struct gtrace_component *sink =NULL ;struct page **pagelist;int cpu = event->cpu, i;cpumask_t *mask;
@@ -120,7 +121,7 @@ static void *gtrace_setup_aux(struct perf_event *event, void **pages,INIT_WORK (&event_data->work, free_event_data); mask = &event_data->mask;/* -* Create the path for each CPU in the mask. In case of any failure skip the CPU +* Create the path for each CPU in the mask. In case of any failure clear the CPU */ for_each_cpu (cpu, mask) {struct gtrace_component *src;
@@ -132,16 +133,28 @@ static void *gtrace_setup_aux(struct perf_event *event, void **pages,continue ; } - path =gtrace_create_path (src,NULL ,GTRACE_COMPONENT_MODE_PERF ); + path =gtrace_create_path (src, sink,GTRACE_COMPONENT_MODE_PERF );if (IS_ERR (path)) {cpumask_clear_cpu (cpu, mask);continue ; } +/* +* The first found sink is saved here and passed to +* gtrace_create_path() to check whether the remaining sources +* have a compatible default sink. +*/ +if (!sink) + sink =gtrace_path_sink (path); + path->event = event; *gtrace_event_cpu_path_ptr (event_data, cpu) = path; } +/* no sink found for any CPU - cannot trace */ +if (!sink) + goto err; +/* If we don't have any CPUs ready for tracing, abort */ cpu =cpumask_first (&event_data->mask);if (cpu >= nr_cpu_ids)
Signature · 1 line
2.34.1
PATCH 18/24 gtrace: Add sink-specific buffer alloc/free callbacks
In reply to Zane LeungExtend gtrace_driver with alloc_buf() and free_buf() so a sink can allocate its own buffer (e.g. an ETR SG table) during perf setup and release it when the event data is freed. Store the resulting buffer in gtrace_perf_auxbuf along with the event pid and snapshot mode.
--- drivers/hwtracing/gtrace/gtrace-perf.c | 34 ++++++++++++++++++++++++++ include/linux/gtrace.h | 12 +++++++++ 2 files changed, 46 insertions(+)
drivers/hwtracing/gtrace/gtrace-perf.c +34 -0
@@ -86,6 +86,27 @@ static struct gtrace_path **gtrace_event_cpu_path_ptr(struct gtrace_event_data *return per_cpu_ptr (data->path, cpu); } +static void free_sink_buffer (struct gtrace_event_data *event_data) +{ +int cpu; +cpumask_t *mask = &event_data->mask; +struct gtrace_path *path; +struct gtrace_component *sink; +struct gtrace_driver *sinkdrv; + +if (!event_data->buf.buf) +return ; + +if (WARN_ON (cpumask_empty (mask))) +return ; + + cpu =cpumask_first (mask); + path = *gtrace_event_cpu_path_ptr (event_data, cpu); + sink =gtrace_path_sink (path); + sinkdrv =to_gtrace_driver (sink->dev.driver); + sinkdrv->free_buf (event_data->buf.buf); +} +static void free_event_data (struct work_struct *work) {struct gtrace_event_data *event_data;
@@ -95,6 +116,7 @@ static void free_event_data(struct work_struct *work) event_data = container_of(work, struct gtrace_event_data, work); mask = &event_data->mask; +free_sink_buffer (event_data);for_each_cpu (cpu, mask) { path = *gtrace_event_cpu_path_ptr (event_data, cpu);gtrace_destroy_path (path);
@@ -110,6 +132,7 @@ static void *gtrace_setup_aux(struct perf_event *event, void **pages, {struct gtrace_event_data *event_data =NULL ;struct gtrace_component *sink =NULL ; +struct gtrace_driver *sinkdrv =NULL ;struct page **pagelist;int cpu = event->cpu, i;cpumask_t *mask;
@@ -175,6 +198,17 @@ static void *gtrace_setup_aux(struct perf_event *event, void **pages, event_data->buf.nr_pages = nr_pages; event_data->buf.length = nr_pages *PAGE_SIZE ; event_data->buf.pos =0 ; + event_data->buf.snapshot = overwrite; + event_data->buf.pages = pages; + + sinkdrv =to_gtrace_driver (sink->dev.driver); +if (sinkdrv && sinkdrv->alloc_buf) { + event_data->buf.buf = sinkdrv->alloc_buf (sink, event, pages, + nr_pages, overwrite); +if (!event_data->buf.buf) + goto err; + } +return event_data; err:gtrace_free_aux (event_data);
include/linux/gtrace.h +12 -0
@@ -355,12 +355,18 @@ int gtrace_path_stop(struct gtrace_path *path);* @nr_pages: Number of pages of the AUX buffer. * @base: Start address of AUX buffer. * @pos: Position in the AUX buffer to commit traced data. +* @snapshot: Is this run in snapshot mode. +* @pages: a handle to the ring buffer. +* @buf: Optional sink-specific buffer. */ struct gtrace_perf_auxbuf {size_t length;int nr_pages;void *base;long pos; +bool snapshot; +void **pages; +void *buf; }; int gtrace_path_copyto_auxbuf(struct gtrace_path *path,
@@ -371,6 +377,8 @@ int gtrace_path_copyto_auxbuf(struct gtrace_path *path,/** * struct gtrace_driver - Representation of a trace driver. * @id_table: Table to match components handled by the driver. +* @alloc_buf: Callback to alloc sink-specific buffer. +* @free_buf: Callback to free sink-specific buffer. * @copyto_auxbuf: Callback to copy data into perf AUX buffer. The driver * reports the PMU specific trace format of the copied data * via @handle (see PERF_AUX_FLAG_PMU_FORMAT_TYPE_MASK).
@@ -386,6 +394,10 @@ int gtrace_path_copyto_auxbuf(struct gtrace_path *path,*/ struct gtrace_driver {const struct gtrace_component_id *id_table; +void *(*alloc_buf)(struct gtrace_component *comp, +struct perf_event *event,void **pages, +int nr_pages,bool overwrite); +void (*free_buf)(void *buf);size_t (*copyto_auxbuf)(struct gtrace_component *comp,struct perf_output_handle *handle,struct gtrace_perf_auxbuf *buf);
Signature · 1 line
2.34.1
PATCH 19/24 gtrace: Add setup_sysfs_buf callback to setup sysfs sink buffer
In reply to Zane LeungAdd a setup_sysfs_buf() callback to gtrace_driver and invoke it from gtrace_enable_sysfs() before the path is started, so the sink can allocate its sysfs trace buffer outside the spinlock held by the core start path.
--- drivers/hwtracing/gtrace/gtrace-sysfs.c | 12 ++++++++++++ include/linux/gtrace.h | 2 ++ 2 files changed, 14 insertions(+)
drivers/hwtracing/gtrace/gtrace-sysfs.c +12 -0
@@ -85,6 +85,7 @@ static int gtrace_validate_source_sysfs(struct gtrace_component *comp,int gtrace_enable_sysfs (struct gtrace_component *comp) {struct gtrace_component *sink; +struct gtrace_driver *sinkdrv;struct gtrace_path *path;int ret;
@@ -114,6 +115,17 @@ int gtrace_enable_sysfs(struct gtrace_component *comp)mutex_lock (>race_mutex); +if (!sink) + sink =gtrace_path_sink (path); + sinkdrv =to_gtrace_driver (sink->dev.driver); +if (sinkdrv && sinkdrv->setup_sysfs_buf) { + ret = sinkdrv->setup_sysfs_buf (sink); +if (ret) { +gtrace_destroy_path (path); + goto out; + } + } + ret =gtrace_path_start (path);if (ret)gtrace_destroy_path (path);
include/linux/gtrace.h +2 -0
@@ -377,6 +377,7 @@ int gtrace_path_copyto_auxbuf(struct gtrace_path *path,/** * struct gtrace_driver - Representation of a trace driver. * @id_table: Table to match components handled by the driver. +* @setup_sysfs_buf: Callback to setup sink-specific sysfs buffer. * @alloc_buf: Callback to alloc sink-specific buffer. * @free_buf: Callback to free sink-specific buffer. * @copyto_auxbuf: Callback to copy data into perf AUX buffer. The driver
@@ -394,6 +395,7 @@ int gtrace_path_copyto_auxbuf(struct gtrace_path *path,*/ struct gtrace_driver {const struct gtrace_component_id *id_table; +int (*setup_sysfs_buf)(struct gtrace_component *comp);void *(*alloc_buf)(struct gtrace_component *comp,struct perf_event *event,void **pages,int nr_pages,bool overwrite);
Signature · 1 line
2.34.1
PATCH 20/24 gtrace: Add CoreSight TMC driver support
In reply to Zane LeungAdd CoreSight Trace Memory Controller (TMC) driver as part of the gtrace framework. ETB and ETF share one driver (ETF additionally works as a link), while ETR uses system memory and provides perf buffer alloc/free callbacks.
--- .../hwtracing/coresight/coresight-tmc-etf.c | 1 - drivers/hwtracing/gtrace/Kconfig | 13 + drivers/hwtracing/gtrace/Makefile | 2 + drivers/hwtracing/gtrace/coresight-tmc-core.c | 1111 ++++++++++ drivers/hwtracing/gtrace/coresight-tmc-etf.c | 573 +++++ drivers/hwtracing/gtrace/coresight-tmc-etr.c | 1888 +++++++++++++++++ drivers/hwtracing/gtrace/coresight-tmc.h | 469 ++++ 7 files changed, 4056 insertions(+), 1 deletion(-) create mode 100644 drivers/hwtracing/gtrace/coresight-tmc-core.c create mode 100644 drivers/hwtracing/gtrace/coresight-tmc-etf.c create mode 100644 drivers/hwtracing/gtrace/coresight-tmc-etr.c create mode 100644 drivers/hwtracing/gtrace/coresight-tmc.h
drivers/hwtracing/coresight/coresight-tmc-etf.c +0 -1
@@ -80,7 +80,6 @@ static void tmc_etb_dump_hw(struct tmc_drvdata *drvdata)if (lost)coresight_insert_barrier_packet (drvdata->buf); -return ; }static void __tmc_etb_disable_hw (struct tmc_drvdata *drvdata)
drivers/hwtracing/gtrace/Kconfig +13 -0
@@ -114,3 +114,16 @@ config CORESIGHT_FUNNEL To compile this driver as a module, choose M here: the module will be called coresight-funnel. + +config CORESIGHT_TMC + tristate "CoreSight generic TMC driver" + depends on GTRACE_CORESIGHT + default y + help + This enables support for the CoreSight Trace Memory Controller + (TMC) driver. Depending on its configuration the device can act + as an embedded trace buffer (ETB), an embedded trace FIFO (ETF) + or a trace router (ETR) that stores trace data in system memory. + + To compile this driver as a module, choose M here: the module + will be called coresight-tmc.
drivers/hwtracing/gtrace/Makefile +2 -0
@@ -13,3 +13,5 @@ obj-$(CONFIG_RVTRACE_FUNNEL) += rvtrace-funnel.o obj-$(CONFIG_RVTRACE_ATBBRIDGE) += rvtrace-atbbridge.o obj-$(CONFIG_GTRACE_CORESIGHT) += coresight-platform.o obj-$(CONFIG_CORESIGHT_FUNNEL) += coresight-funnel.o +obj-$(CONFIG_CORESIGHT_TMC) += coresight-tmc.o +coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o coresight-tmc-etr.o
drivers/hwtracing/gtrace/coresight-tmc-core.c new file +1111 -0
1,111 lines not on this page · raw message
drivers/hwtracing/gtrace/coresight-tmc-etf.c new file +573 -0
573 lines not on this page · raw message
drivers/hwtracing/gtrace/coresight-tmc-etr.c new file +1888 -0
1,288 lines not on this page · raw message
drivers/hwtracing/gtrace/coresight-tmc.h new file +469 -0
469 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
PATCH 21/24 perf tools: riscv: making gtrace PMU listable
In reply to Zane LeungThis commit enhances the RISC-V performance tools by allowing the gtrace PMU to be listed and selected.
--- tools/perf/arch/riscv/util/Build | 1 + tools/perf/arch/riscv/util/pmu.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tools/perf/arch/riscv/util/pmu.c
tools/perf/arch/riscv/util/Build +1 -0
@@ -1,2 +1,3 @@ perf-util-y += header.o perf-util-y += auxtrace.o +perf-util-y += pmu.o
tools/perf/arch/riscv/util/pmu.c new file +19 -0
@@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2026 Spacemit Technologies, Inc. +*/ + +#include <string.h> +#include <linux/perf_event.h> + +#include "../../../util/pmu.h" + +#define GTRACE_PMU_NAME "gtrace" + +void perf_pmu__arch_init (struct perf_pmu *pmu) +{ +if (!strcmp (pmu->name,GTRACE_PMU_NAME )) { + pmu->auxtrace = true; + pmu->selectable = true; + } +}
Signature · 1 line
2.34.1
PATCH 22/24 perf tools: Add Nexus RISC-V Trace decoder
In reply to Zane LeungAdd support for RISC-V Nexus Trace decoder based on the reference implementation from the RISC-V Nexus Trace specification. This includes a CoreSight frame deformatter to remove the trace formatter overhead.
--- tools/arch/riscv/include/asm/insn.h | 645 +++++++++++++ tools/perf/util/Build | 1 + tools/perf/util/rvtrace-decoder/Build | 2 + .../util/rvtrace-decoder/rvtrace-decoder.c | 423 ++++++++ .../util/rvtrace-decoder/rvtrace-decoder.h | 122 +++ .../rvtrace-decoder/rvtrace-ntrace-decoder.c | 910 ++++++++++++++++++ .../rvtrace-decoder/rvtrace-ntrace-decoder.h | 124 +++ 7 files changed, 2227 insertions(+) create mode 100644 tools/arch/riscv/include/asm/insn.h create mode 100644 tools/perf/util/rvtrace-decoder/Build create mode 100644 tools/perf/util/rvtrace-decoder/rvtrace-decoder.c create mode 100644 tools/perf/util/rvtrace-decoder/rvtrace-decoder.h create mode 100644 tools/perf/util/rvtrace-decoder/rvtrace-ntrace-decoder.c create mode 100644 tools/perf/util/rvtrace-decoder/rvtrace-ntrace-decoder.h
tools/arch/riscv/include/asm/insn.h new file +645 -0
@@ -0,0 +1,645 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (C) 2020 SiFive +*/ + +#ifndef _ASM_RISCV_INSN_H +#define _ASM_RISCV_INSN_H + +#include <linux/bits.h> + +#define RV_INSN_FUNCT3_MASK GENMASK(14, 12) +#define RV_INSN_FUNCT3_OPOFF 12 +#define RV_INSN_OPCODE_MASK GENMASK(6, 0) +#define RV_INSN_OPCODE_OPOFF 0 +#define RV_INSN_FUNCT12_OPOFF 20 + +#define RV_ENCODE_FUNCT3 (f_) (RVG_FUNCT3_##f_ << RV_INSN_FUNCT3_OPOFF) +#define RV_ENCODE_FUNCT12 (f_) (RVG_FUNCT12_##f_ << RV_INSN_FUNCT12_OPOFF) + +/* The bit field of immediate value in I-type instruction */ +#define RV_I_IMM_SIGN_OPOFF 31 +#define RV_I_IMM_11_0_OPOFF 20 +#define RV_I_IMM_SIGN_OFF 12 +#define RV_I_IMM_11_0_OFF 0 +#define RV_I_IMM_11_0_MASK GENMASK(11, 0) + +/* The bit field of immediate value in J-type instruction */ +#define RV_J_IMM_SIGN_OPOFF 31 +#define RV_J_IMM_10_1_OPOFF 21 +#define RV_J_IMM_11_OPOFF 20 +#define RV_J_IMM_19_12_OPOFF 12 +#define RV_J_IMM_SIGN_OFF 20 +#define RV_J_IMM_10_1_OFF 1 +#define RV_J_IMM_11_OFF 11 +#define RV_J_IMM_19_12_OFF 12 +#define RV_J_IMM_10_1_MASK GENMASK(9, 0) +#define RV_J_IMM_11_MASK GENMASK(0, 0) +#define RV_J_IMM_19_12_MASK GENMASK(7, 0) + +/* +* U-type IMMs contain the upper 20bits [31:20] of an immediate with +* the rest filled in by zeros, so no shifting required. Similarly, +* bit31 contains the signed state, so no sign extension necessary. +*/ +#define RV_U_IMM_SIGN_OPOFF 31 +#define RV_U_IMM_31_12_OPOFF 0 +#define RV_U_IMM_31_12_MASK GENMASK(31, 12) + +/* The bit field of immediate value in B-type instruction */ +#define RV_B_IMM_SIGN_OPOFF 31 +#define RV_B_IMM_10_5_OPOFF 25 +#define RV_B_IMM_4_1_OPOFF 8 +#define RV_B_IMM_11_OPOFF 7 +#define RV_B_IMM_SIGN_OFF 12 +#define RV_B_IMM_10_5_OFF 5 +#define RV_B_IMM_4_1_OFF 1 +#define RV_B_IMM_11_OFF 11 +#define RV_B_IMM_10_5_MASK GENMASK(5, 0) +#define RV_B_IMM_4_1_MASK GENMASK(3, 0) +#define RV_B_IMM_11_MASK GENMASK(0, 0) + +/* The register offset in RVG instruction */ +#define RVG_RS1_OPOFF 15 +#define RVG_RS2_OPOFF 20 +#define RVG_RD_OPOFF 7 +#define RVG_RS1_MASK GENMASK(4, 0) +#define RVG_RS2_MASK GENMASK(4, 0) +#define RVG_RD_MASK GENMASK(4, 0) + +/* The bit field of immediate value in RVC J instruction */ +#define RVC_J_IMM_SIGN_OPOFF 12 +#define RVC_J_IMM_4_OPOFF 11 +#define RVC_J_IMM_9_8_OPOFF 9 +#define RVC_J_IMM_10_OPOFF 8 +#define RVC_J_IMM_6_OPOFF 7 +#define RVC_J_IMM_7_OPOFF 6 +#define RVC_J_IMM_3_1_OPOFF 3 +#define RVC_J_IMM_5_OPOFF 2 +#define RVC_J_IMM_SIGN_OFF 11 +#define RVC_J_IMM_4_OFF 4 +#define RVC_J_IMM_9_8_OFF 8 +#define RVC_J_IMM_10_OFF 10 +#define RVC_J_IMM_6_OFF 6 +#define RVC_J_IMM_7_OFF 7 +#define RVC_J_IMM_3_1_OFF 1 +#define RVC_J_IMM_5_OFF 5 +#define RVC_J_IMM_4_MASK GENMASK(0, 0) +#define RVC_J_IMM_9_8_MASK GENMASK(1, 0) +#define RVC_J_IMM_10_MASK GENMASK(0, 0) +#define RVC_J_IMM_6_MASK GENMASK(0, 0) +#define RVC_J_IMM_7_MASK GENMASK(0, 0) +#define RVC_J_IMM_3_1_MASK GENMASK(2, 0) +#define RVC_J_IMM_5_MASK GENMASK(0, 0) + +/* The bit field of immediate value in RVC B instruction */ +#define RVC_B_IMM_SIGN_OPOFF 12 +#define RVC_B_IMM_4_3_OPOFF 10 +#define RVC_B_IMM_7_6_OPOFF 5 +#define RVC_B_IMM_2_1_OPOFF 3 +#define RVC_B_IMM_5_OPOFF 2 +#define RVC_B_IMM_SIGN_OFF 8 +#define RVC_B_IMM_4_3_OFF 3 +#define RVC_B_IMM_7_6_OFF 6 +#define RVC_B_IMM_2_1_OFF 1 +#define RVC_B_IMM_5_OFF 5 +#define RVC_B_IMM_4_3_MASK GENMASK(1, 0) +#define RVC_B_IMM_7_6_MASK GENMASK(1, 0) +#define RVC_B_IMM_2_1_MASK GENMASK(1, 0) +#define RVC_B_IMM_5_MASK GENMASK(0, 0) + +#define RVC_INSN_FUNCT4_MASK GENMASK(15, 12) +#define RVC_INSN_FUNCT4_OPOFF 12 +#define RVC_INSN_FUNCT3_MASK GENMASK(15, 13) +#define RVC_INSN_FUNCT3_OPOFF 13 +#define RVC_INSN_J_RS1_MASK GENMASK(11, 7) +#define RVC_INSN_J_RS2_MASK GENMASK(6, 2) +#define RVC_INSN_OPCODE_MASK GENMASK(1, 0) +#define RVC_ENCODE_FUNCT3 (f_) (RVC_FUNCT3_##f_ << RVC_INSN_FUNCT3_OPOFF) +#define RVC_ENCODE_FUNCT4 (f_) (RVC_FUNCT4_##f_ << RVC_INSN_FUNCT4_OPOFF) + +/* The register offset in RVC op=C0 instruction */ +#define RVC_C0_RS1_OPOFF 7 +#define RVC_C0_RS2_OPOFF 2 +#define RVC_C0_RD_OPOFF 2 + +/* The register offset in RVC op=C1 instruction */ +#define RVC_C1_RS1_OPOFF 7 +#define RVC_C1_RS2_OPOFF 2 +#define RVC_C1_RD_OPOFF 7 + +/* The register offset in RVC op=C2 instruction */ +#define RVC_C2_RS1_OPOFF 7 +#define RVC_C2_RS2_OPOFF 2 +#define RVC_C2_RD_OPOFF 7 +#define RVC_C2_RS1_MASK GENMASK(4, 0) + +/* parts of opcode for RVG*/ +#define RVG_OPCODE_FENCE 0x0f +#define RVG_OPCODE_AUIPC 0x17 +#define RVG_OPCODE_BRANCH 0x63 +#define RVG_OPCODE_JALR 0x67 +#define RVG_OPCODE_JAL 0x6f +#define RVG_OPCODE_SYSTEM 0x73 +#define RVG_SYSTEM_CSR_OFF 20 +#define RVG_SYSTEM_CSR_MASK GENMASK(12, 0) + +/* parts of opcode for RVF, RVD and RVQ */ +#define RVFDQ_FL_FS_WIDTH_OFF 12 +#define RVFDQ_FL_FS_WIDTH_MASK GENMASK(2, 0) +#define RVFDQ_FL_FS_WIDTH_W 2 +#define RVFDQ_FL_FS_WIDTH_D 3 +#define RVFDQ_LS_FS_WIDTH_Q 4 +#define RVFDQ_OPCODE_FL 0x07 +#define RVFDQ_OPCODE_FS 0x27 + +/* parts of opcode for RVV */ +#define RVV_OPCODE_VECTOR 0x57 +#define RVV_VL_VS_WIDTH_8 0 +#define RVV_VL_VS_WIDTH_16 5 +#define RVV_VL_VS_WIDTH_32 6 +#define RVV_VL_VS_WIDTH_64 7 +#define RVV_OPCODE_VL RVFDQ_OPCODE_FL +#define RVV_OPCODE_VS RVFDQ_OPCODE_FS + +/* parts of opcode for RVC*/ +#define RVC_OPCODE_C0 0x0 +#define RVC_OPCODE_C1 0x1 +#define RVC_OPCODE_C2 0x2 + +/* parts of funct3 code for I, M, A extension*/ +#define RVG_FUNCT3_JALR 0x0 +#define RVG_FUNCT3_BEQ 0x0 +#define RVG_FUNCT3_BNE 0x1 +#define RVG_FUNCT3_BLT 0x4 +#define RVG_FUNCT3_BGE 0x5 +#define RVG_FUNCT3_BLTU 0x6 +#define RVG_FUNCT3_BGEU 0x7 + +/* parts of funct3 code for C extension*/ +#define RVC_FUNCT3_C_BEQZ 0x6 +#define RVC_FUNCT3_C_BNEZ 0x7 +#define RVC_FUNCT3_C_J 0x5 +#define RVC_FUNCT3_C_JAL 0x1 +#define RVC_FUNCT4_C_JR 0x8 +#define RVC_FUNCT4_C_JALR 0x9 +#define RVC_FUNCT4_C_EBREAK 0x9 + +#define RVG_FUNCT12_ECALL 0x0 +#define RVG_FUNCT12_EBREAK 0x1 +#define RVG_FUNCT12_SRET 0x102 +#define RVG_FUNCT12_MRET 0x303 + +#define RVG_MATCH_AUIPC (RVG_OPCODE_AUIPC) +#define RVG_MATCH_JALR (RV_ENCODE_FUNCT3(JALR) | RVG_OPCODE_JALR) +#define RVG_MATCH_JAL (RVG_OPCODE_JAL) +#define RVG_MATCH_FENCE (RVG_OPCODE_FENCE) +#define RVG_MATCH_BEQ (RV_ENCODE_FUNCT3(BEQ) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BNE (RV_ENCODE_FUNCT3(BNE) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BLT (RV_ENCODE_FUNCT3(BLT) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BGE (RV_ENCODE_FUNCT3(BGE) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BLTU (RV_ENCODE_FUNCT3(BLTU) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_BGEU (RV_ENCODE_FUNCT3(BGEU) | RVG_OPCODE_BRANCH) +#define RVG_MATCH_ECALL (RV_ENCODE_FUNCT12(EBREAK) | RVG_OPCODE_SYSTEM) +#define RVG_MATCH_EBREAK (RV_ENCODE_FUNCT12(EBREAK) | RVG_OPCODE_SYSTEM) +#define RVG_MATCH_SRET (RV_ENCODE_FUNCT12(SRET) | RVG_OPCODE_SYSTEM) +#define RVG_MATCH_MRET (RV_ENCODE_FUNCT12(MRET) | RVG_OPCODE_SYSTEM) +#define RVC_MATCH_C_BEQZ (RVC_ENCODE_FUNCT3(C_BEQZ) | RVC_OPCODE_C1) +#define RVC_MATCH_C_BNEZ (RVC_ENCODE_FUNCT3(C_BNEZ) | RVC_OPCODE_C1) +#define RVC_MATCH_C_J (RVC_ENCODE_FUNCT3(C_J) | RVC_OPCODE_C1) +#define RVC_MATCH_C_JAL (RVC_ENCODE_FUNCT3(C_JAL) | RVC_OPCODE_C1) +#define RVC_MATCH_C_JR (RVC_ENCODE_FUNCT4(C_JR) | RVC_OPCODE_C2) +#define RVC_MATCH_C_JALR (RVC_ENCODE_FUNCT4(C_JALR) | RVC_OPCODE_C2) +#define RVC_MATCH_C_EBREAK (RVC_ENCODE_FUNCT4(C_EBREAK) | RVC_OPCODE_C2) + +#define RVG_MASK_AUIPC (RV_INSN_OPCODE_MASK) +#define RVG_MASK_JALR (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_JAL (RV_INSN_OPCODE_MASK) +#define RVG_MASK_FENCE (RV_INSN_OPCODE_MASK) +#define RVC_MASK_C_JALR (RVC_INSN_FUNCT4_MASK | RVC_INSN_J_RS2_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_JR (RVC_INSN_FUNCT4_MASK | RVC_INSN_J_RS2_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_JAL (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_J (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVG_MASK_BEQ (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BNE (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BLT (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BGE (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BLTU (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVG_MASK_BGEU (RV_INSN_FUNCT3_MASK | RV_INSN_OPCODE_MASK) +#define RVC_MASK_C_BEQZ (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_BNEZ (RVC_INSN_FUNCT3_MASK | RVC_INSN_OPCODE_MASK) +#define RVC_MASK_C_EBREAK 0xffff +#define RVG_MASK_EBREAK 0xffffffff +#define RVG_MASK_ECALL 0xffffffff +#define RVG_MASK_SRET 0xffffffff +#define RVG_MASK_MRET 0xffffffff + +#define __INSN_LENGTH_MASK _UL(0x3) +#define __INSN_LENGTH_GE_32 _UL(0x3) +#define __INSN_OPCODE_MASK _UL(0x7F) +#define __INSN_BRANCH_OPCODE _UL(RVG_OPCODE_BRANCH) + +#define __RISCV_INSN_FUNCS (name, mask, val) \ +static __always_inline bool riscv_insn_is_##name(u32 code) \ +{ \ + BUILD_BUG_ON(~(mask) & (val)); \ + return (code & (mask)) == (val); \ +} \ + +#if __riscv_xlen ==32 +/* C.JAL is an RV32C-only instruction */ +__RISCV_INSN_FUNCS(c_jal, RVC_MASK_C_JAL, RVC_MATCH_C_JAL) +#else +#define riscv_insn_is_c_jal (opcode) 0 +#endif +__RISCV_INSN_FUNCS(auipc, RVG_MASK_AUIPC, RVG_MATCH_AUIPC) +__RISCV_INSN_FUNCS(jalr, RVG_MASK_JALR, RVG_MATCH_JALR) +__RISCV_INSN_FUNCS(jal, RVG_MASK_JAL, RVG_MATCH_JAL) +__RISCV_INSN_FUNCS(c_j, RVC_MASK_C_J, RVC_MATCH_C_J) +__RISCV_INSN_FUNCS(beq, RVG_MASK_BEQ, RVG_MATCH_BEQ) +__RISCV_INSN_FUNCS(bne, RVG_MASK_BNE, RVG_MATCH_BNE) +__RISCV_INSN_FUNCS(blt, RVG_MASK_BLT, RVG_MATCH_BLT) +__RISCV_INSN_FUNCS(bge, RVG_MASK_BGE, RVG_MATCH_BGE) +__RISCV_INSN_FUNCS(bltu, RVG_MASK_BLTU, RVG_MATCH_BLTU) +__RISCV_INSN_FUNCS(bgeu, RVG_MASK_BGEU, RVG_MATCH_BGEU) +__RISCV_INSN_FUNCS(c_beqz, RVC_MASK_C_BEQZ, RVC_MATCH_C_BEQZ) +__RISCV_INSN_FUNCS(c_bnez, RVC_MASK_C_BNEZ, RVC_MATCH_C_BNEZ) +__RISCV_INSN_FUNCS(c_ebreak, RVC_MASK_C_EBREAK, RVC_MATCH_C_EBREAK) +__RISCV_INSN_FUNCS(ebreak, RVG_MASK_EBREAK, RVG_MATCH_EBREAK) +__RISCV_INSN_FUNCS(ecall, RVG_MASK_EBREAK, RVG_MATCH_EBREAK) +__RISCV_INSN_FUNCS(sret, RVG_MASK_SRET, RVG_MATCH_SRET) +__RISCV_INSN_FUNCS(mret, RVG_MASK_MRET, RVG_MATCH_MRET) +__RISCV_INSN_FUNCS (fence,RVG_MASK_FENCE ,RVG_MATCH_FENCE ); + +/* special case to catch _any_ system instruction */ +static __always_inline bool riscv_insn_is_system(u32 code) +{ +return (code &RV_INSN_OPCODE_MASK ) ==RVG_OPCODE_SYSTEM ; +} + +/* special case to catch _any_ branch instruction */ +static __always_inline bool riscv_insn_is_branch(u32 code) +{ +return (code &RV_INSN_OPCODE_MASK ) ==RVG_OPCODE_BRANCH ; +} + +static __always_inline bool riscv_insn_is_c_jr(u32 code) +{ +return (code &RVC_MASK_C_JR ) ==RVC_MATCH_C_JR && + (code &RVC_INSN_J_RS1_MASK ) !=0 ; +} + +static __always_inline bool riscv_insn_is_c_jalr(u32 code) +{ +return (code &RVC_MASK_C_JALR ) ==RVC_MATCH_C_JALR && + (code &RVC_INSN_J_RS1_MASK ) !=0 ; +} + +#define INSN_MATCH_LB 0x3 +#define INSN_MASK_LB 0x707f +#define INSN_MATCH_LH 0x1003 +#define INSN_MASK_LH 0x707f +#define INSN_MATCH_LW 0x2003 +#define INSN_MASK_LW 0x707f +#define INSN_MATCH_LD 0x3003 +#define INSN_MASK_LD 0x707f +#define INSN_MATCH_LBU 0x4003 +#define INSN_MASK_LBU 0x707f +#define INSN_MATCH_LHU 0x5003 +#define INSN_MASK_LHU 0x707f +#define INSN_MATCH_LWU 0x6003 +#define INSN_MASK_LWU 0x707f +#define INSN_MATCH_SB 0x23 +#define INSN_MASK_SB 0x707f +#define INSN_MATCH_SH 0x1023 +#define INSN_MASK_SH 0x707f +#define INSN_MATCH_SW 0x2023 +#define INSN_MASK_SW 0x707f +#define INSN_MATCH_SD 0x3023 +#define INSN_MASK_SD 0x707f + +#define INSN_MATCH_C_LD 0x6000 +#define INSN_MASK_C_LD 0xe003 +#define INSN_MATCH_C_SD 0xe000 +#define INSN_MASK_C_SD 0xe003 +#define INSN_MATCH_C_LW 0x4000 +#define INSN_MASK_C_LW 0xe003 +#define INSN_MATCH_C_SW 0xc000 +#define INSN_MASK_C_SW 0xe003 +#define INSN_MATCH_C_LDSP 0x6002 +#define INSN_MASK_C_LDSP 0xe003 +#define INSN_MATCH_C_SDSP 0xe002 +#define INSN_MASK_C_SDSP 0xe003 +#define INSN_MATCH_C_LWSP 0x4002 +#define INSN_MASK_C_LWSP 0xe003 +#define INSN_MATCH_C_SWSP 0xc002 +#define INSN_MASK_C_SWSP 0xe003 + +#define INSN_OPCODE_MASK 0x007c +#define INSN_OPCODE_SHIFT 2 +#define INSN_OPCODE_SYSTEM 28 + +#define INSN_MASK_WFI 0xffffffff +#define INSN_MATCH_WFI 0x10500073 + +#define INSN_MASK_WRS 0xffffffff +#define INSN_MATCH_WRS 0x00d00073 + +#define INSN_MATCH_CSRRW 0x1073 +#define INSN_MASK_CSRRW 0x707f +#define INSN_MATCH_CSRRS 0x2073 +#define INSN_MASK_CSRRS 0x707f +#define INSN_MATCH_CSRRC 0x3073 +#define INSN_MASK_CSRRC 0x707f +#define INSN_MATCH_CSRRWI 0x5073 +#define INSN_MASK_CSRRWI 0x707f +#define INSN_MATCH_CSRRSI 0x6073 +#define INSN_MASK_CSRRSI 0x707f +#define INSN_MATCH_CSRRCI 0x7073 +#define INSN_MASK_CSRRCI 0x707f + +#define INSN_MATCH_FLW 0x2007 +#define INSN_MASK_FLW 0x707f +#define INSN_MATCH_FLD 0x3007 +#define INSN_MASK_FLD 0x707f +#define INSN_MATCH_FLQ 0x4007 +#define INSN_MASK_FLQ 0x707f +#define INSN_MATCH_FSW 0x2027 +#define INSN_MASK_FSW 0x707f +#define INSN_MATCH_FSD 0x3027 +#define INSN_MASK_FSD 0x707f +#define INSN_MATCH_FSQ 0x4027 +#define INSN_MASK_FSQ 0x707f + +#define INSN_MATCH_C_FLD 0x2000 +#define INSN_MASK_C_FLD 0xe003 +#define INSN_MATCH_C_FLW 0x6000 +#define INSN_MASK_C_FLW 0xe003 +#define INSN_MATCH_C_FSD 0xa000 +#define INSN_MASK_C_FSD 0xe003 +#define INSN_MATCH_C_FSW 0xe000 +#define INSN_MASK_C_FSW 0xe003 +#define INSN_MATCH_C_FLDSP 0x2002 +#define INSN_MASK_C_FLDSP 0xe003 +#define INSN_MATCH_C_FSDSP 0xa002 +#define INSN_MASK_C_FSDSP 0xe003 +#define INSN_MATCH_C_FLWSP 0x6002 +#define INSN_MASK_C_FLWSP 0xe003 +#define INSN_MATCH_C_FSWSP 0xe002 +#define INSN_MASK_C_FSWSP 0xe003 + +#define INSN_MATCH_C_LHU 0x8400 +#define INSN_MASK_C_LHU 0xfc43 +#define INSN_MATCH_C_LH 0x8440 +#define INSN_MASK_C_LH 0xfc43 +#define INSN_MATCH_C_SH 0x8c00 +#define INSN_MASK_C_SH 0xfc43 + +#define INSN_16BIT_MASK 0x3 +#define INSN_IS_16BIT (insn) (((insn) & INSN_16BIT_MASK) != INSN_16BIT_MASK) +#define INSN_LEN (insn) (INSN_IS_16BIT(insn) ? 2 : 4) + +#define SHIFT_RIGHT (x, y) \ + ((y) < 0 ? ((x) << -(y)) : ((x) >> (y))) + +#define REG_MASK \ + ((1 << (5 + LOG_REGBYTES)) - (1 << LOG_REGBYTES)) + +#define REG_OFFSET (insn, pos) \ + (SHIFT_RIGHT((insn), (pos) - LOG_REGBYTES) & REG_MASK) + +#define REG_PTR (insn, pos, regs) \ + ((ulong *)((ulong)(regs) + REG_OFFSET(insn, pos))) + +#define GET_RS1 (insn, regs) (*REG_PTR(insn, SH_RS1, regs)) +#define GET_RS2 (insn, regs) (*REG_PTR(insn, SH_RS2, regs)) +#define GET_RS1S (insn, regs) (*REG_PTR(RVC_RS1S(insn), 0, regs)) +#define GET_RS2S (insn, regs) (*REG_PTR(RVC_RS2S(insn), 0, regs)) +#define GET_RS2C (insn, regs) (*REG_PTR(insn, SH_RS2C, regs)) +#define GET_SP (regs) (*REG_PTR(2, 0, regs)) +#define SET_RD (insn, regs, val) (*REG_PTR(insn, SH_RD, regs) = (val)) +#define IMM_I (insn) ((s32)(insn) >> 20) +#define IMM_S (insn) (((s32)(insn) >> 25 << 5) | \ + (s32)(((insn) >> 7) & 0x1f)) + +#define SH_RD 7 +#define SH_RS1 15 +#define SH_RS2 20 +#define SH_RS2C 2 +#define MASK_RX 0x1f + +#if defined(CONFIG_64BIT ) +#define LOG_REGBYTES 3 +#else +#define LOG_REGBYTES 2 +#endif + +#define MASK_FUNCT3 0x7000 + +#define GET_FUNCT3 (insn) (((insn) >> 12) & 7) + +#define RV_IMM_SIGN (x) (-(((x) >> 31) & 1)) +#define RVC_IMM_SIGN (x) (-(((x) >> 12) & 1)) +#define RV_X_MASK (X , s, mask) (((X) >> (s)) & (mask)) +#define RV_X (X , s, n) RV_X_MASK(X, s, ((1 << (n)) - 1)) +#define RVC_LW_IMM (x) ((RV_X(x, 6, 1) << 2) | \ + (RV_X(x, 10, 3) << 3) | \ + (RV_X(x, 5, 1) << 6)) +#define RVC_LD_IMM (x) ((RV_X(x, 10, 3) << 3) | \ + (RV_X(x, 5, 2) << 6)) +#define RVC_LWSP_IMM (x) ((RV_X(x, 4, 3) << 2) | \ + (RV_X(x, 12, 1) << 5) | \ + (RV_X(x, 2, 2) << 6)) +#define RVC_LDSP_IMM (x) ((RV_X(x, 5, 2) << 3) | \ + (RV_X(x, 12, 1) << 5) | \ + (RV_X(x, 2, 3) << 6)) +#define RVC_SWSP_IMM (x) ((RV_X(x, 9, 4) << 2) | \ + (RV_X(x, 7, 2) << 6)) +#define RVC_SDSP_IMM (x) ((RV_X(x, 10, 3) << 3) | \ + (RV_X(x, 7, 3) << 6)) +#define RVC_RS1S (insn) (8 + RV_X(insn, SH_RD, 3)) +#define RVC_RS2S (insn) (8 + RV_X(insn, SH_RS2C, 3)) +#define RVC_RS2 (insn) RV_X(insn, SH_RS2C, 5) +#define RVC_X (X , s, mask) RV_X_MASK(X, s, mask) + +#define RV_EXTRACT_FUNCT3 (x) \ + ({typeof(x) x_ = (x); \ + (RV_X_MASK(x_, RV_INSN_FUNCT3_OPOFF, \ + RV_INSN_FUNCT3_MASK >> RV_INSN_FUNCT3_OPOFF)); }) + +#define RV_EXTRACT_RS1_REG (x) \ + ({typeof(x) x_ = (x); \ + (RV_X_MASK(x_, RVG_RS1_OPOFF, RVG_RS1_MASK)); }) + +#define RV_EXTRACT_RS2_REG (x) \ + ({typeof(x) x_ = (x); \ + (RV_X_MASK(x_, RVG_RS2_OPOFF, RVG_RS2_MASK)); }) + +#define RV_EXTRACT_RD_REG (x) \ + ({typeof(x) x_ = (x); \ + (RV_X_MASK(x_, RVG_RD_OPOFF, RVG_RD_MASK)); }) + +#define RV_EXTRACT_UTYPE_IMM (x) \ + ({typeof(x) x_ = (x); \ + (RV_X_MASK(x_, RV_U_IMM_31_12_OPOFF, RV_U_IMM_31_12_MASK)); }) + +#define RV_EXTRACT_JTYPE_IMM (x) \ + ({typeof(x) x_ = (x); \ + (RV_X_MASK(x_, RV_J_IMM_10_1_OPOFF, RV_J_IMM_10_1_MASK) << RV_J_IMM_10_1_OFF) | \ + (RV_X_MASK(x_, RV_J_IMM_11_OPOFF, RV_J_IMM_11_MASK) << RV_J_IMM_11_OFF) | \ + (RV_X_MASK(x_, RV_J_IMM_19_12_OPOFF, RV_J_IMM_19_12_MASK) << RV_J_IMM_19_12_OFF) | \ + (RV_IMM_SIGN(x_) << RV_J_IMM_SIGN_OFF); }) + +#define RV_EXTRACT_ITYPE_IMM (x) \ + ({typeof(x) x_ = (x); \ + (RV_X_MASK(x_, RV_I_IMM_11_0_OPOFF, RV_I_IMM_11_0_MASK)) | \ + (RV_IMM_SIGN(x_) << RV_I_IMM_SIGN_OFF); }) + +#define RV_EXTRACT_BTYPE_IMM (x) \ + ({typeof(x) x_ = (x); \ + (RV_X_MASK(x_, RV_B_IMM_4_1_OPOFF, RV_B_IMM_4_1_MASK) << RV_B_IMM_4_1_OFF) | \ + (RV_X_MASK(x_, RV_B_IMM_10_5_OPOFF, RV_B_IMM_10_5_MASK) << RV_B_IMM_10_5_OFF) | \ + (RV_X_MASK(x_, RV_B_IMM_11_OPOFF, RV_B_IMM_11_MASK) << RV_B_IMM_11_OFF) | \ + (RV_IMM_SIGN(x_) << RV_B_IMM_SIGN_OFF); }) + +#define RVC_EXTRACT_C2_RS1_REG (x) \ + ({typeof(x) x_ = (x); \ + (RV_X_MASK(x_, RVC_C2_RS1_OPOFF, RVC_C2_RS1_MASK)); }) + +#define RVC_EXTRACT_JTYPE_IMM (x) \ + ({typeof(x) x_ = (x); \ + (RVC_X(x_, RVC_J_IMM_3_1_OPOFF, RVC_J_IMM_3_1_MASK) << RVC_J_IMM_3_1_OFF) | \ + (RVC_X(x_, RVC_J_IMM_4_OPOFF, RVC_J_IMM_4_MASK) << RVC_J_IMM_4_OFF) | \ + (RVC_X(x_, RVC_J_IMM_5_OPOFF, RVC_J_IMM_5_MASK) << RVC_J_IMM_5_OFF) | \ + (RVC_X(x_, RVC_J_IMM_6_OPOFF, RVC_J_IMM_6_MASK) << RVC_J_IMM_6_OFF) | \ + (RVC_X(x_, RVC_J_IMM_7_OPOFF, RVC_J_IMM_7_MASK) << RVC_J_IMM_7_OFF) | \ + (RVC_X(x_, RVC_J_IMM_9_8_OPOFF, RVC_J_IMM_9_8_MASK) << RVC_J_IMM_9_8_OFF) | \ + (RVC_X(x_, RVC_J_IMM_10_OPOFF, RVC_J_IMM_10_MASK) << RVC_J_IMM_10_OFF) | \ + (RVC_IMM_SIGN(x_) << RVC_J_IMM_SIGN_OFF); }) + +#define RVC_EXTRACT_BTYPE_IMM (x) \ + ({typeof(x) x_ = (x); \ + (RVC_X(x_, RVC_B_IMM_2_1_OPOFF, RVC_B_IMM_2_1_MASK) << RVC_B_IMM_2_1_OFF) | \ + (RVC_X(x_, RVC_B_IMM_4_3_OPOFF, RVC_B_IMM_4_3_MASK) << RVC_B_IMM_4_3_OFF) | \ + (RVC_X(x_, RVC_B_IMM_5_OPOFF, RVC_B_IMM_5_MASK) << RVC_B_IMM_5_OFF) | \ + (RVC_X(x_, RVC_B_IMM_7_6_OPOFF, RVC_B_IMM_7_6_MASK) << RVC_B_IMM_7_6_OFF) | \ + (RVC_IMM_SIGN(x_) << RVC_B_IMM_SIGN_OFF); }) + +#define RVG_EXTRACT_SYSTEM_CSR (x) \ + ({typeof(x) x_ = (x); RV_X_MASK(x_, RVG_SYSTEM_CSR_OFF, RVG_SYSTEM_CSR_MASK); }) + +#define RVFDQ_EXTRACT_FL_FS_WIDTH (x) \ + ({typeof(x) x_ = (x); RV_X_MASK(x_, RVFDQ_FL_FS_WIDTH_OFF, \ + RVFDQ_FL_FS_WIDTH_MASK); }) + +#define RVV_EXTRACT_VL_VS_WIDTH (x) RVFDQ_EXTRACT_FL_FS_WIDTH(x) + +/* +* Get the immediate from a J-type instruction. +* +* @insn: instruction to process +* Return: immediate +*/ +static inline s32 riscv_insn_extract_jtype_imm (u32 insn) +{ +return RV_EXTRACT_JTYPE_IMM (insn); +} + +/* +* Update a J-type instruction with an immediate value. +* +* @insn: pointer to the jtype instruction +* @imm: the immediate to insert into the instruction +*/ +static inline void riscv_insn_insert_jtype_imm (u32 *insn,s32 imm) +{ +/* drop the old IMMs, all jal IMM bits sit at 31:12 */ + *insn &= ~GENMASK (31 ,12 ); + *insn |= (RV_X_MASK (imm,RV_J_IMM_10_1_OFF ,RV_J_IMM_10_1_MASK ) <<RV_J_IMM_10_1_OPOFF ) | + (RV_X_MASK (imm,RV_J_IMM_11_OFF ,RV_J_IMM_11_MASK ) <<RV_J_IMM_11_OPOFF ) | + (RV_X_MASK (imm,RV_J_IMM_19_12_OFF ,RV_J_IMM_19_12_MASK ) <<RV_J_IMM_19_12_OPOFF ) | + (RV_X_MASK (imm,RV_J_IMM_SIGN_OFF ,1 ) <<RV_J_IMM_SIGN_OPOFF ); +} + +/* +* Put together one immediate from a U-type and I-type instruction pair. +* +* The U-type contains an upper immediate, meaning bits[31:12] with [11:0] +* being zero, while the I-type contains a 12bit immediate. +* Combined these can encode larger 32bit values and are used for example +* in auipc + jalr pairs to allow larger jumps. +* +* @utype_insn: instruction containing the upper immediate +* @itype_insn: instruction +* Return: combined immediate +*/ +static inline s32 riscv_insn_extract_utype_itype_imm (u32 utype_insn,u32 itype_insn) +{ +s32 imm; + + imm =RV_EXTRACT_UTYPE_IMM (utype_insn); + imm +=RV_EXTRACT_ITYPE_IMM (itype_insn); + +return imm; +} + +/* +* Update a set of two instructions (U-type + I-type) with an immediate value. +* +* Used for example in auipc+jalrs pairs the U-type instructions contains +* a 20bit upper immediate representing bits[31:12], while the I-type +* instruction contains a 12bit immediate representing bits[11:0]. +* +* This also takes into account that both separate immediates are +* considered as signed values, so if the I-type immediate becomes +* negative (BIT(11) set) the U-type part gets adjusted. +* +* @utype_insn: pointer to the utype instruction of the pair +* @itype_insn: pointer to the itype instruction of the pair +* @imm: the immediate to insert into the two instructions +*/ +static inline void riscv_insn_insert_utype_itype_imm (u32 *utype_insn,u32 *itype_insn,s32 imm) +{ +/* drop possible old IMM values */ + *utype_insn &= ~(RV_U_IMM_31_12_MASK ); + *itype_insn &= ~(RV_I_IMM_11_0_MASK <<RV_I_IMM_11_0_OPOFF ); + +/* add the adapted IMMs */ + *utype_insn |= (imm &RV_U_IMM_31_12_MASK ) + ((imm &BIT (11 )) <<1 ); + *itype_insn |= ((imm &RV_I_IMM_11_0_MASK ) <<RV_I_IMM_11_0_OPOFF ); +} + +/* +* Get the immediate from a B-type instruction. +* +* @insn: instruction to process +* Return: immediate +*/ +static inline s32 riscv_insn_extract_btype_imm (u32 insn) +{ +return RV_EXTRACT_BTYPE_IMM (insn); +} + +/* +* Get the immediate from a RVC B-type instruction. +* +* @insn: instruction to process +* Return: immediate +*/ +static inline s32 riscv_insn_extract_cbtype_imm (u32 insn) +{ +return RVC_EXTRACT_BTYPE_IMM (insn); +} + +/* +* Get the immediate from a RVC J-type instruction. +* +* @insn: instruction to process +* Return: immediate +*/ +static inline s32 riscv_insn_extract_cjtype_imm (u16 insn) +{ +return RVC_EXTRACT_JTYPE_IMM (insn); +} + +#endif /* _ASM_RISCV_INSN_H */
tools/perf/util/Build +1 -0
@@ -150,6 +150,7 @@ perf-util-y += cs-etm-decoder/ endif perf-util-y += cs-etm-base.o perf-util-y += gtrace-decoder.o +perf-util-y += rvtrace-decoder/ perf-util-y += parse-branch-options.o perf-util-y += parse-regs-options.o
tools/perf/util/rvtrace-decoder/Build new file +2 -0
@@ -0,0 +1,2 @@ +perf-util-y += rvtrace-decoder.o +perf-util-y += rvtrace-ntrace-decoder.o
tools/perf/util/rvtrace-decoder/rvtrace-decoder.c new file +423 -0
423 lines not on this page · raw message
tools/perf/util/rvtrace-decoder/rvtrace-decoder.h new file +122 -0
122 lines not on this page · raw message
tools/perf/util/rvtrace-decoder/rvtrace-ntrace-decoder.c new file +910 -0
910 lines not on this page · raw message
tools/perf/util/rvtrace-decoder/rvtrace-ntrace-decoder.h new file +124 -0
124 lines not on this page · raw message
Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 23/24 perf tools: gtrace: Record and parse trace encoder metadata
In reply to Zane LeungCollect the read-only trace encoder control, features and timestamp registers per CPU into the AUXTRACE_INFO metadata and validate the requested context, syncmode, syncmax and timestamp options against the hardware before recording. Parse the metadata back in the decoder.
--- tools/perf/arch/riscv/util/auxtrace.c | 203 +++++++++++++++++++++++++- tools/perf/util/gtrace-decoder.c | 89 ++++++++++- tools/perf/util/gtrace.h | 30 +++- 3 files changed, 311 insertions(+), 11 deletions(-)
tools/perf/arch/riscv/util/auxtrace.c +200 -3
@@ -9,6 +9,7 @@#include <linux/bitops.h> #include <linux/log2.h> #include <linux/zalloc.h> +#include <linux/bitfield.h> #include <errno.h> #include <limits.h> #include <stdlib.h>
@@ -39,28 +40,217 @@ struct rvtrace_recording {struct evlist *evlist; }; +static const char *const metadata_encoder_ro[] = { + [RVTRACE_ENCODER_FORMAT ] ="control/format" , + [RVTRACE_ENCODER_CONTEXT ] ="control/has_context" , + [RVTRACE_ENCODER_SRCBITS ] ="features/srcbits" , + [RVTRACE_ENCODER_TIMESTAMP ] ="timestamp/source" , +}; +static size_t rvtrace_info_priv_size (struct auxtrace_record *itr__maybe_unused ,struct evlist *evlist__maybe_unused ) { -return GTRACE_AUXTRACE_PRIV_SIZE ; +int encoder; +struct perf_cpu_map *event_cpus = evlist->core.user_requested_cpus; +struct perf_cpu_map *intersect_cpus; + +if (!perf_cpu_map__has_any_cpu (event_cpus)) { +/* cpu map is not "any" CPU , we have specific CPUs to work with */ +struct perf_cpu_map *online_cpus =perf_cpu_map__new_online_cpus (); + + intersect_cpus =perf_cpu_map__intersect (event_cpus, online_cpus); +perf_cpu_map__put (online_cpus); + }else { +/* Event can be "any" CPU so count all online CPUs. */ + intersect_cpus =perf_cpu_map__new_online_cpus (); + } + + encoder =perf_cpu_map__nr (intersect_cpus); +perf_cpu_map__put (intersect_cpus); + +return (GTRACE_HEADER_SIZE + encoder *RVTRACE_ENCODER_PRIV_SIZE ); + +} + +static bool gtrace_pmu_path_exists (struct perf_pmu *pmu,struct perf_cpu cpu,const char *path) +{ +char pmu_path[PATH_MAX ]; + +/* Get RO metadata from sysfs */ +snprintf (pmu_path,PATH_MAX ,"cpu%d/%s" , cpu.cpu, path); + +return perf_pmu__file_exists (pmu, pmu_path); +} + +static int rvtrace_get_ro (struct perf_pmu *pmu,struct perf_cpu cpu,const char *path,__u64 *val) +{ +char pmu_path[PATH_MAX ]; +int scan; + +/* Get RO metadata from sysfs */ +snprintf (pmu_path,PATH_MAX ,"cpu%d/%s" , cpu.cpu, path); + + scan =perf_pmu__scan_file (pmu, pmu_path,"%llx" , val); +if (scan !=1 ) { +pr_err ("%s: error reading: %s\n" , __func__, pmu_path); +return -EINVAL ; + } + +return 0 ; +} + +static void rvtrace_get_metadata (struct perf_cpu cpu,u32 *offset, +struct auxtrace_record *itr, +struct perf_record_auxtrace_info *info) +{ + struct rvtrace_recording *ptr = container_of(itr, struct rvtrace_recording, itr); +struct perf_pmu *rvtrace_pmu = ptr->rvtrace_pmu; +bool timestamp_exists; + + info->priv[*offset +RVTRACE_ENCODER_CPU ] = cpu.cpu; + info->priv[*offset +RVTRACE_ENCODER_NR_TRC_PARAMS ] =RVTRACE_ENCODER_NR_TRC_PARAMS_LENGTH ; + +/* Get read-only information from sysFS */ +rvtrace_get_ro (rvtrace_pmu, cpu, metadata_encoder_ro[RVTRACE_ENCODER_FORMAT ], + &info->priv[*offset +RVTRACE_ENCODER_FORMAT ]); +rvtrace_get_ro (rvtrace_pmu, cpu, metadata_encoder_ro[RVTRACE_ENCODER_CONTEXT ], + &info->priv[*offset +RVTRACE_ENCODER_CONTEXT ]); +rvtrace_get_ro (rvtrace_pmu, cpu, metadata_encoder_ro[RVTRACE_ENCODER_SRCBITS ], + &info->priv[*offset +RVTRACE_ENCODER_SRCBITS ]); + + timestamp_exists =gtrace_pmu_path_exists (rvtrace_pmu, cpu, + metadata_encoder_ro[RVTRACE_ENCODER_TIMESTAMP ]); + info->priv[*offset +RVTRACE_ENCODER_TIMESTAMP ] = timestamp_exists ?1 :0 ; + +/* Where the next CPU entry should start from */ + *offset +=RVTRACE_ENCODER_PRIV_MAX ; }static int rvtrace_info_fill (struct auxtrace_record *itr,struct perf_session *session__maybe_unused ,struct perf_record_auxtrace_info *auxtrace_info,size_t priv_size) { +unsigned int i; +u32 offset; +u64 nr_cpu, type; +struct perf_cpu_map *cpu_map; +struct perf_cpu_map *event_cpus =evlist__core (session->evlist)->user_requested_cpus; +struct perf_cpu_map *online_cpus =perf_cpu_map__new_online_cpus (); struct rvtrace_recording *ptr = container_of(itr, struct rvtrace_recording, itr);struct perf_pmu *rvtrace_pmu = ptr->rvtrace_pmu; +struct perf_cpu cpu; + +if (priv_size !=rvtrace_info_priv_size (itr, session->evlist)) +return -EINVAL ; -if (priv_size !=GTRACE_AUXTRACE_PRIV_SIZE ) +if (!evlist__core (session->evlist)->nr_mmaps)return -EINVAL ; +if (perf_cpu_map__has_any_cpu (event_cpus)) { + cpu_map = online_cpus; + }else { +perf_cpu_map__for_each_cpu (cpu, i, event_cpus) { +if (!perf_cpu_map__has (online_cpus, cpu)) +return -EINVAL ; + } + + cpu_map = event_cpus; + } + + nr_cpu =perf_cpu_map__nr (cpu_map); + type = rvtrace_pmu->type; + auxtrace_info->type =PERF_AUXTRACE_GTRACE ; - auxtrace_info->priv[0 ] = rvtrace_pmu->type; + auxtrace_info->priv[GTRACE_PMU_TYPE_CPUS ] = type <<32 ; + auxtrace_info->priv[GTRACE_PMU_TYPE_CPUS ] |= nr_cpu; + + offset =GTRACE_HEADER_MAX ; + +perf_cpu_map__for_each_cpu (cpu, i, cpu_map) { +assert (offset < priv_size); +rvtrace_get_metadata (cpu, &offset, itr, auxtrace_info); + } + +perf_cpu_map__put (online_cpus); + +return 0 ; +} + +static int rvtrace_encoder_validate_context (struct perf_pmu *rvtrace_pmu,struct evsel *evsel, +struct perf_cpu cpu) +{ +int err; +u64 ctxt; +__u64 context; + +evsel__get_config_val (evsel,"context" , &ctxt); + +if (!ctxt) +return 0 ; + + err =rvtrace_get_ro (rvtrace_pmu, cpu, + metadata_encoder_ro[RVTRACE_ENCODER_CONTEXT ], &context); +if (err) +return err; + +if (!context) { +pr_err ("context not supported" ); +return -EINVAL ; + }return 0 ; } +static int rvtrace_encoder_validate_timestamp (struct perf_pmu *rvtrace_pmu,struct evsel *evsel, +struct perf_cpu cpu) +{ +u64 ts; + +evsel__get_config_val (evsel,"timestamp" , &ts); + +if (!ts) +return 0 ; + +if (!gtrace_pmu_path_exists (rvtrace_pmu, cpu, + metadata_encoder_ro[RVTRACE_ENCODER_TIMESTAMP ])) { +pr_err ("timestamp not supported" ); +return -EINVAL ; + } + +return 0 ; +} + +static int rvtrace_validate_config (struct perf_pmu *rvtrace_pmu,struct evsel *evsel) +{ +unsigned int idx; +int err =0 ; +struct perf_cpu_map *event_cpus =evlist__core (evsel->evlist)->user_requested_cpus; +struct perf_cpu_map *intersect_cpus; +struct perf_cpu cpu; + +if (!perf_cpu_map__has_any_cpu (event_cpus)) { +struct perf_cpu_map *online_cpus =perf_cpu_map__new_online_cpus (); + + intersect_cpus =perf_cpu_map__intersect (event_cpus, online_cpus); +perf_cpu_map__put (online_cpus); + }else { + intersect_cpus =perf_cpu_map__new_online_cpus (); + } + +perf_cpu_map__for_each_cpu_skip_any (cpu, idx, intersect_cpus) { + err =rvtrace_encoder_validate_context (rvtrace_pmu, evsel, cpu); +if (err) +break ; + + err =rvtrace_encoder_validate_timestamp (rvtrace_pmu, evsel, cpu); +if (err) +break ; + } + +perf_cpu_map__put (intersect_cpus); +return err; +} +static int rvtrace_set_auxtrace_mmap_page (struct record_opts *opts) {bool privileged =perf_event_paranoid_check (-1 );
@@ -127,6 +317,9 @@ static int rvtrace_recording_options(struct auxtrace_record *itr, struct evlistevlist__to_front (evlist, rvtrace_evsel);evsel__set_sample_bit (rvtrace_evsel,TIME ); +if (opts->sample_time_set) +evsel__set_config_if_unset (rvtrace_evsel,"timestamp" ,1 ); +/* Add dummy event to keep tracking */ err =parse_event (evlist,"dummy:u" );if (err)
@@ -139,6 +332,10 @@ static int rvtrace_recording_options(struct auxtrace_record *itr, struct evlist tracking_evsel->core.attr.sample_period =1 ;evsel__set_sample_bit (tracking_evsel,TIME ); + err =rvtrace_validate_config (rvtrace_pmu, rvtrace_evsel); +if (err) +return err; +return 0 ; }
tools/perf/util/gtrace-decoder.c +82 -7
129 lines not on this page · raw message
tools/perf/util/gtrace.h +29 -1
@@ -11,7 +11,35 @@struct perf_session ; -#define GTRACE_AUXTRACE_PRIV_SIZE sizeof(u64) +/* Supported trace protocol formats */ +enum gtrace_format { +GTRACE_FORMAT_ETRACE , +GTRACE_FORMAT_NTRACE , +}; + +enum { +GTRACE_PMU_TYPE_CPUS , +GTRACE_HEADER_MAX , +}; + +/* RISC-V Trace Encoder metadata */ +enum { +RVTRACE_ENCODER_CPU , +RVTRACE_ENCODER_NR_TRC_PARAMS , +RVTRACE_ENCODER_FORMAT , +RVTRACE_ENCODER_CONTEXT , +RVTRACE_ENCODER_SRCBITS , +RVTRACE_ENCODER_TIMESTAMP , +RVTRACE_ENCODER_PRIV_MAX , +}; + +#define RVTRACE_ENCODER_NR_TRC_PARAMS_LENGTH (RVTRACE_ENCODER_PRIV_MAX - RVTRACE_ENCODER_FORMAT) + +#define GTRACE_HEADER_SIZE (GTRACE_HEADER_MAX * sizeof(u64)) +#define RVTRACE_ENCODER_PRIV_SIZE (RVTRACE_ENCODER_PRIV_MAX * sizeof(u64)) + +#define INFO_HEADER_SIZE (sizeof(((struct perf_record_auxtrace_info *)0)->type) + \ + sizeof(((struct perf_record_auxtrace_info *)0)->reserved__))int gtrace__process_auxtrace_info (union perf_event *event,struct perf_session *session);#endif
Signature · 7 lines
2.34.1 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
PATCH 24/24 perf tools: gtrace: Add AUX trace decoder and branch sample synthesis
In reply to Zane LeungImplement the gtrace auxtrace decoder: queue AUX buffers, run timeless or timestamped decoding, and synthesize branch samples from decoded trace packets. Support machine-mode instruction access via new '-m/--firmware' and '--firmware-base' options.
--- tools/perf/builtin-script.c | 4 + tools/perf/util/gtrace-decoder.c | 1206 +++++++++++++++++++++++++++++- tools/perf/util/symbol_conf.h | 2 + 3 files changed, 1197 insertions(+), 15 deletions(-)
tools/perf/builtin-script.c +4 -0
@@ -4088,6 +4088,10 @@ int cmd_script(int argc, const char **argv) "file", "vmlinux pathname"),OPT_STRING (0 ,"kallsyms" , &symbol_conf.kallsyms_name,"file" ,"kallsyms pathname" ), +OPT_STRING ('m' ,"firmware" , &symbol_conf.firmware_name, +"file" ,"machine mode firmware binary pathname" ), +OPT_STRING (0 ,"firmware-base" , &symbol_conf.firmware_base, +"address" ,"base address for machine mode firmware (e.g., 0x100000000)" ),OPT_BOOLEAN ('G' ,"hide-call-graph" , &no_callchain,"When printing symbols do not display call chain" ), OPT_CALLBACK(0, "symfs", NULL, "directory[,layout]", SYMFS_HELP,
tools/perf/util/gtrace-decoder.c +1191 -15
1,289 lines not on this page · raw message
tools/perf/util/symbol_conf.h +2 -0
@@ -72,6 +72,8 @@ struct symbol_conf { prefer_latency;const char *vmlinux_name, *kallsyms_name, + *firmware_name, + *firmware_base, *source_prefix, *field_sep, *graph_function;
Signature · 1 line
2.34.1