Skip to content

Commit d5088f6

Browse files
matnymanjfvogel
authored andcommitted
xhci: dbc: Avoid event polling busyloop if pending rx transfers are inactive.
[ Upstream commit cab63934c33b12c0d1e9f4da7450928057f2c142 ] 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 <[email protected]> Fixes: fb18e5b ("xhci: dbc: poll at different rate depending on data transfer activity") Cc: [email protected] Signed-off-by: Mathias Nyman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit b9e0997f2e8477ec7f3e9d9898fd16c56e0eb541) Signed-off-by: Jack Vogel <[email protected]>
1 parent f23e7c4 commit d5088f6

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
@@ -822,6 +822,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
822822
{
823823
dma_addr_t deq;
824824
union xhci_trb *evt;
825+
enum evtreturn ret = EVT_DONE;
825826
u32 ctrl, portsc;
826827
bool update_erdp = false;
827828

@@ -906,6 +907,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
906907
break;
907908
case TRB_TYPE(TRB_TRANSFER):
908909
dbc_handle_xfer_event(dbc, evt);
910+
ret = EVT_XFER_DONE;
909911
break;
910912
default:
911913
break;
@@ -924,7 +926,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
924926
lo_hi_writeq(deq, &dbc->regs->erdp);
925927
}
926928

927-
return EVT_DONE;
929+
return ret;
928930
}
929931

930932
static void xhci_dbc_handle_events(struct work_struct *work)
@@ -933,6 +935,7 @@ static void xhci_dbc_handle_events(struct work_struct *work)
933935
struct xhci_dbc *dbc;
934936
unsigned long flags;
935937
unsigned int poll_interval;
938+
unsigned long busypoll_timelimit;
936939

937940
dbc = container_of(to_delayed_work(work), struct xhci_dbc, event_work);
938941
poll_interval = dbc->poll_interval;
@@ -951,11 +954,21 @@ static void xhci_dbc_handle_events(struct work_struct *work)
951954
dbc->driver->disconnect(dbc);
952955
break;
953956
case EVT_DONE:
954-
/* set fast poll rate if there are pending data transfers */
957+
/*
958+
* Set fast poll rate if there are pending out transfers, or
959+
* a transfer was recently processed
960+
*/
961+
busypoll_timelimit = dbc->xfer_timestamp +
962+
msecs_to_jiffies(DBC_XFER_INACTIVITY_TIMEOUT);
963+
955964
if (!list_empty(&dbc->eps[BULK_OUT].list_pending) ||
956-
!list_empty(&dbc->eps[BULK_IN].list_pending))
965+
time_is_after_jiffies(busypoll_timelimit))
957966
poll_interval = 0;
958967
break;
968+
case EVT_XFER_DONE:
969+
dbc->xfer_timestamp = jiffies;
970+
poll_interval = 0;
971+
break;
959972
default:
960973
dev_info(dbc->dev, "stop handling dbc events\n");
961974
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)