]> git.kaiwu.me - nginx.git/commitdiff
Added ngx_ncpu detection for most *nix platforms.
authorValentin Bartenev <vbart@nginx.com>
Fri, 10 Feb 2012 11:24:19 +0000 (11:24 +0000)
committerValentin Bartenev <vbart@nginx.com>
Fri, 10 Feb 2012 11:24:19 +0000 (11:24 +0000)
This inaccurate detection by using sysconf(_SC_NPROCESSORS_ONLN) can improve
usage of the mutex lock optimization on multicore systems.

auto/unix
src/os/unix/ngx_posix_init.c

index 398b9bec411328b26f51670b50ef4428bce4a8fd..5ee8f3734fee419e9989e1f4a082ae66824ce126 100755 (executable)
--- a/auto/unix
+++ b/auto/unix
@@ -721,3 +721,13 @@ ngx_feature_path=
 ngx_feature_libs=
 ngx_feature_test="struct dirent  dir; dir.d_type = DT_REG"
 . auto/feature
+
+
+ngx_feature="sysconf(_SC_NPROCESSORS_ONLN)"
+ngx_feature_name="NGX_HAVE_SC_NPROCESSORS_ONLN"
+ngx_feature_run=no
+ngx_feature_incs=
+ngx_feature_path=
+ngx_feature_libs=
+ngx_feature_test="sysconf(_SC_NPROCESSORS_ONLN)"
+. auto/feature
index 02642bd7ccf28bbda04e651754bbbd7197e20ff0..eea65a9034e3038a34ab8af5c009b387d95adc46 100644 (file)
@@ -47,7 +47,13 @@ ngx_os_init(ngx_log_t *log)
 
     for (n = ngx_pagesize; n >>= 1; ngx_pagesize_shift++) { /* void */ }
 
+#if (NGX_HAVE_SC_NPROCESSORS_ONLN)
     if (ngx_ncpu == 0) {
+        ngx_ncpu = sysconf(_SC_NPROCESSORS_ONLN);
+    }
+#endif
+
+    if (ngx_ncpu < 1) {
         ngx_ncpu = 1;
     }