From f8e28ad07065b55444ba35c0aa0cccd441c4f2bf Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 15 Aug 2021 05:13:21 -0500 Subject: [PATCH] Use wait -n to keep cpus busier during parallel build. (No guarantee children complete in the order they're launched. Ability to wait for "next" was added in bash 4.3 which shipped Feb 2014, now over the 7 year horizon.) --- scripts/make.sh | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/scripts/make.sh b/scripts/make.sh index e050e705..1aecaec4 100755 --- a/scripts/make.sh +++ b/scripts/make.sh @@ -280,11 +280,9 @@ fi # build each generated/obj/*.o file in parallel -PENDING= -LNKFILES= +unset PENDING LNKFILES CLICK DONE=0 COUNT=0 -CLICK= for i in $LIBFILES click $TOYFILES do @@ -295,38 +293,25 @@ do OUT="generated/obj/${X%%.c}.o" LNKFILES="$LNKFILES $OUT" - # $LIBFILES doesn't need to be rebuilt if older than .config, $TOYFILES does + # $LIBFILES don't need to be rebuilt if older than .config, $TOYFILES do # ($TOYFILES contents can depend on CONFIG symbols, lib/*.c never should.) [ "$OUT" -nt "$i" ] && [ -z "$CLICK" -o "$OUT" -nt "$KCONFIG_CONFIG" ] && continue do_loudly $BUILD -c $i -o $OUT & - PENDING="$PENDING $!" - COUNT=$(($COUNT+1)) # ratelimit to $CPUS many parallel jobs, detecting errors - - for j in $PENDING - do - [ "$COUNT" -lt "$CPUS" ] && break; - - wait $j - DONE=$(($DONE+$?)) - COUNT=$(($COUNT-1)) - PENDING="${PENDING## $j}" - done + [ $((++COUNT)) -ge $CPUS ] && { wait -n; DONE=$?; : $((--COUNT)); } [ $DONE -ne 0 ] && break done - # wait for all background jobs, detecting errors -for i in $PENDING +while [ $((COUNT--)) -gt 0 ] do - wait $i - DONE=$(($DONE+$?)) + wait -n; + DONE=$((DONE+$?)) done - [ $DONE -ne 0 ] && exit 1 do_loudly $BUILD $LNKFILES $LINK || exit 1 @@ -335,8 +320,7 @@ if [ ! -z "$NOSTRIP" ] || then [ -z "$NOSTRIP" ] && echo "strip failed, using unstripped" rm -f "$OUTNAME" && - cp "$UNSTRIPPED" "$OUTNAME" || - exit 1 + cp "$UNSTRIPPED" "$OUTNAME" || exit 1 fi # gcc 4.4's strip command is buggy, and doesn't set the executable bit on -- 2.39.2