Skip to content

Commit 3aa367e

Browse files
matnymangregkh
authored andcommitted
xhci: dbc: Avoid event polling busyloop if pending rx transfers are inactive.
[ 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> Stable-dep-of: f3d12ec ("xhci: dbc: fix bogus 1024 byte prefix if ttyDBC read races with stall event") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent dae8555 commit 3aa367e

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

drivers/usb/host/xhci-dbgcap.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
855855
{
856856
dma_addr_t deq;
857857
union xhci_trb *evt;
858+
enum evtreturn ret = EVT_DONE;
858859
u32 ctrl, portsc;
859860
bool update_erdp = false;
860861

@@ -939,6 +940,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
939940
break;
940941
case TRB_TYPE(TRB_TRANSFER):
941942
dbc_handle_xfer_event(dbc, evt);
943+
ret = EVT_XFER_DONE;
942944
break;
943945
default:
944946
break;
@@ -957,7 +959,7 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
957959
lo_hi_writeq(deq, &dbc->regs->erdp);
958960
}
959961

960-
return EVT_DONE;
962+
return ret;
961963
}
962964

963965
static void xhci_dbc_handle_events(struct work_struct *work)
@@ -966,6 +968,7 @@ static void xhci_dbc_handle_events(struct work_struct *work)
966968
struct xhci_dbc *dbc;
967969
unsigned long flags;
968970
unsigned int poll_interval;
971+
unsigned long busypoll_timelimit;
969972

970973
dbc = container_of(to_delayed_work(work), struct xhci_dbc, event_work);
971974
poll_interval = dbc->poll_interval;
@@ -984,11 +987,21 @@ static void xhci_dbc_handle_events(struct work_struct *work)
984987
dbc->driver->disconnect(dbc);
985988
break;
986989
case EVT_DONE:
987-
/* set fast poll rate if there are pending data transfers */
990+
/*
991+
* Set fast poll rate if there are pending out transfers, or
992+
* a transfer was recently processed
993+
*/
994+
busypoll_timelimit = dbc->xfer_timestamp +
995+
msecs_to_jiffies(DBC_XFER_INACTIVITY_TIMEOUT);
996+
988997
if (!list_empty(&dbc->eps[BULK_OUT].list_pending) ||
989-
!list_empty(&dbc->eps[BULK_IN].list_pending))
998+
time_is_after_jiffies(busypoll_timelimit))
990999
poll_interval = 0;
9911000
break;
1001+
case EVT_XFER_DONE:
1002+
dbc->xfer_timestamp = jiffies;
1003+
poll_interval = 0;
1004+
break;
9921005
default:
9931006
dev_info(dbc->dev, "stop handling dbc events\n");
9941007
return;

drivers/usb/host/xhci-dbgcap.h

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

@@ -186,6 +188,7 @@ struct dbc_request {
186188
enum evtreturn {
187189
EVT_ERR = -1,
188190
EVT_DONE,
191+
EVT_XFER_DONE,
189192
EVT_GSER,
190193
EVT_DISC,
191194
};

0 commit comments

Comments
 (0)