MEDIUM: config: simplify cpu-map handling

As there's no more nbproc>1, we can remove some loops and tests in cpu-map.
Both the lack of thread number and thread 1 can count as the whole process
now (which is still used for whole process binding when threads are disabled).
This commit is contained in:
Willy Tarreau 2021-06-15 08:49:05 +02:00
parent 72faef3866
commit bda7c1decd

View File

@ -1024,7 +1024,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
#ifdef USE_CPU_AFFINITY #ifdef USE_CPU_AFFINITY
char *slash; char *slash;
unsigned long proc = 0, thread = 0; unsigned long proc = 0, thread = 0;
int i, j, n, autoinc; int j, n, autoinc;
struct hap_cpuset cpus, cpus_copy; struct hap_cpuset cpus, cpus_copy;
if (!*args[1] || !*args[2]) { if (!*args[1] || !*args[2]) {
@ -1056,14 +1056,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
goto out; goto out;
} }
*slash = '/'; *slash = '/';
if (autoinc && atleast2(proc) && atleast2(thread)) {
ha_alert("parsing [%s:%d] : %s : '%s' : unable to automatically bind "
"a process range _AND_ a thread range\n",
file, linenum, args[0], args[1]);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
} }
if (parse_cpu_set((const char **)args+2, &cpus, 0, &errmsg)) { if (parse_cpu_set((const char **)args+2, &cpus, 0, &errmsg)) {
@ -1086,6 +1078,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
* cpu-map P-Q => mapping for whole processes, numbers P to Q * cpu-map P-Q => mapping for whole processes, numbers P to Q
* cpu-map P-Q/1 => mapping of first thread of processes P to Q * cpu-map P-Q/1 => mapping of first thread of processes P to Q
* cpu-map 1/T-U => mapping of threads T to U of process 1 * cpu-map 1/T-U => mapping of threads T to U of process 1
* (note: P=Q=1 since 2.5).
* Otherwise other combinations are silently ignored since nbthread * Otherwise other combinations are silently ignored since nbthread
* and nbproc cannot both be >1 : * and nbproc cannot both be >1 :
* cpu-map P-Q/T => mapping for thread T for processes P to Q. * cpu-map P-Q/T => mapping for thread T for processes P to Q.
@ -1093,57 +1086,19 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
* cpu-map P/T-U => mapping for threads T to U of process P. Only * cpu-map P/T-U => mapping for threads T to U of process P. Only
* one of P,U may be > 1, others ignored. * one of P,U may be > 1, others ignored.
*/ */
if (!thread) { if (!thread || thread == 0x1) {
/* mapping for whole processes. E.g. cpu-map 1-4 0-3 */ /* mapping for whole process. E.g. cpu-map 1 0-3 or cpu-map 1/1 0-3 */
ha_cpuset_assign(&cpus_copy, &cpus); ha_cpuset_assign(&cpus_copy, &cpus);
for (i = n = 0; i < MAX_PROCS; i++) {
/* No mapping for this process */
if (!(proc & (1UL << i)))
continue;
if (!autoinc) if (!autoinc)
ha_cpuset_assign(&cpu_map.proc[i], &cpus); ha_cpuset_assign(&cpu_map.proc[0], &cpus);
else { else {
ha_cpuset_zero(&cpu_map.proc[i]); ha_cpuset_zero(&cpu_map.proc[0]);
n = ha_cpuset_ffs(&cpus_copy) - 1; n = ha_cpuset_ffs(&cpus_copy) - 1;
ha_cpuset_clr(&cpus_copy, n); ha_cpuset_clr(&cpus_copy, n);
ha_cpuset_set(&cpu_map.proc[i], n); ha_cpuset_set(&cpu_map.proc[0], n);
}
} }
} else { } else {
/* Mapping at the thread level.
* Either proc and/or thread must be 1 and only 1. All
* other combinations are silently ignored.
*/
if (thread == 0x1) {
/* first thread, iterate on processes. E.g. cpu-map 1-4/1 0-3 */
struct hap_cpuset *dst;
ha_cpuset_assign(&cpus_copy, &cpus);
for (i = n = 0; i < MAX_PROCS; i++) {
/* No mapping for this process */
if (!(proc & (1UL << i)))
continue;
/* For first process, thread[0] is used.
* Use proc_t1[N] for all others
*/
dst = i ? &cpu_map.proc_t1[i] :
&cpu_map.thread[0];
if (!autoinc) {
ha_cpuset_assign(dst, &cpus);
}
else {
ha_cpuset_zero(dst);
n = ha_cpuset_ffs(&cpus_copy) - 1;
ha_cpuset_clr(&cpus_copy, n);
ha_cpuset_set(dst, n);
}
}
}
if (proc == 0x1) {
/* first process, iterate on threads. E.g. cpu-map 1/1-4 0-3 */ /* first process, iterate on threads. E.g. cpu-map 1/1-4 0-3 */
ha_cpuset_assign(&cpus_copy, &cpus); ha_cpuset_assign(&cpus_copy, &cpus);
for (j = n = 0; j < MAX_THREADS; j++) { for (j = n = 0; j < MAX_THREADS; j++) {
@ -1160,7 +1115,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
ha_cpuset_set(&cpu_map.thread[j], n); ha_cpuset_set(&cpu_map.thread[j], n);
} }
} }
}
HA_DIAG_WARNING_COND(proc != 0x1 && thread != 0x1, HA_DIAG_WARNING_COND(proc != 0x1 && thread != 0x1,
"parsing [%s:%d] : cpu-map statement is considered invalid and thus ignored as it addresses multiple processes and threads at the same time. At least one of them should be 1 and only 1.", file, linenum); "parsing [%s:%d] : cpu-map statement is considered invalid and thus ignored as it addresses multiple processes and threads at the same time. At least one of them should be 1 and only 1.", file, linenum);