tags 663114 patch
thanks

Hi,

I'm attaching a first attempt at a patch to implement this. It works for me,
but I haven't tested it extensively.

It will pass -j<number of CPUs> to make(1) by default, but this can be
overridden via the command line.

Work on the patch was sponsored by CAE Engineering Kft. The patch is
licensed under GPL-2+, just like DKMS itself.

Andras

-- 
 Good documentation is not written to satisfy a quota specified in cubic feet.
--- dkms.8.orig	2013-12-26 14:33:47.415037496 +0100
+++ dkms.8	2013-12-26 14:39:44.951272101 +0100
@@ -516,6 +516,15 @@
 A supplemental configuration file to the system-wide dkms framework, typically located
 in /etc/dkms/framework.conf.  All option that are normally provided on a command line
 can be provided in this file.
+.TP
+.B \-j number
+Run no more than 
+.I number
+jobs in parallel; see the -j option of 
+.I make(1).
+Defaults to the number of CPUs in the system, detected by parsing 
+.I /proc/cpuinfo.
+Specify 0 to impose no limit on the number of parallel jobs.
 .SH ORIGINAL MODULES
 During the first install of a module for a <kernelversion>,
 .B dkms
--- dkms.orig	2012-10-06 00:00:00.000000000 +0200
+++ dkms	2013-12-26 14:56:58.042271991 +0100
@@ -127,6 +127,7 @@
     echo $"              [--kernelsourcedir=source-location] [--no-prepare-kernel] [--no-initrd]"
     echo $"              [--binaries-only] [--source-only] [-r release (SuSE)] [--verbose]"
     echo $"              [--size] [--spec=specfile] [--media=floppy|iso|tar] [--legacy-postinst=0|1]"
+    echo $"              [-j number]"
 }
 
 VER()
@@ -145,6 +146,19 @@
 		  -e 's: ::g'
 }
 
+# Find out how many CPUs there are so that we may pass an appropriate -j
+# option to make. Ignore hyperthreading for now.
+get_num_cpus()
+{
+   local num_cpus
+   num_cpus=$(egrep -i \
+       '^processor[[:space:]]*:[[:space:]]*[[:digit:]]+[[:space:]]*$' \
+       /proc/cpuinfo \
+       | wc -l)
+   [[ "$num_cpus" -lt 1 ]] && num_cpus=1 # Make sure we return at least 1
+   echo "$num_cpus"
+}
+
 # Figure out the correct module suffix for the kernel we are currently
 # dealing with, which may or may not be the currently installed kernel.
 set_module_suffix()
@@ -1085,7 +1099,7 @@
 	invoke_command "cp /boot/vmlinuz.version.h include/linux/version.h" "using /boot/vmlinux.version.h"
 	invoke_command "cp -f $kernel_config .config" "using $kernel_config"
 	invoke_command "make KERNELRELEASE=$1 cloneconfig" "make cloneconfig" background
-	invoke_command "make CONFIG_MODVERSIONS=1 KERNELRELEASE=$1 dep" "make CONFIG_MODVERSIONS=1 dep" background
+	invoke_command "make -j$parallel_jobs CONFIG_MODVERSIONS=1 KERNELRELEASE=$1 dep" "make CONFIG_MODVERSIONS=1 dep" background
     elif grep -q rhconfig.h $kernel_source_dir/include/linux/{modversions,version}.h 2>/dev/null; then
 	echo $"Running Red Hat style preparation routine"
 	invoke_command "make clean" "make clean" background
@@ -1131,9 +1145,9 @@
 
 	invoke_command "make KERNELRELEASE=$1 oldconfig" "make oldconfig" background
 	if [[ $(VER $1) < $(VER 2.5) ]]; then
-	    invoke_command "make KERNELRELEASE=$1 dep" "make dep" background
+	    invoke_command "make -j$parallel_jobs KERNELRELEASE=$1 dep" "make dep" background
 	else
-	    invoke_command "make KERNELRELEASE=$1 prepare-all scripts" "make prepare-all" background
+	    invoke_command "make -j$parallel_jobs KERNELRELEASE=$1 prepare-all scripts" "make prepare-all" background
 	fi
     fi
     cd - >/dev/null
@@ -1205,7 +1219,7 @@
     invoke_command "$clean" "cleaning build area" background
     echo $"DKMS make.log for $module-$module_version for kernel $kernelver ($arch)" >> "$dkms_tree/$module/$module_version/build/make.log"
     date >> "$dkms_tree/$module/$module_version/build/make.log"
-    local the_make_command="${make_command/#make/make KERNELRELEASE=$kernelver}"
+    local the_make_command="${make_command/#make/make -j$parallel_jobs KERNELRELEASE=$kernelver}"
 
     invoke_command "{ $the_make_command; } >> $dkms_tree/$module/$module_version/build/make.log 2>&1" "$the_make_command" background || \
 	report_build_problem 10 $"Bad return status for module build on kernel: $kernelver ($arch)" \
@@ -3444,6 +3458,7 @@
 	--debug)
 	    export PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): '
 	    set -x;;
+	-j)                  read_arg parallel_jobs "$1" "$2" || shift;;
 	-*|--*)              error $" Unknown option: $1"
 			     show_usage
 			     exit 2;;
@@ -3491,6 +3506,12 @@
 	$"--all on the command line."
 fi
 
+# Default to -j<number of CPUs>
+parallel_jobs=${parallel_jobs:-$(get_num_cpus)}
+
+# Make sure we're not passing -j0 to make; treat -j0 as just "-j"
+[[ "$parallel_jobs" = 0 ]] && parallel_jobs=""
+
 # Run the specified action
 for action_to_run in $action; do
     setup_kernels_arches "$action_to_run"
_______________________________________________
Pkg-dkms-maint mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-dkms-maint

Reply via email to