public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: ming.qian@oss.nxp.com
To: linux-media@vger.kernel.org
Cc: mchehab@kernel.org, hverkuil-cisco@xs4all.nl,
	nicolas@ndufresne.ca, sebastian.fricke@collabora.com,
	shawnguo@kernel.org, s.hauer@pengutronix.de,
	kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com,
	Frank.li@nxp.com, xiahong.bao@nxp.com, eagle.zhou@nxp.com,
	imx@lists.linux.dev, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 0/7] media: amphion: Add DMA memory tracking support
Date: Tue, 31 Mar 2026 15:23:10 +0800	[thread overview]
Message-ID: <20260331072347.253-1-ming.qian@oss.nxp.com> (raw)

From: Ming Qian <ming.qian@oss.nxp.com>

This series adds DMA memory tracking support to the Amphion VPU driver,
allowing userspace to monitor memory consumption of codec instances.

To implement this feature in a reusable way, a new V4L2 memory tracking
infrastructure (v4l2-memtrack) is introduced, which can be adopted by
other V4L2 drivers in the future.

Background
==========

The Amphion VPU codec driver allocates various DMA buffers internally:

- Firmware boot region and RPC buffers
- Stream ring buffers
- Codec-specific buffers (MBI, DCP, reference frames)
- Encoder/decoder working buffers

These allocations are not visible to userspace, making it difficult to
debug memory issues or monitor resource usage in multi-instance scenarios
(e.g., transcoding servers with multiple simultaneous streams).

Solution
========

This series introduces:

1. V4L2_CID_MEMORY_USAGE control
   - New read-only control reporting memory usage in bytes
   - Standard V4L2 interface, queryable via VIDIOC_G_CTRL

2. v4l2-memtrack infrastructure
   - Hierarchical memory tracking (device -> instance -> queue)
   - debugfs interface at /sys/kernel/debug/v4l2-memtrack/
   - Reusable by other V4L2 drivers

3. videobuf2 integration
   - Automatic tracking of vb2 buffer allocations

4. Amphion VPU integration
   - Tracks all internal DMA allocations
   - Organized as: device -> instance -> buffers

Ming Qian (7):
  media: v4l2-ctrls: Add V4L2_CID_MEMORY_USAGE control
  docs: media: v4l2-ctrls: Add V4L2_CID_MEMORY_USAGE control
  media: v4l2-memtrack: Add V4L2 memory tracking infrastructure
  docs: media: v4l2-memtrack: Add driver API documentation
  MAINTAINERS: Add entry for V4L2 memory usage tracker
  media: videobuf2: Add memory tracking support
  media: amphion: Add V4L2 memory tracking support

 Documentation/driver-api/media/v4l2-core.rst  |   1 +
 .../driver-api/media/v4l2-memtrack.rst        | 140 +++
 .../userspace-api/media/v4l/control.rst       |  22 +-
 MAINTAINERS                                   |   8 +
 drivers/media/common/Kconfig                  |   1 +
 drivers/media/common/Makefile                 |   2 +-
 drivers/media/common/v4l2-memtrack/Kconfig    |  19 +
 drivers/media/common/v4l2-memtrack/Makefile   |   3 +
 .../common/v4l2-memtrack/v4l2-memtrack.c      | 825 ++++++++++++++++++
 .../media/common/videobuf2/videobuf2-core.c   |  13 +
 drivers/media/platform/amphion/Kconfig        |   1 +
 drivers/media/platform/amphion/vdec.c         |   9 +
 drivers/media/platform/amphion/venc.c         |   9 +
 drivers/media/platform/amphion/vpu.h          |   7 +
 drivers/media/platform/amphion/vpu_core.c     |   6 +
 drivers/media/platform/amphion/vpu_dbg.c      |   5 +
 drivers/media/platform/amphion/vpu_drv.c      |   2 +
 drivers/media/platform/amphion/vpu_v4l2.c     |  35 +-
 drivers/media/v4l2-core/v4l2-ctrls-defs.c     |   8 +
 include/media/v4l2-memtrack.h                 | 220 +++++
 include/media/videobuf2-core.h                |   4 +
 include/uapi/linux/v4l2-controls.h            |   4 +-
 22 files changed, 1340 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/driver-api/media/v4l2-memtrack.rst
 create mode 100644 drivers/media/common/v4l2-memtrack/Kconfig
 create mode 100644 drivers/media/common/v4l2-memtrack/Makefile
 create mode 100644 drivers/media/common/v4l2-memtrack/v4l2-memtrack.c
 create mode 100644 include/media/v4l2-memtrack.h


base-commit: 4fbeef21f5387234111b5d52924e77757626faa5
prerequisite-patch-id: 0000000000000000000000000000000000000000
-- 
2.53.0



             reply	other threads:[~2026-03-31  7:25 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31  7:23 ming.qian [this message]
2026-03-31  7:23 ` [RFC PATCH 1/7] media: v4l2-ctrls: Add V4L2_CID_MEMORY_USAGE control ming.qian
2026-03-31 14:33   ` Frank Li
2026-03-31 14:54     ` Nicolas Dufresne
2026-04-01  2:23       ` Ming Qian(OSS)
2026-04-02  3:14         ` Ming Qian(OSS)
2026-04-08 21:11           ` Nicolas Dufresne
2026-04-09 14:29             ` Detlev Casanova
2026-04-10  2:53               ` Ming Qian(OSS)
2026-04-01  2:07     ` Ming Qian(OSS)
2026-03-31  7:23 ` [RFC PATCH 2/7] docs: " ming.qian
2026-03-31  7:23 ` [RFC PATCH 3/7] media: v4l2-memtrack: Add V4L2 memory tracking infrastructure ming.qian
2026-03-31  7:23 ` [RFC PATCH 4/7] docs: media: v4l2-memtrack: Add driver API documentation ming.qian
2026-03-31  7:23 ` [RFC PATCH 5/7] MAINTAINERS: Add entry for V4L2 memory usage tracker ming.qian
2026-03-31  7:23 ` [RFC PATCH 6/7] media: videobuf2: Add memory tracking support ming.qian
2026-03-31  7:23 ` [RFC PATCH 7/7] media: amphion: Add V4L2 " ming.qian

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=20260331072347.253-1-ming.qian@oss.nxp.com \
    --to=ming.qian@oss.nxp.com \
    --cc=Frank.li@nxp.com \
    --cc=eagle.zhou@nxp.com \
    --cc=festevam@gmail.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=nicolas@ndufresne.ca \
    --cc=s.hauer@pengutronix.de \
    --cc=sebastian.fricke@collabora.com \
    --cc=shawnguo@kernel.org \
    --cc=xiahong.bao@nxp.com \
    /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