aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2022-10-20 20:22:50 +0300
committerLasse Collin <lasse.collin@tukaani.org>2022-10-20 20:22:50 +0300
commit2611c4d90535652d3eb7ef4a026a6691276fab43 (patch)
tree7277997b90b6b812d101c45e8ef0b84613b81f3f /src/common
parentTests: Skip tests in test_*.sh if encoders and/or decoders are disabled. (diff)
downloadxz-2611c4d90535652d3eb7ef4a026a6691276fab43.tar.xz
tuklib_cpucores: Use HW_NCPUONLINE on OpenBSD.
On OpenBSD the number of cores online is often less than what HW_NCPU would return because OpenBSD disables simultaneous multi-threading (SMT) by default. Thanks to Christian Weisgerber.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/tuklib_cpucores.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/common/tuklib_cpucores.c b/src/common/tuklib_cpucores.c
index cc968dd2..bb3f2f75 100644
--- a/src/common/tuklib_cpucores.c
+++ b/src/common/tuklib_cpucores.c
@@ -72,7 +72,16 @@ tuklib_cpucores(void)
}
#elif defined(TUKLIB_CPUCORES_SYSCTL)
+ // On OpenBSD HW_NCPUONLINE tells the number of processor cores that
+ // are online so it is preferred over HW_NCPU which also counts cores
+ // that aren't currently available. The number of cores online is
+ // often less than HW_NCPU because OpenBSD disables simultaneous
+ // multi-threading (SMT) by default.
+# ifdef HW_NCPUONLINE
+ int name[2] = { CTL_HW, HW_NCPUONLINE };
+# else
int name[2] = { CTL_HW, HW_NCPU };
+# endif
int cpus;
size_t cpus_size = sizeof(cpus);
if (sysctl(name, 2, &cpus, &cpus_size, NULL, 0) != -1