linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michał Pecio" <michal.pecio@gmail.com>
To: FPS <mista.tapas@gmx.net>
Cc: linux-usb@vger.kernel.org, mathias.nyman@linux.intel.com
Subject: Re: Misbehaving Alder Lake-N PCH USB 3.2 xHCI Host Controller
Date: Wed, 21 Aug 2024 15:02:33 +0200	[thread overview]
Message-ID: <20240821150233.4f8f66ef@foxbook> (raw)
In-Reply-To: <bb565e29-10e9-4211-a854-fdd9771149b4@gmx.net>

[-- Attachment #1: Type: text/plain, Size: 1835 bytes --]

The reason I suggested aplay is only because it terminates after a
finite time, reducing the amount of output produced.

Today I found that I have similar issues if I plug my audio dongle into
one particular Asmedia USB 3.1 controller. I quickly confirmed your
finding that aplay has different symptoms - audio is slowed down and
distorted, but no errors in dmesg. Same for Jack in playback only mode.
I need to use Jack in full duplex to reproduce your symptoms.

I automatically stop Jack with timeout to control dmesg pollution:
timeout -s KILL 0.1 jackd -d alsa -d hw:3 -p 48 -n 2


The root cause appears to be that there are those "missed service" and
"underrun" errors in the first place. One means that the controller
failed to execute a transfer in its scheduled (micro)frame for internal
reasons or that the transfer was queued too late by software, the other
means that the controller ran out of queued data to send.

I could believe that maybe we are scheduling transfers too late,
causing these problems, but no idea why it only happens on particular
"bad" host controller, while othres are OK even on the same machine.


In my case, I don't observe the sequence of "missed service" followed
by "underrun" and I don't see the subsequent "WARNs" either. However,
I produced a patch which should fix this problem.

I produced a second patch which improves handling of "missed service"
errors, by reporting them faster to the audio driver. My hope was that
*maybe* this would speed up recovery from such condition and reduce the
disruption created, but it frankly doesn't seem to make much difference.


If you would like to play with the patches, I recommend using the
distribution's kernel config (/lib/modules/`uname -r`/build/.config)
because doing 'make menuconfig' from scratch takes a while nowadays.

Regards,
Michal

[-- Attachment #2: 0001-xhci-don-t-skip-on-isoc-overrun-underrun.patch --]
[-- Type: text/x-patch, Size: 802 bytes --]

From 22be329f3276f98f71a485b6d8ed1063246f0efc Mon Sep 17 00:00:00 2001
From: Michal Pecio <michal.pecio@gmail.com>
Date: Wed, 21 Aug 2024 14:14:47 +0200
Subject: [PATCH 1/2] xhci: don't skip on isoc overrun / underrun

---
 drivers/usb/host/xhci-ring.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index a7d343b78557..376bcbe7b6e9 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2978,6 +2978,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
 cleanup:
 		handling_skipped_tds = ep->skip &&
 			trb_comp_code != COMP_MISSED_SERVICE_ERROR &&
+			trb_comp_code != COMP_RING_UNDERRUN &&
+			trb_comp_code != COMP_RING_OVERRUN &&
 			trb_comp_code != COMP_NO_PING_RESPONSE_ERROR;
 
 		/*
-- 
2.43.0


[-- Attachment #3: 0002-xhci-process-isoc-Missed-Service-faster-on-modern-ho.patch --]
[-- Type: text/x-patch, Size: 1824 bytes --]

From adf5386fa4eba9d12f51db74162760b852d90034 Mon Sep 17 00:00:00 2001
From: Michal Pecio <michal.pecio@gmail.com>
Date: Wed, 21 Aug 2024 14:15:30 +0200
Subject: [PATCH 2/2] xhci: process isoc Missed Service faster on modern hosts

---
 drivers/usb/host/xhci-ring.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 376bcbe7b6e9..7b3a466705ab 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -2451,6 +2451,14 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep,
 		if (ep_trb != td->last_trb)
 			td->error_mid_td = true;
 		break;
+	case COMP_MISSED_SERVICE_ERROR:
+		/* seen in hosts conforming to xHCI revision 1.1 and later */
+		xhci_info(xhci, "Handling Missed Service Error\n");
+		frame->status = -EXDEV;
+		sum_trbs_for_length = true;
+		if (ep_trb != td->last_trb)
+			td->error_mid_td = true;
+		break;
 	case COMP_INCOMPATIBLE_DEVICE_ERROR:
 	case COMP_STALL_ERROR:
 		frame->status = -EPROTO;
@@ -2781,6 +2789,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
 		 * short transfer when process the ep_ring next time.
 		 */
 		ep->skip = true;
+		td_num = list_count_nodes(&ep_ring->td_list);
 		xhci_dbg(xhci,
 			 "Miss service interval error for slot %u ep %u, set skip flag\n",
 			 slot_id, ep_index);
@@ -2977,7 +2986,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
 			process_bulk_intr_td(xhci, ep, ep_ring, td, ep_trb, event);
 cleanup:
 		handling_skipped_tds = ep->skip &&
-			trb_comp_code != COMP_MISSED_SERVICE_ERROR &&
+			(trb_comp_code != COMP_MISSED_SERVICE_ERROR || ep_trb_dma) &&
 			trb_comp_code != COMP_RING_UNDERRUN &&
 			trb_comp_code != COMP_RING_OVERRUN &&
 			trb_comp_code != COMP_NO_PING_RESPONSE_ERROR;
-- 
2.43.0


  reply	other threads:[~2024-08-21 13:02 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-18 20:56 Misbehaving Alder Lake-N PCH USB 3.2 xHCI Host Controller FPS
2024-08-19 13:38 ` Mathias Nyman
2024-08-19 20:12   ` FPS
2024-08-20 11:01     ` Michał Pecio
2024-08-20 21:04       ` FPS
2024-08-21 13:02         ` Michał Pecio [this message]
2024-08-21 13:46           ` fps
2024-08-21 14:15           ` Mathias Nyman
2024-08-21 16:49             ` Michał Pecio
2024-08-23 11:43             ` FPS
2024-08-24 21:22               ` FPS
2024-08-25  4:58                 ` Michał Pecio
2024-08-25  7:46                   ` fps
2024-08-25 15:15                     ` Michał Pecio
2024-08-25 20:38                       ` FPS
2024-08-27 10:30                     ` FPS
2024-08-27 11:31                       ` Mathias Nyman
2024-08-27 12:18                         ` FPS
2024-08-27 13:49                           ` Mathias Nyman
2024-08-27 12:37                 ` Mathias Nyman
2024-08-28  9:15                   ` FPS
2024-08-27 12:38               ` Mathias Nyman
2024-08-27 20:49                 ` FPS

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=20240821150233.4f8f66ef@foxbook \
    --to=michal.pecio@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=mista.tapas@gmx.net \
    /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;
as well as URLs for NNTP newsgroup(s).