summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2012-01-05 15:48:24 -0800
committerJeremy Allison <jra@samba.org>2012-01-06 02:42:25 +0100
commite8a7d9c822ae4be4533f9e34885816a5b7831154 (patch)
tree50352a0092e47131f3858f664740a5cbee8fdd44 /source3/lib
parent200c22b9940f8e222f20f95691bc61dcb883b609 (diff)
downloadsamba-e8a7d9c822ae4be4533f9e34885816a5b7831154.tar.gz
samba-e8a7d9c822ae4be4533f9e34885816a5b7831154.tar.bz2
samba-e8a7d9c822ae4be4533f9e34885816a5b7831154.zip
Add a sys_get_number_of_cores() function that calls sysconf or sysctl
and tunes the aio threads.
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/system.c49
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)
/*******************************************************************