diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2010-07-14 11:03:36 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-08-10 17:35:40 -0400 |
commit | bccbefaae050186bed3bcc74b1fd1a9b8c6710b2 (patch) | |
tree | 26f1da2850c372bd78e733d7b14006d86abb5b0d | |
parent | ae68a83bdc1971cb02fefc7a686ba6d077065e71 (diff) |
USB: EHCI: simplify remainder computations
This patch (as1406) adds a micro-optimization to ehci-hcd's scheduling
code. Instead of computing remainders with respect to the schedule
length, use bitwise-and (which is quicker). We know that the schedule
length will always be a power of two, but the compiler doesn't have
this information.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
CC: David Brownell <david-b@pacbell.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/usb/host/ehci-sched.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c index efadced4ae67..27dd841b9aa2 100644 --- a/drivers/usb/host/ehci-sched.c +++ b/drivers/usb/host/ehci-sched.c | |||
@@ -1417,7 +1417,7 @@ iso_stream_schedule ( | |||
1417 | if (!stream->highspeed) | 1417 | if (!stream->highspeed) |
1418 | period <<= 3; | 1418 | period <<= 3; |
1419 | 1419 | ||
1420 | now = ehci_readl(ehci, &ehci->regs->frame_index) % mod; | 1420 | now = ehci_readl(ehci, &ehci->regs->frame_index) & (mod - 1); |
1421 | 1421 | ||
1422 | /* Typical case: reuse current schedule, stream is still active. | 1422 | /* Typical case: reuse current schedule, stream is still active. |
1423 | * Hopefully there are no gaps from the host falling behind | 1423 | * Hopefully there are no gaps from the host falling behind |
@@ -1461,7 +1461,7 @@ iso_stream_schedule ( | |||
1461 | * jump until after the queue is primed. | 1461 | * jump until after the queue is primed. |
1462 | */ | 1462 | */ |
1463 | start = SCHEDULE_SLOP + (now & ~0x07); | 1463 | start = SCHEDULE_SLOP + (now & ~0x07); |
1464 | start %= mod; | 1464 | start &= mod - 1; |
1465 | stream->next_uframe = start; | 1465 | stream->next_uframe = start; |
1466 | 1466 | ||
1467 | /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */ | 1467 | /* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */ |
@@ -1483,7 +1483,7 @@ iso_stream_schedule ( | |||
1483 | 1483 | ||
1484 | /* schedule it here if there's enough bandwidth */ | 1484 | /* schedule it here if there's enough bandwidth */ |
1485 | if (enough_space) { | 1485 | if (enough_space) { |
1486 | stream->next_uframe = start % mod; | 1486 | stream->next_uframe = start & (mod - 1); |
1487 | goto ready; | 1487 | goto ready; |
1488 | } | 1488 | } |
1489 | } | 1489 | } |
@@ -1599,7 +1599,7 @@ itd_link_urb ( | |||
1599 | struct ehci_iso_sched *iso_sched = urb->hcpriv; | 1599 | struct ehci_iso_sched *iso_sched = urb->hcpriv; |
1600 | struct ehci_itd *itd; | 1600 | struct ehci_itd *itd; |
1601 | 1601 | ||
1602 | next_uframe = stream->next_uframe % mod; | 1602 | next_uframe = stream->next_uframe & (mod - 1); |
1603 | 1603 | ||
1604 | if (unlikely (list_empty(&stream->td_list))) { | 1604 | if (unlikely (list_empty(&stream->td_list))) { |
1605 | ehci_to_hcd(ehci)->self.bandwidth_allocated | 1605 | ehci_to_hcd(ehci)->self.bandwidth_allocated |
@@ -1637,13 +1637,13 @@ itd_link_urb ( | |||
1637 | 1637 | ||
1638 | next_uframe += stream->interval; | 1638 | next_uframe += stream->interval; |
1639 | stream->depth += stream->interval; | 1639 | stream->depth += stream->interval; |
1640 | next_uframe %= mod; | 1640 | next_uframe &= mod - 1; |
1641 | packet++; | 1641 | packet++; |
1642 | 1642 | ||
1643 | /* link completed itds into the schedule */ | 1643 | /* link completed itds into the schedule */ |
1644 | if (((next_uframe >> 3) != frame) | 1644 | if (((next_uframe >> 3) != frame) |
1645 | || packet == urb->number_of_packets) { | 1645 | || packet == urb->number_of_packets) { |
1646 | itd_link (ehci, frame % ehci->periodic_size, itd); | 1646 | itd_link(ehci, frame & (ehci->periodic_size - 1), itd); |
1647 | itd = NULL; | 1647 | itd = NULL; |
1648 | } | 1648 | } |
1649 | } | 1649 | } |
@@ -2020,7 +2020,7 @@ sitd_link_urb ( | |||
2020 | "sched devp %s ep%d%s-iso [%d] %dms/%04x\n", | 2020 | "sched devp %s ep%d%s-iso [%d] %dms/%04x\n", |
2021 | urb->dev->devpath, stream->bEndpointAddress & 0x0f, | 2021 | urb->dev->devpath, stream->bEndpointAddress & 0x0f, |
2022 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", | 2022 | (stream->bEndpointAddress & USB_DIR_IN) ? "in" : "out", |
2023 | (next_uframe >> 3) % ehci->periodic_size, | 2023 | (next_uframe >> 3) & (ehci->periodic_size - 1), |
2024 | stream->interval, hc32_to_cpu(ehci, stream->splits)); | 2024 | stream->interval, hc32_to_cpu(ehci, stream->splits)); |
2025 | stream->start = jiffies; | 2025 | stream->start = jiffies; |
2026 | } | 2026 | } |
@@ -2043,13 +2043,13 @@ sitd_link_urb ( | |||
2043 | sitd->urb = urb; | 2043 | sitd->urb = urb; |
2044 | 2044 | ||
2045 | sitd_patch(ehci, stream, sitd, sched, packet); | 2045 | sitd_patch(ehci, stream, sitd, sched, packet); |
2046 | sitd_link (ehci, (next_uframe >> 3) % ehci->periodic_size, | 2046 | sitd_link(ehci, (next_uframe >> 3) & (ehci->periodic_size - 1), |
2047 | sitd); | 2047 | sitd); |
2048 | 2048 | ||
2049 | next_uframe += stream->interval << 3; | 2049 | next_uframe += stream->interval << 3; |
2050 | stream->depth += stream->interval << 3; | 2050 | stream->depth += stream->interval << 3; |
2051 | } | 2051 | } |
2052 | stream->next_uframe = next_uframe % mod; | 2052 | stream->next_uframe = next_uframe & (mod - 1); |
2053 | 2053 | ||
2054 | /* don't need that schedule data any more */ | 2054 | /* don't need that schedule data any more */ |
2055 | iso_sched_free (stream, sched); | 2055 | iso_sched_free (stream, sched); |
@@ -2258,7 +2258,7 @@ scan_periodic (struct ehci_hcd *ehci) | |||
2258 | now_uframe = ehci->next_uframe; | 2258 | now_uframe = ehci->next_uframe; |
2259 | if (HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { | 2259 | if (HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) { |
2260 | clock = ehci_readl(ehci, &ehci->regs->frame_index); | 2260 | clock = ehci_readl(ehci, &ehci->regs->frame_index); |
2261 | clock_frame = (clock >> 3) % ehci->periodic_size; | 2261 | clock_frame = (clock >> 3) & (ehci->periodic_size - 1); |
2262 | } else { | 2262 | } else { |
2263 | clock = now_uframe + mod - 1; | 2263 | clock = now_uframe + mod - 1; |
2264 | clock_frame = -1; | 2264 | clock_frame = -1; |
@@ -2267,7 +2267,7 @@ scan_periodic (struct ehci_hcd *ehci) | |||
2267 | free_cached_lists(ehci); | 2267 | free_cached_lists(ehci); |
2268 | ehci->clock_frame = clock_frame; | 2268 | ehci->clock_frame = clock_frame; |
2269 | } | 2269 | } |
2270 | clock %= mod; | 2270 | clock &= mod - 1; |
2271 | clock_frame = clock >> 3; | 2271 | clock_frame = clock >> 3; |
2272 | 2272 | ||
2273 | for (;;) { | 2273 | for (;;) { |
@@ -2356,7 +2356,7 @@ restart: | |||
2356 | * frame is current. | 2356 | * frame is current. |
2357 | */ | 2357 | */ |
2358 | if (((frame == clock_frame) || | 2358 | if (((frame == clock_frame) || |
2359 | (((frame + 1) % ehci->periodic_size) | 2359 | (((frame + 1) & (ehci->periodic_size - 1)) |
2360 | == clock_frame)) | 2360 | == clock_frame)) |
2361 | && live | 2361 | && live |
2362 | && (q.sitd->hw_results & | 2362 | && (q.sitd->hw_results & |
@@ -2423,7 +2423,8 @@ restart: | |||
2423 | || ehci->periodic_sched == 0) | 2423 | || ehci->periodic_sched == 0) |
2424 | break; | 2424 | break; |
2425 | ehci->next_uframe = now_uframe; | 2425 | ehci->next_uframe = now_uframe; |
2426 | now = ehci_readl(ehci, &ehci->regs->frame_index) % mod; | 2426 | now = ehci_readl(ehci, &ehci->regs->frame_index) & |
2427 | (mod - 1); | ||
2427 | if (now_uframe == now) | 2428 | if (now_uframe == now) |
2428 | break; | 2429 | break; |
2429 | 2430 | ||
@@ -2436,7 +2437,7 @@ restart: | |||
2436 | } | 2437 | } |
2437 | } else { | 2438 | } else { |
2438 | now_uframe++; | 2439 | now_uframe++; |
2439 | now_uframe %= mod; | 2440 | now_uframe &= mod - 1; |
2440 | } | 2441 | } |
2441 | } | 2442 | } |
2442 | } | 2443 | } |