Merge of r4913: fixed CPU affinity on respawn of dead workers.

Worker processes are now made aware of their sequential number needed
to select CPU affinity mask.  This replaces a workaround from r4865.
This commit is contained in:
Maxim Dounin 2012-12-10 16:00:55 +00:00
parent 4be8258166
commit 032c4f2425
1 changed files with 16 additions and 14 deletions

View File

@ -20,7 +20,7 @@ static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo);
static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle);
static void ngx_master_process_exit(ngx_cycle_t *cycle);
static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority);
static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker);
static void ngx_worker_process_exit(ngx_cycle_t *cycle);
static void ngx_channel_handler(ngx_event_t *ev);
#if (NGX_THREADS)
@ -62,7 +62,6 @@ ngx_int_t ngx_threads_n;
#endif
uint64_t cpu_affinity;
static u_char master_process[] = "master process";
@ -360,10 +359,8 @@ ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, ngx_int_t type)
for (i = 0; i < n; i++) {
cpu_affinity = ngx_get_cpu_affinity(i);
ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
"worker process", type);
ngx_spawn_process(cycle, ngx_worker_process_cycle,
(void *) (intptr_t) i, "worker process", type);
ch.pid = ngx_processes[ngx_process_slot].pid;
ch.slot = ngx_process_slot;
@ -371,8 +368,6 @@ ngx_start_worker_processes(ngx_cycle_t *cycle, ngx_int_t n, ngx_int_t type)
ngx_pass_open_channel(cycle, &ch);
}
cpu_affinity = 0;
}
@ -726,12 +721,14 @@ ngx_master_process_exit(ngx_cycle_t *cycle)
static void
ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
{
ngx_int_t worker = (intptr_t) data;
ngx_uint_t i;
ngx_connection_t *c;
ngx_process = NGX_PROCESS_WORKER;
ngx_worker_process_init(cycle, 1);
ngx_worker_process_init(cycle, worker);
ngx_setproctitle("worker process");
@ -837,9 +834,10 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
static void
ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker)
{
sigset_t set;
uint64_t cpu_affinity;
ngx_int_t n;
ngx_uint_t i;
struct rlimit rlmt;
@ -853,7 +851,7 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
if (priority && ccf->priority != 0) {
if (worker >= 0 && ccf->priority != 0) {
if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
"setpriority(%d) failed", ccf->priority);
@ -917,8 +915,12 @@ ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
}
}
if (cpu_affinity) {
ngx_setaffinity(cpu_affinity, cycle->log);
if (worker >= 0) {
cpu_affinity = ngx_get_cpu_affinity(worker);
if (cpu_affinity) {
ngx_setaffinity(cpu_affinity, cycle->log);
}
}
#if (NGX_HAVE_PR_SET_DUMPABLE)
@ -1298,7 +1300,7 @@ ngx_cache_manager_process_cycle(ngx_cycle_t *cycle, void *data)
ngx_process = NGX_PROCESS_HELPER;
ngx_worker_process_init(cycle, 0);
ngx_worker_process_init(cycle, -1);
ngx_close_listening_sockets(cycle);