[arch-projects] [PATCH 1/2] 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 <dan@archlinux.org> Signed-off-by: Dave Reisner <dreisner@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
Much to my chagrin, we're going back to using ldd directly, as it's otherwise too difficult to account for odd setups, such as idiots wanting to create multilib initramfs images, or more commonly -- a 64 bit kernel on a 32 bit userland. Fortunately, we don't suffer too large a regression in speed compared to the previous implementation. Signed-off-by: Dave Reisner <dreisner@archlinux.org> --- This is one possible solution -- and it's basically what we relied on pre 0.7, but slightly cleaner. There _is_ a small loss of performance, but it's the price we pay. I think this is a preferrably alternative to parsing human formatted output from a tool such as readelf. functions | 10 +++------- mkinitcpio | 18 +----------------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/functions b/functions index 706a64f..c3d79b2 100644 --- a/functions +++ b/functions @@ -204,10 +204,6 @@ add_module() { esac } -_ldd() { - LD_TRACE_LOADED_OBJECTS=1 "$LD_SO" "$@" -} - _add_file() { # add a file to $BUILDROOT # $1: pathname on initcpio @@ -264,10 +260,10 @@ add_binary() { # always add the binary itself _add_file "${dest#$BASEDIR}" "$binary" "$mode" - $LD_SO --verify "$binary" &>/dev/null || return # not a binary! + ldd "$binary" &>/dev/null || return # not a binary! # resolve sodeps - regex='^[[:space:]]*[^/].+ => (.*) \(.*\)' + regex='(/.+) \(0x[a-fA-F0-9]+\)' while read line; do [[ "$line" =~ $regex ]] && sodep=${BASH_REMATCH[1]} || continue @@ -282,7 +278,7 @@ add_binary() { _add_file "${resolved#$BASEDIR}" "$resolved" 755 fi fi - done < <(_ldd "$binary") + done < <(ldd "$binary") return 0 } diff --git a/mkinitcpio b/mkinitcpio index 459c828..71d3e0d 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -22,7 +22,7 @@ INSTDIR=install PRESETDIR=mkinitcpio.d COMPRESSION=gzip -declare TMPDIR BASEDIR MODULE_FILE GENIMG PRESET COMPRESSION_OPTIONS BUILDROOT LD_SO +declare TMPDIR BASEDIR MODULE_FILE GENIMG PRESET COMPRESSION_OPTIONS BUILDROOT declare NC= BOLD= BLUE= GREEN= RED= YELLOW= declare -i QUIET=1 SHOW_AUTOMODS=0 SAVELIST=0 COLOR=1 declare -a SKIPHOOKS ADDED_MODULES @@ -294,22 +294,6 @@ trap '[[ $FUNCNAME = parse_hook ]] && (( ++builderrors ))' ERR #parse 'global' hook, as defined in ${CONFIG} parse_hook -# resolve the linker and add it -case $CARCH in - i686) LD_SO=("$BASEDIR"/lib/ld-linux.so.?*) ;; - x86_64) LD_SO=("$BASEDIR"/lib/ld-linux-${CARCH//_/-}.so.?*) ;; - *) die "unknown architecture: $CARCH" ;; -esac - -if (( ${#LD_SO[*]} != 1 )); then # uh oh... - die "failed to resolve the location of /lib/ld.so. Please report this bug." -fi - -resolved=$(readlink -e "$LD_SO") -_add_file "${resolved#$BASEDIR}" "$resolved" 755 -_add_symlink "${LD_SO#$BASEDIR}" "$resolved" -unset resolved - for hook in ${HOOKS}; do in_array "$hook" "${SKIPHOOKS[@]}" && continue unset MODULES BINARIES FILES SCRIPT -- 1.7.6
participants (1)
-
Dave Reisner