public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: "Ming Qian(OSS)" <ming.qian@oss.nxp.com>
To: Detlev Casanova <detlev.casanova@collabora.com>,
	Nicolas Dufresne <nicolas@ndufresne.ca>,
	Frank Li <Frank.li@nxp.com>
Cc: linux-media@vger.kernel.org, mchehab@kernel.org,
	hverkuil-cisco@xs4all.nl, sebastian.fricke@collabora.com,
	shawnguo@kernel.org, s.hauer@pengutronix.de,
	kernel@pengutronix.de, festevam@gmail.com, linux-imx@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: Re: [RFC PATCH 1/7] media: v4l2-ctrls: Add V4L2_CID_MEMORY_USAGE control
Date: Fri, 10 Apr 2026 10:53:33 +0800	[thread overview]
Message-ID: <ea729302-6dca-443b-80fd-c1f5d9a41613@oss.nxp.com> (raw)
In-Reply-To: <9fdca013-32f7-4ce1-a296-f2f36ef31b50@collabora.com>

Hi Detlev,

On 4/9/2026 10:29 PM, Detlev Casanova wrote:
> 
> 
> On 4/8/26 17:11, Nicolas Dufresne wrote:
>> Le jeudi 02 avril 2026 à 11:14 +0800, Ming Qian(OSS) a écrit :
>>> Hi Nicolas,
>>>
>>> On 4/1/2026 10:23 AM, Ming Qian(OSS) wrote:
>>>> Hi Nicolas,
>>>>
>>>> On 3/31/2026 10:54 PM, Nicolas Dufresne wrote:
>>>>> Le mardi 31 mars 2026 à 10:33 -0400, Frank Li a écrit :
>>>>>> On Tue, Mar 31, 2026 at 03:23:11PM +0800, 
>>>>>> ming.qian@oss.nxp.com wrote:
>>>>>>> From: Ming Qian <ming.qian@oss.nxp.com>
>>>>>>>
>>>>>>> Add a new read-only control V4L2_CID_MEMORY_USAGE that allows
>>>>>>> applications to query the total amount of memory currently used
>>>>>>> by a device instance.
>>>>>>>
>>>>>>> This control reports the memory consumption in bytes, including
>>>>>>> internal buffers, intermediate processing data, and other
>>>>>>> driver-managed allocations. Applications can use this information
>>>>>>> for debugging, resource monitoring, or making informed decisions
>>>>>>> about buffer allocation strategies.
>>>>>>>
>>>>>>> Signed-off-by: Ming Qian <ming.qian@oss.nxp.com>
>>>>>>> ---
>>>>>> Not sure why not export these information by debugfs, or any 
>>>>>> benefit vs
>>>>>> debugfs?
>>>>> There is also a on-going proposal that uses fdinfo.
>>>>>
>>>>> Nicolas
>>>>>
>>>> Thanks for the reminder about the ongoing fdinfo proposal.
>>>>
>>>> Just to confirm, you are referring to Detlev’s ongoing fdinfo proposal,
>>>> specifically this series:
>>>> https://lore.kernel.org/lkml/20260212162328.192217-1-
>>>> detlev.casanova@collabora.com/
>>>>
>>>> I will align my work with it and switch to using fdinfo.
>>>> Once the show_fdinfo support from that series is merged, I will prepare
>>>> the next revision of my patch accordingly.
>>>>
>>>> Regards,
>>>> Ming
>>>>
>>> Regarding the discussion about using fdinfo instead of a V4L2 control, I
>>> have two questions:
>>>
>>>     1. Key consistency in fdinfo
>>>     fdinfo uses key–value pairs, which is flexible, but if multiple
>>>     drivers want to expose the same “memory usage” information,
>>>     they need to agree on a common key name and meaning. Otherwise
>>>     user‑space must handle each driver differently. A V4L2 control
>>>     naturally provides a unified interface without this coordination
>>>     effort.
>>>
>>>
>>>     2. Lack of notification in fdinfo
>>>     With a control, user‑space can subscribe to control events and
>>>     receive notifications when the memory usage changes. fdinfo does
>>>     not have a built‑in event mechanism, so users must either poll
>>>     or rely on additional eventfd‑like or custom event mechanisms.
>>>
>>> Do you have any suggestions or existing practices to address these two
>>> issues when using fdinfo?
>>>
>>> Thanks again for your time and comments.
>> Added Detlev in CC. You can also refer to his work through:
>>
>> https://lore.kernel.org/all/20260212162328.192217-1- 
>> detlev.casanova@collabora.com/
>>
>> Nicolas
> Hi Ming !
> 
> One of the reasons for using fdinfo is that it's already being used in 
> the drm subsystem and it is working well.
> Of course, in DRM, drivers don't allocate a lot of memory themselves, 
> userspace drivers (in mesa) go through the DRM uAPI to allocate buffers, 
> making the DRM subsystem aware of all allocated memory.
> That lets DRM show memory stats in a standard way for all drm drivers. 
> In v4l2, memory allocation is shared between userspace and the driver.
> We could have drivers report memory usage through a callback and v4l2- 
> core can add the standard field based on that.
> 
> For notifications, I don't really see a need for that, most tracing 
> tools will use polling (I'm thinking perfetto, but also top-like tools).
> We could have a max-mem-usage field if we'd want to make sure we don't 
> miss the maximum memory usage between 2 polls.
> 
> Finally, I think v4l2 controls should only be used to control, configure 
> and exchange data with video devices, not get stat information on what 
> the driver is doing.
> 
> Detlev.

Thank you for your detailed explanation and suggestions.
Your points make sense, especially regarding fdinfo for standardized
stats reporting, polling being sufficient for tracing tools, and keeping
V4L2 controls focused on device control rather than driver statistics.

I'll revisit the design accordingly.

Regards,
Ming

>>
>>> Regards,
>>> Ming
>>>
>>>>>> Generanlly document should be first patch, then driver change.
>>>>>>
>>>>>> Frank
>>>>>>
>>>>>>>    drivers/media/v4l2-core/v4l2-ctrls-defs.c | 8 ++++++++
>>>>>>>    include/uapi/linux/v4l2-controls.h        | 4 +++-
>>>>>>>    2 files changed, 11 insertions(+), 1 deletion(-)
>>>>>>>
>>>>>>> diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/
>>>>>>> media/v4l2-core/v4l2-ctrls-defs.c
>>>>>>> index 551426c4cd01..053db78ff661 100644
>>>>>>> --- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
>>>>>>> +++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
>>>>>>> @@ -831,6 +831,7 @@ const char *v4l2_ctrl_get_name(u32 id)
>>>>>>>        case V4L2_CID_ALPHA_COMPONENT:        return "Alpha 
>>>>>>> Component";
>>>>>>>        case V4L2_CID_COLORFX_CBCR:        return "Color Effects, 
>>>>>>> CbCr";
>>>>>>>        case V4L2_CID_COLORFX_RGB:              return "Color 
>>>>>>> Effects,
>>>>>>> RGB";
>>>>>>> +    case V4L2_CID_MEMORY_USAGE:        return "Memory Usage";
>>>>>>>
>>>>>>>        /*
>>>>>>>         * Codec controls
>>>>>>> @@ -1476,6 +1477,13 @@ void v4l2_ctrl_fill(u32 id, const char
>>>>>>> **name, enum v4l2_ctrl_type *type,
>>>>>>>            *min = 0;
>>>>>>>            *max = 0xffff;
>>>>>>>            break;
>>>>>>> +    case V4L2_CID_MEMORY_USAGE:
>>>>>>> +        *type = V4L2_CTRL_TYPE_INTEGER64;
>>>>>>> +        *flags |= V4L2_CTRL_FLAG_READ_ONLY;
>>>>>>> +        *min = 0;
>>>>>>> +        *max = S64_MAX;
>>>>>>> +        *step = 1;
>>>>>>> +        break;
>>>>>>>        case V4L2_CID_FLASH_FAULT:
>>>>>>>        case V4L2_CID_JPEG_ACTIVE_MARKER:
>>>>>>>        case V4L2_CID_3A_LOCK:
>>>>>>> diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/
>>>>>>> linux/v4l2-controls.h
>>>>>>> index 68dd0c4e47b2..02c6f960d38e 100644
>>>>>>> --- a/include/uapi/linux/v4l2-controls.h
>>>>>>> +++ b/include/uapi/linux/v4l2-controls.h
>>>>>>> @@ -110,8 +110,10 @@ enum v4l2_colorfx {
>>>>>>>    #define V4L2_CID_COLORFX_CBCR            (V4L2_CID_BASE+42)
>>>>>>>    #define V4L2_CID_COLORFX_RGB            (V4L2_CID_BASE+43)
>>>>>>>
>>>>>>> +#define V4L2_CID_MEMORY_USAGE            (V4L2_CID_BASE+44)
>>>>>>> +
>>>>>>>    /* last CID + 1 */
>>>>>>> -#define V4L2_CID_LASTP1                         (V4L2_CID_BASE+44)
>>>>>>> +#define V4L2_CID_LASTP1                         (V4L2_CID_BASE+45)
>>>>>>>
>>>>>>>    /* USER-class private control IDs */
>>>>>>>
>>>>>>> -- 
>>>>>>> 2.53.0
>>>>>>>
> 


  reply	other threads:[~2026-04-10  2:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31  7:23 [RFC PATCH 0/7] media: amphion: Add DMA memory tracking support ming.qian
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) [this message]
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=ea729302-6dca-443b-80fd-c1f5d9a41613@oss.nxp.com \
    --to=ming.qian@oss.nxp.com \
    --cc=Frank.li@nxp.com \
    --cc=detlev.casanova@collabora.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