]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: cpu-set: make the proc a single bit field and not an array
authorWilly Tarreau <w@1wt.eu>
Tue, 15 Jun 2021 06:57:56 +0000 (08:57 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 15 Jun 2021 14:52:42 +0000 (16:52 +0200)
We only have a single process now so we don't need to store the per-proc
CPU binding anymore.

include/haproxy/cpuset-t.h
src/cfgparse-global.c
src/haproxy.c

index 36b4a5165cb467e7762dad8df9c374f1fc977852..0d5b6c80454f170e12cb0c009a9edd3032b21f74 100644 (file)
@@ -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 */
 };
 
index 758a5edeb3d34257b3ef57f95668025d33124b12..f8150d454deb676084c52ec2300dc6c0a78c06fe 100644 (file)
@@ -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 */
index 55e9a551ea36f3eb3ebcb5c2fdee4df6f7b70868..f520e1ac9061d9c73a4fc331962425d6a88b3fc2 100644 (file)
@@ -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 */