From: Willy Tarreau Date: Tue, 15 Jun 2021 06:57:56 +0000 (+0200) Subject: MEDIUM: cpu-set: make the proc a single bit field and not an array X-Git-Tag: v2.5-dev1~116 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=44ea631b7765d437302251cf60b7797e96bf1fc3;p=thirdparty%2Fhaproxy.git MEDIUM: cpu-set: make the proc a single bit field and not an array We only have a single process now so we don't need to store the per-proc CPU binding anymore. --- diff --git a/include/haproxy/cpuset-t.h b/include/haproxy/cpuset-t.h index 36b4a5165c..0d5b6c8045 100644 --- a/include/haproxy/cpuset-t.h +++ b/include/haproxy/cpuset-t.h @@ -40,8 +40,8 @@ struct hap_cpuset { }; struct cpu_map { - struct hap_cpuset proc[MAX_PROCS]; /* list of CPU masks for the 32/64 first processes */ - struct hap_cpuset proc_t1[MAX_PROCS]; /* list of CPU masks for the 1st thread of each process */ + struct hap_cpuset proc; /* list of CPU masks for the whole process */ + struct hap_cpuset proc_t1 ; /* list of CPU masks for the 1st thread of the process */ struct hap_cpuset thread[MAX_THREADS]; /* list of CPU masks for the 32/64 first threads of the 1st process */ }; diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c index 758a5edeb3..f8150d454d 100644 --- a/src/cfgparse-global.c +++ b/src/cfgparse-global.c @@ -1091,12 +1091,12 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) ha_cpuset_assign(&cpus_copy, &cpus); if (!autoinc) - ha_cpuset_assign(&cpu_map.proc[0], &cpus); + ha_cpuset_assign(&cpu_map.proc, &cpus); else { - ha_cpuset_zero(&cpu_map.proc[0]); + ha_cpuset_zero(&cpu_map.proc); n = ha_cpuset_ffs(&cpus_copy) - 1; ha_cpuset_clr(&cpus_copy, n); - ha_cpuset_set(&cpu_map.proc[0], n); + ha_cpuset_set(&cpu_map.proc, n); } } else { /* first process, iterate on threads. E.g. cpu-map 1/1-4 0-3 */ diff --git a/src/haproxy.c b/src/haproxy.c index 55e9a551ea..f520e1ac90 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1778,10 +1778,8 @@ static void init(int argc, char **argv) #ifdef USE_CPU_AFFINITY { int i; - for (i = 0; i < MAX_PROCS; ++i) { - ha_cpuset_zero(&cpu_map.proc[i]); - ha_cpuset_zero(&cpu_map.proc_t1[i]); - } + ha_cpuset_zero(&cpu_map.proc); + ha_cpuset_zero(&cpu_map.proc_t1); for (i = 0; i < MAX_THREADS; ++i) { ha_cpuset_zero(&cpu_map.thread[i]); } @@ -3193,13 +3191,13 @@ int main(int argc, char **argv) } #ifdef USE_CPU_AFFINITY - if (!in_parent && ha_cpuset_count(&cpu_map.proc[0])) { /* only do this if the process has a CPU map */ + if (!in_parent && ha_cpuset_count(&cpu_map.proc)) { /* only do this if the process has a CPU map */ #ifdef __FreeBSD__ - struct hap_cpuset *set = &cpu_map.proc[0]; + struct hap_cpuset *set = &cpu_map.proc; ret = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(set->cpuset), &set->cpuset); #elif defined(__linux__) || defined(__DragonFly__) - struct hap_cpuset *set = &cpu_map.proc[0]; + struct hap_cpuset *set = &cpu_map.proc; sched_setaffinity(0, sizeof(set->cpuset), &set->cpuset); #endif } @@ -3397,8 +3395,8 @@ int main(int argc, char **argv) /* Now the CPU affinity for all threads */ for (i = 0; i < global.nbthread; i++) { - if (ha_cpuset_count(&cpu_map.proc[relative_pid-1])) - ha_cpuset_and(&cpu_map.thread[i], &cpu_map.proc[relative_pid-1]); + if (ha_cpuset_count(&cpu_map.proc)) + ha_cpuset_and(&cpu_map.thread[i], &cpu_map.proc); if (i < MAX_THREADS && /* only the first 32/64 threads may be pinned */ ha_cpuset_count(&cpu_map.thread[i])) {/* only do this if the thread has a THREAD map */