linux/drivers
Eric Dumazet 6b31a515e3 [TG3]: Avoid an expensive divide.
During an oprofile session of linux-2.6.20 on a dual opteron system, I noticed
an expensive divide was done in tg3_poll().

I am using gcc-4.1.1, so the following comment from drivers/net/tg3.c seems
over-optimistic :

/* Do not place this n-ring entries value into the tp struct itself,
  * we really want to expose these constants to GCC so that modulo et
  * al.  operations are done with shifts and masks instead of with
  * hw multiply/modulo instructions.  Another solution would be to
  * replace things like '% foo' with '& (foo - 1)'.
  */
#define TG3_RX_RCB_RING_SIZE(tp)        \
         ((tp->tg3_flags2 & TG3_FLG2_5705_PLUS) ?  512 : 1024)

Assembly code before patch :
(oprofile results included)
   6434  0.0088 :ffffffff803684b9:       mov    0x6f0(%r15),%eax
    587 8.0e-04 :ffffffff803684c0:       and    $0x40000,%eax
   2170  0.0030 :ffffffff803684c5:       cmp    $0x1,%eax
                :ffffffff803684c8:       lea    0x1(%r13),%eax
                :ffffffff803684cc:       sbb    %ecx,%ecx
   2051  0.0028 :ffffffff803684ce:       xor    %edx,%edx
                :ffffffff803684d0:       and    $0x200,%ecx
     20 2.7e-05 :ffffffff803684d6:       add    $0x200,%ecx
   1986  0.0027 :ffffffff803684dc:       div    %ecx
103427  0.1410 :ffffffff803684de:       cmp    %edx,0xffffffffffffff7c(%rbp)

Assembly code after the suggested patch :

ffffffff803684b9:           mov    0x6f0(%r15),%eax
ffffffff803684c0:           and    $0x40000,%eax
ffffffff803684c5:           cmp    $0x1,%eax
ffffffff803684c8:           sbb    %eax,%eax
ffffffff803684ca:           inc    %r13d
ffffffff803684cd:           and    $0x200,%eax
ffffffff803684d2:           add    $0x1ff,%eax
ffffffff803684d7:           and    %eax,%r13d
ffffffff803684da:           cmp    %r13d,0xffffffffffffff7c(%rbp)

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Acked-by: Michael Chan <mchan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-02-08 12:38:57 -08:00
..
acorn
acpi Pull acpica into test branch 2007-02-06 15:30:03 -05:00
amba
ata Revert "PCI: remove duplicate device id from ata_piix" 2007-02-07 16:17:27 -08:00
atm [PATCH] horizon.c: missing __devinit 2007-01-23 11:09:49 -08:00
base Driver Core: Increase the default timeout value of the firmware subsystem 2007-02-07 10:37:14 -08:00
block
bluetooth
cdrom
char Merge master.kernel.org:/pub/scm/linux/kernel/git/paulus/powerpc 2007-02-08 10:04:20 -08:00
clocksource
connector
cpufreq [CPUFREQ] check sysfs_create_link return value 2007-01-29 00:06:27 -05:00
crypto [S390] Support for s390 Pseudo Random Number Generator 2007-02-05 21:18:22 +01:00
dio
dma
edac
eisa
fc4
firmware ACPICA: Remove duplicate table definitions (non-conflicting), cont 2007-02-02 21:14:29 -05:00
hid HID: move away from DEBUG defines in favor of CONFIG_HID_DEBUG 2007-02-05 10:00:45 +01:00
hwmon
i2c USB: <linux/usb_ch9.h> becomes <linux/usb/ch9.h> 2007-02-07 15:44:32 -08:00
ide Merge master.kernel.org:/pub/scm/linux/kernel/git/bart/ide-2.6 2007-02-07 19:32:36 -08:00
ieee1394
infiniband Network: convert network devices to use struct device instead of class_device 2007-02-07 10:37:11 -08:00
input SERIO: add the sysfs driver name to all modules 2007-02-07 10:37:12 -08:00
isdn [PATCH] Gigaset ISDN driver error handling fixes 2007-01-26 13:50:58 -08:00
kvm [PATCH] KVM: fix lockup on 32-bit intel hosts with nx disabled in the bios 2007-02-01 16:22:41 -08:00
leds
macintosh [POWERPC] windfarm: don't die on suspend thread signal 2007-02-08 16:08:39 +11:00
mca
md [PATCH] md: remove unnecessary printk when raid5 gets an unaligned read. 2007-01-26 13:51:00 -08:00
media USB: remove duplicate device id from zc0301 2007-02-07 15:44:40 -08:00
message
mfd
misc Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6 2007-02-07 15:36:08 -08:00
mmc mmc: tifm: replace kmap with page_address 2007-02-04 20:54:12 +01:00
mtd [PATCH] mtd/nand/cafe.c missing include of dma-mapping.h 2007-01-30 08:39:20 -08:00
net [TG3]: Avoid an expensive divide. 2007-02-08 12:38:57 -08:00
nubus
oprofile
parisc
parport
pci Merge master.kernel.org:/pub/scm/linux/kernel/git/bart/ide-2.6 2007-02-07 19:32:36 -08:00
pcmcia Driver core: convert pcmcia code to use struct device 2007-02-07 10:37:11 -08:00
pnp PNPACPI: remove EXPERIMENTAL dependency 2007-01-26 02:15:57 -05:00
ps3 [POWERPC] PS3: Move vuart declarations to ps3.h 2007-02-07 14:03:20 +11:00
rapidio
rtc [PATCH] remove __devinit markings from rtc_sysfs_add_device() 2007-01-26 13:51:00 -08:00
s390 [S390] Avoid excessive inlining. 2007-02-05 21:18:53 +01:00
sbus
scsi PCI: remove duplicate device id from ipr 2007-02-07 15:50:06 -08:00
serial Merge branch 'linux-2.6' 2007-02-07 14:05:13 +11:00
sh
sn
spi Revert "Driver core: convert SPI code to use struct device" 2007-02-07 21:34:08 -08:00
tc
telephony
usb Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/usb-2.6 2007-02-07 19:23:21 -08:00
video Pull output-switch into test branch 2007-02-03 01:39:22 -05:00
w1
zorro
Kconfig
Makefile