Re: [PATCH v6 09/14] gtrace: Add RISC-V Trace ramsink driver
From: Leo Yu-Chi Liang
Date: Thu Nov 26 2026 - 01:56:10 EST
Hi Mayuresh,
> + if (wrap) {
> + rvtrace_ramsink_write_pair(comp->pdata, priv->start, RVTRACE_RAMSINK_WPLOW_OFF);
> + src.cur = wp - priv->start;
> + priv->prev_wp = priv->start;
> + /*
> + * There is no way to tell if trRamWp wrapped around more than once. As a
> + * result priv->prev_wp can't be used and the entire buffer must be copied
> + * even though some data might be duplicated.
> + */
> + bytes = priv->size;
> + } else {
> + src.cur = priv->prev_wp - priv->start;
> + bytes = wp - priv->prev_wp;
> + priv->prev_wp = wp;
> + }
Consider the following trace sessions:
session 1 writes 60 bytes, no wrap, WP = 60 buffer: [0,60) = S1
session 2 writes 70 bytes: [60,100), wraps, [0,30) WP = 30, wrap set
buffer: [0,30) = S2 (end of it)
[30,60) = S1 (stale)
[60,100)= S2 (start of it)
The wrap path copies the whole buffer starting at WP, so the AUX buffer gets
30 stale bytes of S1 followed by all 70 bytes of S2. Nothing from S2 is lost,
but the output contains data that does not belong to the session.
Could we reset WP to the start of the buffer after every copy ?
The non-wrap case then always copies [start, wp), and a wrap can only
happen when one session produces more data than the buffer holds.
Does something like below make sense?
--- a/drivers/hwtracing/gtrace/rvtrace-ramsink.c
+++ b/drivers/hwtracing/gtrace/rvtrace-ramsink.c
@@ rvtrace_ramsink_copyto_auxbuf()
if (wrap) {
- rvtrace_ramsink_write_pair(comp->pdata, priv->start, RVTRACE_RAMSINK_WPLOW_OFF);
src.cur = wp - priv->start;
- priv->prev_wp = priv->start;
/*
* There is no way to tell if trRamWp wrapped around more than once.
* The entire buffer must be copied even though some data might be duplicated.
*/
bytes = priv->size;
} else {
- src.cur = priv->prev_wp - priv->start;
- bytes = wp - priv->prev_wp;
- priv->prev_wp = wp;
+ src.cur = 0;
+ bytes = wp - priv->start;
}
tbuf_to_pbuf_copy(&src, &dst, bytes);
+
+ /* Next session starts at the beginning of the buffer */
+ rvtrace_ramsink_write_pair(comp->pdata, priv->start, RVTRACE_RAMSINK_WPLOW_OFF);
+
dev_dbg(&comp->dev, "Copied %zu bytes\n", bytes);
return bytes;
}
Best regards,
Leo