Linux USB
 help / color / mirror / Atom feed
From: Michal Pecio <michal.pecio@gmail.com>
To: Dylan Robinson <dylan_robinson@motu.com>
Cc: Alan Stern <stern@rowland.harvard.edu>,
	linux-usb@vger.kernel.org, mathias.nyman@intel.com
Subject: Re: [Bug 220748] usb: xhci_queue_isoc_tx_prepare ignore start_frame and always assumes URB_ISO_ASAP is set
Date: Sat, 9 May 2026 13:10:04 +0200	[thread overview]
Message-ID: <20260509131004.61ce52b9.michal.pecio@gmail.com> (raw)
In-Reply-To: <CA+Df+jfkQ1QXyh=oQrX2y2x8N2=ZRFWFai5QHiZ2FC-hQqEsmQ@mail.gmail.com>

On Fri, 8 May 2026 17:39:20 -0400, Dylan Robinson wrote:
> On Thu, May 7, 2026 at 5:54 PM Michal Pecio wrote:
> > It would surely need to be optional on per-URB basis, to avoid
> > updating all drivers and to enable sub-1ms URBs without gaps on HW
> > like xHCI, where we can't request starting frame with microframe
> > granularity.
> >
> > I suppose Windows/OSX have to be doing it this way too?  
> 
> Windows isochronous transfers behave similarly to the outdated
> documentation in Documentation/driver-api/usb.
> 
> Setting USBD_START_ISO_TRANSFER_ASAP in the URB instructs the USB
> driver stack to schedule the transfer in the next appropriate frame.
> For the first URB on a pipe, transfers with this flag are scheduled as
> soon as possible. For subsequent URBs, the stack automatically tracks
> stream continuity.
> 
> Otherwise, the UrbIsochronousTransfer.StartFrame member specifies the
> starting USB frame number for the transfer.
> 
> Source:
> https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/transfer-data-to-isochronous-endpoints

Looks like Windows ASAP is similar to Linux non-ASAP behavior, except
that they consider new URBs to continue the stream for 1024 USB frames
after the last completed URB. In Linux that number is 0 instead, as
there is no way to indicate a new stream by other means.

Windows requires isoc URBs to be frame-aligned. Linux doesn't have this
limitation. I can run a high-speed UAC dongle with two 0.5ms URBs just
fine, though ALSA won't let me go shorter for some reason. 

> The USBDriverKit API on macOS for submitting isochronous transfers is:
> 
> virtual kern_return_t IsochIO(
>     IOMemoryDescriptor *dataBuffer,
>     IOMemoryDescriptor *frameList,
>     uint64_t firstFrameNumber,
>     OSAction *completion);
> 
> firstFrameNumber: The starting frame number for the request. You can
> get the current frame number from the GetFrameNumber method of
> IOUSBHostDevice or IOUSBHostInterface. Specify 0 to begin the transfer
> on the next available frame (XHCI only).
> 
> Source:
> https://developer.apple.com/documentation/usbdriverkit/iousbhostpipe/isochio

Not sure how Apple and MS deal with the "phase" issue, i.e. does a
bInterval=6 endpoint run in frames 0,4,8,... or 3,7,11,... and how
are drivers supposed to set firstFrameNumber then.

Looking at the MS article, I suspect they want drivers to pretend it's
always 0,4,8, which is what the xHCI spec requires too.

> > It's supposed to be implied that submission from a complete()
> > callback is a continuation. I believe one of the submitted patches
> > fixes that.  
> 
> Because our devices use the implicit feedback synchronization model,
> our drivers typically submit OUT transfers from the IN pipe's
> completion callbacks. Would those submissions also be considered
> continuations of the existing OUT stream, or is continuity only
> inferred when a URB is submitted from the completion handler
> associated with the same pipe?

I meant completion at the same endpoint because it's a common case,
but submission while any URBs are pending and not completed yet also
is supposed to continues the stream, regardless of who submits.

Or at least that's the intent stated by Alan and what it was before
"BH giveback". I think today there is a short window after completion
by HW and before complete() runs, where even ehci-hcd may fail to
detect that the last remaining URB is still "in flight". In this case
it's likely too late to avoid a gap on OUT, but the gap should produce
EXDEV completions rather than delay the next URB by a few uframes.

Perhaps this should be fixed for all HCDs. The alternative is to ask
drivers to make the IN completion give the OUT completion any required
information to resubmit, which increases latency and chance of EXDEV,
or they risk potential hard to detect gaps due to SW latency. (The gaps
could be detected by looking at frame_desc->start_frame, at least when
xhci-hcd is fixed to fill it properly on non-CFC chips).

Regards,
Michal

  reply	other threads:[~2026-05-09 11:10 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-04 21:25 [Bug 220748] New: usb: xhci_queue_isoc_tx_prepare ignore start_frame and always assumes URB_ISO_ASAP is set bugzilla-daemon
2025-11-05  8:40 ` [Bug 220748] " bugzilla-daemon
2025-11-05  8:48 ` bugzilla-daemon
2025-11-05  8:53 ` bugzilla-daemon
2025-11-05  9:06 ` bugzilla-daemon
2025-11-05 15:47 ` bugzilla-daemon
2025-11-05 18:28 ` bugzilla-daemon
2025-11-05 18:30 ` bugzilla-daemon
2025-11-05 20:16 ` bugzilla-daemon
2025-11-05 21:18 ` bugzilla-daemon
2025-11-06  3:52 ` bugzilla-daemon
2025-11-06  8:27 ` bugzilla-daemon
2025-11-06  8:35 ` bugzilla-daemon
2025-11-06 15:03 ` bugzilla-daemon
2025-11-08 10:33 ` bugzilla-daemon
2025-11-08 16:09 ` bugzilla-daemon
2025-11-10 10:23 ` bugzilla-daemon
2025-11-10 10:42 ` bugzilla-daemon
2026-05-04 23:53 ` bugzilla-daemon
2026-05-04 23:54 ` bugzilla-daemon
2026-05-05  1:14 ` bugzilla-daemon
2026-05-05  9:59 ` bugzilla-daemon
2026-05-05 17:09 ` bugzilla-daemon
2026-05-05 17:10 ` bugzilla-daemon
2026-05-05 17:10 ` bugzilla-daemon
2026-05-05 17:13 ` bugzilla-daemon
2026-05-06 13:32 ` bugzilla-daemon
2026-05-06 15:03 ` bugzilla-daemon
2026-05-07  2:38   ` Alan Stern
2026-05-07 16:17     ` Dylan Robinson
2026-05-07 17:24       ` Alan Stern
2026-05-07 21:16         ` Dylan Robinson
2026-05-08  3:02           ` Alan Stern
2026-05-08 17:20             ` Dylan Robinson
2026-05-09  1:25               ` Alan Stern
2026-05-09 22:12               ` Michal Pecio
2026-05-10 12:39                 ` Dylan Robinson
2026-05-11 19:21                   ` [RFT PATCH] xhci: fix frame id calculation for isoc transfer Mathias Nyman
2026-05-11 19:36                     ` Mathias Nyman
2026-05-07 21:54       ` [Bug 220748] usb: xhci_queue_isoc_tx_prepare ignore start_frame and always assumes URB_ISO_ASAP is set Michal Pecio
2026-05-08  3:09         ` Alan Stern
2026-05-08  9:41           ` Michal Pecio
2026-05-08 14:54             ` Alan Stern
2026-05-08 21:39         ` Dylan Robinson
2026-05-09 11:10           ` Michal Pecio [this message]
2026-05-09 20:18             ` Dylan Robinson
2026-05-11 19:15 ` bugzilla-daemon

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=20260509131004.61ce52b9.michal.pecio@gmail.com \
    --to=michal.pecio@gmail.com \
    --cc=dylan_robinson@motu.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=stern@rowland.harvard.edu \
    /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