8 # Check how to find out the number of available CPU cores in the system.
9 # This information is used by tuklib_cpucores.c.
12 # - sysctl(): BSDs, OS/2
13 # - sysconf(): GNU/Linux, Solaris, Tru64, IRIX, AIX, Cygwin
14 # - pstat_getdynamic(): HP-UX
18 # Author: Lasse Collin
20 # This file has been put into the public domain.
21 # You can do whatever you want with this file.
24 AC_DEFUN_ONCE([TUKLIB_CPUCORES], [
25 AC_REQUIRE([TUKLIB_COMMON])
27 # sys/param.h might be needed by sys/sysctl.h.
28 AC_CHECK_HEADERS([sys/param.h])
30 AC_CACHE_CHECK([how to detect the number of available CPU cores],
31 [tuklib_cv_cpucores_method], [
33 # Look for sysctl() solution first, because on OS/2, both sysconf()
34 # and sysctl() pass the tests in this file, but only sysctl()
36 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
37 #include <sys/types.h>
38 #ifdef HAVE_SYS_PARAM_H
39 # include <sys/param.h>
41 #include <sys/sysctl.h>
45 int name[2] = { CTL_HW, HW_NCPU };
47 size_t cpus_size = sizeof(cpus);
48 sysctl(name, 2, &cpus, &cpus_size, NULL, 0);
51 ]])], [tuklib_cv_cpucores_method=sysctl], [
53 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
59 #ifdef _SC_NPROCESSORS_ONLN
60 /* Many systems using sysconf() */
61 i = sysconf(_SC_NPROCESSORS_ONLN);
64 i = sysconf(_SC_NPROC_ONLN);
68 ]])], [tuklib_cv_cpucores_method=sysconf], [
70 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
71 #include <sys/param.h>
72 #include <sys/pstat.h>
77 struct pst_dynamic pst;
78 pstat_getdynamic(&pst, sizeof(pst), 1, 0);
79 (void)pst.psd_proc_cnt;
82 ]])], [tuklib_cv_cpucores_method=pstat_getdynamic], [
84 tuklib_cv_cpucores_method=unknown
87 case $tuklib_cv_cpucores_method in
89 AC_DEFINE([TUKLIB_CPUCORES_SYSCTL], [1],
90 [Define to 1 if the number of available CPU cores
91 can be detected with sysctl().])
94 AC_DEFINE([TUKLIB_CPUCORES_SYSCONF], [1],
95 [Define to 1 if the number of available CPU cores
96 can be detected with sysconf(_SC_NPROCESSORS_ONLN)
97 or sysconf(_SC_NPROC_ONLN).])
100 AC_DEFINE([TUKLIB_CPUCORES_PSTAT_GETDYNAMIC], [1],
101 [Define to 1 if the number of available CPU cores
102 can be detected with pstat_getdynamic().])