[arch-projects] [PATCH 1/2] functions: reduce calls to modinfo
Dave Reisner
d at falconindy.com
Thu Jun 30 20:15:32 EDT 2011
Cut back to a single call to modinfo, instead of 3, which yields roughly
a 30% decrease in execution time for a single run of add_module. This of
course varies by module but it's an overall win.
Suggested-by: Dan McGee <dan at archlinux.org>
Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
functions | 51 ++++++++++++++++++++++++---------------------------
1 files changed, 24 insertions(+), 27 deletions(-)
diff --git a/functions b/functions
index 3e3fee9..706a64f 100644
--- a/functions
+++ b/functions
@@ -56,14 +56,6 @@ in_array() {
return 1 # Not Found
}
-kmodinfo() {
- # A wrapper around modinfo, which is aware of our $BASEDIR and
- # $KERNELVERSION
- # $@: args to modinfo
-
- modinfo -b "$BASEDIR" -k "$KERNELVERSION" "$@" 2>/dev/null
-}
-
auto_modules() {
# Perform auto detection of modules via sysfs.
@@ -171,34 +163,39 @@ add_module() {
# discovered and added.
# $1: module name
- local module path fw dep deps
+ local module path dep deps field value
module=${1%.ko*}
# skip expensive stuff if this module has already been added
in_array "${module//-/_}" "${ADDED_MODULES[@]}" && return
- path=$(kmodinfo -0F filename "$module")
- if [[ $path ]]; then
- # get module firmware
- while read -r -d '' fw; do
- if [[ -e "$BASEDIR/lib/firmware/$fw" ]]; then
- add_file "/lib/firmware/$fw"
- fi
- done < <(kmodinfo -0F firmware "$module")
-
- # get module depends
- IFS=',' read -r -d '' -a deps < <(kmodinfo -0F depends "$module")
- for dep in "${deps[@]}"; do
- add_module "$dep"
- done
-
- ADDED_MODULES+=("${module//-/_}")
- add_file "${path#$BASEDIR}" || return
- else
+ while IFS=':= ' read -r -d '' field value; do
+ case "$field" in
+ filename)
+ path=$value
+ ;;
+ depends)
+ IFS=',' read -r -a deps <<< "$value"
+ for dep in "${deps[@]}"; do
+ add_module "$dep"
+ done
+ ;;
+ firmware)
+ if [[ -e "$BASEDIR/lib/firmware/$value" ]]; then
+ add_file "/lib/firmware/$value"
+ fi
+ ;;
+ esac
+ done < <(modinfo -b "$BASEDIR" -k "$KERNELVERSION" -0 "$module" 2>/dev/null)
+
+ if [[ -z $path ]]; then
error "module '$module' not found"
return 1
fi
+ add_file "${path#$BASEDIR}"
+ ADDED_MODULES+=("${module//-/_}")
+
# explicit module depends
case "$module" in
fat) add_module "nls_cp437" ;;
--
1.7.6
More information about the arch-projects
mailing list