Linux USB
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: Michal Pecio <michal.pecio@gmail.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: Fri, 7 Aug 2026 03:07:08 +0300	[thread overview]
Message-ID: <e3c66325-0291-40f9-a87e-1bb337ce4427@linux.intel.com> (raw)
In-Reply-To: <20260807000155.2960c741.michal.pecio@gmail.com>

On 8/7/26 01:01, Michal Pecio wrote:
> On Thu, 6 Aug 2026 16:25:15 +0300, Mathias Nyman wrote:
>> On 8/6/26 11:17, Michal Pecio wrote:
>>> Besides initialization, it's made -1 if and only if xHCI endpoint
>>> state isn't Running at the time of submission. This effectively
>>> means that to start a new "isoch data flow" aka "stream", class
>>> driver must unlink the last remaining URB of the previous flow. If
>>> the driver doesn't unlink (or tries too late), the endpoint goes
>>> Running-Idle.
>>
>> If class driver doesn't unlink remaining urbs then list won't be empty
>> and you have the exact same situation.
> 
> Obviously not, it can simply stop resubmitting and wait. Or there may
> be no URBs left to unlink at all, when recovering from ring underrun.
> 
> Then HW endpoint state will still be Running, not Stopped, and new
> URBs will be scheduled into the past, doomed to complete with -EXDEV.
> 

Isn't this exactly what we want?

Lets take the underrun case. Audio playback as an relatable example.

If class driver fails to queue more URBs in time mid audio stream then
the ring will trigger underrun. td_list will be empty but hardware
ep ctx will still show the more correct "running" state.

A list empty check would incorrectly assume a new stream started when
the next late URB is queued. It will be given a new future frame_id,
so instead of dropping the data we will delay playback mid stream.
Not the intention with isoc transfers.

With the hardware ep ctx check we will set the frame_id of the late URB to
point to the past, to the real time it was supposed to be played back.
xHC hardware will then trigger a 'missed service event' for that TD as it
was incapable of playing it at the correct time, and then fast forward with MSE
until it finds a TD with a frame_id it can play, and play at the correct timeslot.
Here we lost the late data but playback stays in sync, as isoc transfer are
intended to work.


>>> Moreover, we know that Endpoint Context state is one of the least
>>> trustworthy piecese of information, and notably it may remain
>>> Stopped for a while after a doorbell ring. This means that multiple
>>> URBs may be scheduled as new "streams" and get assigned the same
>>> start_frame.
>>
>> Ok, we basically have different opinion on how to identify when a new
>> isoc data flow starts. You would rely on checking if list is empty,
>> and I'm looking at harware endpoint state.
> 
> I would rely on SW state, sure.
> 
> 1. The check implemented here isn't even right - see above.
> 2. Bogosity of xHCI HW is well known - see below.
> 3. For consistency with other HCDs, which use similar SW state.
> 
>> I don't trust the 'empty list check' as I'm not convinced there can't
>> be cases in software where list is empty even mid isoc data flow.
>> Something like extreme long interval and BH delay in class driver
>> receiving URB.
> 
> Other HCDs implement a rule that resubmission from completion callback
> on the same endpoint always counts as continuation of the stream, to
> work around BH. This seems to have worked so far and is trivial to do,
> somebody submitted a patch earlier this year.
> 
>> We can add empty list check as well in some places.
>> For example xhci_isoc_tx_prepare() could benefit from having both
>> empty list and hw endpoint state check when setting next_uframe = -1;
> 
> The HW state check is bogus. Before removing it I patched to log when
> URBs are pending but HW state is still Stopped. It happens sometimes.
> 
> The only robust solution is to completely disregard EP Context state.
> xHCI 4.8.3 doesn't promise much and outright advises SW to track actual
> HW state itself, based on issued commands etc.
> 

Disagree, see underrun example above.

But we can add an empty list check in addition to checking hw ep ctx state.
This should cover both empty list mid stream cases, and slow ep ctx
state change by HW.

That's a one line change during during 7.3 rc cycle

> The Stopped => Running transition is only guaranteed to become visible
> to SW when the first service interval passes and an event is posted.
> 
>> This patch is tested, solves an existing issue, and moves the
>> frame_id code in the right direction.
> 
> To be fair, it may be that in practice it fixes more than it breaks,
> but it also strays away from documented USB subsystem rules and looks
> half-baked, so I was surprised to see it queued in such state.

It's been a year, nobody else cooked anything, it improves current situation.
And honestly, it's not that bad.
Real disagreement is one line regarding how we check if we are mid stream.

Thanks
Mathias


  reply	other threads:[~2026-08-07  0:07 UTC|newest]

Thread overview: 74+ 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 [this message]
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-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=e3c66325-0291-40f9-a87e-1bb337ce4427@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=dylan_robinson@motu.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=michal.pecio@gmail.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