Package: hotplug
Version: 0.0.20040329-25
Severity: wishlist
Tags: patch
Attached is a patch for '/etc/hotplug/isapnp.rc'. To make the code line
up better I put in about a dozen indentations, that may make it seem
very busy, but it's simpler than it looks. Here's a diff without any
cosmetic whitespace, only three lines changed:
% diff -w /etc/hotplug/isapnp.rc /tmp/isapnp.rc
28,29c28,29
< cat /sys/bus/pnp/devices/*/id \
< | while read PNPID; do
---
> for PNPDEVFILE in /sys/bus/pnp/devices/*/id ; do # loop
through PNP device names
> while read PNPID; do
54a55
> done < $PNPDEVFILE # like "cat FOO* | while read BAR", but
faster
Note: the variable name $PNPDEVFILE is arbitrary, and can safely be
renamed to something more appropriate.
How it works; the old loop did it this way:
% cat /sys/bus/pnp/devices/*/id | while read F ; do echo $F ; done
PNP0c01
PNP0c02
{ ...etc...}
PNP0303
...the 'for ... | while' version does this:
% for f in /sys/bus/pnp/devices/*/id ; do while read F ; do echo $F ; done
< $f ; done
PNP0c01
PNP0c02
{ ...etc...}
PNP0303
The code's a little longer, but 4x faster because it stays in the shell --
on my system anyway. A quick benchmark:
% N=`seq 10000` # run it 10,000 times
% time for n in $N ; do cat /sys/bus/pnp/devices/*/id | while read F ;
do : ; done ; done
real 1m4.128s
user 0m18.254s
sys 0m43.230s
% time for n in $N ; do for f in /sys/bus/pnp/devices/*/id ; do while
read F ; do : ; done < $f ; done done
real 0m22.051s
user 0m14.614s
sys 0m6.989s
Hope this helps...
-- System Information:
Debian Release: testing/unstable
APT prefers unstable
APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: i386 (i686)
Shell: /bin/sh linked to /bin/dash
Kernel: Linux 2.6.11-1-686
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968) (ignored: LC_ALL set to C)
Versions of packages hotplug depends on:
ii bash 3.0-15 The GNU Bourne Again SHell
ii debconf [debconf-2.0] 1.4.54 Debian configuration management sy
ii grep 2.5.1.ds1-5 GNU grep, egrep and fgrep
ii module-init-tools 3.2-pre1-2 tools for managing Linux kernel mo
ii modutils 2.4.27.0-3 Linux module utilities
ii procps 1:3.2.5-1 /proc file system utilities
ii sed 4.1.4-2 The GNU sed stream editor
Versions of packages hotplug recommends:
ii ifupdown 0.6.7 high level tools to configure netw
ii pciutils 1:2.1.11-15 Linux PCI Utilities
ii usbutils 0.71-5 USB console utilities
-- debconf information:
hotplug/ignore_pci_class_display: true
hotplug/net_agent_policy: hotplug
hotplug/static_module_list:
* hotplug/usb_keyboard:
hotplug/x11_usbmice_hack: false
--- /etc/hotplug/isapnp.rc 2005-07-11 13:59:14.000000000 -0400
+++ /tmp/isapnp.rc 2005-08-05 06:39:56.000000000 -0400
@@ -25,33 +25,34 @@
return 0
fi
- cat /sys/bus/pnp/devices/*/id \
- | while read PNPID; do
- # get the name of the module which should be loaded
- MODULE=$(modprobe --show-depends -q pnp:d$PNPID \
+ for PNPDEVFILE in /sys/bus/pnp/devices/*/id ; do # loop through
PNP device names
+ while read PNPID; do
+ # get the name of the module which should be loaded
+ MODULE=$(modprobe --show-depends -q pnp:d$PNPID \
| sed -e '$!d;s/.*\/\(.*\)\.ko .*/\1/')
- case "$MODULE" in
- "") # continue if there is no alias available
- continue
- ;;
- install*) # skip the blacklist check if install is used
- MODULE="pnp:d$PNPID"
- ;;
- *) # ignore blacklisted devices
- if is_blacklisted $MODULE; then
- mesg " $MODULE: blacklisted"
- continue
- fi
- ;;
- esac
+ case "$MODULE" in
+ "") # continue if there is no alias available
+ continue
+ ;;
+ install*) # skip the blacklist check if install is used
+ MODULE="pnp:d$PNPID"
+ ;;
+ *) # ignore blacklisted devices
+ if is_blacklisted $MODULE; then
+ mesg " $MODULE: blacklisted"
+ continue
+ fi
+ ;;
+ esac
- # see do_pnp_entry() in /usr/src/linux/scripts/file2alias.c
- if $MODPROBE -q $MODULE; then
- mesg " $MODULE: loaded successfully"
- else
- mesg " $MODULE: can't be loaded"
- fi
+ # see do_pnp_entry() in /usr/src/linux/scripts/file2alias.c
+ if $MODPROBE -q $MODULE; then
+ mesg " $MODULE: loaded successfully"
+ else
+ mesg " $MODULE: can't be loaded"
+ fi
+ done < $PNPDEVFILE # like "cat FOO* | while read BAR", but faster
done
}