mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: eric.piel@tremplin-utc.net
To: Johannes Erdfelt <johannes@erdfelt.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] Slight optimisation of the uhci-hcd init code
Date: Mon,  9 Feb 2004 15:05:24 +0100	[thread overview]
Message-ID: <1076335524.402793a4d04e9@mailetu.utc.fr> (raw)

[-- 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);

             reply	other threads:[~2004-02-09 14:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-09 14:05 eric.piel [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1076335524.402793a4d04e9@mailetu.utc.fr \
    --to=eric.piel@tremplin-utc.net \
    --cc=johannes@erdfelt.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®