aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/ehci-q.c
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2012-07-11 11:22:53 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-16 19:56:47 -0400
commit32830f207691176234b4c4dd17f0d7ab6d87d94b (patch)
tree4b352a92dfc720418288c541d87e93594f97f859 /drivers/usb/host/ehci-q.c
parent3c273a056bf46167f0a1309c2ba72282a17d2541 (diff)
USB: EHCI: use hrtimer for unlinking empty async QHs
This patch (as1583) changes ehci-hcd to use an hrtimer event for unlinking empty (unused) async QHs instead of using a kernel timer. The check for empty QHs is moved to a new routine, where it doesn't require going through an entire scan of both the async and periodic schedules. And it can unlink multiple QHs at once, unlike the current code. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/host/ehci-q.c')
-rw-r--r--drivers/usb/host/ehci-q.c78
1 files changed, 53 insertions, 25 deletions
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 181832921c53..bae931767825 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -1205,7 +1205,7 @@ static void start_iaa_cycle(struct ehci_hcd *ehci, bool nested)
1205 end_unlink_async(ehci); 1205 end_unlink_async(ehci);
1206 1206
1207 /* Otherwise start a new IAA cycle */ 1207 /* Otherwise start a new IAA cycle */
1208 } else { 1208 } else if (likely(ehci->rh_state == EHCI_RH_RUNNING)) {
1209 /* Make sure the unlinks are all visible to the hardware */ 1209 /* Make sure the unlinks are all visible to the hardware */
1210 wmb(); 1210 wmb();
1211 1211
@@ -1253,6 +1253,39 @@ static void end_unlink_async(struct ehci_hcd *ehci)
1253 } 1253 }
1254} 1254}
1255 1255
1256static void unlink_empty_async(struct ehci_hcd *ehci)
1257{
1258 struct ehci_qh *qh, *next;
1259 bool stopped = (ehci->rh_state < EHCI_RH_RUNNING);
1260 bool check_unlinks_later = false;
1261
1262 /* Unlink all the async QHs that have been empty for a timer cycle */
1263 next = ehci->async->qh_next.qh;
1264 while (next) {
1265 qh = next;
1266 next = qh->qh_next.qh;
1267
1268 if (list_empty(&qh->qtd_list) &&
1269 qh->qh_state == QH_STATE_LINKED) {
1270 if (!stopped && qh->unlink_cycle ==
1271 ehci->async_unlink_cycle)
1272 check_unlinks_later = true;
1273 else
1274 single_unlink_async(ehci, qh);
1275 }
1276 }
1277
1278 /* Start a new IAA cycle if any QHs are waiting for it */
1279 if (ehci->async_unlink)
1280 start_iaa_cycle(ehci, false);
1281
1282 /* QHs that haven't been empty for long enough will be handled later */
1283 if (check_unlinks_later) {
1284 ehci_enable_event(ehci, EHCI_HRTIMER_ASYNC_UNLINKS, true);
1285 ++ehci->async_unlink_cycle;
1286 }
1287}
1288
1256/* makes sure the async qh will become idle */ 1289/* makes sure the async qh will become idle */
1257/* caller must own ehci->lock */ 1290/* caller must own ehci->lock */
1258 1291
@@ -1277,12 +1310,8 @@ static void start_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh)
1277 1310
1278static void scan_async (struct ehci_hcd *ehci) 1311static void scan_async (struct ehci_hcd *ehci)
1279{ 1312{
1280 bool stopped;
1281 struct ehci_qh *qh; 1313 struct ehci_qh *qh;
1282 enum ehci_timer_action action = TIMER_IO_WATCHDOG; 1314 bool check_unlinks_later = false;
1283
1284 timer_action_done (ehci, TIMER_ASYNC_SHRINK);
1285 stopped = (ehci->rh_state < EHCI_RH_RUNNING);
1286 1315
1287 ehci->qh_scan_next = ehci->async->qh_next.qh; 1316 ehci->qh_scan_next = ehci->async->qh_next.qh;
1288 while (ehci->qh_scan_next) { 1317 while (ehci->qh_scan_next) {
@@ -1301,28 +1330,27 @@ static void scan_async (struct ehci_hcd *ehci)
1301 * in single_unlink_async(). 1330 * in single_unlink_async().
1302 */ 1331 */
1303 temp = qh_completions(ehci, qh); 1332 temp = qh_completions(ehci, qh);
1304 if (qh->needs_rescan) 1333 if (qh->needs_rescan) {
1305 start_unlink_async(ehci, qh); 1334 start_unlink_async(ehci, qh);
1306 qh->unlink_time = jiffies + EHCI_SHRINK_JIFFIES; 1335 } else if (list_empty(&qh->qtd_list)
1307 if (temp != 0) 1336 && qh->qh_state == QH_STATE_LINKED) {
1337 qh->unlink_cycle = ehci->async_unlink_cycle;
1338 check_unlinks_later = true;
1339 } else if (temp != 0)
1308 goto rescan; 1340 goto rescan;
1309 } 1341 }
1342 }
1310 1343
1311 /* unlink idle entries, reducing DMA usage as well 1344 /*
1312 * as HCD schedule-scanning costs. delay for any qh 1345 * Unlink empty entries, reducing DMA usage as well
1313 * we just scanned, there's a not-unusual case that it 1346 * as HCD schedule-scanning costs. Delay for any qh
1314 * doesn't stay idle for long. 1347 * we just scanned, there's a not-unusual case that it
1315 * (plus, avoids some kind of re-activation race.) 1348 * doesn't stay idle for long.
1316 */ 1349 */
1317 if (list_empty(&qh->qtd_list) 1350 if (check_unlinks_later && ehci->rh_state == EHCI_RH_RUNNING &&
1318 && qh->qh_state == QH_STATE_LINKED) { 1351 !(ehci->enabled_hrtimer_events &
1319 if (!ehci->async_unlink && (stopped || 1352 BIT(EHCI_HRTIMER_ASYNC_UNLINKS))) {
1320 time_after_eq(jiffies, qh->unlink_time))) 1353 ehci_enable_event(ehci, EHCI_HRTIMER_ASYNC_UNLINKS, true);
1321 start_unlink_async(ehci, qh); 1354 ++ehci->async_unlink_cycle;
1322 else
1323 action = TIMER_ASYNC_SHRINK;
1324 }
1325 } 1355 }
1326 if (action == TIMER_ASYNC_SHRINK)
1327 timer_action (ehci, TIMER_ASYNC_SHRINK);
1328} 1356}