Mercurial > hg > nginx
comparison src/core/nginx.c @ 4549:f31162fefe01
worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Wed, 21 Mar 2012 13:58:51 +0000 |
parents | d620f497c50f |
children | 834049edae24 |
comparison
equal
deleted
inserted
replaced
4548:4c1e6cef1453 | 4549:f31162fefe01 |
---|---|
981 ngx_conf_init_msec_value(ccf->timer_resolution, 0); | 981 ngx_conf_init_msec_value(ccf->timer_resolution, 0); |
982 | 982 |
983 ngx_conf_init_value(ccf->worker_processes, 1); | 983 ngx_conf_init_value(ccf->worker_processes, 1); |
984 ngx_conf_init_value(ccf->debug_points, 0); | 984 ngx_conf_init_value(ccf->debug_points, 0); |
985 | 985 |
986 #if (NGX_HAVE_SCHED_SETAFFINITY) | 986 #if (NGX_HAVE_CPU_AFFINITY) |
987 | 987 |
988 if (ccf->cpu_affinity_n | 988 if (ccf->cpu_affinity_n |
989 && ccf->cpu_affinity_n != 1 | 989 && ccf->cpu_affinity_n != 1 |
990 && ccf->cpu_affinity_n != (ngx_uint_t) ccf->worker_processes) | 990 && ccf->cpu_affinity_n != (ngx_uint_t) ccf->worker_processes) |
991 { | 991 { |
992 ngx_log_error(NGX_LOG_WARN, cycle->log, 0, | 992 ngx_log_error(NGX_LOG_WARN, cycle->log, 0, |
993 "number of the \"worker_processes\" is not equal to " | 993 "the number of \"worker_processes\" is not equal to " |
994 "the number of the \"worker_cpu_affinity\" mask, " | 994 "the number of \"worker_cpu_affinity\" masks, " |
995 "using last mask for remaining worker processes"); | 995 "using last mask for remaining worker processes"); |
996 } | 996 } |
997 | 997 |
998 #endif | 998 #endif |
999 | 999 |
1240 | 1240 |
1241 | 1241 |
1242 static char * | 1242 static char * |
1243 ngx_set_cpu_affinity(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1243 ngx_set_cpu_affinity(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
1244 { | 1244 { |
1245 #if (NGX_HAVE_SCHED_SETAFFINITY) | 1245 #if (NGX_HAVE_CPU_AFFINITY) |
1246 ngx_core_conf_t *ccf = conf; | 1246 ngx_core_conf_t *ccf = conf; |
1247 | 1247 |
1248 u_char ch; | 1248 u_char ch; |
1249 u_long *mask; | 1249 uint64_t *mask; |
1250 ngx_str_t *value; | 1250 ngx_str_t *value; |
1251 ngx_uint_t i, n; | 1251 ngx_uint_t i, n; |
1252 | 1252 |
1253 if (ccf->cpu_affinity) { | 1253 if (ccf->cpu_affinity) { |
1254 return "is duplicate"; | 1254 return "is duplicate"; |
1255 } | 1255 } |
1256 | 1256 |
1257 mask = ngx_palloc(cf->pool, (cf->args->nelts - 1) * sizeof(long)); | 1257 mask = ngx_palloc(cf->pool, (cf->args->nelts - 1) * sizeof(uint64_t)); |
1258 if (mask == NULL) { | 1258 if (mask == NULL) { |
1259 return NGX_CONF_ERROR; | 1259 return NGX_CONF_ERROR; |
1260 } | 1260 } |
1261 | 1261 |
1262 ccf->cpu_affinity_n = cf->args->nelts - 1; | 1262 ccf->cpu_affinity_n = cf->args->nelts - 1; |
1264 | 1264 |
1265 value = cf->args->elts; | 1265 value = cf->args->elts; |
1266 | 1266 |
1267 for (n = 1; n < cf->args->nelts; n++) { | 1267 for (n = 1; n < cf->args->nelts; n++) { |
1268 | 1268 |
1269 if (value[n].len > 32) { | 1269 if (value[n].len > 64) { |
1270 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1270 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1271 "\"worker_cpu_affinity\" supports up to 32 CPU only"); | 1271 "\"worker_cpu_affinity\" supports up to 64 CPUs only"); |
1272 return NGX_CONF_ERROR; | 1272 return NGX_CONF_ERROR; |
1273 } | 1273 } |
1274 | 1274 |
1275 mask[n - 1] = 0; | 1275 mask[n - 1] = 0; |
1276 | 1276 |
1309 | 1309 |
1310 return NGX_CONF_OK; | 1310 return NGX_CONF_OK; |
1311 } | 1311 } |
1312 | 1312 |
1313 | 1313 |
1314 u_long | 1314 uint64_t |
1315 ngx_get_cpu_affinity(ngx_uint_t n) | 1315 ngx_get_cpu_affinity(ngx_uint_t n) |
1316 { | 1316 { |
1317 ngx_core_conf_t *ccf; | 1317 ngx_core_conf_t *ccf; |
1318 | 1318 |
1319 ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, | 1319 ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, |