From: Zane Leung <liangzhen@linux.spacemit.com>
To: gregkh@linuxfoundation.org, palmer@dabbelt.com, pjw@kernel.org,
alexander.shishkin@linux.intel.com, suzuki.poulose@arm.com,
mchitale@gmail.com, anup@brainfault.org, irogers@google.com
Cc: mike.leach@arm.com, james.clark@linaro.org, leo.yan@arm.com,
peterz@infradead.org, mingo@redhat.com, namhyung@kernel.org,
mark.rutland@arm.com, jolsa@kernel.org, adrian.hunter@intel.com,
alex@ghiti.fr, atish.patra@linux.dev,
andrew.jones@oss.qualcomm.com, sunilvl@oss.qualcomm.com,
liangzhen@linux.spacemit.com, zhuangqiubin@linux.spacemit.com,
coresight@lists.linaro.org, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 18/24] gtrace: Add sink-specific buffer alloc/free callbacks
Date: Fri, 23 Oct 2026 11:14:59 +0800 [thread overview]
Message-ID: <20261023031505.2020925-19-liangzhen@linux.spacemit.com> (raw)
In-Reply-To: <20261023031505.2020925-1-liangzhen@linux.spacemit.com>
Extend 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.
Signed-off-by: Zane Leung <liangzhen@linux.spacemit.com>
---
drivers/hwtracing/gtrace/gtrace-perf.c | 34 ++++++++++++++++++++++++++
include/linux/gtrace.h | 12 +++++++++
2 files changed, 46 insertions(+)
diff --git a/drivers/hwtracing/gtrace/gtrace-perf.c b/drivers/hwtracing/gtrace/gtrace-perf.c
index 9b874daa807f..e05a833aa6a4 100644
--- a/drivers/hwtracing/gtrace/gtrace-perf.c
+++ b/drivers/hwtracing/gtrace/gtrace-perf.c
@@ -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);
diff --git a/include/linux/gtrace.h b/include/linux/gtrace.h
index 39ae13701615..a3d125882ec9 100644
--- a/include/linux/gtrace.h
+++ b/include/linux/gtrace.h
@@ -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);
--
2.34.1
next prev parent reply other threads:[~2026-10-23 3:17 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 3:14 [RFC PATCH 00/24] Add Linux RISC-V trace support via the gtrace framework Zane Leung
2026-10-23 3:14 ` [PATCH 01/24] gtrace: Move connection release into component unregister Zane Leung
2026-10-23 3:14 ` [PATCH 02/24] gtrace: Initial implementation of gtrace sysfs framework Zane Leung
2026-10-23 3:14 ` [PATCH 03/24] gtrace: Drop trace format field and helper function Zane Leung
2026-10-23 3:14 ` [PATCH 04/24] gtrace: Add RISC-V trace encoder sysfs support Zane Leung
2026-10-23 3:14 ` [PATCH 05/24] gtrace: Introduce some PMU format attributes Zane Leung
2026-10-23 3:14 ` [PATCH 06/24] gtrace: Replace owner PID with perf_event pointer in gtrace_path Zane Leung
2026-10-23 3:14 ` [PATCH 07/24] gtrace: Parse RISC-V Trace encoder config from perf event Zane Leung
2026-10-23 3:14 ` [PATCH 08/24] gtrace: add perf symlink support for gtrace components Zane Leung
2026-10-23 3:14 ` [PATCH 09/24] gtrace: Add port-level start/stop driver callbacks Zane Leung
2026-10-23 3:14 ` [PATCH 10/24] gtrace: Add RISC-V trace funnel driver Zane Leung
2026-10-23 3:14 ` [PATCH 11/24] gtrace: Add RISC-V trace timestamp support Zane Leung
2026-10-23 3:14 ` [PATCH 12/24] gtrace: Add RISC-V trace ATB bridge driver Zane Leung
2026-10-23 3:14 ` [PATCH 13/24] gtrace: Add CoreSight platform core APIs Zane Leung
2026-10-23 3:14 ` [PATCH 14/24] gtrace: Add CoreSight funnel driver Zane Leung
2026-10-23 3:14 ` [PATCH 15/24] gtrace: Only copy AUX data from the path sink Zane Leung
2026-10-23 3:14 ` [PATCH 16/24] perf: Flag whether gtrace AUX data carries CoreSight framing Zane Leung
2026-10-23 3:14 ` [PATCH 17/24] gtrace: Unify default sink selection across CPUs in perf setup Zane Leung
2026-10-23 3:14 ` Zane Leung [this message]
2026-10-23 3:15 ` [PATCH 19/24] gtrace: Add setup_sysfs_buf callback to setup sysfs sink buffer Zane Leung
2026-10-23 3:15 ` [PATCH 20/24] gtrace: Add CoreSight TMC driver support Zane Leung
2026-10-23 3:15 ` [PATCH 21/24] perf tools: riscv: making gtrace PMU listable Zane Leung
2026-10-23 3:15 ` [PATCH 22/24] perf tools: Add Nexus RISC-V Trace decoder Zane Leung
2026-10-23 3:15 ` [PATCH 23/24] perf tools: gtrace: Record and parse trace encoder metadata Zane Leung
2026-10-23 3:15 ` [PATCH 24/24] perf tools: gtrace: Add AUX trace decoder and branch sample synthesis Zane Leung
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261023031505.2020925-19-liangzhen@linux.spacemit.com \
--to=liangzhen@linux.spacemit.com \
--cc=adrian.hunter@intel.com \
--cc=alex@ghiti.fr \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrew.jones@oss.qualcomm.com \
--cc=anup@brainfault.org \
--cc=atish.patra@linux.dev \
--cc=coresight@lists.linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=leo.yan@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=mchitale@gmail.com \
--cc=mike.leach@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=palmer@dabbelt.com \
--cc=peterz@infradead.org \
--cc=pjw@kernel.org \
--cc=sunilvl@oss.qualcomm.com \
--cc=suzuki.poulose@arm.com \
--cc=zhuangqiubin@linux.spacemit.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®