* [PATCH 0/3] media: Add fdinfo support for v4l2 drivers
@ 2026-06-12 14:26 Detlev Casanova
2026-06-12 14:26 ` [PATCH 1/3] media: v4l2: Add callback for show_fdinfo Detlev Casanova
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Detlev Casanova @ 2026-06-12 14:26 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Nicolas Dufresne, Benjamin Gaignard,
Philipp Zabel
Cc: linux-media, linux-kernel, linux-rockchip, kernel,
Detlev Casanova, Christopher Healy
fdinfo is useful to poll information from the driver.
Unlike the ftrace interface, it lets userspace tools get a snapshot of
the state of the driver at their own pace, instead of getting events for
each driver status change.
This works better to get information like HW usage time or clock
frequencies, as well as memory usage.
This patch set focuses on mem2mem drivers that are per-frame based and
an implementation is proposed for the Verisilicon Hantro driver, limited
to clock frequencies and HW usage time.
An example of usage of this from userspace is implemented in v4l2top:
https://github.com/cazou/v4l2top
checkpatch.pl warning: The 2 arguments in the show_fdinfo callback
definition are kept unnamed to match with the rest of the struct
definition.
Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
Christopher Healy (2):
docs: media: add documentation for media client usage stats
media: hantro: add per-context fdinfo usage stats
Detlev Casanova (1):
media: v4l2: Add callback for show_fdinfo
.../userspace-api/media/drivers/index.rst | 1 +
.../media/drivers/media-usage-stats.rst | 84 ++++++++++++++++++++++
drivers/media/platform/verisilicon/hantro.h | 5 ++
drivers/media/platform/verisilicon/hantro_drv.c | 22 ++++++
drivers/media/v4l2-core/v4l2-dev.c | 10 +++
include/media/v4l2-dev.h | 1 +
6 files changed, 123 insertions(+)
---
base-commit: acb7500801e98639f6d8c2d796ed9f64cba83d3a
change-id: 20260610-v4l2-add-fdinfo-a790fceab329
Best regards,
--
Detlev Casanova <detlev.casanova@collabora.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] media: v4l2: Add callback for show_fdinfo
2026-06-12 14:26 [PATCH 0/3] media: Add fdinfo support for v4l2 drivers Detlev Casanova
@ 2026-06-12 14:26 ` Detlev Casanova
2026-06-12 14:26 ` [PATCH 2/3] docs: media: add documentation for media client usage stats Detlev Casanova
2026-06-12 14:26 ` [PATCH 3/3] media: hantro: add per-context fdinfo " Detlev Casanova
2 siblings, 0 replies; 6+ messages in thread
From: Detlev Casanova @ 2026-06-12 14:26 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Nicolas Dufresne, Benjamin Gaignard,
Philipp Zabel
Cc: linux-media, linux-kernel, linux-rockchip, kernel, Detlev Casanova
Allow v4l2 drivers to add information in the fdinfo file matching the
opened /dev/videoX file.
Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
drivers/media/v4l2-core/v4l2-dev.c | 10 ++++++++++
include/media/v4l2-dev.h | 1 +
2 files changed, 11 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 6ce623a1245a..3878fa2ff73e 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -481,6 +481,15 @@ static int v4l2_release(struct inode *inode, struct file *filp)
return ret;
}
+/* Override for the show_fdinfo function */
+static void v4l2_show_fdinfo(struct seq_file *m, struct file *filp)
+{
+ struct video_device *vdev = video_devdata(filp);
+
+ if (vdev->fops->show_fdinfo)
+ vdev->fops->show_fdinfo(m, filp);
+}
+
static const struct file_operations v4l2_fops = {
.owner = THIS_MODULE,
.read = v4l2_read,
@@ -494,6 +503,7 @@ static const struct file_operations v4l2_fops = {
#endif
.release = v4l2_release,
.poll = v4l2_poll,
+ .show_fdinfo = v4l2_show_fdinfo,
};
/**
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 2e0f6d2e6a78..1635ab186f21 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -212,6 +212,7 @@ struct v4l2_file_operations {
int (*mmap) (struct file *, struct vm_area_struct *);
int (*open) (struct file *);
int (*release) (struct file *);
+ void (*show_fdinfo)(struct seq_file *, struct file *);
};
/*
--
2.54.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/3] docs: media: add documentation for media client usage stats
2026-06-12 14:26 [PATCH 0/3] media: Add fdinfo support for v4l2 drivers Detlev Casanova
2026-06-12 14:26 ` [PATCH 1/3] media: v4l2: Add callback for show_fdinfo Detlev Casanova
@ 2026-06-12 14:26 ` Detlev Casanova
2026-06-12 14:26 ` [PATCH 3/3] media: hantro: add per-context fdinfo " Detlev Casanova
2 siblings, 0 replies; 6+ messages in thread
From: Detlev Casanova @ 2026-06-12 14:26 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Nicolas Dufresne, Benjamin Gaignard,
Philipp Zabel
Cc: linux-media, linux-kernel, linux-rockchip, kernel,
Detlev Casanova, Christopher Healy
From: Christopher Healy <healych@amazon.com>
Document the media fdinfo interface for per-file-descriptor usage
statistics exposed by stateless V4L2 codec drivers via
/proc/<pid>/fdinfo/<fd>.
This interface is specific to stateless (request API based) codec
devices where the kernel driver has per-job visibility into hardware
execution. Stateful codecs cannot support this because their firmware
manages job scheduling opaquely.
The specification defines media- prefixed keys for engine utilization
time, hardware cycle counts, and operating frequency, following the
same conventions as the DRM fdinfo mechanism documented in
drm-usage-stats.rst.
Signed-off-by: Christopher Healy <healych@amazon.com>
---
.../userspace-api/media/drivers/index.rst | 1 +
.../media/drivers/media-usage-stats.rst | 84 ++++++++++++++++++++++
2 files changed, 85 insertions(+)
diff --git a/Documentation/userspace-api/media/drivers/index.rst b/Documentation/userspace-api/media/drivers/index.rst
index 02967c9b18d6..61879738836c 100644
--- a/Documentation/userspace-api/media/drivers/index.rst
+++ b/Documentation/userspace-api/media/drivers/index.rst
@@ -34,6 +34,7 @@ For more details see the file COPYING in the source distribution of Linux.
imx-uapi
mali-c55
max2175
+ media-usage-stats
npcm-video
omap3isp-uapi
thp7312
diff --git a/Documentation/userspace-api/media/drivers/media-usage-stats.rst b/Documentation/userspace-api/media/drivers/media-usage-stats.rst
new file mode 100644
index 000000000000..835a74902e6e
--- /dev/null
+++ b/Documentation/userspace-api/media/drivers/media-usage-stats.rst
@@ -0,0 +1,84 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+.. _media-usage-stats:
+
+==========================
+Media client usage stats
+==========================
+
+Stateless V4L2 codec drivers can optionally expose per-file-descriptor usage
+statistics via ``/proc/<pid>/fdinfo/<fd>``. This is analogous to the DRM fdinfo
+mechanism documented in :ref:`drm-client-usage-stats`, but uses the ``media-``
+key prefix for V4L2 media devices.
+
+This interface is specific to stateless (request API based) codec devices,
+including both decoders and encoders. With stateless codecs, the kernel driver
+explicitly submits each frame to the hardware and receives a completion
+interrupt, providing a clean per-job boundary that can be attributed to the
+submitting file descriptor.
+
+Stateful codec devices cannot support this interface because their firmware
+manages job scheduling internally. The kernel driver submits bitstream data
+but has no visibility into per-frame hardware execution timing.
+
+Implementation
+==============
+
+The V4L2 core provides the plumbing: drivers implement the ``show_fdinfo``
+callback in ``struct v4l2_file_operations``, and the core wires it into the
+kernel ``struct file_operations`` so that ``/proc/<pid>/fdinfo/<fd>`` output
+includes the driver-provided keys.
+
+File format specification
+=========================
+
+- File shall contain one key value pair per one line of text.
+- Colon character (``:``) must be used to delimit keys and values.
+- All standardised keys shall be prefixed with ``media-``.
+- Driver-specific keys shall be prefixed with ``driver_name-``.
+
+Mandatory keys
+--------------
+
+- media-driver: <valstr>
+
+ String shall contain the name of the media driver.
+
+Utilization keys
+----------------
+
+- media-engine-<keystr>: <uint> ns
+
+ Time in nanoseconds that the hardware engine spent busy processing work
+ belonging to this file descriptor. The ``<keystr>`` identifies the engine
+ (e.g. ``decoder``, ``encoder``).
+
+ Values are not required to be constantly monotonic if it makes the driver
+ implementation easier, but are required to catch up with the previously
+ reported larger value within a reasonable period.
+
+Frequency keys
+--------------
+
+- media-maxfreq-<keystr>: <uint> Hz
+
+ Maximum operating frequency of the engine identified by ``<keystr>``.
+
+- media-curfreq-<keystr>: <uint> Hz
+
+ Current operating frequency of the engine identified by ``<keystr>``.
+
+Example output
+==============
+
+::
+
+ media-driver: hantro-vpu
+ media-engine-decoder: 123456789 ns
+ media-maxfreq-decoder: 600000000 Hz
+ media-curfreq-decoder: 600000000 Hz
+
+Driver specific implementations
+===============================
+
+* Hantro VPU (``drivers/media/platform/verisilicon/``)
--
2.54.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] media: hantro: add per-context fdinfo usage stats
2026-06-12 14:26 [PATCH 0/3] media: Add fdinfo support for v4l2 drivers Detlev Casanova
2026-06-12 14:26 ` [PATCH 1/3] media: v4l2: Add callback for show_fdinfo Detlev Casanova
2026-06-12 14:26 ` [PATCH 2/3] docs: media: add documentation for media client usage stats Detlev Casanova
@ 2026-06-12 14:26 ` Detlev Casanova
2026-06-12 15:18 ` Nicolas Dufresne
2 siblings, 1 reply; 6+ messages in thread
From: Detlev Casanova @ 2026-06-12 14:26 UTC (permalink / raw)
To: Mauro Carvalho Chehab, Nicolas Dufresne, Benjamin Gaignard,
Philipp Zabel
Cc: linux-media, linux-kernel, linux-rockchip, kernel,
Detlev Casanova, Christopher Healy
From: Christopher Healy <healych@amazon.com>
Add per-file-descriptor hardware utilization tracking to the Hantro
VPU stateless codec driver, exposed via /proc/<pid>/fdinfo/<fd>.
Record a ktime timestamp when each job is submitted to hardware in
device_run(), and accumulate the elapsed nanoseconds when the job
completes in hantro_job_finish(). Report the accumulated time along
with the current clock frequency through the new V4L2 show_fdinfo
callback.
The output uses a media- key prefix with the following keys:
media-driver: driver name
media-engine-<eng>: accumulated busy time in nanoseconds
media-maxfreq-<eng>: maximum engine frequency in Hz
media-curfreq-<eng>: current engine frequency in Hz
Where <eng> is "decoder" or "encoder" depending on the context.
This enables userspace monitoring tools to compute per-process decoder
and encoder utilization. The current and max frequency keys report the
same value today since the driver lacks devfreq support, but will
diverge once DVFS is added, allowing userspace to approximate true
capacity utilization without any fdinfo code changes. A future series
can add hardware cycle counter support (via media-cycles-<eng>) for
exact utilization under DVFS, with no changes to the existing uAPI.
Signed-off-by: Christopher Healy <healych@amazon.com>
Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
drivers/media/platform/verisilicon/hantro.h | 5 +++++
drivers/media/platform/verisilicon/hantro_drv.c | 22 ++++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h
index 0353de154a1e..10287e5cebac 100644
--- a/drivers/media/platform/verisilicon/hantro.h
+++ b/drivers/media/platform/verisilicon/hantro.h
@@ -16,6 +16,7 @@
#include <linux/videodev2.h>
#include <linux/wait.h>
#include <linux/clk.h>
+#include <linux/ktime.h>
#include <linux/reset.h>
#include <media/v4l2-ctrls.h>
@@ -268,6 +269,10 @@ struct hantro_ctx {
struct hantro_postproc_ctx postproc;
bool need_postproc;
+ /* Statistics for debugging and performance measurements. */
+ ktime_t start_time;
+ u64 total_ns;
+
/* Specific for particular codec modes. */
union {
struct hantro_h264_dec_hw_ctx h264_dec;
diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c
index 2e81877f640f..139c2e6a83aa 100644
--- a/drivers/media/platform/verisilicon/hantro_drv.c
+++ b/drivers/media/platform/verisilicon/hantro_drv.c
@@ -90,6 +90,8 @@ static void hantro_job_finish(struct hantro_dev *vpu,
struct hantro_ctx *ctx,
enum vb2_buffer_state result)
{
+ ctx->total_ns += ktime_to_ns(ktime_sub(ktime_get(), ctx->start_time));
+
pm_runtime_put_autosuspend(vpu->dev);
clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
@@ -186,6 +188,8 @@ static void device_run(void *priv)
v4l2_m2m_buf_copy_metadata(src, dst);
+ ctx->start_time = ktime_get();
+
if (ctx->codec_ops->run(ctx))
goto err_cancel_job;
@@ -701,10 +705,28 @@ static int hantro_release(struct file *filp)
return 0;
}
+static void hantro_show_fdinfo(struct seq_file *m, struct file *f)
+{
+ struct hantro_ctx *ctx = file_to_ctx(f);
+ struct hantro_dev *vpu = ctx->dev;
+
+ seq_printf(m, "media-driver:\t%s\n", DRIVER_NAME);
+ seq_printf(m, "media-engine-%s:\t%llu ns\n",
+ ctx->is_encoder ? "encoder" : "decoder",
+ ctx->total_ns);
+ seq_printf(m, "media-maxfreq-%s:\t%lu Hz\n",
+ ctx->is_encoder ? "encoder" : "decoder",
+ clk_get_rate(vpu->clocks[0].clk));
+ seq_printf(m, "media-curfreq-%s:\t%lu Hz\n",
+ ctx->is_encoder ? "encoder" : "decoder",
+ clk_get_rate(vpu->clocks[0].clk));
+}
+
static const struct v4l2_file_operations hantro_fops = {
.owner = THIS_MODULE,
.open = hantro_open,
.release = hantro_release,
+ .show_fdinfo = hantro_show_fdinfo,
.poll = v4l2_m2m_fop_poll,
.unlocked_ioctl = video_ioctl2,
.mmap = v4l2_m2m_fop_mmap,
--
2.54.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] media: hantro: add per-context fdinfo usage stats
2026-06-12 14:26 ` [PATCH 3/3] media: hantro: add per-context fdinfo " Detlev Casanova
@ 2026-06-12 15:18 ` Nicolas Dufresne
2026-06-12 17:25 ` Detlev Casanova
0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Dufresne @ 2026-06-12 15:18 UTC (permalink / raw)
To: Detlev Casanova, Mauro Carvalho Chehab, Benjamin Gaignard, Philipp Zabel
Cc: linux-media, linux-kernel, linux-rockchip, kernel, Christopher Healy
[-- Attachment #1: Type: text/plain, Size: 5139 bytes --]
Hi,
Le vendredi 12 juin 2026 à 10:26 -0400, Detlev Casanova a écrit :
> From: Christopher Healy <healych@amazon.com>
>
> Add per-file-descriptor hardware utilization tracking to the Hantro
> VPU stateless codec driver, exposed via /proc/<pid>/fdinfo/<fd>.
>
> Record a ktime timestamp when each job is submitted to hardware in
> device_run(), and accumulate the elapsed nanoseconds when the job
> completes in hantro_job_finish(). Report the accumulated time along
> with the current clock frequency through the new V4L2 show_fdinfo
> callback.
>
> The output uses a media- key prefix with the following keys:
> media-driver: driver name
> media-engine-<eng>: accumulated busy time in nanoseconds
> media-maxfreq-<eng>: maximum engine frequency in Hz
> media-curfreq-<eng>: current engine frequency in Hz
>
> Where <eng> is "decoder" or "encoder" depending on the context.
>
> This enables userspace monitoring tools to compute per-process decoder
> and encoder utilization. The current and max frequency keys report the
> same value today since the driver lacks devfreq support, but will
> diverge once DVFS is added, allowing userspace to approximate true
> capacity utilization without any fdinfo code changes. A future series
> can add hardware cycle counter support (via media-cycles-<eng>) for
> exact utilization under DVFS, with no changes to the existing uAPI.
>
> Signed-off-by: Christopher Healy <healych@amazon.com>
> Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
> ---
> drivers/media/platform/verisilicon/hantro.h | 5 +++++
> drivers/media/platform/verisilicon/hantro_drv.c | 22 ++++++++++++++++++++++
> 2 files changed, 27 insertions(+)
>
> diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h
> index 0353de154a1e..10287e5cebac 100644
> --- a/drivers/media/platform/verisilicon/hantro.h
> +++ b/drivers/media/platform/verisilicon/hantro.h
> @@ -16,6 +16,7 @@
> #include <linux/videodev2.h>
> #include <linux/wait.h>
> #include <linux/clk.h>
> +#include <linux/ktime.h>
> #include <linux/reset.h>
>
> #include <media/v4l2-ctrls.h>
> @@ -268,6 +269,10 @@ struct hantro_ctx {
> struct hantro_postproc_ctx postproc;
> bool need_postproc;
>
> + /* Statistics for debugging and performance measurements. */
> + ktime_t start_time;
> + u64 total_ns;
> +
> /* Specific for particular codec modes. */
> union {
> struct hantro_h264_dec_hw_ctx h264_dec;
> diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c
> index 2e81877f640f..139c2e6a83aa 100644
> --- a/drivers/media/platform/verisilicon/hantro_drv.c
> +++ b/drivers/media/platform/verisilicon/hantro_drv.c
> @@ -90,6 +90,8 @@ static void hantro_job_finish(struct hantro_dev *vpu,
> struct hantro_ctx *ctx,
> enum vb2_buffer_state result)
> {
> + ctx->total_ns += ktime_to_ns(ktime_sub(ktime_get(), ctx->start_time));
> +
> pm_runtime_put_autosuspend(vpu->dev);
>
> clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
> @@ -186,6 +188,8 @@ static void device_run(void *priv)
>
> v4l2_m2m_buf_copy_metadata(src, dst);
>
> + ctx->start_time = ktime_get();
> +
> if (ctx->codec_ops->run(ctx))
> goto err_cancel_job;
>
> @@ -701,10 +705,28 @@ static int hantro_release(struct file *filp)
> return 0;
> }
>
> +static void hantro_show_fdinfo(struct seq_file *m, struct file *f)
> +{
> + struct hantro_ctx *ctx = file_to_ctx(f);
> + struct hantro_dev *vpu = ctx->dev;
> +
> + seq_printf(m, "media-driver:\t%s\n", DRIVER_NAME);
> + seq_printf(m, "media-engine-%s:\t%llu ns\n",
> + ctx->is_encoder ? "encoder" : "decoder",
> + ctx->total_ns);
> + seq_printf(m, "media-maxfreq-%s:\t%lu Hz\n",
> + ctx->is_encoder ? "encoder" : "decoder",
> + clk_get_rate(vpu->clocks[0].clk));
> + seq_printf(m, "media-curfreq-%s:\t%lu Hz\n",
> + ctx->is_encoder ? "encoder" : "decoder",
> + clk_get_rate(vpu->clocks[0].clk));
Similar to what was done in DRM helpers, I would create a common structure,
maybe in a v4l2-stats library (or some better name). The driver would fill that
structure directly, or through helpers (such as software timer helper, cycle
count translation helper), and finally, this show_fd_info() would be a one
liners, just like DRM do.
This will ensure full consistency in the trace, and avoid possible future
unresolvable compatibility issue due to past mistakes. If we ever let a bug
through (of course we won't :-D) all driver will have the same bug, and it will
be easier to not break userspace.
Nicolas
> +}
> +
> static const struct v4l2_file_operations hantro_fops = {
> .owner = THIS_MODULE,
> .open = hantro_open,
> .release = hantro_release,
> + .show_fdinfo = hantro_show_fdinfo,
> .poll = v4l2_m2m_fop_poll,
> .unlocked_ioctl = video_ioctl2,
> .mmap = v4l2_m2m_fop_mmap,
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] media: hantro: add per-context fdinfo usage stats
2026-06-12 15:18 ` Nicolas Dufresne
@ 2026-06-12 17:25 ` Detlev Casanova
0 siblings, 0 replies; 6+ messages in thread
From: Detlev Casanova @ 2026-06-12 17:25 UTC (permalink / raw)
To: Nicolas Dufresne, Mauro Carvalho Chehab, Benjamin Gaignard,
Philipp Zabel
Cc: linux-media, linux-kernel, linux-rockchip, kernel, Christopher Healy
Hi Nicolas,
On 6/12/26 11:18, Nicolas Dufresne wrote:
> Hi,
>
> Le vendredi 12 juin 2026 à 10:26 -0400, Detlev Casanova a écrit :
>> From: Christopher Healy <healych@amazon.com>
>>
>> Add per-file-descriptor hardware utilization tracking to the Hantro
>> VPU stateless codec driver, exposed via /proc/<pid>/fdinfo/<fd>.
>>
>> Record a ktime timestamp when each job is submitted to hardware in
>> device_run(), and accumulate the elapsed nanoseconds when the job
>> completes in hantro_job_finish(). Report the accumulated time along
>> with the current clock frequency through the new V4L2 show_fdinfo
>> callback.
>>
>> The output uses a media- key prefix with the following keys:
>> media-driver: driver name
>> media-engine-<eng>: accumulated busy time in nanoseconds
>> media-maxfreq-<eng>: maximum engine frequency in Hz
>> media-curfreq-<eng>: current engine frequency in Hz
>>
>> Where <eng> is "decoder" or "encoder" depending on the context.
>>
>> This enables userspace monitoring tools to compute per-process decoder
>> and encoder utilization. The current and max frequency keys report the
>> same value today since the driver lacks devfreq support, but will
>> diverge once DVFS is added, allowing userspace to approximate true
>> capacity utilization without any fdinfo code changes. A future series
>> can add hardware cycle counter support (via media-cycles-<eng>) for
>> exact utilization under DVFS, with no changes to the existing uAPI.
>>
>> Signed-off-by: Christopher Healy <healych@amazon.com>
>> Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
>> ---
>> drivers/media/platform/verisilicon/hantro.h | 5 +++++
>> drivers/media/platform/verisilicon/hantro_drv.c | 22 ++++++++++++++++++++++
>> 2 files changed, 27 insertions(+)
>>
>> diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h
>> index 0353de154a1e..10287e5cebac 100644
>> --- a/drivers/media/platform/verisilicon/hantro.h
>> +++ b/drivers/media/platform/verisilicon/hantro.h
>> @@ -16,6 +16,7 @@
>> #include <linux/videodev2.h>
>> #include <linux/wait.h>
>> #include <linux/clk.h>
>> +#include <linux/ktime.h>
>> #include <linux/reset.h>
>>
>> #include <media/v4l2-ctrls.h>
>> @@ -268,6 +269,10 @@ struct hantro_ctx {
>> struct hantro_postproc_ctx postproc;
>> bool need_postproc;
>>
>> + /* Statistics for debugging and performance measurements. */
>> + ktime_t start_time;
>> + u64 total_ns;
>> +
>> /* Specific for particular codec modes. */
>> union {
>> struct hantro_h264_dec_hw_ctx h264_dec;
>> diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c
>> index 2e81877f640f..139c2e6a83aa 100644
>> --- a/drivers/media/platform/verisilicon/hantro_drv.c
>> +++ b/drivers/media/platform/verisilicon/hantro_drv.c
>> @@ -90,6 +90,8 @@ static void hantro_job_finish(struct hantro_dev *vpu,
>> struct hantro_ctx *ctx,
>> enum vb2_buffer_state result)
>> {
>> + ctx->total_ns += ktime_to_ns(ktime_sub(ktime_get(), ctx->start_time));
>> +
>> pm_runtime_put_autosuspend(vpu->dev);
>>
>> clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
>> @@ -186,6 +188,8 @@ static void device_run(void *priv)
>>
>> v4l2_m2m_buf_copy_metadata(src, dst);
>>
>> + ctx->start_time = ktime_get();
>> +
>> if (ctx->codec_ops->run(ctx))
>> goto err_cancel_job;
>>
>> @@ -701,10 +705,28 @@ static int hantro_release(struct file *filp)
>> return 0;
>> }
>>
>> +static void hantro_show_fdinfo(struct seq_file *m, struct file *f)
>> +{
>> + struct hantro_ctx *ctx = file_to_ctx(f);
>> + struct hantro_dev *vpu = ctx->dev;
>> +
>> + seq_printf(m, "media-driver:\t%s\n", DRIVER_NAME);
>> + seq_printf(m, "media-engine-%s:\t%llu ns\n",
>> + ctx->is_encoder ? "encoder" : "decoder",
>> + ctx->total_ns);
>> + seq_printf(m, "media-maxfreq-%s:\t%lu Hz\n",
>> + ctx->is_encoder ? "encoder" : "decoder",
>> + clk_get_rate(vpu->clocks[0].clk));
>> + seq_printf(m, "media-curfreq-%s:\t%lu Hz\n",
>> + ctx->is_encoder ? "encoder" : "decoder",
>> + clk_get_rate(vpu->clocks[0].clk));
> Similar to what was done in DRM helpers, I would create a common structure,
> maybe in a v4l2-stats library (or some better name). The driver would fill that
> structure directly, or through helpers (such as software timer helper, cycle
> count translation helper), and finally, this show_fd_info() would be a one
> liners, just like DRM do.
>
> This will ensure full consistency in the trace, and avoid possible future
> unresolvable compatibility issue due to past mistakes. If we ever let a bug
> through (of course we won't :-D) all driver will have the same bug, and it will
> be easier to not break userspace.
Yes, that makes a lot of sense actually, And will also help with the
ftrace HW info if we have stats and debug info centralized in v4l2
> Nicolas
>
>> +}
>> +
>> static const struct v4l2_file_operations hantro_fops = {
>> .owner = THIS_MODULE,
>> .open = hantro_open,
>> .release = hantro_release,
>> + .show_fdinfo = hantro_show_fdinfo,
>> .poll = v4l2_m2m_fop_poll,
>> .unlocked_ioctl = video_ioctl2,
>> .mmap = v4l2_m2m_fop_mmap,
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-06-12 17:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-12 14:26 [PATCH 0/3] media: Add fdinfo support for v4l2 drivers Detlev Casanova
2026-06-12 14:26 ` [PATCH 1/3] media: v4l2: Add callback for show_fdinfo Detlev Casanova
2026-06-12 14:26 ` [PATCH 2/3] docs: media: add documentation for media client usage stats Detlev Casanova
2026-06-12 14:26 ` [PATCH 3/3] media: hantro: add per-context fdinfo " Detlev Casanova
2026-06-12 15:18 ` Nicolas Dufresne
2026-06-12 17:25 ` Detlev Casanova
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®