From: Daehwan Jung <dh10.jung@samsung.com>
To: Avichal Rakesh <arakesh@google.com>
Cc: "open list:USB SUBSYSTEM" <linux-usb@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
selvarasu.g@samsung.com,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
jchowdhary@google.com
Subject: Re: [PATCH] usb: gadget: uvc: reserve frame interval headroom for the zero length backlog
Date: Mon, 19 Oct 2026 16:25:15 +0900 [thread overview]
Message-ID: <atXF1OT2GUkSgRi+@ubuntu> (raw)
In-Reply-To: <ebf20112-a767-4eb6-a6cd-4d2f724bd19f@google.com>
[-- Attachment #1: Type: text/plain, Size: 3801 bytes --]
On Tue, Oct 13, 2026 at 02:15:36PM -0700, Avichal Rakesh wrote:
>
> On 10/11/26 8:40 PM, Daehwan Jung wrote:
> > uvc_video_prep_requests() spreads a frame over every service interval of
> > the negotiated frame interval:
> >
> > nreq = DIV_ROUND_UP(video->interval, interval_duration);
> >
> > and uvc_buffer_prepare() then splits every buffer into exactly
> > reqs_per_frame requests - only the request size varies, never the count.
> > So transmitting one frame always occupies nreq service intervals, 100% of
> > the frame interval, with nothing left over.
> >
> > That budget cannot be met. While no video buffer is available,
> > uvcg_video_hw_submit() deliberately keeps a backlog of zero length
> > requests queued to the endpoint:
> >
> > if (list_empty(&video->req_free) ||
> > (atomic_read(&video->queued) > UVCG_REQ_MAX_ZERO_COUNT)) {
> >
> > Up to UVCG_REQ_MAX_ZERO_COUNT + 1 of them are in flight whenever the
> > encoder is late, each occupying a service interval that carries no
> > payload, and the ring is FIFO so they all drain before the next frame's
> > payload moves. The frame period is therefore reqs_per_frame plus that
> > backlog, always longer than the frame interval the host asked for. The
> > UVCG_REQ_MAX_ZERO_COUNT compensation already in this function only sizes
> > the request pool; it buys the backlog no time.
> >
> > At 60fps over SuperSpeed with bInterval 1 the backlog is 33 of the 133
> > intervals a frame interval has - 4.125ms, a quarter of the budget. The
> > waste is a fixed count, so it hurts in inverse proportion to the frame
> > interval: 24.8% at 60fps down to 6.2% at 15fps.
> >
> > Reserve it. Measured on a SuperSpeed gadget (isoc IN, wMaxPacketSize
> > 1024, bMaxBurst 2, bInterval 1) running the Android DeviceAsWebcam
> > service, as reported by the CTS Verifier "Camera - Webcam" test, next to
> > the rate the microframe accounting predicts:
> >
> > target predicted measured | predicted measured
> > (before) (before) | (after) (after)
> > 60 47.9 46 | 59.7 56
> > 30 26.7 26 | 30.0 28
> > 24 21.8 22 | 24.5 22
> > 15 14.1 13 | 16.0 13
>
> We recently fixed this exact issue in Android's DeviceAsWebcam client. In
> our case, DeviceAsWebcam was only queuing a frame when the previous one was
> returned.
>
> With the changes to uvc_video_prep_requests(), a frame stays queued for one
> frame interval, and subsequent ioctl/scheduling delays meant that the gadget
> driver had to insert empty requests between two frames bringing down the
> effective FPS.
>
> Our fix was to maintain two queued buffers to UVC Gadget Driver ensuring
> that the UVC gadget driver has a frame ready to send immediately after one
> is complete. This prevents insertion of zero length requests between two
> consecutive frames (fixing the FPS degradation you see) and gives
> DeviceAsWebcam a little bit of breathing room for ioctl and scheduling
> delays.
>
> It is not clear if you are working with Android or not. If not, it is well
> worth checking if you have the same issue as us instead of adding an
> arbitrary headroom here. The numbers you report are extremely similar to
> what we were seeing.
>
> If this was motivated from Android's DeviceAsWebcam, take a look at
> https://android-review.googlesource.com/c/platform/packages/services/DeviceAsWebcam/+/4353888
> and the comments in that change.
>
> The change itself has been abandoned but it has context on the underlying
> issue, fix, and where to find the fix until it makes its way to AOSP.
>
> Best Regards,
> Avi
>
Thanks for sharing it. I'm working with Android.
Let me check AOSP.
Best Regards,
Daehwan Jung
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
prev parent reply other threads:[~2026-10-19 7:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20261012034422epcas2p486b38818b542d2fff5b5fed58863ec6e@epcas2p4.samsung.com>
2026-10-12 3:40 ` Daehwan Jung
2026-10-13 21:15 ` Avichal Rakesh
2026-10-19 7:25 ` Daehwan Jung [this message]
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=atXF1OT2GUkSgRi+@ubuntu \
--to=dh10.jung@samsung.com \
--cc=arakesh@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=jchowdhary@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=selvarasu.g@samsung.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
all inboxes | Powered by JetHome®