From: "Neronin, Niklas" <niklas.neronin@linux.intel.com>
To: raoxu <raoxu@uniontech.com>
Cc: gregkh@linuxfoundation.org, kenny@panix.com,
linux-usb@vger.kernel.org, mathias.nyman@linux.intel.com,
michal.pecio@gmail.com, zhanjun@uniontech.com
Subject: Re: [PATCH v11 2/2] usb: xhci: enable secondary interrupters and route transfers per slot
Date: Tue, 27 Jan 2026 14:57:00 +0200 [thread overview]
Message-ID: <8deab843-8ff5-4925-93a9-31dcbdd0720e@linux.intel.com> (raw)
In-Reply-To: <FF69E7CC57E8D606+20260127023900.2145949-1-raoxu@uniontech.com>
On 27/01/2026 4.39, raoxu wrote:
> From: Xu Rao <raoxu@uniontech.com>
>
> Some xHCI hosts expose multiple MSI/MSI-X vectors and support multiple
> interrupters with independent event rings, but Linux commonly routes all
> transfer completions through interrupter 0.
>
> This is not about increasing USB link throughput, but about avoiding a
> driver-imposed single hot spot. On hosts that already provide multiple
> MSI/MSI-X vectors and independent event rings, routing all completions
> through interrupter 0 creates unnecessary contention (serialized event
> handling/locks and coupled moderation), increasing CPU cost and tail
> latency under many active devices/endpoints. Using secondary interrupters
> simply matches the hardware's design, similar in spirit to merged
> xHCI-sideband work: exploit available parallel paths rather than
> funneling all events through one.
>
> Allocate a small capped set of secondary interrupters in xhci_mem_init()
> (MAX_SECONDARY_INTRNUM, default 4) and request up to the matching number
> of IRQ vectors (bounded by what PCI core provides). Dispatch each vector
> to its interrupter via the per-vector irq_ctx.
>
> Route transfers per USB device (slot) by assigning vdev->interrupter at
> device allocation time and programming the interrupter target (slot
> context + TRB_INTR_TARGET) from that selection, so completions land on the
> selected event ring. Drain a slot's secondary event ring at selected
> command completion boundaries to reduce late-event artifacts when teardown
> happens on interrupter 0.
>
> Signed-off-by: Xu Rao <raoxu@uniontech.com>
>
...
> diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
> index b3efd6d8fd9c..4ff3e29070b1 100644
> --- a/drivers/usb/host/xhci-pci.c
> +++ b/drivers/usb/host/xhci-pci.c
> @@ -150,6 +150,8 @@ static int xhci_try_enable_msi(struct usb_hcd *hcd)
> struct pci_dev *pdev = to_pci_dev(hcd->self.controller);
> struct xhci_hcd *xhci = hcd_to_xhci(hcd);
> int ret;
> + unsigned int irqs_num;
> + int i;
> struct xhci_irq_ctx *ctx;
>
> /*
> @@ -173,7 +175,7 @@ static int xhci_try_enable_msi(struct usb_hcd *hcd)
>
> /* TODO: Check with MSI Soc for sysdev */
> xhci->nvecs = pci_alloc_irq_vectors(pdev, 1, xhci->nvecs,
> - PCI_IRQ_MSIX | PCI_IRQ_MSI);
> + PCI_IRQ_MSIX | PCI_IRQ_MSI | PCI_IRQ_AFFINITY);
> if (xhci->nvecs < 0) {
> xhci_dbg_trace(xhci, trace_xhci_dbg_init,
> "failed to allocate IRQ vectors");
> @@ -183,14 +185,30 @@ static int xhci_try_enable_msi(struct usb_hcd *hcd)
> memset(xhci->irq_ctx, 0, sizeof(xhci->irq_ctx));
> xhci->irqs_enabled = 0;
>
> - ctx = &xhci->irq_ctx[0];
> - ctx->hcd = hcd;
> - ctx->intr_num = 0;
> - ret = request_irq(pci_irq_vector(pdev, 0), xhci_msi_irq, 0, "xhci_hcd", ctx);
> - if (ret)
> - goto free_irq_vectors;
> + /*
> + * Request up to 1 + secondary_irqs_alloc vectors (vector 0 + secondary),
> + * limited by what PCI core actually allocated.
> + */
> + irqs_num = min_t(unsigned int,
> + (unsigned int)xhci->nvecs,
> + (unsigned int)(1 + xhci->secondary_irqs_alloc));
> +
> + for (i = 0; i < irqs_num; i++) {
> + ctx = &xhci->irq_ctx[i];
> + ctx->hcd = hcd;
> + ctx->intr_num = i;
> + ret = request_irq(pci_irq_vector(pdev, i), xhci_msi_irq, 0,
> + "xhci_hcd", ctx);
> + if (ret) {
> + while (--i >= 0)
> + free_irq(pci_irq_vector(pdev, i), &xhci->irq_ctx[i]);
> + xhci->irqs_enabled = 0;
> + memset(xhci->irq_ctx, 0, sizeof(xhci->irq_ctx));
> + goto free_irq_vectors;
Won't this 'goto' end up freeing all IRQ vectors?
Now, if requesting an IRQ for a secondary interrupter fails,
the xhci driver will then fall back to using the legacy IRQ?
> + }
> + xhci->irqs_enabled++;
> + }
Maybe it would be useful to add a debug message here, for example:
xhci_dbg_trace(xhci, trace_xhci_dbg_init, "enabled %u %s interrupters",
xhci->irqs_enabled, pdev->msix_enabled ? "MSI-X" : "MSI");
I'm not sure whether this information is already reported elsewhere.
Thanks,
Niklas
next prev parent reply other threads:[~2026-01-27 12:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-27 2:34 [PATCH v11 0/2] usb: xhci: route device to secondary interrupters raoxu
2026-01-27 2:38 ` [PATCH v11 1/2] usb: xhci: refactor IRQ/interrupter plumbing for multi-vector support raoxu
2026-01-27 12:54 ` Neronin, Niklas
2026-01-27 2:39 ` [PATCH v11 2/2] usb: xhci: enable secondary interrupters and route transfers per slot raoxu
2026-01-27 7:39 ` Greg KH
2026-01-27 10:55 ` raoxu
2026-01-27 11:04 ` Greg KH
2026-01-28 8:09 ` raoxu
2026-01-28 8:35 ` Greg KH
2026-01-29 14:22 ` Michal Pecio
2026-01-29 19:43 ` Mathias Nyman
2026-01-29 20:03 ` Kenneth Crudup
2026-01-30 3:48 ` raoxu
2026-01-30 5:34 ` Greg KH
2026-02-02 13:29 ` [PATCH v12 " raoxu
2026-01-27 12:57 ` Neronin, Niklas [this message]
2026-01-27 7:33 ` [PATCH v11 0/2] usb: xhci: route device to secondary interrupters Greg KH
2026-01-28 13:19 ` Kenneth Crudup
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=8deab843-8ff5-4925-93a9-31dcbdd0720e@linux.intel.com \
--to=niklas.neronin@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=kenny@panix.com \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@linux.intel.com \
--cc=michal.pecio@gmail.com \
--cc=raoxu@uniontech.com \
--cc=zhanjun@uniontech.com \
/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