Mercurial > hg > nginx-quic
comparison src/os/unix/ngx_process_cycle.c @ 4912:e8ef31c58d43
Fixed setting of CPU affinity on respawn of dead worker processes.
Worker processes are now made aware of their sequential number needed
to select CPU affinity mask. This replaces a workaround from r4865.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Fri, 16 Nov 2012 09:25:52 +0000 |
parents | 8a9b7b4e9f2d |
children | 484aec758d2c |
comparison
equal
deleted
inserted
replaced
4911:0d3bb5b62345 | 4912:e8ef31c58d43 |
---|---|
18 static void ngx_pass_open_channel(ngx_cycle_t *cycle, ngx_channel_t *ch); | 18 static void ngx_pass_open_channel(ngx_cycle_t *cycle, ngx_channel_t *ch); |
19 static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo); | 19 static void ngx_signal_worker_processes(ngx_cycle_t *cycle, int signo); |
20 static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle); | 20 static ngx_uint_t ngx_reap_children(ngx_cycle_t *cycle); |
21 static void ngx_master_process_exit(ngx_cycle_t *cycle); | 21 static void ngx_master_process_exit(ngx_cycle_t *cycle); |
22 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); | 22 static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data); |
23 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority); | 23 static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker); |
24 static void ngx_worker_process_exit(ngx_cycle_t *cycle); | 24 static void ngx_worker_process_exit(ngx_cycle_t *cycle); |
25 static void ngx_channel_handler(ngx_event_t *ev); | 25 static void ngx_channel_handler(ngx_event_t *ev); |
26 #if (NGX_THREADS) | 26 #if (NGX_THREADS) |
27 static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle); | 27 static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle); |
28 static ngx_thread_value_t ngx_worker_thread_cycle(void *data); | 28 static ngx_thread_value_t ngx_worker_thread_cycle(void *data); |
60 volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS]; | 60 volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS]; |
61 ngx_int_t ngx_threads_n; | 61 ngx_int_t ngx_threads_n; |
62 #endif | 62 #endif |
63 | 63 |
64 | 64 |
65 uint64_t cpu_affinity; | |
66 static u_char master_process[] = "master process"; | 65 static u_char master_process[] = "master process"; |
67 | 66 |
68 | 67 |
69 static ngx_cache_manager_ctx_t ngx_cache_manager_ctx = { | 68 static ngx_cache_manager_ctx_t ngx_cache_manager_ctx = { |
70 ngx_cache_manager_process_handler, "cache manager process", 0 | 69 ngx_cache_manager_process_handler, "cache manager process", 0 |
358 | 357 |
359 ch.command = NGX_CMD_OPEN_CHANNEL; | 358 ch.command = NGX_CMD_OPEN_CHANNEL; |
360 | 359 |
361 for (i = 0; i < n; i++) { | 360 for (i = 0; i < n; i++) { |
362 | 361 |
363 cpu_affinity = ngx_get_cpu_affinity(i); | 362 ngx_spawn_process(cycle, ngx_worker_process_cycle, |
364 | 363 (void *) (intptr_t) i, "worker process", type); |
365 ngx_spawn_process(cycle, ngx_worker_process_cycle, NULL, | |
366 "worker process", type); | |
367 | 364 |
368 ch.pid = ngx_processes[ngx_process_slot].pid; | 365 ch.pid = ngx_processes[ngx_process_slot].pid; |
369 ch.slot = ngx_process_slot; | 366 ch.slot = ngx_process_slot; |
370 ch.fd = ngx_processes[ngx_process_slot].channel[0]; | 367 ch.fd = ngx_processes[ngx_process_slot].channel[0]; |
371 | 368 |
372 ngx_pass_open_channel(cycle, &ch); | 369 ngx_pass_open_channel(cycle, &ch); |
373 } | 370 } |
374 | |
375 cpu_affinity = 0; | |
376 } | 371 } |
377 | 372 |
378 | 373 |
379 static void | 374 static void |
380 ngx_start_cache_manager_processes(ngx_cycle_t *cycle, ngx_uint_t respawn) | 375 ngx_start_cache_manager_processes(ngx_cycle_t *cycle, ngx_uint_t respawn) |
724 | 719 |
725 | 720 |
726 static void | 721 static void |
727 ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) | 722 ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) |
728 { | 723 { |
724 ngx_int_t worker = (intptr_t) data; | |
725 | |
729 ngx_uint_t i; | 726 ngx_uint_t i; |
730 ngx_connection_t *c; | 727 ngx_connection_t *c; |
731 | 728 |
732 ngx_process = NGX_PROCESS_WORKER; | 729 ngx_process = NGX_PROCESS_WORKER; |
733 | 730 |
734 ngx_worker_process_init(cycle, 1); | 731 ngx_worker_process_init(cycle, worker); |
735 | 732 |
736 ngx_setproctitle("worker process"); | 733 ngx_setproctitle("worker process"); |
737 | 734 |
738 #if (NGX_THREADS) | 735 #if (NGX_THREADS) |
739 { | 736 { |
835 } | 832 } |
836 } | 833 } |
837 | 834 |
838 | 835 |
839 static void | 836 static void |
840 ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority) | 837 ngx_worker_process_init(ngx_cycle_t *cycle, ngx_int_t worker) |
841 { | 838 { |
842 sigset_t set; | 839 sigset_t set; |
840 uint64_t cpu_affinity; | |
843 ngx_int_t n; | 841 ngx_int_t n; |
844 ngx_uint_t i; | 842 ngx_uint_t i; |
845 struct rlimit rlmt; | 843 struct rlimit rlmt; |
846 ngx_core_conf_t *ccf; | 844 ngx_core_conf_t *ccf; |
847 ngx_listening_t *ls; | 845 ngx_listening_t *ls; |
851 exit(2); | 849 exit(2); |
852 } | 850 } |
853 | 851 |
854 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); | 852 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); |
855 | 853 |
856 if (priority && ccf->priority != 0) { | 854 if (worker >= 0 && ccf->priority != 0) { |
857 if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) { | 855 if (setpriority(PRIO_PROCESS, 0, ccf->priority) == -1) { |
858 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | 856 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
859 "setpriority(%d) failed", ccf->priority); | 857 "setpriority(%d) failed", ccf->priority); |
860 } | 858 } |
861 } | 859 } |
915 /* fatal */ | 913 /* fatal */ |
916 exit(2); | 914 exit(2); |
917 } | 915 } |
918 } | 916 } |
919 | 917 |
920 if (cpu_affinity) { | 918 if (worker >= 0) { |
921 ngx_setaffinity(cpu_affinity, cycle->log); | 919 cpu_affinity = ngx_get_cpu_affinity(worker); |
920 | |
921 if (cpu_affinity) { | |
922 ngx_setaffinity(cpu_affinity, cycle->log); | |
923 } | |
922 } | 924 } |
923 | 925 |
924 #if (NGX_HAVE_PR_SET_DUMPABLE) | 926 #if (NGX_HAVE_PR_SET_DUMPABLE) |
925 | 927 |
926 /* allow coredump after setuid() in Linux 2.4.x */ | 928 /* allow coredump after setuid() in Linux 2.4.x */ |
1296 | 1298 |
1297 cycle->connection_n = 512; | 1299 cycle->connection_n = 512; |
1298 | 1300 |
1299 ngx_process = NGX_PROCESS_HELPER; | 1301 ngx_process = NGX_PROCESS_HELPER; |
1300 | 1302 |
1301 ngx_worker_process_init(cycle, 0); | 1303 ngx_worker_process_init(cycle, -1); |
1302 | 1304 |
1303 ngx_close_listening_sockets(cycle); | 1305 ngx_close_listening_sockets(cycle); |
1304 | 1306 |
1305 ngx_memzero(&ev, sizeof(ngx_event_t)); | 1307 ngx_memzero(&ev, sizeof(ngx_event_t)); |
1306 ev.handler = ctx->handler; | 1308 ev.handler = ctx->handler; |