From: Hans de Goede <hdegoede@redhat.com>
To: Ricardo Ribalda <ribalda@chromium.org>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
Yunke Cao <yunkec@chromium.org>,
Hans Verkuil <hverkuil@xs4all.nl>
Subject: Re: [PATCH v2 0/6] media: uvcvideo: Implement the Privacy GPIO as a subdevice
Date: Mon, 25 Nov 2024 15:02:33 +0100 [thread overview]
Message-ID: <9779fcb0-e28d-4651-b04c-ca492e30c452@redhat.com> (raw)
In-Reply-To: <CANiDSCtvLB=tWb7ZCFCw9gn26R2xHnOf=yTLj+M_4AuQKYvgOQ@mail.gmail.com>
Hi Ricardo,
On 25-Nov-24 2:39 PM, Ricardo Ribalda wrote:
> On Mon, 25 Nov 2024 at 13:25, Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> Hi Ricardo,
>>
>> On 9-Nov-24 5:29 PM, Ricardo Ribalda wrote:
>>
>> <snip>
>>
>>>> I have been discussing UVC power-management with Laurent, also
>>>> related to power-consumption issues caused by libcamera's pipeline
>>>> handler holding open the /dev/video# node as long as the camera
>>>> manager object exists.
>>
>> <snip>
>>
>>>> Here is what I have in mind for this:
>>>>
>>>> 1. Assume that the results of trying a specific fmt do not change over time.
>>>>
>>>> 2. Only allow userspace to request fmts which match one of the enum-fmts ->
>>>> enum-frame-sizes -> enum-frame-rates tripplet results
>>>> (constrain what userspace requests to these)
>>>>
>>>> 3. Run the equivalent of tryfmt on all possible combinations (so the usaul
>>>> 3 levels nested loop for this) on probe() and cache the results
>>>>
>>>> 4. Make try_fmt / set_fmt not poweron the device but instead constrain
>>>> the requested fmt to one from our cached fmts
>>>>
>>>> 5. On stream-on do the actual power-on + set-fmt + verify that we get
>>>> what we expect based on the cache, and otherwise return -EIO.
>>>
>>> Can we start powering up the device during try/set fmt and then
>>> implement the format caching as an improvement?
>>
>> Yes, actually looking at how complex this is when e.g. also taking
>> controls into account I think that taking small steps is a good idea.
>>
>> I have lately mostly been working on sensor drivers where delaying
>> applying format settings + all controls to stream-on is normal.
>>
>> So that is the mental model I'm applying to uvc here, but that might
>> not be entirely applicable.
>>
>>> Laurent mentioned that some cameras missbehave if a lot of controls
>>> are set during probing. I hope that this approach does not trigger
>>> those, and if it does it would be easier to revert if we do the work
>>> in two steps.
>>
>> Ack, taking small steps sounds like a good plan.
>>
>> <snip>
>>
>>>> This should also make camera enumeration faster for apps, since
>>>> most apps / frameworks do the whole 3 levels nested loop for this
>>>> on startup, for which atm we go out to the hw, which now instead
>>>> will come from the fmts cache and thus will be much much faster,
>>>> so this should lead to a noticeable speedup for apps accessing UVC
>>>> cameras which would be another nice win.
>>>>
>>>> Downside is that the initial probe will take longer see we do
>>>> all the tryfmt-s there now. But I think that taking a bit longer
>>>> to probe while the machine is booting should not be an issue.
>>>
>>> How do you pretend to handle the controls? Do you plan to power-up the
>>> device during s_ctrl() or set them only during streamon()?
>>> If we power-up the device during s_ctrl we need to take care of the
>>> asynchronous controls (typically pan/tilt/zoom), The device must be
>>> powered until the control finishes, and the device might never reply
>>> control_done if the firmware is not properly implemented.
>>> If we set the controls only during streamon, we will break some
>>> usecases. There are some video conferencing equipment that do homing
>>> during streamoff. That will be a serious API breakage.
>>
>> How to handle controls is a good idea.
>>
>> Based on my sensor experience my initial idea was to just cache them
>> all. Basically make set_ctrl succeed but do not actually do anyhing
>> when the camera is not already powered on and then on stream-on call
>> __v4l2_ctrl_handler_setup() to get all current values applied.
>>
>> But as you indicate that will likely not work well with async controls,
>> although we already have this issue when using v4l2-ctl from the cmdline
>> on such a control and that seems to work fine.
>
> -----
>> Just because we allow
>> the USB connection to sleep, does not mean that the camera cannot finish
>> doing applying the async control.
>>
> Not sure what you mean with this sentence. Could you explain it
> differently? Sorry
>
>> But I can see how some cameras might not like this and having 2 different
>> paths for different controls also is undesirable.
>>
>> Combine that with what Laurent said about devices not liking it when
>> you set too much controls in a short time and I do think we need to
>> immediately apply ctrls.
>>
>> I see 2 ways of doing that:
>>
>> 1. Use pm_runtime_set_autosuspend_delay() with a delay of say 1 second
>> and then on set_ctrl do a pm_runtime_get_sync() +
>> pm_runtime_put_autosuspend() giving the camera 1 second to finish
>> applying the async ctrl (which might not be enough for e.g homing) +
>> also avoid doing suspend + resume all the time if multiple ctrls are send
>
> What about 1.5:
>
> during s_ctrl():
> usb_autopm_get_interface()
> if the control is UVC_CTRL_FLAG_ASYNCHRONOUS.
> usb_autopm_get_interface()
> set the actual control in the hardware
> usb_autopm_put_interface()
>
> during uvc_ctrl_status_event():
> usb_autopm_put_interface()
How do we match this to the usb_autopm_get_interface()
call ? At a minimum we would need some counter to
track pending (not acked through status interrupt urb)
async control requests and only do the put() if that
counter >= 1 (and then decrease the counter).
We don't want to do unbalanced puts here in case of
buggy cameras sending unexpected / too many
ctrl status events.
> during close():
> send all the missing usb_autopm_put_interface()
Except for my one remark this is an interesting
proposal.
Maybe also do a dev_warn() if there are missing
usb_autopm_put_interface() calls pending on close() ?
> This way:
> - we do not have an artificial delay that might not work for all the use cases
> - cameras with noncompliant async controls will have the same PM
> behaviour as now (will be powered on until close() )
>
> We do the same with the rest of the actions that require hardware access, like:
> https://lore.kernel.org/linux-media/20220920-resend-powersave-v5-2-692e6df6c1e2@chromium.org/
>
> This way:
> - Apps that do not need to access the hardware, do not wake it up, and
> we do not break usecases.
>
> Next steps will be:
> - cache the formats
> - move the actual set_ctrl to streamon... but if we can do that I
> would argue than we can move completely to the control framework.
Right I had forgotten that the UVC driver does not use the control
framework. I think moving to that would be a prerequisite for moving
the set_ctrl to stream_on.
Regards,
Hans
next prev parent reply other threads:[~2024-11-25 14:02 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-08 20:25 [PATCH v2 0/6] media: uvcvideo: Implement the Privacy GPIO as a subdevice Ricardo Ribalda
2024-11-08 20:25 ` [PATCH v2 1/6] media: uvcvideo: Factor out gpio functions to its own file Ricardo Ribalda
2024-11-08 20:25 ` [PATCH v2 2/6] media: uvcvideo: Re-implement privacy GPIO as a separate subdevice Ricardo Ribalda
2024-11-08 20:25 ` [PATCH v2 3/6] Revert "media: uvcvideo: Allow entity-defined get_info and get_cur" Ricardo Ribalda
2024-11-08 20:25 ` [PATCH v2 4/6] media: uvcvideo: Create ancillary link for GPIO subdevice Ricardo Ribalda
2024-11-10 10:05 ` Sakari Ailus
2024-11-08 20:25 ` [PATCH v2 5/6] media: v4l2-core: Add new MEDIA_ENT_F_GPIO Ricardo Ribalda
2024-11-08 20:25 ` [PATCH v2 6/6] media: uvcvideo: Use MEDIA_ENT_F_GPIO for the GPIO entity Ricardo Ribalda
2024-11-09 14:04 ` [PATCH v2 0/6] media: uvcvideo: Implement the Privacy GPIO as a subdevice Mauro Carvalho Chehab
2024-11-09 14:57 ` Ricardo Ribalda
2024-11-09 15:37 ` Hans de Goede
2024-11-09 16:29 ` Ricardo Ribalda
2024-11-10 10:02 ` Mauro Carvalho Chehab
2024-11-10 10:29 ` Hans Verkuil
2024-11-10 10:37 ` Ricardo Ribalda
2024-11-10 10:47 ` Hans Verkuil
2024-11-10 12:48 ` Mauro Carvalho Chehab
2024-11-10 10:32 ` Ricardo Ribalda
2024-11-10 10:59 ` Ricardo Ribalda
2024-11-10 12:46 ` Mauro Carvalho Chehab
2024-11-10 16:01 ` Ricardo Ribalda
2024-11-10 15:14 ` Laurent Pinchart
2024-11-10 16:04 ` Ricardo Ribalda
2024-11-25 12:31 ` Hans de Goede
2024-11-25 12:56 ` Laurent Pinchart
2024-11-25 13:35 ` Hans de Goede
2024-11-10 16:07 ` Ricardo Ribalda
2024-11-25 12:39 ` Hans de Goede
2024-11-25 12:58 ` Laurent Pinchart
2024-11-25 13:44 ` Hans de Goede
2024-11-25 13:50 ` Ricardo Ribalda
2024-11-11 12:03 ` Hans de Goede
2024-11-25 12:25 ` Hans de Goede
2024-11-25 12:49 ` Laurent Pinchart
2024-11-25 13:29 ` Hans de Goede
2024-11-26 17:22 ` Laurent Pinchart
2024-11-25 13:39 ` Ricardo Ribalda
2024-11-25 14:02 ` Hans de Goede [this message]
2024-11-26 16:22 ` Ricardo Ribalda
2024-11-26 17:18 ` Laurent Pinchart
2024-11-26 17:29 ` Ricardo Ribalda
2024-11-10 15:08 ` Laurent Pinchart
2024-11-11 12:59 ` Hans de Goede
2024-11-11 14:35 ` Hans de Goede
2024-11-12 17:31 ` Ricardo Ribalda
2024-11-13 15:19 ` Hans de Goede
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=9779fcb0-e28d-4651-b04c-ca492e30c452@redhat.com \
--to=hdegoede@redhat.com \
--cc=hverkuil@xs4all.nl \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=ribalda@chromium.org \
--cc=sakari.ailus@linux.intel.com \
--cc=yunkec@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