From 370bedb42d1c933de7769c562c45386254409903 Mon Sep 17 00:00:00 2001 From: Andrei Aldea <7153954+Grippy98@users.noreply.github.com> Date: Sun, 13 Jul 2025 09:33:48 +0200 Subject: [PATCH] Add option for number of threads used by build system (#8346) * Add option for number of threads used by build system Attempt to fix https://github.com/armbian/build/issues/6907 * Add CPUTHREADS to replace USEALLTHREADS Defaults to 150% as was always the case, otherwise allow user to override number of threads. --- lib/functions/configuration/compilation-config.sh | 13 +++++++++---- lib/functions/configuration/main-config.sh | 2 -- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/functions/configuration/compilation-config.sh b/lib/functions/configuration/compilation-config.sh index 8b416d0e54..83cf5f2d04 100644 --- a/lib/functions/configuration/compilation-config.sh +++ b/lib/functions/configuration/compilation-config.sh @@ -24,10 +24,15 @@ function prepare_compilation_vars() { # moved from config: this does not belong in configuration. it's a compilation thing. # optimize build time with 100% CPU usage CPUS=$(grep -c 'processor' /proc/cpuinfo) - if [[ $USEALLCORES != no ]]; then - CTHREADS="-j$((CPUS + CPUS / 2))" - else - CTHREADS="-j1" + + # Default to 150% of CPUs to maximize compilation speed + CTHREADS="-j$((CPUS + CPUS / 2))" + + # If CPUTHREADS is defined and a valid positive integer allow user to override CTHREADS + # This is useful for limiting Armbian build to a specific number of threads, e.g. for build servers + if [[ "$CPUTHREADS" =~ ^[1-9][0-9]*$ ]]; then + CTHREADS="-j$CPUTHREADS" + echo "Using user-defined thread count: $CTHREADS" fi call_extension_method "post_determine_cthreads" "config_post_determine_cthreads" <<- 'POST_DETERMINE_CTHREADS' diff --git a/lib/functions/configuration/main-config.sh b/lib/functions/configuration/main-config.sh index dedbeb32a2..a731305a20 100644 --- a/lib/functions/configuration/main-config.sh +++ b/lib/functions/configuration/main-config.sh @@ -95,8 +95,6 @@ function do_main_configuration() { TZDATA="Etc/UTC" # If not /etc/timezone at host, default to UTC. fi - USEALLCORES=yes # Use all CPU cores for compiling - [[ -z $EXIT_PATCHING_ERROR ]] && EXIT_PATCHING_ERROR="" # exit patching if failed [[ -z $HOST ]] && HOST="$BOARD" cd "${SRC}" || exit