Re: [PATCH 11/11] media: hantro: Add fdinfo callback

Nicolas Dufresne
2026-04-28T19:41:16Z

[-- Attachment #1: Type: text/plain, Size: 4001 bytes --]

Le jeudi 12 février 2026 à 11:23 -0500, Detlev Casanova a écrit :
> The fdinfo shows the number of buffers in each queue and the total amount
> of video buffer memory.
>
> Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>

Notice that the FD info is not linked with all the ftrace work, and could have
been kept separate. I think overall that this fdinfo implementation is a bit
limited, and lack helpers or introducing of common statistics that would be
opted in by other drivers. I would hold on that until we have a bigger and
robust plan.

Nicolas

> ---
>  drivers/media/platform/verisilicon/hantro.h      |  1 +
>  drivers/media/platform/verisilicon/hantro_drv.c  | 15 +++++++++++++++
>  drivers/media/platform/verisilicon/hantro_v4l2.c | 10 +++++++++-
>  3 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/verisilicon/hantro.h
> b/drivers/media/platform/verisilicon/hantro.h
> index d5cddc783688..9e9fc0658586 100644
> --- a/drivers/media/platform/verisilicon/hantro.h
> +++ b/drivers/media/platform/verisilicon/hantro.h
> @@ -268,6 +268,7 @@ struct hantro_ctx {
>   const struct hantro_codec_ops *codec_ops;
>   struct hantro_postproc_ctx postproc;
>   bool need_postproc;
> + u64 stats_buf_memory;
>
>   /* Specific for particular codec modes. */
>   union {
> diff --git a/drivers/media/platform/verisilicon/hantro_drv.c
> b/drivers/media/platform/verisilicon/hantro_drv.c
> index 8dd26ca32459..86d316a8a3e8 100644
> --- a/drivers/media/platform/verisilicon/hantro_drv.c
> +++ b/drivers/media/platform/verisilicon/hantro_drv.c
> @@ -17,6 +17,7 @@
>  #include <linux/platform_device.h>
>  #include <linux/pm.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/seq_file.h>
>  #include <linux/slab.h>
>  #include <linux/videodev2.h>
>  #include <linux/workqueue.h>
> @@ -711,6 +712,19 @@ static int hantro_release(struct file *filp)
>   return 0;
>  }
>
> +static void hantro_show_fdinfo(struct seq_file *m, struct file *filp)
> +{
> + struct hantro_ctx *ctx =
> + container_of(filp->private_data, struct hantro_ctx, fh);
> +
> + struct vb2_queue *src_q = v4l2_m2m_get_src_vq(ctx->fh.m2m_ctx);
> + struct vb2_queue *dst_q = v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx);
> +
> + seq_printf(m, "src-queued-count: %04u\n", src_q->queued_count);
> + seq_printf(m, "dst-queued-count: %04u\n", dst_q->queued_count);
> + seq_printf(m, "buf-size: %llu\n", ctx->stats_buf_memory);
> +}
> +
>  static const struct v4l2_file_operations hantro_fops = {
>   .owner = THIS_MODULE,
>   .open = hantro_open,
> @@ -718,6 +732,7 @@ static const struct v4l2_file_operations hantro_fops = {
>   .poll = v4l2_m2m_fop_poll,
>   .unlocked_ioctl = video_ioctl2,
>   .mmap = v4l2_m2m_fop_mmap,
> + .show_fdinfo = hantro_show_fdinfo,
>  };
>
>  static const struct of_device_id of_hantro_match[] = {
> diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c
> b/drivers/media/platform/verisilicon/hantro_v4l2.c
> index fcf3bd9bcda2..6d129613ea3d 100644
> --- a/drivers/media/platform/verisilicon/hantro_v4l2.c
> +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c
> @@ -820,18 +820,26 @@ hantro_queue_setup(struct vb2_queue *vq, unsigned int
> *num_buffers,
>   return -EINVAL;
>   }
>
> + ctx->stats_buf_memory = 0;
> +
>   if (*num_planes) {
>   if (*num_planes != pixfmt->num_planes)
>   return -EINVAL;
> - for (i = 0; i < pixfmt->num_planes; ++i)
> + for (i = 0; i < pixfmt->num_planes; ++i) {
>   if (sizes[i] < pixfmt->plane_fmt[i].sizeimage)
>   return -EINVAL;
> + ctx->stats_buf_memory += pixfmt-
> >plane_fmt[i].sizeimage;
> + }
> +
> + ctx->stats_buf_memory *= *num_buffers;
> +
>   return 0;
>   }
>
>   *num_planes = pixfmt->num_planes;
>   for (i = 0; i < pixfmt->num_planes; ++i)
>   sizes[i] = pixfmt->plane_fmt[i].sizeimage;
> +
>   return 0;
>  }
>

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]