From 5471c717452262caa6dbdc0cfeb30751a1d7a206 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Wed, 11 Jun 2025 10:48:44 +0200 Subject: [PATCH] pkg-auto: Move get_num_proc to util This will come in handy for spawning jobs for handling package updates. Since we don't want to spawn as many jobs as there are packages, then limiting ourselves to the job count matching the processor or core count sounds like a better idea. Signed-off-by: Krzesimir Nowak --- pkg_auto/impl/inside_sdk_container_lib.sh | 14 -------------- pkg_auto/impl/util.sh | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pkg_auto/impl/inside_sdk_container_lib.sh b/pkg_auto/impl/inside_sdk_container_lib.sh index ec7480dd74..3f1bdd2007 100644 --- a/pkg_auto/impl/inside_sdk_container_lib.sh +++ b/pkg_auto/impl/inside_sdk_container_lib.sh @@ -434,20 +434,6 @@ function clean_empty_warning_files() { done } -function get_num_proc() { - local -n num_proc_ref=${1}; shift - local -i num_proc=1 rv=1 - - # stolen from portage - [[ rv -eq 0 ]] || { rv=0; num_proc=$(getconf _NPROCESSORS_ONLN 2>/dev/null) || rv=1; } - [[ rv -eq 0 ]] || { rv=0; num_proc=$(sysctl -n hw.ncpu 2>/dev/null) || rv=1; } - # stolen from common.sh - [[ rv -eq 0 ]] || { rv=0; num_proc=$(grep -c "^processor" /proc/cpuinfo 2>/dev/null) || rv=1; } - [[ rv -eq 0 ]] || { rv=0; num_proc=1; } - - num_proc_ref=${num_proc} -} - function generate_cache_for() { local repo=${1}; shift diff --git a/pkg_auto/impl/util.sh b/pkg_auto/impl/util.sh index 267b550d11..2f1b0d4d32 100644 --- a/pkg_auto/impl/util.sh +++ b/pkg_auto/impl/util.sh @@ -333,4 +333,20 @@ function struct_declare() { declare "${args[@]}" "${@}" } +function get_num_proc() { + local -n num_proc_ref=${1}; shift + local -i num_proc=1 rv=1 + + # stolen from portage + [[ rv -eq 0 ]] || { rv=0; num_proc=$(getconf _NPROCESSORS_ONLN 2>/dev/null) || rv=1; } + [[ rv -eq 0 ]] || { rv=0; num_proc=$(sysctl -n hw.ncpu 2>/dev/null) || rv=1; } + # stolen from my head + [[ rv -eq 0 ]] || { rv=0; num_proc=$(nproc) || rv=1; } + # stolen from common.sh + [[ rv -eq 0 ]] || { rv=0; num_proc=$(grep -c "^processor" /proc/cpuinfo 2>/dev/null) || rv=1; } + [[ rv -eq 0 ]] || { rv=0; num_proc=1; } + + num_proc_ref=${num_proc} +} + fi