lkml.org 
[lkml]   [2004]   [Feb]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[PATCH] Slight optimisation of the uhci-hcd init code
    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?--- 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);
    \
     
     \ /
      Last update: 2005-03-22 14:00    [W:0.024 / U:1.092 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site