From nobody Wed Nov 25 17:40:03 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.251.105.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795619659; b=W9v1AGKycUDp+aN6X9EOHu8Y8ERKmfML484R00YfWJFcVfiWq+2SqSfW8hPff2iP3KPb X7aTAZBP/BD3kSf+jDxY8klpX5Cs8YudDmKrelrbHpx8Wev0+Ar8Kp+Qs+k9e/CuvCeuP beBWnn6Nh+xiRaGCdAudiJi0boQ9oNxXWLZSgkewEsPDyxYo4sn93UPg8oJdW6BK5jgMv 1zHGlM/Ts29R3Bg4dSi3Qmckm0DFcpg27Cmtl5U9pDKBRzqMAzqjhlQZMPgWPl3R17c8F CvkSm7kNnOy8Y2KczXzREilB/ehNFuqt4/VZrc9QLUWhSnLMTgT9UqfZ4Pg5KgJU/0w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795619659; h=DMARC-Filter:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer; bh=CPGHdi5hn3UUOKK1RE9pKHspisRxsJXHsd478u7KaXE=; b=18BpM4XZWKp3bGCjifyoHLoq5sCUHBG7IDOBfo8Co9Q5jYiVVNQ+c+zzc/zW9ZaiAPMV VMVl2J6NRIOX55oXFXTWTmDPlapE08IO+vt4aNllEc1ZQe5EtxT9uPKP/KMZGvAd+Ojgj 5w7k4RnI4YIHjIm4HoPiYaxM8vmj8Rj+V0ILSTdcp8kdB26JQgr+p368L4CMKuLZJOhan 5JYUD6s91sEHM1LjZrnN2YXLn/1vsmyZisx2rvpD8QlbnnPV5zJzC83m9FJhf9cKQZGWN TTnjbgUK365SJdoiI9jqmb2tK8jZ7aBISTK6X6249wS+yQjmqi7Wv5qs51rWyEvulYQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=SDpNnEOa; arc=none smtp.remote-ip=148.251.105.195 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1CD0606A32D; Wed, 25 Nov 2026 15:14:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B1CD0606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=SDpNnEOa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1795619657; bh=5SVJit0opG7N0D4+Pi1jC59zsOBfQVNHBUgYfuYT6WM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SDpNnEOa9na5DUl++Ar85gb61ANlPHVYx0XxQJlY58/NX7wLvPymkux4kHvn+KUtF yR/TXWJjlZAzJXZekBPON+buancX5p0XxP+nLKSBWPwhPbvcyq4TIpcIv3mhgp2K0B YMIGjmF+o7/+lQQ2FShBrMUCwKpq4okoY3zIg94F1oJnkp8cGBUmNicBON2T99vZ1V YxDIs5rg+UAwnuiACe3Wluiw/b7X+CeGdLp3FHFOwRRAn/ZNBZkkA1NldjPvxfyZZX +pAjxdnZiJa/kkoY8WO/tvoA60rJefqOfylMW51ABskMJY0QEbUMmzj/W4XSmJ/3Fp Dg57LivNcARmA== Received: from [192.168.0.15] (unknown [100.64.0.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: detlev) by bali.collaboradmins.com (Postfix) with ESMTPSA id A4A2317E00C4; Wed, 25 Nov 2026 16:14:15 +0100 (CET) From: Detlev Casanova Date: Wed, 25 Nov 2026 10:11:58 -0500 Subject: [PATCH v4 1/5] media: v4l2: Add callback for show_fdinfo X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261125-v4l2-add-fdinfo-v4-1-2dc73fad9932@collabora.com> References: <20261125-v4l2-add-fdinfo-v4-0-2dc73fad9932@collabora.com> In-Reply-To: <20261125-v4l2-add-fdinfo-v4-0-2dc73fad9932@collabora.com> To: Mauro Carvalho Chehab , Nicolas Dufresne , Benjamin Gaignard , Philipp Zabel , Ezequiel Garcia , Heiko Stuebner Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Detlev Casanova , linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.15.2 Allow v4l2 drivers to add information in the fdinfo file matching the opened /dev/videoX file. The core prints the standard "v4l2-driver:" key with the driver name and then calls the driver's optional show_fdinfo callback, added to struct v4l2_file_operations, to let drivers append their own key:value pairs. Signed-off-by: Detlev Casanova --- drivers/media/v4l2-core/v4l2-dev.c | 10 ++++++++++ include/media/v4l2-dev.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v= 4l2-dev.c index fd267fb74905..8a350ef3a9ed 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 fi= le *filp) return ret; } =20 +/* Override for the show_fdinfo function */ +static void v4l2_show_fdinfo(struct seq_file *m, struct file *filp) +{ + struct video_device *vdev =3D video_devdata(filp); + + if (vdev->fops->show_fdinfo) + vdev->fops->show_fdinfo(m, filp); +} + static const struct file_operations v4l2_fops =3D { .owner =3D THIS_MODULE, .read =3D v4l2_read, @@ -494,6 +503,7 @@ static const struct file_operations v4l2_fops =3D { #endif .release =3D v4l2_release, .poll =3D v4l2_poll, + .show_fdinfo =3D v4l2_show_fdinfo, }; =20 /** diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h index 2e0f6d2e6a78..258b3e7a76e7 100644 --- a/include/media/v4l2-dev.h +++ b/include/media/v4l2-dev.h @@ -191,6 +191,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enu= m v4l2_priority local); * @mmap: operations needed to implement the mmap() syscall * @open: operations needed to implement the open() syscall * @release: operations needed to implement the release() syscall + * @show_fdinfo: operations needed to implement the show_fdinfo() syscall * * .. note:: * @@ -212,6 +213,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 *); }; =20 /* --=20 2.56.1 From nobody Wed Nov 25 17:40:03 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.251.105.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795619661; b=PJErYcejFjeJvxlc4nsCXKUO+odrEVA6bVb49MwNxb3+TslN8TOrFjbYOoFQo/ja66uR a53sQgiC/cvKIYl9FCQ8JjHWliJBaMhWBPh2faNgxAOC01oM3rXZyOKUu/xBryh64vtxF xTbt7BTd42oklSFdv+7LfAMuiT21L0l5rOeVJyMtKE1XVL+vFtGEwm0nfX5M9V3yk/rk4 C4klg07An+6Itzor0Bu6h7bWQToewYxU6xMMxvylBhWA+B15ZSJwCb9BuXqmnGB7f1yjU 25H8v+3ZVJxgS5ImioeXIX5luaSQHeyZbYEeuhEuOis375N+LBCC0e9mqFcQQY427wA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795619661; h=DMARC-Filter:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer; bh=G0TYUpJg36o+7nLbbA7hJOngSeOqnT9Tjext4wkdPLo=; b=KdsjuD1pWATcTE0WQL++1WhnE5jONqxdYoMshHShSLQDOO0gK82pbdDq1QJZkTgeW7yO 432U1jEg5pAu0s6oAk5dz1zubWbnGxPkcv0m+K8dVxrYb+54kfnLK+SEnXvvAMfjOKn9q tRmKAWnbh7dkmtk78VjP/lkEU1uJVwvV0ZQmW+D+GOEvXWh2Yg6113Mrtk9/Fu7m7WS9I KD9A662RIYMIiRZeGZRCeS7rxRitf2f7fAS2ytOpMCrX0YEqjerTrcGHLtkIqv7zU/DE8 MRf+dL4lZU8HU5ErvSIb8/y6ffuQ4OI9KPf8zhEa4FroD+mSnA0xgqxejsFKrcWqd8w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=Yu48+IuB; arc=none smtp.remote-ip=148.251.105.195 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAFF1606A687; Wed, 25 Nov 2026 15:14:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AAFF1606A687 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=Yu48+IuB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1795619659; bh=rCpXDMQPfFzoGIsLhtfBC28BG6dh8sM5ocD3/j2uLeA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Yu48+IuBOdp1M5jbLyx3bXM65dLBZy0VNh3grrsR5SR59Hf8ilFhJFoxKxVIFkaFh 6SI38Kao7mliUQs9/gXHpApsupzSj7fIi+mmzKDrCeST4JR7o9dJ0qS5ShubRvX99K TOdwhuPX4rqA6zJswCKquUkKUo1A39Xyoyx9Klms6o4CnRS6y+G+aN9KhSqRK1qnlz m+j9pVbdqB2HoprRVs1bBUVt7ktopIsjzSoEC5WvBBnPhKQPvolOiwIxgsU4iwWSQg pXTLUnzr8zcdzHSDjRjhxgrBxZNOhctfvpJyfgrKDDliz/5u4lSh1pgrea+mtrMNOv 0WCRalx7unHWw== Received: from [192.168.0.15] (unknown [100.64.0.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: detlev) by bali.collaboradmins.com (Postfix) with ESMTPSA id 6FA7B17E1090; Wed, 25 Nov 2026 16:14:17 +0100 (CET) From: Detlev Casanova Date: Wed, 25 Nov 2026 10:11:59 -0500 Subject: [PATCH v4 2/5] docs: media: add documentation for V4L2 driver usage metrics X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261125-v4l2-add-fdinfo-v4-2-2dc73fad9932@collabora.com> References: <20261125-v4l2-add-fdinfo-v4-0-2dc73fad9932@collabora.com> In-Reply-To: <20261125-v4l2-add-fdinfo-v4-0-2dc73fad9932@collabora.com> To: Mauro Carvalho Chehab , Nicolas Dufresne , Benjamin Gaignard , Philipp Zabel , Ezequiel Garcia , Heiko Stuebner Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Detlev Casanova , linux-arm-kernel@lists.infradead.org, Christopher Healy X-Mailer: b4 0.15.2 From: Christopher Healy Document the V4L2 fdinfo interface for per-file-descriptor usage metrics exposed by V4L2 drivers via /proc//fdinfo/. The interface is defined generically for V4L2 drivers, with a set of mandatory keys ("v4l2-driver", "v4l2-driver-type") that identify the driver and its type, and per-driver-type sections describing additional keys. This leaves room to extend the interface to other driver types (stateful codecs, capture devices, ISPs, ...) later without breaking existing users. The initial per-type section targets stateless (request API based) codec devices, 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 metrics update. The specification defines "v4l2-" prefixed keys for per-core engine utilization time and operating frequency, following the same conventions as the DRM fdinfo mechanism documented in drm-usage-stats.rst. "v4l2-core-usage-cycles-" is added as an optional key for HW cycle counters, when supported. Also provide ABI documentation, currently as testing. Signed-off-by: Christopher Healy Signed-off-by: Detlev Casanova --- Documentation/ABI/testing/procfs-fdinfo-v4l2 | 129 +++++++++++++++++= ++ .../userspace-api/media/drivers/index.rst | 1 + .../media/drivers/v4l2-usage-metrics.rst | 137 +++++++++++++++++= ++++ 3 files changed, 267 insertions(+) diff --git a/Documentation/ABI/testing/procfs-fdinfo-v4l2 b/Documentation/A= BI/testing/procfs-fdinfo-v4l2 new file mode 100644 index 000000000000..7c64403b6814 --- /dev/null +++ b/Documentation/ABI/testing/procfs-fdinfo-v4l2 @@ -0,0 +1,129 @@ +What: /proc//fdinfo/ (V4L2 device file descriptors) +Date: July 2026 +Contact: Detlev Casanova + linux-media@vger.kernel.org +Description: + Per-file-descriptor usage metrics for V4L2 devices, exposed + as a set of "key:\tvalue\n" lines in the fdinfo file + associated with an open /dev/video file descriptor. + + All standardised keys are prefixed with "v4l2-". Driver + specific keys are prefixed with "-". + + Counter values are cumulative since the file descriptor was + created and strictly monotonically increasing. + + See Documentation/userspace-api/media/drivers/v4l2-usage-metrics.rst + for the full specification. + +What: /proc//fdinfo/: v4l2-driver +Date: July 2026 +Contact: Detlev Casanova + linux-media@vger.kernel.org +Description: + String. Name of the V4L2 driver backing this file descriptor. + + Format: + v4l2-driver:\t\n + + Mandatory for every driver that implements this interface. + +What: /proc//fdinfo/: v4l2-driver-type +Date: July 2026 +Contact: Detlev Casanova + linux-media@vger.kernel.org +Description: + String. Type of V4L2 device exposed through this file + descriptor. Tells userspace which additional type-specific + keys to expect. + + Format: + v4l2-driver-type:\t\n + + Standard values currently defined: + - "stateless-decoder" + - "stateless-encoder" + + Additional values will be defined as the interface is + extended to other driver types. + + Mandatory for every driver that implements this interface. + +What: /proc//fdinfo/: v4l2-core-usage-time- +Date: July 2026 +Contact: Detlev Casanova + linux-media@vger.kernel.org +Description: + Unsigned integer, in nanoseconds. Time the hardware core + identified by spent busy processing work belonging + to this file descriptor, cumulative since the file descriptor + was created. + + must be a non-negative decimal integer (0, 1, 2, + ...). Strings or other non-numeric identifiers are not + allowed. + + Format: + v4l2-core-usage-time-:\t ns\n + + Time is measured by the driver, typically from just before + the hardware is started to just after the completion + interrupt is handled, so it is slightly less precise than a + hardware cycle counter but is always available. + + Mandatory for stateless-decoder and stateless-encoder driver + types. + +What: /proc//fdinfo/: v4l2-core-usage-cycles- +Date: July 2026 +Contact: Detlev Casanova + linux-media@vger.kernel.org +Description: + Unsigned integer. Number of hardware clock cycles the core + identified by spent busy processing work belonging + to this file descriptor, cumulative since the file descriptor + was created. + + must be a non-negative decimal integer. + + Format: + v4l2-core-usage-cycles-:\t\n + + More precise than v4l2-core-usage-time-, but + requires the hardware to expose a cycle counter. When + available together with v4l2-maxfreq- and + v4l2-curfreq-, userspace can derive an accurate + utilization percentage. Otherwise, userspace should fall back + to v4l2-core-usage-time-. + + Optional. + +What: /proc//fdinfo/: v4l2-maxfreq- +Date: July 2026 +Contact: Detlev Casanova + linux-media@vger.kernel.org +Description: + Unsigned integer, in Hz. Maximum operating frequency of the + main clock of the core identified by . + + must be a non-negative decimal integer. + + Format: + v4l2-maxfreq-:\t Hz\n + + A core may have several clocks associated with it, but only + the one that actually clocks the hardware processing engine + of the core (its "main clock") is reported. + +What: /proc//fdinfo/: v4l2-curfreq- +Date: July 2026 +Contact: Detlev Casanova + linux-media@vger.kernel.org +Description: + Unsigned integer, in Hz. Current operating frequency of the + main clock of the core identified by . + + must be a non-negative decimal integer. + + Format: + v4l2-curfreq-:\t Hz\n diff --git a/Documentation/userspace-api/media/drivers/index.rst b/Document= ation/userspace-api/media/drivers/index.rst index 8d2c489b8453..88442a806ad8 100644 --- a/Documentation/userspace-api/media/drivers/index.rst +++ b/Documentation/userspace-api/media/drivers/index.rst @@ -35,6 +35,7 @@ For more details see the file COPYING in the source distr= ibution of Linux. imx-uapi mali-c55 max2175 + v4l2-usage-metrics npcm-video omap3isp-uapi thp7312 diff --git a/Documentation/userspace-api/media/drivers/v4l2-usage-metrics.r= st b/Documentation/userspace-api/media/drivers/v4l2-usage-metrics.rst new file mode 100644 index 000000000000..c56b1d608cd4 --- /dev/null +++ b/Documentation/userspace-api/media/drivers/v4l2-usage-metrics.rst @@ -0,0 +1,137 @@ +.. SPDX-License-Identifier: GPL-2.0 + +.. _v4l2-usage-metrics: + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D +V4L2 client usage metrics +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + +V4L2 drivers can optionally expose per-file-descriptor usage metrics via +``/proc//fdinfo/``. This is analogous to the DRM fdinfo mechanism +documented in :ref:`drm-client-usage-stats`, but uses the ``v4l2-`` key +prefix for V4L2 devices. + +The interface is generic to V4L2: any driver type (stateless or stateful +codecs, capture devices, ISPs, converters, ...) may implement it and provi= de +the metrics relevant to its hardware. This document defines a common set of +mandatory keys that identify the driver and the kind of device, plus per +driver-type sections describing additional keys. + +The initial set of type-specific keys documented here targets stateless +(request API based) codec devices, 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. Other +device types (stateful codecs, capture devices, ISPs, ...) can be added +later with their own set of type-specific keys. + +Implementation +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +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//fdinfo/`` outp= ut +includes the driver-provided keys. + +File format specification +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + +- 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 ``v4l2-``. +- Driver-specific keys shall be prefixed with ``driver_name-``. + +All counter values reported through this interface are cumulative since the +file descriptor was created, and are strictly monotonically increasing. + +Mandatory keys +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The following keys must be exposed by every driver that implements this +interface, regardless of the device type. + +- v4l2-driver: + + String shall contain the name of the V4L2 driver. + +- v4l2-driver-type: + + String shall identify the type of V4L2 device exposed through this file + descriptor. This key tells userspace which additional type-specific keys + to expect. Standard values currently defined are ``stateless-decoder`` + and ``stateless-encoder``. Additional values will be defined as this + interface is extended to other driver types. + +Stateless codec keys +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +The keys described in this section apply to file descriptors whose +``v4l2-driver-type`` is ``stateless-decoder`` or ``stateless-encoder``. + +A stateless codec may be composed of one or more independent hardware +cores. Per-core metrics are reported using keys suffixed with a +```` identifier, so a single file descriptor can report metrics +for multiple cores. + +```` must be a non-negative decimal integer (e.g. ``0``, ``1``, +``2``, ...). Strings or other non-numeric identifiers are not allowed, so +that userspace can reliably parse and enumerate cores. + +Utilization keys +---------------- + +- v4l2-core-usage-time-: ns + + Mandatory. + + Time in nanoseconds that the hardware core identified by ```` + spent busy processing work belonging to this file descriptor, cumulative + since the file descriptor was created. + + Time is measured by the driver, typically from just before the hardware + is started to just after the completion interrupt is handled, so it is + slightly less precise than a hardware cycle counter but is always + available. + +- v4l2-core-usage-cycles-: + + Optional. + + Number of hardware clock cycles that the core identified by ```` + spent busy processing work belonging to this file descriptor, cumulative + since the file descriptor was created. + + This is more precise than ``v4l2-core-usage-time-`` but requires + the hardware to expose a cycle counter. When available together with + ``v4l2-maxfreq-`` and ``v4l2-curfreq-``, userspace can + derive an accurate utilization percentage. Otherwise, userspace should + fall back to ``v4l2-core-usage-time-``. + +Frequency keys +-------------- + +- v4l2-maxfreq-: Hz + + Maximum operating frequency of the main clock of the core identified by + ````. + +- v4l2-curfreq-: Hz + + Current operating frequency of the main clock of the core identified by + ````. + +A core may have several clocks associated with it, but only the one that +actually clocks the hardware processing engine of the core (its "main +clock") should be reported through these keys. + +Example output +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +:: + + v4l2-driver: hantro-vpu + v4l2-driver-type: stateless-decoder + v4l2-core-usage-time-0: 123456789 ns + v4l2-core-usage-cycles-0: 74000000 + v4l2-maxfreq-0: 600000000 Hz + v4l2-curfreq-0: 600000000 Hz --=20 2.56.1 From nobody Wed Nov 25 17:40:03 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.251.105.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795619663; b=Kd7NwbG0e1d/A6NDRqFYE6noQi9TJ2N1rHiK0hYBifAxDUUH3QuvlLnraTbe2BukUriW b8wLkTVapKacT+J58PtWouXVfIm+DQOI2LLlE0e1NuDNVfOfn52dHnAQm2GEr888nJcsL kHY2M1m8MhTFh6/NmvdkNRtkktqkeAP8i4dgmcdsDYmKGzQ4GkmOTtoaYymNzEvXww70D NfSvUBoEtX7sAdqsPS96ravCFm+tkARSqoGfjtqFe3VaN3Np0MMMn4b/J/V76TDmvwuHl 9rvcRbXwOHkK6SJCPmlRe6736ycK31Y9iBXuAea3NcJztz46OckoZ/c78r6L3nw94PQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795619663; h=DMARC-Filter:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer; bh=pswBG59guH62lCEWMkmDWSD12p1MDexE4B9kdFA3m4U=; b=elouYSZ+6YetCZ+QRtdFJvX6tIlIuZFQS7W0hUCnhhIdGYVQAsrGcsH++cjOWlZ7UZU7 WV/QtKiN4CDj5WUxzvC+cMUpPil3TCaGsBVYsP7qvEtTpTGrMmcV3ftEALyyh6UxoslIN AwYRN6wl0dFpn+/vpAJ+fEF9GvSaN3PA6M1RJrzsa+jl107i2ff8LiwGtXb/5eLpVBnoT p3SUSn8SRAGjYKXemObxNHXddL+pOxAd0TgArGTePrD7lwjlrAaGrLnbAajEVAXi/fJnv KQU8S2b7zZpHnFuTj11DYq0NLcdKddpGoC18i6WNGJwqSBB14v2JyW7zOYgdOd6Nsjw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=ASbH5ClL; arc=none smtp.remote-ip=148.251.105.195 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BD15606A329; Wed, 25 Nov 2026 15:14:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8BD15606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=ASbH5ClL DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1795619660; bh=3FBbaws9N7wLOiseRH6Q6m5ib4Wx+e8jlcCc3+XKZBw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ASbH5ClLNnGjUwfH7e4o5b685+X9TmNyXcyV2jrR8F9qsFaazzGmR80zqS0QvO+BO 1UMlSbcnnDO/ZyLCoNTljTsJmYXREZHlf4XICNX3v/hX+DjcNLzN5aEBB7MXytgn0b Z5PQu2vRRaLYfwqUDbzeBO1e0ByrFP8Z+oMuspP5aT8JKPcHoROqIopzfxcQXvgIhz mJp2zCl3SpQ1bVT01MK4G1NMZRl1BO2GKDUhpNRzKJYWggazT3+rN0nbE2NfMOh+pO yksSLrSbrocvinVpZ3Hl2/8rYLYNX2cxSECaFXplMLCGMkQsj+TixcNUK5P1qtXKMx gAz2mmE97GalA== Received: from [192.168.0.15] (unknown [100.64.0.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: detlev) by bali.collaboradmins.com (Postfix) with ESMTPSA id 733A717E11E0; Wed, 25 Nov 2026 16:14:19 +0100 (CET) From: Detlev Casanova Date: Wed, 25 Nov 2026 10:12:00 -0500 Subject: [PATCH v4 3/5] media: v4l2-core: Add v4l2-metrics interface X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261125-v4l2-add-fdinfo-v4-3-2dc73fad9932@collabora.com> References: <20261125-v4l2-add-fdinfo-v4-0-2dc73fad9932@collabora.com> In-Reply-To: <20261125-v4l2-add-fdinfo-v4-0-2dc73fad9932@collabora.com> To: Mauro Carvalho Chehab , Nicolas Dufresne , Benjamin Gaignard , Philipp Zabel , Ezequiel Garcia , Heiko Stuebner Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Detlev Casanova , linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.15.2 Provide helpers for V4L2 drivers to set fdinfo data and print the key:value pairs in a standard way. Drivers can set metrics values with helpers like: - v4l2_metrics_update_hw_usage - v4l2_metrics_set_driver_type And also call the show helpers from their show_fdinfo callback with: - v4l2_metrics_show -- Shows the values set previously - v4l2_metrics_show_clock -- Shows the main clock state. Per-core metrics are supported by passing a numeric core_id to the show helpers, so a single file descriptor can report metrics for multiple hardware cores. The show_clock helper is used instead of storing a clock reference in v4l2_metrics for the following reasons: - Clocks are at the device level, this is not a per-fd information - This avoids having clock references in v4l2-core - Drivers can use different approaches to manage clocks (e.g.: bulk_data or not: A set helper wouldn't please all drivers) - Arguably, clocks could be exposed elsewhere (like a debugfs), but we want something close to what DRM does and centralizing information has its advantages for userspace tooling. In DRM the key:value pair format for clocks is documented and each driver can write them directly based on that. In this case, provide a helper and document the format. Signed-off-by: Detlev Casanova --- drivers/media/v4l2-core/Makefile | 2 +- drivers/media/v4l2-core/v4l2-dev.c | 2 + drivers/media/v4l2-core/v4l2-fh.c | 3 ++ drivers/media/v4l2-core/v4l2-metrics.c | 78 ++++++++++++++++++++++++++++++= ++++ include/media/v4l2-fh.h | 3 ++ include/media/v4l2-metrics.h | 47 ++++++++++++++++++++ 6 files changed, 134 insertions(+), 1 deletion(-) diff --git a/drivers/media/v4l2-core/Makefile b/drivers/media/v4l2-core/Mak= efile index 329f0eadce99..4bfd4e19dff8 100644 --- a/drivers/media/v4l2-core/Makefile +++ b/drivers/media/v4l2-core/Makefile @@ -9,7 +9,7 @@ ccflags-y +=3D -I$(srctree)/drivers/media/tuners tuner-objs :=3D tuner-core.o =20 videodev-objs :=3D v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \ - v4l2-event.o v4l2-subdev.o v4l2-common.o \ + v4l2-event.o v4l2-subdev.o v4l2-common.o v4l2-metrics.o \ v4l2-ctrls-core.o v4l2-ctrls-api.o \ v4l2-ctrls-request.o v4l2-ctrls-defs.o =20 diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v= 4l2-dev.c index 8a350ef3a9ed..b71d48eef9d8 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -486,6 +486,8 @@ static void v4l2_show_fdinfo(struct seq_file *m, struct= file *filp) { struct video_device *vdev =3D video_devdata(filp); =20 + seq_printf(m, "v4l2-driver:\t%s\n", vdev->v4l2_dev->name); + if (vdev->fops->show_fdinfo) vdev->fops->show_fdinfo(m, filp); } diff --git a/drivers/media/v4l2-core/v4l2-fh.c b/drivers/media/v4l2-core/v4= l2-fh.c index b184bed8aca9..1ed91d344f4e 100644 --- a/drivers/media/v4l2-core/v4l2-fh.c +++ b/drivers/media/v4l2-core/v4l2-fh.c @@ -17,6 +17,7 @@ #include #include #include +#include =20 void v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev) { @@ -38,6 +39,7 @@ void v4l2_fh_init(struct v4l2_fh *fh, struct video_device= *vdev) INIT_LIST_HEAD(&fh->subscribed); fh->sequence =3D -1; mutex_init(&fh->subscribe_lock); + v4l2_metrics_init(&fh->metrics); } EXPORT_SYMBOL_GPL(v4l2_fh_init); =20 @@ -88,6 +90,7 @@ void v4l2_fh_exit(struct v4l2_fh *fh) v4l2_event_unsubscribe_all(fh); mutex_destroy(&fh->subscribe_lock); fh->vdev =3D NULL; + v4l2_metrics_exit(&fh->metrics); } EXPORT_SYMBOL_GPL(v4l2_fh_exit); =20 diff --git a/drivers/media/v4l2-core/v4l2-metrics.c b/drivers/media/v4l2-co= re/v4l2-metrics.c new file mode 100644 index 000000000000..5de68c0f3969 --- /dev/null +++ b/drivers/media/v4l2-core/v4l2-metrics.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * v4l2-metrics.c + * + * V4L2 metrics management. + * + * Maintain a per-file handle list of metrics about the hardware and handle + * exposing it in the fdinfo. + * + * Copyright (C) 2026 Collabora. + * + * Contact: Detlev Casanova + */ + +#include +#include +#include +#include + +static const char * const driver_type_name[] =3D { + [V4L2_DRIVER_TYPE_UNKNOWN] =3D "unknown", + [V4L2_DRIVER_TYPE_STATELESS_ENCODER] =3D "stateless-encoder", + [V4L2_DRIVER_TYPE_STATELESS_DECODER] =3D "stateless-decoder", +}; + +void v4l2_metrics_init(struct v4l2_metrics *metrics) +{ + metrics->hw_usage_time =3D 0; + metrics->hw_usage_cycles =3D 0; + metrics->has_hw_usage_cycles =3D false; + metrics->driver_type =3D V4L2_DRIVER_TYPE_UNKNOWN; +} + +void v4l2_metrics_exit(struct v4l2_metrics *metrics) +{ +} + +void v4l2_metrics_update_hw_time(struct v4l2_metrics *metrics, u64 time_ns) +{ + metrics->hw_usage_time +=3D time_ns; +} +EXPORT_SYMBOL_GPL(v4l2_metrics_update_hw_time); + +void v4l2_metrics_update_hw_cycles(struct v4l2_metrics *metrics, u64 cycle= s) +{ + metrics->hw_usage_cycles +=3D cycles; + metrics->has_hw_usage_cycles =3D true; +} +EXPORT_SYMBOL_GPL(v4l2_metrics_update_hw_cycles); + +void v4l2_metrics_set_driver_type(struct v4l2_metrics *metrics, enum v4l2_= driver_type type) +{ + if (type >=3D V4L2_DRIVER_TYPE_COUNT) + return; + + metrics->driver_type =3D type; +} +EXPORT_SYMBOL_GPL(v4l2_metrics_set_driver_type); + +void v4l2_metrics_show(struct v4l2_metrics *metrics, struct seq_file *m, u= nsigned int core_id) +{ + seq_printf(m, "v4l2-driver-type:\t%s\n", driver_type_name[metrics->driver= _type]); + seq_printf(m, "v4l2-core-usage-time-%u:\t%llu ns\n", core_id, metrics->hw= _usage_time); + + if (metrics->has_hw_usage_cycles) + seq_printf(m, "v4l2-core-usage-cycles-%u:\t%llu\n", + core_id, metrics->hw_usage_cycles); +} +EXPORT_SYMBOL_GPL(v4l2_metrics_show); + +void v4l2_metrics_show_clock(struct seq_file *m, struct clk *clk, unsigned= int core_id) +{ + seq_printf(m, "v4l2-maxfreq-%u:\t%lu Hz\n", + core_id, clk_get_rate(clk)); + seq_printf(m, "v4l2-curfreq-%u:\t%lu Hz\n", + core_id, clk_get_rate(clk)); +} +EXPORT_SYMBOL_GPL(v4l2_metrics_show_clock); diff --git a/include/media/v4l2-fh.h b/include/media/v4l2-fh.h index aad4b3689d7e..4f1ca1bbc61f 100644 --- a/include/media/v4l2-fh.h +++ b/include/media/v4l2-fh.h @@ -17,6 +17,7 @@ #include #include #include +#include =20 struct video_device; struct v4l2_ctrl_handler; @@ -27,6 +28,7 @@ struct v4l2_ctrl_handler; * @list: list of file handlers * @vdev: pointer to &struct video_device * @ctrl_handler: pointer to &struct v4l2_ctrl_handler + * @metrics: metrics information for this handle * @prio: priority of the file handler, as defined by &enum v4l2_priority * * @wait: event' s wait queue @@ -43,6 +45,7 @@ struct v4l2_fh { struct list_head list; struct video_device *vdev; struct v4l2_ctrl_handler *ctrl_handler; + struct v4l2_metrics metrics; enum v4l2_priority prio; =20 /* Events */ diff --git a/include/media/v4l2-metrics.h b/include/media/v4l2-metrics.h new file mode 100644 index 000000000000..fc493b65f117 --- /dev/null +++ b/include/media/v4l2-metrics.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * v4l2-metrics.h + * + * V4L2 metrics management. + * + * Maintain a per-file handle list of statistics about the hardware and ha= ndle + * exposing it in the fdinfo. + * + * Copyright (C) 2026 Collabora. + * + * Contact: Detlev Casanova + */ +#ifndef V4L2_METRICS_H +#define V4L2_METRICS_H + +#include + +struct clk; +struct seq_file; + +enum v4l2_driver_type { + V4L2_DRIVER_TYPE_UNKNOWN =3D 0, + V4L2_DRIVER_TYPE_STATELESS_ENCODER, + V4L2_DRIVER_TYPE_STATELESS_DECODER, + + V4L2_DRIVER_TYPE_COUNT, +}; + +struct v4l2_metrics { + u64 hw_usage_time; + u64 hw_usage_cycles; + bool has_hw_usage_cycles; + enum v4l2_driver_type driver_type; +}; + +void v4l2_metrics_init(struct v4l2_metrics *metrics); +void v4l2_metrics_exit(struct v4l2_metrics *metrics); + +void v4l2_metrics_update_hw_time(struct v4l2_metrics *metrics, u64 time_ns= ); +void v4l2_metrics_update_hw_cycles(struct v4l2_metrics *metrics, u64 cycle= s); +void v4l2_metrics_set_driver_type(struct v4l2_metrics *metrics, enum v4l2_= driver_type type); + +void v4l2_metrics_show(struct v4l2_metrics *metrics, struct seq_file *m, u= nsigned int core_id); +void v4l2_metrics_show_clock(struct seq_file *m, struct clk *clk, unsigned= int core_id); + +#endif /* V4L2_METRICS_H */ --=20 2.56.1 From nobody Wed Nov 25 17:40:03 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.251.105.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795619665; b=ll6als5LyVj7lpD1krTLXOfZDKBiqbDwxK3PNaRNGsFVLfg0dJH4WEaxQD3p+eEv7A4P h34VOQm+H94WEGFw/Viasi9b7Q5O1Cd4+XueIBA479Gqyd8Dep4AvsEvbJOD9GluEqWR9 s6L/YKVwkCBytXp6vDH1JIouosscQUNgsjR9SkiEZLDZK1C6fJEwwDj+ojH3le5z/pU/a sQpW8RLo3wcJ3EZt9FZx2AU8lR+FzPikZ5BNOhySElOPD1GCnseXfRyDPZ9mEH9fr2tVp kte75k4+bWJeRPamsDBzxz0qrW6M7NHYW5gEkbJtu0XDgDmFDKdZlt9u56yvLdPSogA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795619665; h=DMARC-Filter:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer; bh=PSgf6sZ4Qtawl85/N6yrprouFZukFIZKD96Hi7eveoI=; b=SdjXSBZKOze1pDAVzk7Qt9JxWEdhjbW4xGQnvO1OJk3pY49RVQ9o9brxNeqHYFFMjD/y HYMc1QrByqvIHQNYIMXAHsHQ1icmRqLWAPoSLvExAbdtfrVF1QI0IsNi8NL7Z1u0F71o2 y+leEnH69WykiK/I9Heb3EyNxPKdadJBMwzQpmQn85u+8y8lUZDqaBJv3UpFkEXjEWJEU tPrKh5brPAzt7x72CNKrhJK+8yQjmNqC1mdGGnQYQiqhLHqT/fDwSztSAWmVrNrCCm+Bf fQgFR03DkjqadM1CSBybMHq9bkIsEAMFJochp6NlN76J+vJoJyiQFu9NzKJyEbsKniw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=AoPuYpEg; arc=none smtp.remote-ip=148.251.105.195 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EF16606A6A2; Wed, 25 Nov 2026 15:14:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6EF16606A6A2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=AoPuYpEg DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1795619662; bh=tBuZgwzt7+tIWp9kUOKRVQyHT1nAxNT4CFenV+1jQGw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AoPuYpEg952pRBEfI7ge8wHcg98UqA/cL7JLli864A6UNuql3FWr4K4UwmGzMRgIS QEQPZa87q3J6cOFRjAcxYHCPXUylcD6OeusWnWq5TweEfq+9ubYhhNEorL5jv8XaBo K3Rx9z0Ln2FYImDawOU5qyOPrAfIBvblaRcP0FkaOpA88WxDdOt4dlY1H5zDYR9A2/ O2C3s5iXkRiQPqtXz4oV3elLyJU7e8gZ5TNwzl+S5hRp+u6/9pZy8H5rkaobWry2Bb dyuSg9slOnDNxs7lnKOFyf7qAqDHenOcTUenyweIicrdICApbbkSMrAEf9MLNVj1Gq Dihuv5YaXDqPg== Received: from [192.168.0.15] (unknown [100.64.0.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: detlev) by bali.collaboradmins.com (Postfix) with ESMTPSA id 3C98D17E120C; Wed, 25 Nov 2026 16:14:21 +0100 (CET) From: Detlev Casanova Date: Wed, 25 Nov 2026 10:12:01 -0500 Subject: [PATCH v4 4/5] media: hantro: Add per-context fdinfo usage metrics X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261125-v4l2-add-fdinfo-v4-4-2dc73fad9932@collabora.com> References: <20261125-v4l2-add-fdinfo-v4-0-2dc73fad9932@collabora.com> In-Reply-To: <20261125-v4l2-add-fdinfo-v4-0-2dc73fad9932@collabora.com> To: Mauro Carvalho Chehab , Nicolas Dufresne , Benjamin Gaignard , Philipp Zabel , Ezequiel Garcia , Heiko Stuebner Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Detlev Casanova , linux-arm-kernel@lists.infradead.org, Christopher Healy X-Mailer: b4 0.15.2 From: Christopher Healy Add VPU981 hardware utilization metrics to the Hantro VPU stateless codec driver, exposed via v4l2_metrics. Update the v4l2_metrics instance each time a job completes with the time it took in ns and the nuber of cycles reported by the hardware. 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. Signed-off-by: Christopher Healy Signed-off-by: Detlev Casanova --- drivers/media/platform/verisilicon/hantro.h | 4 ++++ drivers/media/platform/verisilicon/hantro_drv.c | 19 +++++++++++++++= ++++ drivers/media/platform/verisilicon/hantro_hw.h | 1 + .../media/platform/verisilicon/rockchip_vpu981_regs.h | 1 + drivers/media/platform/verisilicon/rockchip_vpu_hw.c | 6 ++++++ 5 files changed, 31 insertions(+) diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/pl= atform/verisilicon/hantro.h index 0353de154a1e..2c136350d37a 100644 --- a/drivers/media/platform/verisilicon/hantro.h +++ b/drivers/media/platform/verisilicon/hantro.h @@ -16,6 +16,7 @@ #include #include #include +#include #include =20 #include @@ -236,6 +237,7 @@ struct hantro_dev { * @bit_depth: Bit depth of current frame * @need_postproc: Set to true if the bitstream features require to * use the post-processor. + * @start_time: The time at which the running job has been started. * * @codec_ops: Set of operations related to codec mode. * @postproc: Post-processing context. @@ -268,6 +270,8 @@ struct hantro_ctx { struct hantro_postproc_ctx postproc; bool need_postproc; =20 + ktime_t start_time; + /* 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/medi= a/platform/verisilicon/hantro_drv.c index 3734ea701145..6b57343ec062 100644 --- a/drivers/media/platform/verisilicon/hantro_drv.c +++ b/drivers/media/platform/verisilicon/hantro_drv.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -90,6 +91,9 @@ static void hantro_job_finish(struct hantro_ctx *ctx, { struct hantro_dev *vpu =3D ctx->dev; =20 + v4l2_metrics_update_hw_time(&ctx->fh.metrics, + ktime_to_ns(ktime_sub(ktime_get(), ctx->start_time))); + pm_runtime_put_autosuspend(vpu->dev); hantro_job_finish_no_pm(ctx, result); } @@ -182,6 +186,8 @@ static void device_run(void *priv) =20 v4l2_m2m_buf_copy_metadata(src, dst); =20 + ctx->start_time =3D ktime_get(); + ret =3D ctx->codec_ops->run(ctx); if (ret) hantro_job_finish(ctx, VB2_BUF_STATE_ERROR); @@ -656,6 +662,9 @@ static int hantro_open(struct file *filp) =20 v4l2_fh_init(&ctx->fh, vdev); v4l2_fh_add(&ctx->fh, filp); + v4l2_metrics_set_driver_type(&ctx->fh.metrics, + ctx->is_encoder ? V4L2_DRIVER_TYPE_STATELESS_ENCODER + : V4L2_DRIVER_TYPE_STATELESS_DECODER); =20 hantro_reset_fmts(ctx); =20 @@ -693,10 +702,20 @@ static int hantro_release(struct file *filp) return 0; } =20 +static void hantro_show_fdinfo(struct seq_file *m, struct file *f) +{ + struct hantro_ctx *ctx =3D file_to_ctx(f); + struct hantro_dev *vpu =3D ctx->dev; + + v4l2_metrics_show(&ctx->fh.metrics, m, 0); + v4l2_metrics_show_clock(m, vpu->clocks[0].clk, 0); +} + static const struct v4l2_file_operations hantro_fops =3D { .owner =3D THIS_MODULE, .open =3D hantro_open, .release =3D hantro_release, + .show_fdinfo =3D hantro_show_fdinfo, .poll =3D v4l2_m2m_fop_poll, .unlocked_ioctl =3D video_ioctl2, .mmap =3D v4l2_m2m_fop_mmap, diff --git a/drivers/media/platform/verisilicon/hantro_hw.h b/drivers/media= /platform/verisilicon/hantro_hw.h index 13e573f1f19d..7259ea89adcc 100644 --- a/drivers/media/platform/verisilicon/hantro_hw.h +++ b/drivers/media/platform/verisilicon/hantro_hw.h @@ -28,6 +28,7 @@ #define FMT_MIN_WIDTH 48 #define FMT_MIN_HEIGHT 48 #define FMT_HD_WIDTH 1280 + #define FMT_HD_HEIGHT 720 #define FMT_FHD_WIDTH 1920 #define FMT_FHD_HEIGHT 1088 diff --git a/drivers/media/platform/verisilicon/rockchip_vpu981_regs.h b/dr= ivers/media/platform/verisilicon/rockchip_vpu981_regs.h index e4008da64f19..5a1d1e1e941e 100644 --- a/drivers/media/platform/verisilicon/rockchip_vpu981_regs.h +++ b/drivers/media/platform/verisilicon/rockchip_vpu981_regs.h @@ -451,6 +451,7 @@ #define av1_pp0_dup_ver AV1_DEC_REG(394, 16, 0xff) #define av1_pp0_dup_hor AV1_DEC_REG(394, 24, 0xff) =20 +#define AV1_CYCLE_COUNT (AV1_SWREG(63)) #define AV1_TILE_OUT_LU (AV1_SWREG(65)) #define AV1_REFERENCE_Y(i) (AV1_SWREG(67) + ((i) * 0x8)) #define AV1_SEGMENTATION (AV1_SWREG(81)) diff --git a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c b/drivers= /media/platform/verisilicon/rockchip_vpu_hw.c index 02673be9878e..fd3081242685 100644 --- a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c +++ b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c @@ -423,13 +423,19 @@ static irqreturn_t rockchip_vpu2_vepu_irq(int irq, vo= id *dev_id) static irqreturn_t rk3588_vpu981_irq(int irq, void *dev_id) { struct hantro_dev *vpu =3D dev_id; + struct hantro_ctx *ctx =3D + v4l2_m2m_get_curr_priv(vpu->m2m_dev); enum vb2_buffer_state state; u32 status; + u32 cycles; =20 status =3D vdpu_read(vpu, AV1_REG_INTERRUPT); state =3D (status & AV1_REG_INTERRUPT_DEC_RDY_INT) ? VB2_BUF_STATE_DONE : VB2_BUF_STATE_ERROR; =20 + cycles =3D vdpu_read(vpu, AV1_CYCLE_COUNT); + v4l2_metrics_update_hw_cycles(&ctx->fh.metrics, cycles); + vdpu_write(vpu, 0, AV1_REG_INTERRUPT); vdpu_write(vpu, AV1_REG_CONFIG_DEC_CLK_GATE_E, AV1_REG_CONFIG); =20 --=20 2.56.1 From nobody Wed Nov 25 17:40:03 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.251.105.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795619666; b=tDO1lESP1isAbXgYtZjlmhZV13GIYnMvS2b8DIQzy7XzHtL6lfbuv+57j8iuj1Lj/xDN DSH+xYf44Kl67SG7SHfbXDz5xibKE2MKmXbTIMF9kwubr9b1o8tVuKXIbfJTFut8TszlX BUIjpLkn0+duvS7hqHnq7C0ICH4//8kD73zE2GlYc6MYoXbFzZLGF4PErzujXX09Mhlnq vKLv+AiRpT2DMP8r4uMKANT2FcLorauiCwZ0XYfc/kehcUBJhKmcFXJM9KnLf9ln2/Ly9 zfYrlmtxFDUShOEDvrHCvgHiEsr4RdGRm39eU9aztmLca0GYF0RgItmYtdBMoWKpgJg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795619666; h=DMARC-Filter:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer; bh=qKStgZwQURkYirvMcrFHgwHoDBXf4cbgorTNw0h/b4k=; b=zmp+BUqnNT/xOLVyaStoJ41X43bsxpt2RJjnACtx5gOJGAc0jvdbd5j4JBmb2uBjf9f0 MFUS9qEOtj8evYMPWtp8C9CmxJ8NQDVZMT0WuLi0jygZtBIsu7nei1y6ulejdQ02kb+FC wlaXZEKyUM9GeRfgQ37bbChZeJFAqX6LvlUfz9C/14l9VG83INWq1ZuQIbnRXaFv4V9h0 v6aJsKPf0SAcLM8YywyJ8xLRHs7xLj3ttSIpktyjdIwApx2IeFrEuE3SnxB8t0rraV9sQ 8hzwUi6B2QMsWIORPDsYLINcQi0GVH7WLxS6DZLjRrSh/NOSlXOcjMjBwSs0J8gjWCw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=aj9wkuf9; arc=none smtp.remote-ip=148.251.105.195 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30CD8606A331; Wed, 25 Nov 2026 15:14:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 30CD8606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=aj9wkuf9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1795619664; bh=5g72xFrgHxlQSNw1j1WuF55/AYxuBWjsHHYjMfQDYv8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aj9wkuf9lqKu+f5419u812EMh28XnoNsfGJvUFwP8/PyrXU8UHlROx8S8P5AOkZLD qjF2ChkzEV7tKkOa3soEGl7V8pCpXjUNGDlYYEIxzWUgtlEf/fjH34Fs+GjM3B3Rlk PpMEstdzBNygwlwnP1ZR5QShTT8ZjZhPkQE7tjQ5NSgLyw6q1aIoiCukU+15TCXs4O d2f220Ixri0oQB86PWbRas5C0EOMe1K8JG3IejK2mLPmXyGVyDZmXCZfo5jJYNVdRV D8vDBebXZ1ie3VLfs5Z/y+AwJnXmI0dmviKUdvcdnYRMPwQvswrxVExHIAUE9tx2wh kQdUkM8D7g/Bw== Received: from [192.168.0.15] (unknown [100.64.0.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: detlev) by bali.collaboradmins.com (Postfix) with ESMTPSA id 2480D17E130C; Wed, 25 Nov 2026 16:14:23 +0100 (CET) From: Detlev Casanova Date: Wed, 25 Nov 2026 10:12:02 -0500 Subject: [PATCH v4 5/5] media: rkvdec: Add per-context fdinfo usage metrics X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261125-v4l2-add-fdinfo-v4-5-2dc73fad9932@collabora.com> References: <20261125-v4l2-add-fdinfo-v4-0-2dc73fad9932@collabora.com> In-Reply-To: <20261125-v4l2-add-fdinfo-v4-0-2dc73fad9932@collabora.com> To: Mauro Carvalho Chehab , Nicolas Dufresne , Benjamin Gaignard , Philipp Zabel , Ezequiel Garcia , Heiko Stuebner Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Detlev Casanova , linux-arm-kernel@lists.infradead.org X-Mailer: b4 0.15.2 Add hardware utilization tracking to the rkvdec stateless codec driver, exposed via v4l2_metrics. Update the v4l2_metrics instance each time a job completes with the time it took in ns. 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. Signed-off-by: Detlev Casanova --- drivers/media/platform/rockchip/rkvdec/rkvdec.c | 19 +++++++++++++++++++ drivers/media/platform/rockchip/rkvdec/rkvdec.h | 1 + 2 files changed, 20 insertions(+) diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.c b/drivers/medi= a/platform/rockchip/rkvdec/rkvdec.c index 5250dd59df2e..4c9c80ac591e 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec.c +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include =20 @@ -1094,6 +1095,9 @@ static void rkvdec_job_finish(struct rkvdec_ctx *ctx, { struct rkvdec_dev *rkvdec =3D ctx->dev; =20 + v4l2_metrics_update_hw_time(&ctx->fh.metrics, + ktime_to_ns(ktime_sub(ktime_get(), ctx->start_time))); + pm_runtime_put_autosuspend(rkvdec->dev); rkvdec_job_finish_no_pm(ctx, result); } @@ -1174,6 +1178,8 @@ static void rkvdec_device_run(void *priv) return; } =20 + ctx->start_time =3D ktime_get(); + ret =3D desc->ops->run(ctx); if (ret) rkvdec_job_finish(ctx, VB2_BUF_STATE_ERROR); @@ -1304,6 +1310,8 @@ static int rkvdec_open(struct file *filp) =20 v4l2_fh_add(&ctx->fh, filp); =20 + v4l2_metrics_set_driver_type(&ctx->fh.metrics, V4L2_DRIVER_TYPE_STATELESS= _DECODER); + return 0; =20 err_cleanup_m2m_ctx: @@ -1327,10 +1335,21 @@ static int rkvdec_release(struct file *filp) return 0; } =20 +static void rkvdec_show_fdinfo(struct seq_file *m, struct file *file) +{ + struct rkvdec_ctx *ctx =3D file_to_rkvdec_ctx(file); + struct rkvdec_dev *rkvdec =3D ctx->dev; + + v4l2_metrics_show(&ctx->fh.metrics, m, 0); + + v4l2_metrics_show_clock(m, rkvdec->axi_clk, 0); +} + static const struct v4l2_file_operations rkvdec_fops =3D { .owner =3D THIS_MODULE, .open =3D rkvdec_open, .release =3D rkvdec_release, + .show_fdinfo =3D rkvdec_show_fdinfo, .poll =3D v4l2_m2m_fop_poll, .unlocked_ioctl =3D video_ioctl2, .mmap =3D v4l2_m2m_fop_mmap, diff --git a/drivers/media/platform/rockchip/rkvdec/rkvdec.h b/drivers/medi= a/platform/rockchip/rkvdec/rkvdec.h index a24be6638b6b..590e213bd800 100644 --- a/drivers/media/platform/rockchip/rkvdec/rkvdec.h +++ b/drivers/media/platform/rockchip/rkvdec/rkvdec.h @@ -157,6 +157,7 @@ struct rkvdec_ctx { void *priv; u8 has_sps_st_rps: 1; u8 has_sps_lt_rps: 1; + ktime_t start_time; }; =20 static inline struct rkvdec_ctx *file_to_rkvdec_ctx(struct file *filp) --=20 2.56.1