From: Leo Yu-Chi Liang <leo.liang@sifive.com>
To: Mayuresh Chitale <mchitale@gmail.com>,
Anup Patel <anup@brainfault.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Samuel Holland <samuel.holland@sifive.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
Leo Yu-Chi Liang <leo.liang@sifive.com>,
linmin@eswincomputing.com, vincent.chen@sifive.com,
luyulin@eswincomputing.com, pritesh.patel@einfochips.com,
ganboing@gmail.com, dongxuyang@eswincomputing.com,
pinkesh.vaghela@einfochips.com, nick.hu@sifive.com,
eric.lin@sifive.com, huangyifeng@eswincomputing.com,
darshan.prajapati@einfochips.com
Subject: [PATCH 10/10] gtrace: rvtrace: Add copyto_auxbuf callback for pre-ratified encoder and funnel
Date: Thu, 26 Nov 2026 01:07:16 -0800 [thread overview]
Message-ID: <20261126-send-preratified-trace-v1-10-1e686fd75be7@sifive.com> (raw)
In-Reply-To: <20261126-send-preratified-trace-v1-0-1e686fd75be7@sifive.com>
From: Eric Lin <eric.lin@sifive.com>
Unlike the standard RISC-V trace ramsink, which is an independent
device, the pre-ratified ramsink are embedded within the trace encoder
or funnel MMIO registers.
When pre-ratified encoder and funnel components act as a sink, the
trace data must be copied from the trace buffer to the perf AUX buffer
after tracing is stopped. To support this, add
rvtrace_v0_ramsink_copyto_auxbuf() which shares the copy logic with the
standard ramsink, and use it to implement the copyto_auxbuf callback of
the encoder and funnel drivers. The callback copies nothing when the
component doesn't act as a sink.
Note: an encoder or funnel component may be in the middle of a given
path, so gtrace_path_copyto_auxbuf() now only invokes the copyto_auxbuf()
callback of the path's sink instead of the first component in the path
implementing it.
Co-developed-by: Nick Hu <nick.hu@sifive.com>
Signed-off-by: Nick Hu <nick.hu@sifive.com>
Co-developed-by: Vincent Chen <vincent.chen@sifive.com>
Signed-off-by: Vincent Chen <vincent.chen@sifive.com>
Signed-off-by: Eric Lin <eric.lin@sifive.com>
Signed-off-by: Leo Yu-Chi Liang <leo.liang@sifive.com>
---
drivers/hwtracing/gtrace/gtrace-core.c | 19 ++++++++-------
drivers/hwtracing/gtrace/rvtrace-encoder.c | 10 ++++++++
drivers/hwtracing/gtrace/rvtrace-funnel.c | 10 ++++++++
drivers/hwtracing/gtrace/rvtrace-ramsink.c | 37 ++++++++++++++++++++++++++----
drivers/hwtracing/gtrace/rvtrace-ramsink.h | 12 ++++++++++
5 files changed, 74 insertions(+), 14 deletions(-)
diff --git a/drivers/hwtracing/gtrace/gtrace-core.c b/drivers/hwtracing/gtrace/gtrace-core.c
index 6fe71c5cd0cf..7a818d647372 100644
--- a/drivers/hwtracing/gtrace/gtrace-core.c
+++ b/drivers/hwtracing/gtrace/gtrace-core.c
@@ -714,10 +714,9 @@ int gtrace_path_copyto_auxbuf(struct gtrace_path *path,
struct gtrace_perf_auxbuf *buf,
size_t *bytes_copied, u64 *format)
{
- struct gtrace_comp_priv *sink = to_gtrace_comp_priv(gtrace_path_sink(path));
+ struct gtrace_component *comp = gtrace_path_sink(path);
+ struct gtrace_comp_priv *sink = to_gtrace_comp_priv(comp);
const struct gtrace_driver *gtdrv;
- struct gtrace_component *comp;
- struct gtrace_path_node *node;
int ret = -EOPNOTSUPP;
unsigned long flags;
@@ -735,15 +734,15 @@ int gtrace_path_copyto_auxbuf(struct gtrace_path *path,
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;
-
+ /*
+ * Only the sink of the path holds the trace data. Other components in
+ * the path may implement copyto_auxbuf() as well, e.g. when they embed
+ * a sink which is only used when they are at the end of a path.
+ */
+ gtdrv = to_gtrace_driver(comp->dev.driver);
+ if (gtdrv && gtdrv->copyto_auxbuf) {
*bytes_copied = gtdrv->copyto_auxbuf(comp, buf, format);
ret = 0;
- break;
}
out:
raw_spin_unlock_irqrestore(&sink->lock, flags);
diff --git a/drivers/hwtracing/gtrace/rvtrace-encoder.c b/drivers/hwtracing/gtrace/rvtrace-encoder.c
index 8d2f7ac5e0fe..a854c4695351 100644
--- a/drivers/hwtracing/gtrace/rvtrace-encoder.c
+++ b/drivers/hwtracing/gtrace/rvtrace-encoder.c
@@ -164,6 +164,15 @@ static int rvtrace_encoder_probe(struct gtrace_component *comp)
return 0;
}
+static size_t rvtrace_encoder_copyto_auxbuf(struct gtrace_component *comp,
+ struct gtrace_perf_auxbuf *buf,
+ u64 *format)
+{
+ struct rvtrace_encoder_priv *priv = dev_get_drvdata(&comp->dev);
+
+ return rvtrace_v0_ramsink_copyto_auxbuf(comp, priv->sink, buf, format);
+}
+
static void rvtrace_encoder_remove(struct gtrace_component *comp)
{
struct rvtrace_encoder_priv *priv = dev_get_drvdata(&comp->dev);
@@ -261,6 +270,7 @@ static const struct gtrace_component_id rvtrace_encoder_ids[] = {
static struct gtrace_driver rvtrace_encoder_driver = {
.id_table = rvtrace_encoder_ids,
+ .copyto_auxbuf = rvtrace_encoder_copyto_auxbuf,
.probe = rvtrace_encoder_probe,
.remove = rvtrace_encoder_remove,
.start = rvtrace_encoder_start,
diff --git a/drivers/hwtracing/gtrace/rvtrace-funnel.c b/drivers/hwtracing/gtrace/rvtrace-funnel.c
index 463e504aaa92..48d1084957c1 100644
--- a/drivers/hwtracing/gtrace/rvtrace-funnel.c
+++ b/drivers/hwtracing/gtrace/rvtrace-funnel.c
@@ -75,6 +75,15 @@ static int rvtrace_funnel_probe(struct gtrace_component *comp)
return 0;
}
+static size_t rvtrace_funnel_copyto_auxbuf(struct gtrace_component *comp,
+ struct gtrace_perf_auxbuf *buf,
+ u64 *format)
+{
+ struct rvtrace_funnel_priv *priv = dev_get_drvdata(&comp->dev);
+
+ return rvtrace_v0_ramsink_copyto_auxbuf(comp, priv->sink, buf, format);
+}
+
static void rvtrace_funnel_remove(struct gtrace_component *comp)
{
struct rvtrace_funnel_priv *priv = dev_get_drvdata(&comp->dev);
@@ -95,6 +104,7 @@ static const struct gtrace_component_id rvtrace_funnel_ids[] = {
static struct gtrace_driver rvtrace_funnel_driver = {
.id_table = rvtrace_funnel_ids,
+ .copyto_auxbuf = rvtrace_funnel_copyto_auxbuf,
.start = rvtrace_funnel_start,
.stop = rvtrace_funnel_stop,
.probe = rvtrace_funnel_probe,
diff --git a/drivers/hwtracing/gtrace/rvtrace-ramsink.c b/drivers/hwtracing/gtrace/rvtrace-ramsink.c
index f183dcd71c7c..cc0a5785bda4 100644
--- a/drivers/hwtracing/gtrace/rvtrace-ramsink.c
+++ b/drivers/hwtracing/gtrace/rvtrace-ramsink.c
@@ -188,11 +188,11 @@ 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)
+static size_t __rvtrace_ramsink_copyto_auxbuf(struct gtrace_component *comp,
+ struct rvtrace_ramsink_priv *priv,
+ struct gtrace_perf_auxbuf *buf,
+ u64 *format)
{
- struct rvtrace_ramsink_priv *priv = dev_get_drvdata(&comp->dev);
const struct rvtrace_ramsink_regs *regs = priv->regs;
struct trace_buf src, dst;
size_t bytes = 0;
@@ -231,6 +231,13 @@ static size_t rvtrace_ramsink_copyto_auxbuf(struct gtrace_component *comp,
return bytes;
}
+static size_t rvtrace_ramsink_copyto_auxbuf(struct gtrace_component *comp,
+ struct gtrace_perf_auxbuf *buf,
+ u64 *format)
+{
+ return __rvtrace_ramsink_copyto_auxbuf(comp, dev_get_drvdata(&comp->dev), buf, format);
+}
+
static int rvtrace_ramsink_setup_buf(struct gtrace_component *comp,
struct rvtrace_ramsink_priv *priv)
{
@@ -448,6 +455,28 @@ void rvtrace_v0_ramsink_release(struct gtrace_component *comp,
of_reserved_mem_device_release(comp->pdata->dev);
}
EXPORT_SYMBOL_GPL(rvtrace_v0_ramsink_release);
+
+/**
+ * rvtrace_v0_ramsink_copyto_auxbuf() - Copy trace data from the sink embedded
+ * in a pre-ratified trace encoder/funnel into the perf AUX buffer.
+ * @comp: Pre-ratified trace encoder/funnel component.
+ * @priv: Sink private data returned by rvtrace_v0_ramsink_setup().
+ * @buf: Perf AUX buffer.
+ * @format: Trace format of the copied data.
+ *
+ * Return: Number of bytes copied, 0 if the component doesn't act as a sink.
+ */
+size_t rvtrace_v0_ramsink_copyto_auxbuf(struct gtrace_component *comp,
+ struct rvtrace_ramsink_priv *priv,
+ struct gtrace_perf_auxbuf *buf,
+ u64 *format)
+{
+ if (!priv)
+ return 0;
+
+ return __rvtrace_ramsink_copyto_auxbuf(comp, priv, buf, format);
+}
+EXPORT_SYMBOL_GPL(rvtrace_v0_ramsink_copyto_auxbuf);
#endif /* CONFIG_RVTRACE_V0 */
static int rvtrace_ramsink_probe(struct gtrace_component *comp)
diff --git a/drivers/hwtracing/gtrace/rvtrace-ramsink.h b/drivers/hwtracing/gtrace/rvtrace-ramsink.h
index 0c1b346af8c0..ff767da7f861 100644
--- a/drivers/hwtracing/gtrace/rvtrace-ramsink.h
+++ b/drivers/hwtracing/gtrace/rvtrace-ramsink.h
@@ -15,6 +15,10 @@ struct rvtrace_ramsink_priv;
struct rvtrace_ramsink_priv *rvtrace_v0_ramsink_setup(struct gtrace_component *comp);
void rvtrace_v0_ramsink_release(struct gtrace_component *comp,
struct rvtrace_ramsink_priv *priv);
+size_t rvtrace_v0_ramsink_copyto_auxbuf(struct gtrace_component *comp,
+ struct rvtrace_ramsink_priv *priv,
+ struct gtrace_perf_auxbuf *buf,
+ u64 *format);
#else
static inline struct rvtrace_ramsink_priv *
rvtrace_v0_ramsink_setup(struct gtrace_component *comp)
@@ -26,6 +30,14 @@ static inline void rvtrace_v0_ramsink_release(struct gtrace_component *comp,
struct rvtrace_ramsink_priv *priv)
{
}
+
+static inline size_t rvtrace_v0_ramsink_copyto_auxbuf(struct gtrace_component *comp,
+ struct rvtrace_ramsink_priv *priv,
+ struct gtrace_perf_auxbuf *buf,
+ u64 *format)
+{
+ return 0;
+}
#endif
#endif /* __RVTRACE_RAMSINK_H__ */
--
2.43.7
prev parent reply other threads:[~2026-11-26 9:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 9:07 [PATCH 00/10] gtrace: Add support for SiFive pre-ratified RISC-V trace components Leo Yu-Chi Liang
2026-11-26 9:07 ` [PATCH 01/10] dt-bindings: riscv: Add SiFive pre-ratified " Leo Yu-Chi Liang
2026-11-26 9:07 ` [PATCH 02/10] gtrace: rvtrace: Add pre-ratified implementation callback Leo Yu-Chi Liang
2026-11-26 9:07 ` [PATCH 03/10] gtrace: rvtrace: Add pre-ratified private data callback Leo Yu-Chi Liang
2026-11-26 9:07 ` [PATCH 04/10] gtrace: rvtrace: Add pre-ratified encoder support Leo Yu-Chi Liang
2026-11-26 9:07 ` [PATCH 05/10] gtrace: Terminate id_table iteration on GTRACE_COMPONENT_TYPE_NONE Leo Yu-Chi Liang
2026-11-26 9:07 ` [PATCH 06/10] gtrace: rvtrace: Add pre-ratified trace sink config Leo Yu-Chi Liang
2026-11-26 9:07 ` [PATCH 07/10] gtrace: rvtrace: Add pre-ratified trace funnel driver Leo Yu-Chi Liang
2026-11-26 9:07 ` [PATCH 08/10] gtrace: rvtrace: Introduce struct rvtrace_ramsink_regs to abstract register offsets Leo Yu-Chi Liang
2026-11-26 9:07 ` [PATCH 09/10] gtrace: rvtrace: Add pre-ratified ramsink setup Leo Yu-Chi Liang
2026-11-26 9:07 ` Leo Yu-Chi Liang [this message]
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=20261126-send-preratified-trace-v1-10-1e686fd75be7@sifive.com \
--to=leo.liang@sifive.com \
--cc=alex@ghiti.fr \
--cc=alexander.shishkin@linux.intel.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=conor+dt@kernel.org \
--cc=darshan.prajapati@einfochips.com \
--cc=devicetree@vger.kernel.org \
--cc=dongxuyang@eswincomputing.com \
--cc=eric.lin@sifive.com \
--cc=ganboing@gmail.com \
--cc=huangyifeng@eswincomputing.com \
--cc=krzk+dt@kernel.org \
--cc=linmin@eswincomputing.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=luyulin@eswincomputing.com \
--cc=mchitale@gmail.com \
--cc=nick.hu@sifive.com \
--cc=palmer@dabbelt.com \
--cc=pinkesh.vaghela@einfochips.com \
--cc=pjw@kernel.org \
--cc=pritesh.patel@einfochips.com \
--cc=robh@kernel.org \
--cc=samuel.holland@sifive.com \
--cc=vincent.chen@sifive.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®