* [PATCH v2] spi: spi-mem: Trace exec_op
@ 2025-10-21 14:47 Sean Anderson
2025-10-28 11:17 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Sean Anderson @ 2025-10-21 14:47 UTC (permalink / raw)
To: Mark Brown, linux-spi
Cc: Masami Hiramatsu, Mathieu Desnoyers, linux-kernel, Steven Rostedt,
linux-trace-kernel, Sean Anderson
The spi subsystem has tracing, which is very convenient when debugging
problems. Add tracing for spi-mem too so that accesses that skip the spi
subsystem can still be seen.
The format is roughly based on the existing spi tracing. We don't bother
tracing the op's address because the tracing happens while the memory is
locked, so there can be no confusion about the matching of start and
stop. The conversion of cmd/addr/dummy to an array is directly analogous
to the conversion in the latter half of spi_mem_exec_op.
Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
---
Changes in v2:
- Fix old use of __assign_str
MAINTAINERS | 1 +
drivers/spi/spi-mem.c | 5 ++
include/trace/events/spi-mem.h | 106 +++++++++++++++++++++++++++++++++
3 files changed, 112 insertions(+)
create mode 100644 include/trace/events/spi-mem.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 545a4776795e..abad89f4ac4e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -24237,6 +24237,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
F: Documentation/devicetree/bindings/spi/
F: Documentation/spi/
F: drivers/spi/
+F: include/trace/events/spi*
F: include/linux/spi/
F: include/uapi/linux/spi/
F: tools/spi/
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
index 064b99204d9a..c8b2add2640e 100644
--- a/drivers/spi/spi-mem.c
+++ b/drivers/spi/spi-mem.c
@@ -12,6 +12,9 @@
#include <linux/spi/spi-mem.h>
#include <linux/sched/task_stack.h>
+#define CREATE_TRACE_POINTS
+#include <trace/events/spi-mem.h>
+
#include "internals.h"
#define SPI_MEM_MAX_BUSWIDTH 8
@@ -403,7 +406,9 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
if (ret)
return ret;
+ trace_spi_mem_start_op(mem, op);
ret = ctlr->mem_ops->exec_op(mem, op);
+ trace_spi_mem_stop_op(mem, op);
spi_mem_access_end(mem);
diff --git a/include/trace/events/spi-mem.h b/include/trace/events/spi-mem.h
new file mode 100644
index 000000000000..d13f0bcff5e7
--- /dev/null
+++ b/include/trace/events/spi-mem.h
@@ -0,0 +1,106 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM spi-mem
+
+#undef TRACE_SYSTEM_VAR
+#define TRACE_SYSTEM_VAR spi_mem
+
+#if !defined(_TRACE_SPI_MEM_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_SPI_MEM_H
+
+#include <linux/tracepoint.h>
+#include <linux/spi/spi-mem.h>
+
+#define decode_dtr(dtr) \
+ __print_symbolic(dtr, \
+ { 0, "S" }, \
+ { 1, "D" })
+
+TRACE_EVENT(spi_mem_start_op,
+ TP_PROTO(struct spi_mem *mem, const struct spi_mem_op *op),
+ TP_ARGS(mem, op),
+
+ TP_STRUCT__entry(
+ __string(name, mem->name)
+ __dynamic_array(u8, op, 1 + op->addr.nbytes + op->dummy.nbytes)
+ __dynamic_array(u8, data, op->data.dir == SPI_MEM_DATA_OUT ?
+ min(op->data.nbytes, 64) : 0)
+ __field(u32, data_len)
+ __field(u32, max_freq)
+ __field(u8, cmd_buswidth)
+ __field(bool, cmd_dtr)
+ __field(u8, addr_buswidth)
+ __field(bool, addr_dtr)
+ __field(u8, dummy_nbytes)
+ __field(u8, data_buswidth)
+ __field(bool, data_dtr)
+ ),
+
+ TP_fast_assign(
+ int i;
+
+ __assign_str(name);
+ __entry->max_freq = op->max_freq ?: mem->spi->max_speed_hz;
+
+ __entry->cmd_buswidth = op->cmd.buswidth;
+ __entry->cmd_dtr = op->cmd.dtr;
+ *((u8 *)__get_dynamic_array(op)) = op->cmd.opcode;
+
+ __entry->addr_buswidth = op->addr.buswidth;
+ __entry->addr_dtr = op->addr.dtr;
+ for (i = 0; i < op->addr.nbytes; i++)
+ ((u8 *)__get_dynamic_array(op))[i + 1] =
+ op->addr.val >> (8 * (op->addr.nbytes - i - 1));
+
+ memset(((u8 *)__get_dynamic_array(op)) + op->addr.nbytes + 1,
+ 0xff, op->dummy.nbytes);
+
+ __entry->data_len = op->data.nbytes;
+ __entry->data_buswidth = op->data.buswidth;
+ __entry->data_dtr = op->data.dtr;
+ if (op->data.dir == SPI_MEM_DATA_OUT)
+ memcpy(__get_dynamic_array(data), op->data.buf.out,
+ __get_dynamic_array_len(data));
+ ),
+
+ TP_printk("%s %u%s-%u%s-%u%s @%u Hz op=[%*phD] len=%u tx=[%*phD]",
+ __get_str(name),
+ __entry->cmd_buswidth, decode_dtr(__entry->cmd_dtr),
+ __entry->addr_buswidth, decode_dtr(__entry->addr_dtr),
+ __entry->data_buswidth, decode_dtr(__entry->data_dtr),
+ __entry->max_freq,
+ __get_dynamic_array_len(op), __get_dynamic_array(op),
+ __entry->data_len,
+ __get_dynamic_array_len(data), __get_dynamic_array(data))
+);
+
+TRACE_EVENT(spi_mem_stop_op,
+ TP_PROTO(struct spi_mem *mem, const struct spi_mem_op *op),
+ TP_ARGS(mem, op),
+
+ TP_STRUCT__entry(
+ __string(name, mem->name)
+ __dynamic_array(u8, data, op->data.dir == SPI_MEM_DATA_IN ?
+ min(op->data.nbytes, 64) : 0)
+ __field(u32, data_len)
+ ),
+
+ TP_fast_assign(
+ __assign_str(name);
+ __entry->data_len = op->data.nbytes;
+ if (op->data.dir == SPI_MEM_DATA_IN)
+ memcpy(__get_dynamic_array(data), op->data.buf.in,
+ __get_dynamic_array_len(data));
+ ),
+
+ TP_printk("%s len=%u rx=[%*phD]",
+ __get_str(name),
+ __entry->data_len,
+ __get_dynamic_array_len(data), __get_dynamic_array(data))
+);
+
+
+#endif /* _TRACE_SPI_MEM_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
--
2.35.1.1320.gc452695387.dirty
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] spi: spi-mem: Trace exec_op
2025-10-21 14:47 [PATCH v2] spi: spi-mem: Trace exec_op Sean Anderson
@ 2025-10-28 11:17 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2025-10-28 11:17 UTC (permalink / raw)
To: linux-spi, Sean Anderson
Cc: Masami Hiramatsu, Mathieu Desnoyers, linux-kernel, Steven Rostedt,
linux-trace-kernel
On Tue, 21 Oct 2025 10:47:03 -0400, Sean Anderson wrote:
> The spi subsystem has tracing, which is very convenient when debugging
> problems. Add tracing for spi-mem too so that accesses that skip the spi
> subsystem can still be seen.
>
> The format is roughly based on the existing spi tracing. We don't bother
> tracing the op's address because the tracing happens while the memory is
> locked, so there can be no confusion about the matching of start and
> stop. The conversion of cmd/addr/dummy to an array is directly analogous
> to the conversion in the latter half of spi_mem_exec_op.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/1] spi: spi-mem: Trace exec_op
commit: 77a58ba7c64ccca20616aa03599766ccb0d1a330
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-28 11:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-21 14:47 [PATCH v2] spi: spi-mem: Trace exec_op Sean Anderson
2025-10-28 11:17 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).