Mercurial > hg > nginx-vendor-current
diff src/core/nginx.c @ 126:df17fbafec8f NGINX_0_3_10
nginx 0.3.10
*) Change: the "valid_referers" directive and the "$invalid_referer"
variable were moved to the new ngx_http_referer_module from the
ngx_http_rewrite_module.
*) Change: the "$apache_bytes_sent" variable name was changed to
"$body_bytes_sent".
*) Feature: the "$sent_http_..." variables.
*) Feature: the "if" directive supports the "=" and "!=" operations.
*) Feature: the "proxy_pass" directive supports the HTTPS protocol.
*) Feature: the "proxy_set_body" directive.
*) Feature: the "post_action" directive.
*) Feature: the ngx_http_empty_gif_module.
*) Feature: the "worker_cpu_affinity" directive for Linux.
*) Bugfix: the "rewrite" directive did not unescape URI part in
redirect, now it is unescaped except the %00-%25 and %7F-%FF
characters.
*) Bugfix: nginx could not be built by the icc 9.0 compiler.
*) Bugfix: if the SSI was enabled for zero size static file, then the
chunked response was encoded incorrectly.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 15 Nov 2005 00:00:00 +0300 |
parents | 408f195b3482 |
children | 8e6d4d96ec4c |
line wrap: on
line diff
--- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -17,13 +17,15 @@ static void *ngx_core_module_create_conf static char *ngx_core_module_init_conf(ngx_cycle_t *cycle, void *conf); static char *ngx_set_user(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); static char *ngx_set_priority(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +static char *ngx_set_cpu_affinity(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf); static ngx_conf_enum_t ngx_debug_points[] = { { ngx_string("stop"), NGX_DEBUG_POINTS_STOP }, { ngx_string("abort"), NGX_DEBUG_POINTS_ABORT }, { ngx_null_string, 0 } -}; +}; static ngx_command_t ngx_core_commands[] = { @@ -84,6 +86,13 @@ static ngx_command_t ngx_core_commands[ 0, NULL }, + { ngx_string("worker_cpu_affinity"), + NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_1MORE, + ngx_set_cpu_affinity, + 0, + 0, + NULL }, + { ngx_string("worker_rlimit_nofile"), NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1, ngx_conf_set_num_slot, @@ -537,6 +546,8 @@ ngx_core_module_create_conf(ngx_cycle_t * ccf->pid = NULL; * ccf->oldpid = NULL; * ccf->priority = 0; + * ccf->cpu_affinity_n = 0; + * ccf->cpu_affinity = NULL; */ ccf->daemon = NGX_CONF_UNSET; @@ -578,10 +589,26 @@ ngx_core_module_init_conf(ngx_cycle_t *c ngx_conf_init_value(ccf->worker_processes, 1); ngx_conf_init_value(ccf->debug_points, 0); +#if (NGX_HAVE_SCHED_SETAFFINITY) + + if (ccf->cpu_affinity_n + && ccf->cpu_affinity_n != 1 + && ccf->cpu_affinity_n != (ngx_uint_t) ccf->worker_processes) + { + ngx_log_error(NGX_LOG_WARN, cycle->log, 0, + "number of the \"worker_processes\" is not equal to " + "the number of the \"worker_cpu_affinity\" mask, " + "using last mask for remaining worker processes"); + } + +#endif + #if (NGX_THREADS) + ngx_conf_init_value(ccf->worker_threads, 0); ngx_threads_n = ccf->worker_threads; ngx_conf_init_size_value(ccf->thread_stack_size, 2 * 1024 * 1024); + #endif #if !(NGX_WIN32) @@ -732,3 +759,95 @@ ngx_set_priority(ngx_conf_t *cf, ngx_com return NGX_CONF_OK; } + + +static char * +ngx_set_cpu_affinity(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ +#if (NGX_HAVE_SCHED_SETAFFINITY) + ngx_core_conf_t *ccf = conf; + + u_char ch; + u_long *mask; + ngx_str_t *value; + ngx_uint_t i, n; + + if (ccf->cpu_affinity) { + return "is duplicate"; + } + + mask = ngx_palloc(cf->pool, (cf->args->nelts - 1) * sizeof(long)); + if (mask == NULL) { + return NGX_CONF_ERROR; + } + + ccf->cpu_affinity_n = cf->args->nelts - 1; + ccf->cpu_affinity = mask; + + value = cf->args->elts; + + for (n = 1; n < cf->args->nelts; n++) { + + if (value[n].len > 32) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "\"worker_cpu_affinity\" supports up to 32 CPU only"); + return NGX_CONF_ERROR; + } + + mask[n - 1] = 0; + + for (i = 0; i < value[n].len; i++) { + + ch = value[n].data[i]; + + if (ch == ' ') { + continue; + } + + mask[n - 1] <<= 1; + + if (ch == '0') { + continue; + } + + if (ch == '1') { + mask[n - 1] |= 1; + continue; + } + + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "invalid character \"%c\" in \"worker_cpu_affinity\"", + ch); + return NGX_CONF_ERROR ; + } + } + +#else + + ngx_conf_log_error(NGX_LOG_WARN, cf, 0, + "\"worker_cpu_affinity\" is not supported " + "on this platform, ignored"); +#endif + + return NGX_CONF_OK; +} + + +u_long +ngx_get_cpu_affinity(ngx_uint_t n) +{ + ngx_core_conf_t *ccf; + + ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, + ngx_core_module); + + if (ccf->cpu_affinity == NULL) { + return 0; + } + + if (ccf->cpu_affinity_n > n) { + return ccf->cpu_affinity[n]; + } + + return ccf->cpu_affinity[ccf->cpu_affinity_n - 1]; +}