chore: add ability to override hardware concurrency from environment

This commit is contained in:
Marcus Holland-Moritz 2025-08-18 18:59:29 +02:00
parent 9a87749358
commit 7a386ee443
2 changed files with 10 additions and 1 deletions

View File

@ -361,6 +361,8 @@ if [[ "-$BUILD_TYPE-" == *-static-* ]]; then
if [[ -n "$CROSS_ARCH" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=$_MARCH -DCMAKE_CROSSCOMPILING_EMULATOR=/usr/bin/qemu-$_MARCH -DFOLLY_HAVE_UNALIGNED_ACCESS=OFF -DFOLLY_HAVE_WEAK_SYMBOLS=ON -DFOLLY_HAVE_LINUX_VDSO=OFF -DFOLLY_HAVE_WCHAR_SUPPORT=OFF -DHAVE_VSNPRINTF_ERRORS=OFF"
# Limit emulated parallelism to 4 threads, otherwise the slowdown is substantial
export DWARFS_OVERRIDE_HARDWARE_CONCURRENCY=4
fi
fi

View File

@ -424,7 +424,14 @@ std::string exception_str(std::exception_ptr const& e) {
}
unsigned int hardware_concurrency() noexcept {
return folly::hardware_concurrency();
static auto const env = [] {
std::optional<int> concurrency;
if (auto env = std::getenv("DWARFS_OVERRIDE_HARDWARE_CONCURRENCY")) {
concurrency = try_to<int>(env);
}
return concurrency;
}();
return env.value_or(folly::hardware_concurrency());
}
int get_current_umask() {