* [PATCH] Slight optimisation of the uhci-hcd init code
@ 2004-02-09 14:05 eric.piel
2004-02-09 22:07 ` Alan Stern
2004-02-11 19:40 ` Alan Stern
0 siblings, 2 replies; 5+ messages in thread
From: eric.piel @ 2004-02-09 14:05 UTC (permalink / raw)
To: Johannes Erdfelt; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 602 bytes --]
Hello,
While trying to understand why starting usb on my laptop made the bus master
activity full I came accross a strange code in uhci-hcd: a seven level nested
"if". The same thing can be achieved with a simgle ffz(). The attached patch
should give to the code a bit better looking, on my x86 it even saves 96 bytes,
cool ;-)
hoping you like it,
Eric Piel
PS: still, I'm not sure it's normal to see ffffffff as "bus master activity" in
/proc/acpi/processor/CPU0/power as soon as uhci-hcd is loaded. In particular, it
prevents the processor to go to C3 state. Could you give me your pint of view?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: uhci-hcd-uses-ffz.patch --]
[-- Type: text/x-patch; name="uhci-hcd-uses-ffz.patch", Size: 1438 bytes --]
--- drivers/usb/host/uhci-hcd.c.orig 2004-02-08 12:30:23.730934744 +0100
+++ drivers/usb/host/uhci-hcd.c 2004-02-08 13:12:11.723661896 +0100
@@ -52,6 +52,7 @@
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/system.h>
+#include <asm/bitops.h>
#include "../core/hcd.h"
#include "uhci-hcd.h"
@@ -2213,10 +2214,11 @@
{
struct uhci_hcd *uhci = hcd_to_uhci(hcd);
int retval = -EBUSY;
- int i, port;
+ int port;
unsigned io_size;
dma_addr_t dma_handle;
struct usb_device *udev;
+ unsigned long i;
#ifdef CONFIG_PROC_FS
struct proc_dir_entry *ent;
#endif
@@ -2321,7 +2323,7 @@
for (i = 0; i < UHCI_NUM_SKELQH; i++) {
uhci->skelqh[i] = uhci_alloc_qh(uhci, udev);
if (!uhci->skelqh[i]) {
- err("unable to allocate QH %d", i);
+ err("unable to allocate QH %lu", i);
goto err_alloc_skelqh;
}
}
@@ -2360,28 +2362,8 @@
* us a reasonable dynamic range for irq latencies.
*/
for (i = 0; i < UHCI_NUMFRAMES; i++) {
- int irq = 0;
-
- if (i & 1) {
- irq++;
- if (i & 2) {
- irq++;
- if (i & 4) {
- irq++;
- if (i & 8) {
- irq++;
- if (i & 16) {
- irq++;
- if (i & 32) {
- irq++;
- if (i & 64)
- irq++;
- }
- }
- }
- }
- }
- }
+ unsigned long irq;
+ irq = ffz(i & ((1<<7) - 1));
/* Only place we don't use the frame list routines */
uhci->fl->frame[i] = cpu_to_le32(uhci->skelqh[7 - irq]->dma_handle);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Slight optimisation of the uhci-hcd init code
2004-02-09 14:05 [PATCH] Slight optimisation of the uhci-hcd init code eric.piel
@ 2004-02-09 22:07 ` Alan Stern
2004-02-11 10:40 ` eric.piel
2004-02-11 19:40 ` Alan Stern
1 sibling, 1 reply; 5+ messages in thread
From: Alan Stern @ 2004-02-09 22:07 UTC (permalink / raw)
To: Johannes Erdfelt, eric.piel; +Cc: Kernel development list
Thanks for fowarding this, Johannes.
On Mon, 9 Feb 2004 eric.piel@tremplin-utc.net wrote:
> Hello,
>
> While trying to understand why starting usb on my laptop made the bus master
> activity full I came accross a strange code in uhci-hcd: a seven level nested
> "if". The same thing can be achieved with a simgle ffz(). The attached patch
> should give to the code a bit better looking, on my x86 it even saves 96 bytes,
> cool ;-)
>
> hoping you like it,
> Eric Piel
It's a nice idea. I was planning to alter the logic behind that nested
"if" anyway, and I'll keep your recommendation in mind when I do it.
> PS: still, I'm not sure it's normal to see ffffffff as "bus master activity" in
> /proc/acpi/processor/CPU0/power as soon as uhci-hcd is loaded. In particular, it
> prevents the processor to go to C3 state. Could you give me your pint of view?
I'm not sure exactly what the ffffffff value means -- maximum utilization?
Anyway, a UHCI host controller is a bus master and it can generate a lot
of activity depending on what USB devices are plugged in. If no USB
devices are plugged, the controller will be suspended after 1 second.
Of course then it shouldn't be accessing the PCI bus at all.
There is one exception to this. Some manufacturers try to disable unused
USB ports on their motherboards by tying the overcurrent input permanently
high. (This seems to be particularly common among laptops.) With some
Intel controllers this strategy generates "device-connected" interrupts,
so the driver doesn't try to suspend the controller. There's a patch to
fix this behavior currently being tested.
Alan Stern
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Slight optimisation of the uhci-hcd init code
2004-02-09 22:07 ` Alan Stern
@ 2004-02-11 10:40 ` eric.piel
2004-02-11 15:12 ` Alan Stern
0 siblings, 1 reply; 5+ messages in thread
From: eric.piel @ 2004-02-11 10:40 UTC (permalink / raw)
To: Alan Stern; +Cc: Johannes Erdfelt, Kernel development list
Quoting Alan Stern <stern@rowland.harvard.edu>:
> It's a nice idea. I was planning to alter the logic behind that nested
> "if" anyway, and I'll keep your recommendation in mind when I do it.
Great
> > PS: still, I'm not sure it's normal to see ffffffff as "bus master
> activity" in
> > /proc/acpi/processor/CPU0/power as soon as uhci-hcd is loaded. In
> particular, it
> > prevents the processor to go to C3 state. Could you give me your pint of
> view?
>
> I'm not sure exactly what the ffffffff value means -- maximum utilization?
Yes, more exactly it means that the last 64 times the idle task was called the
bus master was detected as being used.
> Anyway, a UHCI host controller is a bus master and it can generate a lot
> of activity depending on what USB devices are plugged in. If no USB
> devices are plugged, the controller will be suspended after 1 second.
> Of course then it shouldn't be accessing the PCI bus at all.
>
> There is one exception to this. Some manufacturers try to disable unused
> USB ports on their motherboards by tying the overcurrent input permanently
> high. (This seems to be particularly common among laptops.) With some
> Intel controllers this strategy generates "device-connected" interrupts,
> so the driver doesn't try to suspend the controller. There's a patch to
> fix this behavior currently being tested.
Well, my laptop seems fine. When I unplug the mouse the bus master activity goes
to 0000000. I've very little idea about how the bus master has to be used and
even less about the uhci host controller. However, at a first glance I thought
it was weird to see full bus master activity when all that is connected is a
mouse not being used. Do you think it's normal?
Eric
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Slight optimisation of the uhci-hcd init code
2004-02-11 10:40 ` eric.piel
@ 2004-02-11 15:12 ` Alan Stern
0 siblings, 0 replies; 5+ messages in thread
From: Alan Stern @ 2004-02-11 15:12 UTC (permalink / raw)
To: eric.piel; +Cc: Johannes Erdfelt, Kernel development list
On Wed, 11 Feb 2004 eric.piel@tremplin-utc.net wrote:
> > I'm not sure exactly what the ffffffff value means -- maximum utilization?
> Yes, more exactly it means that the last 64 times the idle task was called the
> bus master was detected as being used.
By "detected as being used", do you mean that the device was actually
carrying out bus transactions or only that it was enabled as a bus master?
And if it's the first, do you mean that the bus activity was occurring
just as the idle task happened to check or that some bus activity had
occurred since the last time the idle task checked?
USB controllers are more or less permanently enabled, but they only create
bus activity when they actually have some work to do. If the only USB
device you have connected is a mouse then there should be a small amount
of bus activity occuring once every millisecond, with a little more than
that every 32 milliseconds (or whatever polling period your mouse uses --
look in /proc/bus/usb/devices), and even more when you actually move the
mouse or press a button.
> Well, my laptop seems fine. When I unplug the mouse the bus master activity goes
> to 0000000. I've very little idea about how the bus master has to be used and
> even less about the uhci host controller. However, at a first glance I thought
> it was weird to see full bus master activity when all that is connected is a
> mouse not being used. Do you think it's normal?
Since I don't really understand the value being reported, I can't say.
You can judge for yourself from the explanation above.
Alan Stern
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Slight optimisation of the uhci-hcd init code
2004-02-09 14:05 [PATCH] Slight optimisation of the uhci-hcd init code eric.piel
2004-02-09 22:07 ` Alan Stern
@ 2004-02-11 19:40 ` Alan Stern
1 sibling, 0 replies; 5+ messages in thread
From: Alan Stern @ 2004-02-11 19:40 UTC (permalink / raw)
To: eric.piel; +Cc: Johannes Erdfelt, Kernel development list
Eric, Johannes:
Thought you might like to see this... I need to make sure it works right,
and then it's going in.
Alan Stern
===== uhci-hcd.c 1.80 vs edited =====
--- 1.80/drivers/usb/host/uhci-hcd.c Tue Feb 10 00:33:10 2004
+++ edited/drivers/usb/host/uhci-hcd.c Wed Feb 11 14:34:51 2004
@@ -2336,16 +2336,17 @@
}
/*
- * 8 Interrupt queues; link int2 to int1, int4 to int2, etc
+ * 8 Interrupt queues; link all higher int queues to int1,
* then link int1 to control and control to bulk
*/
- uhci->skel_int128_qh->link = cpu_to_le32(uhci->skel_int64_qh->dma_handle) | UHCI_PTR_QH;
- uhci->skel_int64_qh->link = cpu_to_le32(uhci->skel_int32_qh->dma_handle) | UHCI_PTR_QH;
- uhci->skel_int32_qh->link = cpu_to_le32(uhci->skel_int16_qh->dma_handle) | UHCI_PTR_QH;
- uhci->skel_int16_qh->link = cpu_to_le32(uhci->skel_int8_qh->dma_handle) | UHCI_PTR_QH;
- uhci->skel_int8_qh->link = cpu_to_le32(uhci->skel_int4_qh->dma_handle) | UHCI_PTR_QH;
- uhci->skel_int4_qh->link = cpu_to_le32(uhci->skel_int2_qh->dma_handle) | UHCI_PTR_QH;
- uhci->skel_int2_qh->link = cpu_to_le32(uhci->skel_int1_qh->dma_handle) | UHCI_PTR_QH;
+ uhci->skel_int128_qh->link =
+ uhci->skel_int64_qh->link =
+ uhci->skel_int32_qh->link =
+ uhci->skel_int16_qh->link =
+ uhci->skel_int8_qh->link =
+ uhci->skel_int4_qh->link =
+ uhci->skel_int2_qh->link =
+ cpu_to_le32(uhci->skel_int1_qh->dma_handle) | UHCI_PTR_QH;
uhci->skel_int1_qh->link = cpu_to_le32(uhci->skel_ls_control_qh->dma_handle) | UHCI_PTR_QH;
uhci->skel_ls_control_qh->link = cpu_to_le32(uhci->skel_hs_control_qh->dma_handle) | UHCI_PTR_QH;
@@ -2361,39 +2362,33 @@
uhci->skel_term_qh->element = cpu_to_le32(uhci->term_td->dma_handle);
/*
- * Fill the frame list: make all entries point to
- * the proper interrupt queue.
+ * Fill the frame list: make all entries point to the proper
+ * interrupt queue.
*
- * This is probably silly, but it's a simple way to
- * scatter the interrupt queues in a way that gives
- * us a reasonable dynamic range for irq latencies.
+ * The interrupt queues will be interleaved as evenly as possible.
+ * There's not much to be done about period-1 interrupts; they have
+ * to occur in every frame. But we can schedule period-2 interrupts
+ * in odd-numbered frames, period-4 interrupts in frames congruent
+ * to 2 (mod 4), and so on. This way each frame only has two
+ * interrupt QHs, which will help spread out bandwidth utilization.
*/
for (i = 0; i < UHCI_NUMFRAMES; i++) {
- int irq = 0;
+ int irq;
- if (i & 1) {
- irq++;
- if (i & 2) {
- irq++;
- if (i & 4) {
- irq++;
- if (i & 8) {
- irq++;
- if (i & 16) {
- irq++;
- if (i & 32) {
- irq++;
- if (i & 64)
- irq++;
- }
- }
- }
- }
- }
- }
+ /*
+ * ffs (Find First bit Set) does exactly what we need:
+ * 1,3,5,... => ffs = 0 => use skel_int2_qh = skelqh[6],
+ * 2,6,10,... => ffs = 1 => use skel_int4_qh = skelqh[5], etc.
+ * ffs > 6 => not on any high-period queue, so use
+ * skel_int1_qh = skelqh[7].
+ * Add UHCI_NUMFRAMES to insure at least one bit is set.
+ */
+ irq = 6 - (int) __ffs(i + UHCI_NUMFRAMES);
+ if (irq < 0)
+ irq = 7;
/* Only place we don't use the frame list routines */
- uhci->fl->frame[i] = cpu_to_le32(uhci->skelqh[7 - irq]->dma_handle);
+ uhci->fl->frame[i] = cpu_to_le32(uhci->skelqh[irq]->dma_handle);
}
start_hc(uhci);
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-02-11 19:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-09 14:05 [PATCH] Slight optimisation of the uhci-hcd init code eric.piel
2004-02-09 22:07 ` Alan Stern
2004-02-11 10:40 ` eric.piel
2004-02-11 15:12 ` Alan Stern
2004-02-11 19:40 ` Alan Stern
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®