Skip to content

Commit

Permalink
xhci: dbc: Avoid event polling busyloop if pending rx transfers are i…
Browse files Browse the repository at this point in the history
…nactive.

[ Upstream commit cab6393 ]

Event polling delay is set to 0 if there are any pending requests in
either rx or tx requests lists. Checking for pending requests does
not work well for "IN" transfers as the tty driver always queues
requests to the list and TRBs to the ring, preparing to receive data
from the host.

This causes unnecessary busylooping and cpu hogging.

Only set the event polling delay to 0 if there are pending tx "write"
transfers, or if it was less than 10ms since last active data transfer
in any direction.

Cc: Łukasz Bartosik <ukaszb@chromium.org>
Fixes: fb18e5b ("xhci: dbc: poll at different rate depending on data transfer activity")
Cc: stable@vger.kernel.org
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20250505125630.561699-3-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Mathias Nyman authored and Greg Kroah-Hartman committed May 22, 2025
1 parent 651eaaa commit b9e0997
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 16 additions & 3 deletions drivers/usb/host/xhci-dbgcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
{
dma_addr_t deq;
union xhci_trb *evt;
enum evtreturn ret = EVT_DONE;
u32 ctrl, portsc;
bool update_erdp = false;

Expand Down Expand Up @@ -906,6 +907,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
break;
case TRB_TYPE(TRB_TRANSFER):
dbc_handle_xfer_event(dbc, evt);
ret = EVT_XFER_DONE;
break;
default:
break;
Expand All @@ -924,7 +926,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
lo_hi_writeq(deq, &dbc->regs->erdp);
}

return EVT_DONE;
return ret;
}

static void xhci_dbc_handle_events(struct work_struct *work)
Expand All @@ -933,6 +935,7 @@ static void xhci_dbc_handle_events(struct work_struct *work)
struct xhci_dbc *dbc;
unsigned long flags;
unsigned int poll_interval;
unsigned long busypoll_timelimit;

dbc = container_of(to_delayed_work(work), struct xhci_dbc, event_work);
poll_interval = dbc->poll_interval;
Expand All @@ -951,11 +954,21 @@ static void xhci_dbc_handle_events(struct work_struct *work)
dbc->driver->disconnect(dbc);
break;
case EVT_DONE:
/* set fast poll rate if there are pending data transfers */
/*
* Set fast poll rate if there are pending out transfers, or
* a transfer was recently processed
*/
busypoll_timelimit = dbc->xfer_timestamp +
msecs_to_jiffies(DBC_XFER_INACTIVITY_TIMEOUT);

if (!list_empty(&dbc->eps[BULK_OUT].list_pending) ||
!list_empty(&dbc->eps[BULK_IN].list_pending))
time_is_after_jiffies(busypoll_timelimit))
poll_interval = 0;
break;
case EVT_XFER_DONE:
dbc->xfer_timestamp = jiffies;
poll_interval = 0;
break;
default:
dev_info(dbc->dev, "stop handling dbc events\n");
return;
Expand Down
3 changes: 3 additions & 0 deletions drivers/usb/host/xhci-dbgcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct dbc_ep {
#define DBC_WRITE_BUF_SIZE 8192
#define DBC_POLL_INTERVAL_DEFAULT 64 /* milliseconds */
#define DBC_POLL_INTERVAL_MAX 5000 /* milliseconds */
#define DBC_XFER_INACTIVITY_TIMEOUT 10 /* milliseconds */
/*
* Private structure for DbC hardware state:
*/
Expand Down Expand Up @@ -142,6 +143,7 @@ struct xhci_dbc {
enum dbc_state state;
struct delayed_work event_work;
unsigned int poll_interval; /* ms */
unsigned long xfer_timestamp;
unsigned resume_required:1;
struct dbc_ep eps[2];

Expand Down Expand Up @@ -187,6 +189,7 @@ struct dbc_request {
enum evtreturn {
EVT_ERR = -1,
EVT_DONE,
EVT_XFER_DONE,
EVT_GSER,
EVT_DISC,
};
Expand Down

0 comments on commit b9e0997

Please sign in to comment.