summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/configure.in3
-rw-r--r--source3/include/proto.h1
-rw-r--r--source3/lib/system.c49
-rw-r--r--source3/modules/vfs_aio_pthread.c15
-rw-r--r--source3/wscript2
5 files changed, 66 insertions, 4 deletions
diff --git a/source3/configure.in b/source3/configure.in
index 7ed093cd22..6a41f9786f 100644
--- a/source3/configure.in
+++ b/source3/configure.in
@@ -1119,8 +1119,9 @@ AC_SEARCH_LIBS(backtrace_symbols, [execinfo])
AC_CHECK_FUNCS(backtrace_symbols)
AC_CHECK_LIB(exc, trace_back_stack)
-# check for sysctlbyname for BSD systems
+# check for sysctlbyname and sysctl for BSD systems
AC_CHECK_FUNCS(sysctlbyname)
+AC_CHECK_FUNCS(sysctl)
#################################################
# Check to see if core dump directory is defined in linux
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 2c12a5f5a5..7a7f60a765 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -390,6 +390,7 @@ int sys_lsetxattr (const char *path, const char *name, const void *value, size_t
int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags);
uint32 unix_dev_major(SMB_DEV_T dev);
uint32 unix_dev_minor(SMB_DEV_T dev);
+int sys_get_number_of_cores(void);
int sys_aio_read(SMB_STRUCT_AIOCB *aiocb);
int sys_aio_write(SMB_STRUCT_AIOCB *aiocb);
ssize_t sys_aio_return(SMB_STRUCT_AIOCB *aiocb);
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)
/*******************************************************************
diff --git a/source3/modules/vfs_aio_pthread.c b/source3/modules/vfs_aio_pthread.c
index cccaa332e0..9217b69e80 100644
--- a/source3/modules/vfs_aio_pthread.c
+++ b/source3/modules/vfs_aio_pthread.c
@@ -55,7 +55,17 @@ static void aio_pthread_handle_completion(struct event_context *event_ctx,
static int aio_get_num_threads(void)
{
- return 10;
+ int num_cores = sys_get_number_of_cores();
+ DEBUG(10,("aio_get_num_threads: sys_get_number_of_cores "
+ "returned %d\n",
+ num_cores));
+ num_cores *= 2;
+ if (num_cores < 1) {
+ num_cores = 1;
+ }
+ /* Even on a single processor box give a little
+ concurrency. */
+ return MIN(4,num_cores);
}
#if 0
@@ -102,7 +112,7 @@ static bool init_aio_threadpool(void)
{
struct fd_event *sock_event = NULL;
int ret = 0;
- int num_threads = aio_get_num_threads();
+ int num_threads;
#if 0
struct timeval ne;
#endif
@@ -111,6 +121,7 @@ static bool init_aio_threadpool(void)
return true;
}
+ num_threads = aio_get_num_threads();
ret = pthreadpool_init(num_threads, &pool);
if (ret) {
errno = ret;
diff --git a/source3/wscript b/source3/wscript
index 846917c13b..9a32ab7e75 100644
--- a/source3/wscript
+++ b/source3/wscript
@@ -256,7 +256,7 @@ seekdir64 select setea setenv setgidx setgroups setlocale setluid
setmntent setpgid setpriv setproplist setsid setuidx
setxattr shmget shm_open sigaction sigblock sigprocmask sigset
sizeof_proplist_entry _stat __stat stat64 _stat64 __stat64 statvfs
-strcasecmp strchr strpbrk strsignal strtol strupr sysconf sysctlbyname
+strcasecmp strchr strpbrk strsignal strtol strupr sysconf sysctl sysctlbyname
__sys_llseek syslog _telldir __telldir telldir64 textdomain timegm
utimensat vsyslog _write __write __xstat
''')