Skip to content

Commit cab6393

Browse files
matnymangregkh
authored andcommitted
xhci: dbc: Avoid event polling busyloop if pending rx transfers are inactive.
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>
1 parent 6328bdc commit cab6393

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

drivers/usb/host/xhci-dbgcap.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
823823
{
824824
dma_addr_t deq;
825825
union xhci_trb *evt;
826+
enum evtreturn ret = EVT_DONE;
826827
u32 ctrl, portsc;
827828
bool update_erdp = false;
828829

@@ -909,6 +910,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
909910
break;
910911
case TRB_TYPE(TRB_TRANSFER):
911912
dbc_handle_xfer_event(dbc, evt);
913+
ret = EVT_XFER_DONE;
912914
break;
913915
default:
914916
break;
@@ -927,7 +929,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
927929
lo_hi_writeq(deq, &dbc->regs->erdp);
928930
}
929931

930-
return EVT_DONE;
932+
return ret;
931933
}
932934

933935
static void xhci_dbc_handle_events(struct work_struct *work)
@@ -936,6 +938,7 @@ static void xhci_dbc_handle_events(struct work_struct *work)
936938
struct xhci_dbc *dbc;
937939
unsigned long flags;
938940
unsigned int poll_interval;
941+
unsigned long busypoll_timelimit;
939942

940943
dbc = container_of(to_delayed_work(work), struct xhci_dbc, event_work);
941944
poll_interval = dbc->poll_interval;
@@ -954,11 +957,21 @@ static void xhci_dbc_handle_events(struct work_struct *work)
954957
dbc->driver->disconnect(dbc);
955958
break;
956959
case EVT_DONE:
957-
/* set fast poll rate if there are pending data transfers */
960+
/*
961+
* Set fast poll rate if there are pending out transfers, or
962+
* a transfer was recently processed
963+
*/
964+
busypoll_timelimit = dbc->xfer_timestamp +
965+
msecs_to_jiffies(DBC_XFER_INACTIVITY_TIMEOUT);
966+
958967
if (!list_empty(&dbc->eps[BULK_OUT].list_pending) ||
959-
!list_empty(&dbc->eps[BULK_IN].list_pending))
968+
time_is_after_jiffies(busypoll_timelimit))
960969
poll_interval = 0;
961970
break;
971+
case EVT_XFER_DONE:
972+
dbc->xfer_timestamp = jiffies;
973+
poll_interval = 0;
974+
break;
962975
default:
963976
dev_info(dbc->dev, "stop handling dbc events\n");
964977
return;

drivers/usb/host/xhci-dbgcap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct dbc_ep {
9696
#define DBC_WRITE_BUF_SIZE 8192
9797
#define DBC_POLL_INTERVAL_DEFAULT 64 /* milliseconds */
9898
#define DBC_POLL_INTERVAL_MAX 5000 /* milliseconds */
99+
#define DBC_XFER_INACTIVITY_TIMEOUT 10 /* milliseconds */
99100
/*
100101
* Private structure for DbC hardware state:
101102
*/
@@ -142,6 +143,7 @@ struct xhci_dbc {
142143
enum dbc_state state;
143144
struct delayed_work event_work;
144145
unsigned int poll_interval; /* ms */
146+
unsigned long xfer_timestamp;
145147
unsigned resume_required:1;
146148
struct dbc_ep eps[2];
147149

@@ -187,6 +189,7 @@ struct dbc_request {
187189
enum evtreturn {
188190
EVT_ERR = -1,
189191
EVT_DONE,
192+
EVT_XFER_DONE,
190193
EVT_GSER,
191194
EVT_DISC,
192195
};

0 commit comments

Comments
 (0)