From: Michal Pecio <michal.pecio@gmail.com>
To: Mathias Nyman <mathias.nyman@linux.intel.com>
Cc: dylan_robinson@motu.com, linux-usb@vger.kernel.org,
mathias.nyman@intel.com, stern@rowland.harvard.edu
Subject: Re: [RFT PATCHv3 1/3] xhci: fix frame id calculation and checks for isoc URBs
Date: Thu, 13 Aug 2026 19:56:56 +0200 [thread overview]
Message-ID: <20260813195656.132ba1c9.michal.pecio@gmail.com> (raw)
In-Reply-To: <27c1fc3a-6122-4658-b5df-567eeb66284f@linux.intel.com>
On Thu, 13 Aug 2026 16:19:13 +0300, Mathias Nyman wrote:
> On 8/13/26 01:56, Michal Pecio wrote:
> > This does make a difference with snd-usb-audio. If I run
> >
> > jackd -d alsa -d hw:... -p 24 -n 2
> >
> > Ring Underrun and Missed Service are reported every now and then,
> > sometimes repeatedly, and it doesn't take long to enter this loop:
> >
> > 1. playback Ring Underrun (xHCI EP state is Running)
> > 2. capture URB unlink (xHCI EP state is Stopped)
> > 3. multiple capture URBs scheduled to the same start_frame before
> > EP state becomes Running
>
> agree, and this needs to be fixed with something like:
>
> - if (GET_EP_CTX_STATE(ep_ctx) != EP_STATE_RUNNING)
> + if (list_empty(&ep_ring->td_list) &&
> + GET_EP_CTX_STATE(ep_ctx) != EP_STATE_RUNNING)
Sure, it fixes 3, but not the "4, 5, goto 1" sequence below.
> > 4. new playback URB is scheduled into a distant past due Running EP
> > 5. 2 uframes later OUT endpoint reports Missed Service for all
> > those misscheduled TDs
> > 6. goto 1
Example:
AFAICT, notify_xrun means userspace didn't submit new playback
samples before the last OUT URB completed. No OUT URBs are left,
endpoint state is Running-Idle, the driver only unlinks IN URBs.
[300299.231743] usb 10-1: notify_xrun 01 from 577
[300299.231749] usb 10-1: Stopping data EP 0x81 (running 1)
[300299.231815] usb 10-1: 2:2 Stop Capture PCM
[300299.231817] usb 10-1: Stopping data EP 0x1 (running 1)
[300299.231819] usb 10-1: 1:3 Stop Playback PCM
Some time later, IN is restarted and scheduled 0x11 uframes ahead.
On second submission we see the "ep state not yet running" race.
[300299.233588] usb 10-1: Starting data EP 0x81 (running 0)
[300299.233616] xhci_hcd 0000:08:00.0: xdebug ep 81 uframe 0f47: scheduling new stream for 0f58
[300299.233628] xhci_hcd 0000:08:00.0: xdebug ep 81 uframe 0f47: pending URBs but not running
[300299.233705] usb 10-1: 12 URBs submitted for EP 0x81
[300299.233710] usb 10-1: 2:2 Start Capture PCM
Then OUT is restarted and mis-scheduled to a random uframe 1018,
far away from IN URBs, because xHCI endpoint state is Running.
[300299.233713] usb 10-1: Starting data EP 0x1 (running 0)
[300299.233722] xhci_hcd 0000:08:00.0: xdebug ep 01 uframe 0f48: running without pending URBs
[300299.233726] xhci_hcd 0000:08:00.0: xdebug ep 01 uframe 0f48: mis-scheduling new stream for 1018
[300299.233739] usb 10-1: 2 URBs submitted for EP 0x1
[300299.233741] usb 10-1: 1:3 Start Playback PCM
And this smells like regression, because the original condition was:
if (list_empty || EP_STATE != RUNNING)
start new stream
so the driver would never *fail* to start a new stream when no URBs
are pending at all, it could only attempt to start a new stream while
URBs are pending, due to the pointless EP_STATE test or BH giveback.
> > Changing the condition from "running endpoint" back to "empty list"
> > breaks this pathological cycle. Experimental patch below.
> >
>
> But this is different from incorrectly assuming a new stream started
> mid stream just because list_empty(&ring->td_list) is true and the
> urb completion workqueue isn't at this instance processing a work
> item belonging to this endpoint.
Yes, this behavior is inconsistent with documentiation and disliked
by one out-of-tree driver developer (probably rightly so), but it's
been this way for over a decade, both in xhci-hcd and ehci-hcd.
And it doesn't affect drivers that resubmit from completion, which is
apparently good enough that people stopped complaining when Alan added
the "or completion is running now on this CPU" hack.
If somebody is very bothered by this, it seems it could be fixed, for
example by counting submitted URBs and having the BH worker decrement
the count after each finished completion.
In fact, I wrote a hack which does this for xhci-hcd (by replacing
the complete callback with a wrapper that performs counting). So
far I found no case where this check makes a difference, but finding
one could become an argument for fixing this in core for real.
Regards,
Michal
next prev parent reply other threads:[~2026-08-13 17:52 UTC|newest]
Thread overview: 78+ 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-12 9:08 ` Michal Pecio
2026-05-13 14:30 ` Mathias Nyman
2026-05-13 14:35 ` [RFT PATCHv2 1/2] xhci: fix frame id calculation and checks for isoc URBs Mathias Nyman
2026-05-13 14:35 ` [RFT PATCHv2 2/2] xhci: Set frame ID field of isoc TRB when starting an isoch stream Mathias Nyman
2026-05-14 21:16 ` [RFT PATCH] xhci: fix frame id calculation for isoc transfer Dylan Robinson
2026-05-14 22:10 ` Dylan Robinson
2026-05-15 4:32 ` Michal Pecio
2026-05-15 18:13 ` Dylan Robinson
2026-05-18 7:13 ` Michal Pecio
2026-05-21 14:20 ` Dylan Robinson
2026-05-21 15:24 ` Mathias Nyman
2026-05-21 15:27 ` [RFT PATCHv3 1/3] xhci: fix frame id calculation and checks for isoc URBs Mathias Nyman
2026-05-21 15:27 ` [RFT PATCHv3 2/3] xhci: Set frame ID field of isoc TRB when starting an isoch stream Mathias Nyman
2026-05-21 15:27 ` [RFT PATCHv3 3/3] xhci: tune urb->start_frame in ring overrun and underrun cases Mathias Nyman
2026-05-26 0:49 ` Dylan Robinson
2026-05-26 12:15 ` Michal Pecio
2026-05-27 20:20 ` Dylan Robinson
2026-08-06 8:17 ` [RFT PATCHv3 1/3] xhci: fix frame id calculation and checks for isoc URBs Michal Pecio
2026-08-06 13:25 ` Mathias Nyman
2026-08-06 22:01 ` Michal Pecio
2026-08-07 0:07 ` Mathias Nyman
2026-08-07 8:26 ` Michal Pecio
2026-08-07 11:10 ` Mathias Nyman
2026-08-07 16:48 ` Alan Stern
2026-08-07 17:30 ` Dylan Robinson
2026-08-07 21:29 ` Michal Pecio
2026-08-10 14:12 ` Mathias Nyman
2026-08-11 22:11 ` Dylan Robinson
2026-08-12 22:56 ` Michal Pecio
2026-08-13 13:19 ` Mathias Nyman
2026-08-13 17:56 ` Michal Pecio [this message]
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
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=20260813195656.132ba1c9.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=mathias.nyman@linux.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