diff options
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/system.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/source3/lib/system.c b/source3/lib/system.c index 85988417a6..6934f62710 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -26,6 +26,10 @@ #include "system/passwd.h" #include "system/filesys.h" +#ifdef HAVE_SYS_SYSCTL_H +#include <sys/sysctl.h> +#endif + #ifdef HAVE_SYS_PRCTL_H #include <sys/prctl.h> #endif @@ -2476,6 +2480,51 @@ uint32 unix_dev_minor(SMB_DEV_T dev) #endif } +/******************************************************************* + Return the number of CPUs. +********************************************************************/ + +int sys_get_number_of_cores(void) +{ + int ret = -1; + +#if defined(HAVE_SYSCONF) +#if defined(_SC_NPROCESSORS_ONLN) + ret = (int)sysconf(_SC_NPROCESSORS_ONLN); +#endif +#if defined(_SC_NPROCESSORS_CONF) + if (ret < 1) { + ret = (int)sysconf(_SC_NPROCESSORS_CONF); + } +#endif +#elif defined(HAVE_SYSCTL) && defined(CTL_HW) + int name[2]; + unsigned int len = sizeof(ret); + + name[0] = CTL_HW; +#if defined(HW_AVAILCPU) + name[1] = HW_AVAILCPU; + + if (sysctl(name, 2, &ret, &len, NULL, 0) == -1) { + ret = -1; + } +#endif +#if defined(HW_NCPU) + if(ret < 1) { + name[0] = CTL_HW; + name[1] = HW_NCPU; + if (sysctl(nm, 2, &count, &len, NULL, 0) == -1) { + ret = -1; + } + } +#endif +#endif + if (ret < 1) { + ret = 1; + } + return ret; +} + #if defined(WITH_AIO) /******************************************************************* |