Re: [PATCH] usb: gadget: uvc: reserve frame interval headroom for the zero length backlog

From: Daehwan Jung

Date: Thu Dec 03 2026 - 03:02:28 EST


On Thu, Dec 03, 2026 at 12:50:16AM +0000, Keisuke Tsukuda wrote:
> On Mon, Oct 12, 2026, Daehwan Jung wrote:
> > The frame period is therefore reqs_per_frame plus that backlog, always
> > longer than the frame interval the host asked for.
>
> I tested this on a Tinker Board 3N (RK3568/DWC3) at SuperSpeed, using
> usb-testing 9357829ac604 and a Mac host. The gadget offered 160x120
> YUYV at 60 fps (166666 x 100 ns), with bInterval 1, wMaxPacketSize
> 1024 and bMaxBurst 2. I used the same test-pattern source with and
> without the patch.
>
> I queued four buffers before STREAMON and requeued each after DQBUF.
> The host received 60.6 fps without the patch and 80.0 fps with it.
> The five-second gadget traces contained no zero-length requests, and
> the gadget completed 303 versus 400 frames.
> Between completed frames, there were 132 versus 100 payload requests.
> Those counts are slightly below the 134 versus 101 budgeted by
> reqs_per_frame because the driver emits 8-byte headers for this test
> source where the sizing calculation allows for 12.
>
> I then allocated two buffers but kept only one queued, putting it back
> after DQBUF.
> The trace showed 33 empty request completions between successive
> completed frames. The host rate went from 48.5 to 60.2 fps with the
> patch.
>
> This test source fills buffers as soon as they are returned; a camera
> that captures at a fixed rate might behave differently. The patch
> still reduces the requests per frame from 132 to 100 when no empty
> requests are queued. The four-buffer stream ran at 80 fps with a
> selected 60 fps interval. Is that expected? Should userspace pace the
> frames?

Hi Keisuke,

Thanks a lot for testing this.

No, 80 fps is not expected, and userspace should not have to pace the
frames. The patch takes the headroom from every frame interval, even
when no zero length request is queued. So when userspace keeps enough
buffers queued, it breaks the pacing added by commit 48dbe731171e and
the gadget sends frames faster than the interval the host selected.

Your one-buffer test shows the same 33 zero length requests I measured.
They only appear when no buffer is queued as the previous frame
completes. As Avi pointed out, that is a buffer depth problem in
DeviceAsWebcam, not in the gadget driver.

Best Regards,
Daehwan Jung