changeset 115:0595c16ed26f

Autodetect CPU count and tailor parallelism to machine we're running on.
author Rob Landley <rob@landley.net>
date Mon, 02 May 2011 14:22:10 -0500
parents d8293ee80a4a
children 0b8a67c8aa66
files make/functions.sh
diffstat 1 files changed, 15 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/make/functions.sh	Mon May 02 14:21:07 2011 -0500
+++ b/make/functions.sh	Mon May 02 14:22:10 2011 -0500
@@ -10,6 +10,9 @@
   exit 1
 fi
 
+[ -z "$CPUS" ] && CPUS=$(echo /sys/devices/system/cpu/cpu[0-9]* | wc -w)
+[ "$CPUS" -lt 1 ] && CPUS=1
+
 # Update Documentation directory
 
 function update_documentation_dir()
@@ -55,7 +58,7 @@
   # Make the chdir local
   (
     cd "$LNXDIR" &&
-    make -j 4 htmldocs
+    make -j $CPUS htmldocs
   )
 }
 
@@ -63,15 +66,22 @@
 {
   # Make the chdir local
   (
+    # Because $$ always points to the top level bash process, which () isn't.
+    CHILD=$(pgrep -P$$)
+
     cd "$LNXDIR" &&
-    # Probably redundant, but just in case...
-    make -j 4 xmldocs &&
     cd Documentation/DocBook &&
     for i in *.xml
     do
       echo "Converting $i"
-      xmlto --skip-validation xhtml-nochunks $i -o xhtml-nochunks
+      xmlto --skip-validation xhtml-nochunks $i -o xhtml-nochunks &
+      # Rate limit spawn to number of CPUS + 1
+      if [ $(pgrep -P$CHILD | wc -w) -gt $CPUS ]
+      then
+        sleep 1
+      fi
     done
+    wait
   )
 }
 
@@ -258,19 +268,6 @@
 
     # Do setup we'll need later.
     make allnoconfig > /dev/null &&
-    make -j 4 xmldocs
+    make -j $CPUS xmldocs
   )
 }
-
-function wait4background()
-{
-  # Wait for background task to finish
-  while [ $(jobs | wc -l) -ne 0 ]
-  do
-    sleep 1
-    # Without this next line, bash never notices a change in the number of jobs.
-    # Bug noticed in Ubuntu 7.04
-    jobs > /dev/null
-  done
-}
-