mirror of
https://github.com/nginx/nginx.git
synced 2025-02-25 18:55:26 -06:00
Core: added support for more than 64 CPUs in worker_cpu_affinity.
This commit is contained in:
@@ -784,9 +784,9 @@ static void
|
||||
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;
|
||||
ngx_cpuset_t *cpu_affinity;
|
||||
struct rlimit rlmt;
|
||||
ngx_core_conf_t *ccf;
|
||||
ngx_listening_t *ls;
|
||||
|
||||
@@ -10,29 +10,20 @@
|
||||
|
||||
#if (NGX_HAVE_CPUSET_SETAFFINITY)
|
||||
|
||||
#include <sys/cpuset.h>
|
||||
|
||||
void
|
||||
ngx_setaffinity(uint64_t cpu_affinity, ngx_log_t *log)
|
||||
ngx_setaffinity(ngx_cpuset_t *cpu_affinity, ngx_log_t *log)
|
||||
{
|
||||
cpuset_t mask;
|
||||
ngx_uint_t i;
|
||||
|
||||
ngx_log_error(NGX_LOG_NOTICE, log, 0,
|
||||
"cpuset_setaffinity(0x%08Xl)", cpu_affinity);
|
||||
|
||||
CPU_ZERO(&mask);
|
||||
i = 0;
|
||||
do {
|
||||
if (cpu_affinity & 1) {
|
||||
CPU_SET(i, &mask);
|
||||
for (i = 0; i < CPU_SETSIZE; i++) {
|
||||
if (CPU_ISSET(i, cpu_affinity)) {
|
||||
ngx_log_error(NGX_LOG_NOTICE, log, 0,
|
||||
"cpuset_setaffinity(): using cpu #%ui", i);
|
||||
}
|
||||
i++;
|
||||
cpu_affinity >>= 1;
|
||||
} while (cpu_affinity);
|
||||
}
|
||||
|
||||
if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1,
|
||||
sizeof(cpuset_t), &mask) == -1)
|
||||
sizeof(cpuset_t), cpu_affinity) == -1)
|
||||
{
|
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
|
||||
"cpuset_setaffinity() failed");
|
||||
@@ -42,25 +33,18 @@ ngx_setaffinity(uint64_t cpu_affinity, ngx_log_t *log)
|
||||
#elif (NGX_HAVE_SCHED_SETAFFINITY)
|
||||
|
||||
void
|
||||
ngx_setaffinity(uint64_t cpu_affinity, ngx_log_t *log)
|
||||
ngx_setaffinity(ngx_cpuset_t *cpu_affinity, ngx_log_t *log)
|
||||
{
|
||||
cpu_set_t mask;
|
||||
ngx_uint_t i;
|
||||
|
||||
ngx_log_error(NGX_LOG_NOTICE, log, 0,
|
||||
"sched_setaffinity(0x%08Xl)", cpu_affinity);
|
||||
|
||||
CPU_ZERO(&mask);
|
||||
i = 0;
|
||||
do {
|
||||
if (cpu_affinity & 1) {
|
||||
CPU_SET(i, &mask);
|
||||
for (i = 0; i < CPU_SETSIZE; i++) {
|
||||
if (CPU_ISSET(i, cpu_affinity)) {
|
||||
ngx_log_error(NGX_LOG_NOTICE, log, 0,
|
||||
"sched_setaffinity(): using cpu #%ui", i);
|
||||
}
|
||||
i++;
|
||||
cpu_affinity >>= 1;
|
||||
} while (cpu_affinity);
|
||||
}
|
||||
|
||||
if (sched_setaffinity(0, sizeof(cpu_set_t), &mask) == -1) {
|
||||
if (sched_setaffinity(0, sizeof(cpu_set_t), cpu_affinity) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
|
||||
"sched_setaffinity() failed");
|
||||
}
|
||||
|
||||
@@ -11,12 +11,26 @@
|
||||
|
||||
#define NGX_HAVE_CPU_AFFINITY 1
|
||||
|
||||
void ngx_setaffinity(uint64_t cpu_affinity, ngx_log_t *log);
|
||||
#if (NGX_HAVE_SCHED_SETAFFINITY)
|
||||
|
||||
typedef cpu_set_t ngx_cpuset_t;
|
||||
|
||||
#elif (NGX_HAVE_CPUSET_SETAFFINITY)
|
||||
|
||||
#include <sys/cpuset.h>
|
||||
|
||||
typedef cpuset_t ngx_cpuset_t;
|
||||
|
||||
#endif
|
||||
|
||||
void ngx_setaffinity(ngx_cpuset_t *cpu_affinity, ngx_log_t *log);
|
||||
|
||||
#else
|
||||
|
||||
#define ngx_setaffinity(cpu_affinity, log)
|
||||
|
||||
typedef uint64_t ngx_cpuset_t;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ typedef DWORD ngx_pid_t;
|
||||
(sizeof("ngx_cache_manager_mutex_") + NGX_INT32_LEN)
|
||||
|
||||
|
||||
typedef uint64_t ngx_cpuset_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
HANDLE handle;
|
||||
ngx_pid_t pid;
|
||||
|
||||
Reference in New Issue
Block a user