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.
This commit is contained in:
Andrei Aldea 2025-07-13 09:33:48 +02:00 committed by GitHub
parent 3a9babee14
commit 370bedb42d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View File

@ -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'

View File

@ -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