aboutsummaryrefslogtreecommitdiff
path: root/m4/tuklib_cpucores.m4
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2015-02-10 15:28:30 +0200
committerLasse Collin <lasse.collin@tukaani.org>2015-02-10 15:28:30 +0200
commitd935b0cdf3db440269b9d952b2b281b18f8c7b08 (patch)
treedaaa0a7ee9b6a2b10248396cc1b15a535e084a43 /m4/tuklib_cpucores.m4
parentxzdiff: Make the mktemp usage compatible with FreeBSD's mktemp. (diff)
downloadxz-d935b0cdf3db440269b9d952b2b281b18f8c7b08.tar.xz
tuklib_cpucores: Use cpuset_getaffinity() on FreeBSD if available.
In FreeBSD, cpuset_getaffinity() is the preferred way to get the number of available cores. Thanks to Rui Paulo for the patch. I edited it slightly, but hopefully I didn't break anything.
Diffstat (limited to 'm4/tuklib_cpucores.m4')
-rw-r--r--m4/tuklib_cpucores.m423
1 files changed, 22 insertions, 1 deletions
diff --git a/m4/tuklib_cpucores.m4 b/m4/tuklib_cpucores.m4
index 64a6b43c..08e2cb0d 100644
--- a/m4/tuklib_cpucores.m4
+++ b/m4/tuklib_cpucores.m4
@@ -45,6 +45,22 @@ compile error
#endif
]])], [tuklib_cv_cpucores_method=special], [
+# FreeBSD has both cpuset and sysctl. Look for cpuset first because
+# it's a better approach.
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+#include <sys/param.h>
+#include <sys/cpuset.h>
+
+int
+main(void)
+{
+ cpuset_t set;
+ cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1,
+ sizeof(set), &set);
+ return 0;
+}
+]])], [tuklib_cv_cpucores_method=cpuset], [
+
# Look for sysctl() solution first, because on OS/2, both sysconf()
# and sysctl() pass the tests in this file, but only sysctl()
# actually works.
@@ -97,9 +113,14 @@ main(void)
]])], [tuklib_cv_cpucores_method=pstat_getdynamic], [
tuklib_cv_cpucores_method=unknown
-])])])])])
+])])])])])])
case $tuklib_cv_cpucores_method in
+ cpuset)
+ AC_DEFINE([TUKLIB_CPUCORES_CPUSET], [1],
+ [Define to 1 if the number of available CPU cores
+ can be detected with cpuset(2).])
+ ;;
sysctl)
AC_DEFINE([TUKLIB_CPUCORES_SYSCTL], [1],
[Define to 1 if the number of available CPU cores