From: Detlev Casanova <detlev.casanova@collabora.com>
To: Tomasz Figa <tfiga@chromium.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Nicolas Dufresne <nicolas.dufresne@collabora.com>,
Benjamin Gaignard <benjamin.gaignard@collabora.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Heiko Stuebner <heiko@sntech.de>,
Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Cc: kernel@collabora.com, linux-kernel@vger.kernel.org,
linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
Detlev Casanova <detlev.casanova@collabora.com>
Subject: [PATCH v2 0/4] media: Track v4l2 buffers through an allocator
Date: Fri, 27 Nov 2026 12:16:09 -0500 [thread overview]
Message-ID: <20261127-v4l2-add-mem-tracker-v2-0-73b0494260e7@collabora.com> (raw)
Hello,
Currently, the only way to track buffers allocated by v4l2 from usespace
is to use the subsystem available debug information (e.g.:
/sys/kernel/debug/dma_buf/bufinfo).
But that information is generic and cannot be matched to a v4l2 driver or
to a userspace application: It is merely information about the allocation.
Other types of allocations require the developper to find where they are
exposed and how to link them to their test.
This can become hard to track when mutliple drivers are working at the
same time.
To improve that, add a small wrapper around buffer allocations to keep
track of them at the video device level so that we can add debug
information to them like a name, userspace pid/fd that did the
allocation,... and expose them to userspace via a debugfs entry.
It currently only supports DMA buffer allocations and adds support for
VB2 allocations too.
Other kind of memory tracking can be added later.
The verisilicon and rkvdec drivers have been ported to use the tracked
dma alloactions.
Note that this depends on the ftrace support patch series[1] that
provides fd/pid info in the v4l2_fh struct.
That series is a bit old, so this is based on an older linux version, but
that only changes things for the last 2 commits.
A v4l2top utility[2] has been made, to be used in parallel with the
fdinfo patch series[3], to show the list of active streams with their HW
and memory usage.
With this, debugfs looks like this when decoding a HEVC 1080p stream with
rkvdec on rk3588:
root # cat /sys/kernel/debug/v4l2/fdc38100.video-codec/mem
created-by fd pid size label
-------------------------------------------------------------------------------------
gst-launch-1.0 7 635 39184 vdpu381-hevc-priv-tbl
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-7
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-6
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-5
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-4
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-3
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-2
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-1
gst-launch-1.0 7 635 4177920 cap-00000000ac34392e-0
gst-launch-1.0 7 635 3133440 out-000000005c0230f6-1
gst-launch-1.0 7 635 3133440 out-000000005c0230f6-0
=====================================================================================
Total size: 39729424
[1]: https://lore.kernel.org/all/20260610-v4l2-add-ftrace-v2-0-9756edf72ac1@collabora.com/
[2]: https://github.com/cazou/v4l2top/tree/upstream
[3]: https://lore.kernel.org/all/20260706-v4l2-add-fdinfo-v3-0-d556568cf38e@collabora.com/
Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
Changes in v2:
- Use the already created v4l2 debugfs directory.
- Link to v1: https://patch.msgid.link/20260916-v4l2-add-mem-tracker-v1-0-900fa45e3e6a@collabora.com
To: Tomasz Figa <tfiga@chromium.org>
To: Marek Szyprowski <m.szyprowski@samsung.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>
To: Nicolas Dufresne <nicolas.dufresne@collabora.com>
To: Benjamin Gaignard <benjamin.gaignard@collabora.com>
To: Philipp Zabel <p.zabel@pengutronix.de>
To: Heiko Stuebner <heiko@sntech.de>
To: Detlev Casanova <detlev.casanova@collabora.com>
To: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Cc: kernel@collabora.com
Cc: linux-kernel@vger.kernel.org
Cc: linux-media@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
Cc: linux-arm-kernel@lists.infradead.org
---
Detlev Casanova (4):
media: Add a v4l2 memory allocations tracker
media: Store v4l2_fh in the vb_queue
media: verisilicon: Switch to tracked dma allocations
media: rkvdec: Switch to tracked dma allocations
.../media/common/videobuf2/videobuf2-dma-contig.c | 27 ++-
.../media/platform/rockchip/rkvdec/rkvdec-h264.c | 14 +-
.../media/platform/rockchip/rkvdec/rkvdec-hevc.c | 14 +-
.../media/platform/rockchip/rkvdec/rkvdec-rcb.c | 21 ++-
.../platform/rockchip/rkvdec/rkvdec-vdpu381-h264.c | 14 +-
.../platform/rockchip/rkvdec/rkvdec-vdpu381-hevc.c | 14 +-
.../platform/rockchip/rkvdec/rkvdec-vdpu383-h264.c | 14 +-
.../platform/rockchip/rkvdec/rkvdec-vdpu383-hevc.c | 14 +-
.../media/platform/rockchip/rkvdec/rkvdec-vp9.c | 33 ++--
drivers/media/platform/rockchip/rkvdec/rkvdec.c | 4 +
drivers/media/platform/verisilicon/hantro.h | 1 +
drivers/media/platform/verisilicon/hantro_drv.c | 4 +
drivers/media/platform/verisilicon/hantro_h264.c | 7 +-
drivers/media/platform/verisilicon/hantro_hevc.c | 100 ++++++-----
drivers/media/platform/verisilicon/hantro_mpeg2.c | 16 +-
.../media/platform/verisilicon/hantro_postproc.c | 14 +-
drivers/media/platform/verisilicon/hantro_vp8.c | 25 +--
drivers/media/platform/verisilicon/hantro_vp9.c | 34 +++-
.../verisilicon/rockchip_vpu981_hw_av1_dec.c | 160 +++++++++++-------
drivers/media/v4l2-core/Makefile | 1 +
drivers/media/v4l2-core/v4l2-allocator.c | 187 +++++++++++++++++++++
drivers/media/v4l2-core/v4l2-device.c | 4 +-
include/media/v4l2-allocator.h | 26 +++
include/media/v4l2-device.h | 3 +
include/media/videobuf2-core.h | 5 +
25 files changed, 559 insertions(+), 197 deletions(-)
---
base-commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
change-id: 20260612-v4l2-add-mem-tracker-da0088c74a64
prerequisite-change-id: 20260608-v4l2-add-ftrace-aec6e7f60a6c:v4
prerequisite-patch-id: 1642377e7eb8e2b9c08ba2edfe1627f246d18dec
prerequisite-patch-id: cbb31b868fe441e12390ed4f722c66a09d5da018
prerequisite-patch-id: 9f311d567e9c362b5ed00330e5d6cc6de9c94118
prerequisite-patch-id: fe7cd355f47da859fb1384cb02285f01ea230d35
prerequisite-patch-id: a92d7089a6ddef832e764a958d83e0402f6d83f3
prerequisite-patch-id: a9d89bb00db27935b66419eb3e6b225ef9381fe6
prerequisite-patch-id: 4bec038b584ae24fe4127164998ff81e30fe14d6
prerequisite-patch-id: 662455e7c49a81f89759dd6b576650d7803015d3
prerequisite-patch-id: 088f331d5bc7ce94e392ec07d954838ee294aefa
Best regards,
--
Detlev Casanova <detlev.casanova@collabora.com>
next reply other threads:[~2026-11-27 17:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 17:16 Detlev Casanova [this message]
2026-11-27 17:16 ` [PATCH v2 1/4] media: Add a v4l2 memory allocations tracker Detlev Casanova
2026-11-27 17:16 ` [PATCH v2 2/4] media: Store v4l2_fh in the vb_queue Detlev Casanova
2026-11-27 17:16 ` [PATCH v2 3/4] media: verisilicon: Switch to tracked dma allocations Detlev Casanova
2026-11-27 17:16 ` [PATCH v2 4/4] media: rkvdec: " Detlev Casanova
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=20261127-v4l2-add-mem-tracker-v2-0-73b0494260e7@collabora.com \
--to=detlev.casanova@collabora.com \
--cc=benjamin.gaignard@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--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=m.szyprowski@samsung.com \
--cc=mchehab@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=p.zabel@pengutronix.de \
--cc=tfiga@chromium.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®