From 549af8c1b9a72cacf8cda41f8dd4b76983930945 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Thu, 30 Jun 2011 19:06:13 -0400 Subject: functions: reduce calls to modinfo 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 Signed-off-by: Dave Reisner --- functions | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'functions') diff --git a/functions b/functions index 3e3fee9..1aea1a7 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" "$BASEDIR/lib/firmware/$value" 644 + 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" ;; -- cgit v1.2.3-24-g4f1b