summaryrefslogtreecommitdiff
path: root/src/os/unix/ngx_setaffinity.c
diff options
context:
space:
mode:
authorNGINX team <nginx@nginx.org>2012-03-28 14:00:08 +0000
committerJon Kolb <jon@b0g.us>2012-03-28 14:00:08 +0000
commit60a50f7b445d1ac18ea0b1ff140745b6844c6794 (patch)
treeb2edd9e3a38a3e58a0b348b6988e55f7f8be7cd0 /src/os/unix/ngx_setaffinity.c
parent3e2cd7431101761df65f2242c667c037599aa0c4 (diff)
downloadnginx-60a50f7b445d1ac18ea0b1ff140745b6844c6794.tar.gz
Changes with nginx 1.1.18 28 Mar 2012v1.1.18
*) Change: keepalive connections are no longer disabled for Safari by default. *) Feature: the $connection_requests variable. *) Feature: $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd and $tcpinfo_rcv_space variables. *) Feature: the "worker_cpu_affinity" directive now works on FreeBSD. *) Feature: the "xslt_param" and "xslt_string_param" directives. Thanks to Samuel Behan. *) Bugfix: in configure tests. Thanks to Piotr Sikora. *) Bugfix: in the ngx_http_xslt_filter_module. *) Bugfix: nginx could not be built on Debian GNU/Hurd.
Diffstat (limited to 'src/os/unix/ngx_setaffinity.c')
-rw-r--r--src/os/unix/ngx_setaffinity.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/os/unix/ngx_setaffinity.c b/src/os/unix/ngx_setaffinity.c
new file mode 100644
index 000000000..8f6cf3594
--- /dev/null
+++ b/src/os/unix/ngx_setaffinity.c
@@ -0,0 +1,69 @@
+
+/*
+ * Copyright (C) Nginx, Inc.
+ */
+
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+
+
+#if (NGX_HAVE_CPUSET_SETAFFINITY)
+
+#include <sys/cpuset.h>
+
+void
+ngx_setaffinity(uint64_t cpu_affinity, ngx_log_t *log)
+{
+ cpuset_t mask;
+ ngx_uint_t i;
+
+ ngx_log_error(NGX_LOG_NOTICE, log, 0,
+ "cpuset_setaffinity(0x%08Xl)", cpu_affinity);
+
+ CPU_ZERO(&mask);
+ i = 0;
+ do {
+ if (cpu_affinity & 1) {
+ CPU_SET(i, &mask);
+ }
+ i++;
+ cpu_affinity >>= 1;
+ } while (cpu_affinity);
+
+ if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1,
+ sizeof(cpuset_t), &mask) == -1)
+ {
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
+ "cpuset_setaffinity() failed");
+ }
+}
+
+#elif (NGX_HAVE_SCHED_SETAFFINITY)
+
+void
+ngx_setaffinity(uint64_t cpu_affinity, ngx_log_t *log)
+{
+ cpu_set_t mask;
+ ngx_uint_t i;
+
+ ngx_log_error(NGX_LOG_NOTICE, log, 0,
+ "sched_setaffinity(0x%08Xl)", cpu_affinity);
+
+ CPU_ZERO(&mask);
+ i = 0;
+ do {
+ if (cpu_affinity & 1) {
+ CPU_SET(i, &mask);
+ }
+ i++;
+ cpu_affinity >>= 1;
+ } while (cpu_affinity);
+
+ if (sched_setaffinity(0, sizeof(cpu_set_t), &mask) == -1) {
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
+ "sched_setaffinity() failed");
+ }
+}
+
+#endif