From: Detlev Casanova <detlev.casanova@collabora.com>
To: Daniel Almeida <daniel.almeida@collabora.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Nicolas Dufresne <nicolas.dufresne@collabora.com>,
Benjamin Gaignard <benjamin.gaignard@collabora.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Heiko Stuebner <heiko@sntech.de>
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
linux-trace-kernel@vger.kernel.org,
linux-rockchip@lists.infradead.org,
linux-arm-kernel@lists.infradead.org, kernel@collabora.com,
Detlev Casanova <detlev.casanova@collabora.com>
Subject: [PATCH v2 7/9] media: Add stream on/off traces and run them in the ioctl
Date: Wed, 10 Jun 2026 10:33:37 -0400 [thread overview]
Message-ID: <20260610-v4l2-add-ftrace-v2-7-9756edf72ac1@collabora.com> (raw)
In-Reply-To: <20260610-v4l2-add-ftrace-v2-0-9756edf72ac1@collabora.com>
This will automatically add stream on/off tracing for all v4l2 drivers.
Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
drivers/media/v4l2-core/v4l2-ioctl.c | 20 +++++++++++++++++--
include/trace/events/v4l2.h | 37 ++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index c8746a1637f5..b09489baff3e 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1963,13 +1963,29 @@ static int v4l_try_fmt(const struct v4l2_ioctl_ops *ops, struct file *file,
static int v4l_streamon(const struct v4l2_ioctl_ops *ops, struct file *file,
void *arg)
{
- return ops->vidioc_streamon(file, NULL, *(unsigned int *)arg);
+ struct v4l2_fh *fh = file_to_v4l2_fh(file);
+ int err;
+
+ err = ops->vidioc_streamon(file, NULL, *(unsigned int *)arg);
+
+ if (!err)
+ trace_v4l2_streamon(fh->tgid, fh->fd);
+
+ return err;
}
static int v4l_streamoff(const struct v4l2_ioctl_ops *ops, struct file *file,
void *arg)
{
- return ops->vidioc_streamoff(file, NULL, *(unsigned int *)arg);
+ struct v4l2_fh *fh = file_to_v4l2_fh(file);
+ int err;
+
+ err = ops->vidioc_streamoff(file, NULL, *(unsigned int *)arg);
+
+ if (!err)
+ trace_v4l2_streamoff(fh->tgid, fh->fd);
+
+ return err;
}
static int v4l_g_tuner(const struct v4l2_ioctl_ops *ops, struct file *file,
diff --git a/include/trace/events/v4l2.h b/include/trace/events/v4l2.h
index 248bc09bfc99..e5b80aeecc30 100644
--- a/include/trace/events/v4l2.h
+++ b/include/trace/events/v4l2.h
@@ -262,6 +262,43 @@ DEFINE_EVENT(vb2_v4l2_event_class, vb2_v4l2_qbuf,
TP_ARGS(q, vb)
);
+
+/* Events for stream on/off.
+ *
+ * These events will be fired every time userspace starts or stops a stream.
+ * tgid and fd are used to identify the process that opened the video device.
+ *
+ * Note that this even can be fired multiple times for a given tgid/fd pair.
+ * E.g.: mem2mem drivers expect stream on/off on both output and capture queues.
+ */
+DECLARE_EVENT_CLASS(v4l2_stream_class,
+ TP_PROTO(u32 tgid, u32 fd),
+ TP_ARGS(tgid, fd),
+
+ TP_STRUCT__entry(
+ __field(u32, tgid)
+ __field(u32, fd)
+ ),
+
+ TP_fast_assign(
+ __entry->tgid = tgid;
+ __entry->fd = fd;
+ ),
+
+ TP_printk("tgid = %u, fd = %u",
+ __entry->tgid, __entry->fd)
+);
+
+DEFINE_EVENT(v4l2_stream_class, v4l2_streamon,
+ TP_PROTO(u32 tgid, u32 fd),
+ TP_ARGS(tgid, fd)
+);
+
+DEFINE_EVENT(v4l2_stream_class, v4l2_streamoff,
+ TP_PROTO(u32 tgid, u32 fd),
+ TP_ARGS(tgid, fd)
+);
+
#endif /* if !defined(_TRACE_V4L2_H) || defined(TRACE_HEADER_MULTI_READ) */
/* This part must be outside protection */
--
2.54.0
next prev parent reply other threads:[~2026-06-10 14:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-10 14:33 [PATCH v2 0/9] v4l2: Add tracing for stateless codecs Detlev Casanova
2026-06-10 14:33 ` [PATCH v2 1/9] media: Move visl traces to v4l2-core Detlev Casanova
2026-06-10 14:33 ` [PATCH v2 2/9] media: Map each struct field to its own trace field Detlev Casanova
2026-06-10 14:33 ` [PATCH v2 3/9] media: Add tgid and fd fields in v4l2_fh struct Detlev Casanova
2026-06-10 14:33 ` [PATCH v2 4/9] media: Add tgid and fd to the v4l2-requests trace fields Detlev Casanova
2026-06-10 14:33 ` [PATCH v2 5/9] media: Add missing types to v4l2_ctrl_ptr Detlev Casanova
2026-06-10 14:33 ` [PATCH v2 6/9] media: Trace the stateless controls when set in v4l2-ctrls-core.c Detlev Casanova
2026-06-10 14:33 ` Detlev Casanova [this message]
2026-06-10 14:33 ` [PATCH v2 8/9] media: Add HW run/done trace events Detlev Casanova
2026-06-10 14:33 ` [PATCH v2 9/9] media: hantro: Add v4l2_hw run/done traces Detlev Casanova
2026-11-17 22:08 ` [PATCH v2 0/9] v4l2: Add tracing for stateless codecs Nicolas Dufresne
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=20260610-v4l2-add-ftrace-v2-7-9756edf72ac1@collabora.com \
--to=detlev.casanova@collabora.com \
--cc=benjamin.gaignard@collabora.com \
--cc=daniel.almeida@collabora.com \
--cc=heiko@sntech.de \
--cc=kernel@collabora.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mchehab@kernel.org \
--cc=mhiramat@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=p.zabel@pengutronix.de \
--cc=rostedt@goodmis.org \
/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®