Skip to contentSkip to conversation

bitbake.conf: Limit the number of OpenMP threads

PATCH New Joshua Watt 1 participant 1 message Apr 1, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bitbake.conf: Limit the number of OpenMP threads

Limits the number of OpenMP threads to match BB_NUMBER_THREADS. This prevents OpenMP (libgomp in particular) from falling back to using all the available CPUs, which behaves poorly when attempting to limit build usage, especially when attempting to build in a container.

---
 meta/conf/bitbake.conf | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
meta/conf/bitbake.conf +6 -1
index d87d7cafb6..385fc7dd55 100644
@@ -810,6 +810,10 @@ XZ_THREADS ?= "${@oe.utils.cpu_count(at_least=2)}"
 XZ_DEFAULTS ?= "--memlimit=${XZ_MEMLIMIT} --threads=${XZ_THREADS}"
 XZ_DEFAULTS[vardepsexclude] += "XZ_MEMLIMIT XZ_THREADS"
 
+# Limit the number of threads that OpenMP libraries will use. Otherwise they
+# may fallback to using all CPUs
+export OMP_NUM_THREADS = "${BB_NUMBER_THREADS}"
+
 ##################################################################
 # Magic Cookie for SANITY CHECK
 ##################################################################
@@ -891,7 +895,8 @@ BB_HASHEXCLUDE_COMMON ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH BBSERVER DL_DI
     WARN_QA ERROR_QA WORKDIR STAMPCLEAN PKGDATA_DIR BUILD_ARCH SSTATE_PKGARCH \
     BB_WORKERCONTEXT BB_LIMITEDDEPS BB_UNIHASH extend_recipe_sysroot DEPLOY_DIR \
     SSTATE_HASHEQUIV_METHOD SSTATE_HASHEQUIV_REPORT_TASKDATA \
-    SSTATE_HASHEQUIV_OWNER CCACHE_TOP_DIR BB_HASHSERVE GIT_CEILING_DIRECTORIES"
+    SSTATE_HASHEQUIV_OWNER CCACHE_TOP_DIR BB_HASHSERVE GIT_CEILING_DIRECTORIES \
+    OMP_NUM_THREADS"
 BB_HASHBASE_WHITELIST ?= "${BB_HASHEXCLUDE_COMMON} PSEUDO_IGNORE_PATHS BUILDHISTORY_DIR SSTATE_DIR "
 BB_HASHCONFIG_WHITELIST ?= "${BB_HASHEXCLUDE_COMMON} DATE TIME SSH_AGENT_PID \
     SSH_AUTH_SOCK PSEUDO_BUILD BB_ENV_EXTRAWHITE DISABLE_SANITY_CHECKS \
Signature · 1 line
2.30.0