aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-06-12 00:40:37 -0700
committerGarrett D'Amore <garrett@damore.org>2018-06-12 00:40:37 -0700
commite60308808f58a3517170edf61245031cb899e59e (patch)
tree79c78ac8fbde2efef1c179e5c2cc6c23fff1f64d /src/core
parent061beeabd9859f92917ae3f0c5657dd8eca44d68 (diff)
downloadnng-e60308808f58a3517170edf61245031cb899e59e.tar.gz
nng-e60308808f58a3517170edf61245031cb899e59e.tar.bz2
nng-e60308808f58a3517170edf61245031cb899e59e.zip
fixes #32 autoscale based on CPUs available
This should work on both Windows and the most common POSIX variants. We will create at least two threads for running completions, but there are numerous other threads in the code.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/platform.h4
-rw-r--r--src/core/taskq.c11
2 files changed, 11 insertions, 4 deletions
diff --git a/src/core/platform.h b/src/core/platform.h
index 07bfc14c..b709e3ba 100644
--- a/src/core/platform.h
+++ b/src/core/platform.h
@@ -190,6 +190,10 @@ extern int nni_plat_init(int (*)(void));
// will be called until nni_platform_init is called.
extern void nni_plat_fini(void);
+// nni_plat_ncpu returns the number of logical CPUs on the system. This is
+// used to scale the number of independent threads started.
+extern int nni_plat_ncpu(void);
+
//
// TCP Support.
//
diff --git a/src/core/taskq.c b/src/core/taskq.c
index ae66ec67..82a7456b 100644
--- a/src/core/taskq.c
+++ b/src/core/taskq.c
@@ -261,11 +261,14 @@ nni_task_fini(nni_task *task)
int
nni_taskq_sys_init(void)
{
- int rv;
+ int nthrs;
- // XXX: Make the "16" = NCPUs * 2
- rv = nni_taskq_init(&nni_taskq_systq, 16);
- return (rv);
+ nthrs = nni_plat_ncpu() * 2;
+ if (nthrs < 2) {
+ nthrs = 2;
+ }
+
+ return (nni_taskq_init(&nni_taskq_systq, nthrs));
}
void