[Pkg-dkms-maint] Bug#663114: [PATCH] Parallel build of dkms modules
Aron Xu
aron at debian.org
Thu Apr 28 08:08:47 UTC 2016
From: Andras Korn <korn-debbugs at elan.rulez.org>
---
dkms | 28 ++++++++++++++++++++++++----
dkms.8 | 9 +++++++++
2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/dkms b/dkms
index 042acc0..2c4099e 100644
--- a/dkms
+++ b/dkms
@@ -126,6 +126,7 @@ show_usage()
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()
@@ -144,6 +145,18 @@ VER()
-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()
+{
+ # use nproc(1) from coreutils 8.1-1+ if available, otherwise single job
+ if [ -x /usr/bin/nproc ]; then
+ nproc
+ else
+ echo "1"
+ fi
+}
+
# 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()
@@ -1084,7 +1097,7 @@ prepare_kernel()
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
@@ -1130,9 +1143,9 @@ prepare_kernel()
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
@@ -1204,7 +1217,7 @@ do_build()
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)" \
@@ -3440,6 +3453,7 @@ while (($# > 0)); do
--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;;
@@ -3487,6 +3501,12 @@ if [[ $arch && $all ]]; then
$"--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"
diff --git a/dkms.8 b/dkms.8
index 908d9db..e322aa6 100644
--- a/dkms.8
+++ b/dkms.8
@@ -516,6 +516,15 @@ prior than DKMS 2.1. This option currently defaults to 1.
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
+.I nproc(1).
+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
--
2.1.4
More information about the Pkg-dkms-maint
mailing list