From 85229acf04027036932537039f5077827a119a09 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 30 Sep 2021 18:24:21 +0200 Subject: [PATCH] Limit make parallelism to the number of CPUs Don't default to unbridled -j, which causes a load spike and isn't really faster. "Number of CPUs" is implemented here as a reasonable compromise between portability, correctness and simplicity. This is just a default that can be overridden by setting MAKEFLAGS in the environment. Signed-off-by: Gilles Peskine --- tests/scripts/all.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/scripts/all.sh b/tests/scripts/all.sh index a7d1b7afd..aeb6d7b70 100755 --- a/tests/scripts/all.sh +++ b/tests/scripts/all.sh @@ -165,7 +165,7 @@ pre_initialize_variables () { # if MAKEFLAGS is not set add the -j option to speed up invocations of make if [ -z "${MAKEFLAGS+set}" ]; then - export MAKEFLAGS="-j" + export MAKEFLAGS="-j$(all_sh_nproc)" fi # Include more verbose output for failing tests run by CMake or make @@ -313,6 +313,18 @@ trap 'fatal_signal HUP' HUP trap 'fatal_signal INT' INT trap 'fatal_signal TERM' TERM +# Number of processors on this machine. Used as the default setting +# for parallel make. +all_sh_nproc () +{ + { + nproc || # Linux + sysctl -n hw.ncpuonline || # NetBSD, OpenBSD + sysctl -n hw.ncpu || # FreeBSD + echo 1 + } 2>/dev/null +} + msg() { if [ -n "${current_component:-}" ]; then