mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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

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®