Klaus Demo nginx / 50832b0
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. Maxim Dounin 6 years ago
1 changed file(s) with 16 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
1919 static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle);
2020 static void ngx_master_process_exit(ngx_cycle_t *cycle);
2121 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data);
22 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority);
22 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker);
2323 static void ngx_worker_process_exit(ngx_cycle_t *cycle);
2424 static void ngx_channel_handler(ngx_event_t *ev);
2525 #if (NGX_THREADS)
6161 #endif
6262
6363
64 uint64_t cpu_affinity;
6564 static u_char master_process[] = "master process";
6665
6766
359358
360359 for (i = 0; i < n; i++) {
361360
362 cpu_affinity = ngx_get_cpu_affinity(i);
363
364 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL,
365 "worker process", type);
361 ngx_spawn_process(cycle, ngx_worker_process_cycle,
362 (void *) (intptr_t) i, "worker process", type);
366363
367364 ch.pid = ngx_processes[ngx_process_slot].pid;
368365 ch.slot = ngx_process_slot;
370367
371368 ngx_pass_open_channel(cycle, &ch);
372369 }
373
374 cpu_affinity = 0;
375370 }
376371
377372
725720 static void
726721 ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data)
727722 {
723 ngx_int_t worker = (intptr_t) data;
724
728725 ngx_uint_t i;
729726 ngx_connection_t *c;
730727
731728 ngx_process = NGX_PROCESS_WORKER;
732729
733 ngx_worker_process_init(cycle, 1);
730 ngx_worker_process_init(cycle, worker);
734731
735732 ngx_setproctitle("worker process");
736733
836833
837834
838835 static void
839 ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority)
836 ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker)
840837 {
841838 sigset_t set;
839 uint64_t cpu_affinity;
842840 ngx_int_t n;
843841 ngx_uint_t i;
844842 struct rlimit rlmt;
852850
853851 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
854852
855 if (priority && ccf->priority != 0) {
853 if (worker >= 0 && ccf->priority != 0) {
856854 if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) {
857855 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
858856 "setpriority(%d) failed", ccf->priority);
916914 }
917915 }
918916
919 if (cpu_affinity) {
920 ngx_setaffinity(cpu_affinity, cycle->log);
917 if (worker >= 0) {
918 cpu_affinity = ngx_get_cpu_affinity(worker);
919
920 if (cpu_affinity) {
921 ngx_setaffinity(cpu_affinity, cycle->log);
922 }
921923 }
922924
923925 #if (NGX_HAVE_PR_SET_DUMPABLE)
12971299
12981300 ngx_process = NGX_PROCESS_HELPER;
12991301
1300 ngx_worker_process_init(cycle, 0);
1302 ngx_worker_process_init(cycle, -1);
13011303
13021304 ngx_close_listening_sockets(cycle);
13031305