From: Willy Tarreau Date: Mon, 22 Aug 2022 08:38:00 +0000 (+0200) Subject: BUG/MEDIUM: cpu-map: fix thread 1's affinity affecting all threads X-Git-Tag: v2.7-dev5~78 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3cd71acd0683147add7ce87ce799561ba55d7f7b;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: cpu-map: fix thread 1's affinity affecting all threads Since 2.7-dev2 with commit 5b09341c02 ("MEDIUM: cpu-map: replace the process number with the thread group number"), the thread group has replaced the process number in the "cpu-map" directive. In part due to a design limit in 2.4 and 2.5, a special case was made of thread 1 in commit bda7c1decd ("MEDIUM: config: simplify cpu-map handling"), because there was no other location to store a single-threaded setup's mask by then. The combination of the two resulted in a problem with thread groups, by which as soon as one line exhibiting thread number 1 alone was found in a config, the mask would be applied to all threads in the group. The loop was reworked to avoid this obsolete special case, and was factored for better legibility. One obsolete comment about nbproc was also removed. No backport is needed. --- diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c index 43aded112a..a7c1a40ead 100644 --- a/src/cfgparse-global.c +++ b/src/cfgparse-global.c @@ -1094,21 +1094,19 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) * cpu-map P-Q => mapping for whole tgroups, numbers P to Q * cpu-map P-Q/1 => mapping of first thread of groups P to Q * cpu-map P/T-U => mapping of threads T to U of tgroup P - * Otherwise other combinations are silently ignored since nbthread - * and nbproc cannot both be >1 : - * cpu-map P-Q/T => mapping for thread T for processes P to Q. - * Only one of T,Q may be > 1, others ignored. - * cpu-map P/T-U => mapping for threads T to U of process P. Only - * one of P,U may be > 1, others ignored. */ - if (!thread || thread == 0x1) { - /* mapping for whole tgroups. E.g. cpu-map 1 0-3 or cpu-map 1/1 0-3 */ - for (g = 0; g < MAX_TGROUPS; g++) { - /* No mapping for this tgroup */ - if (!(tgroup & (1UL << g))) - continue; + /* first tgroup, iterate on threads. E.g. cpu-map 1/1-4 0-3 */ + for (g = 0; g < MAX_TGROUPS; g++) { + /* No mapping for this tgroup */ + if (!(tgroup & (1UL << g))) + continue; - ha_cpuset_assign(&cpus_copy, &cpus); + ha_cpuset_assign(&cpus_copy, &cpus); + + if (!thread) { + /* no thread set was specified, apply + * the CPU set to the whole group. + */ if (!autoinc) ha_cpuset_assign(&cpu_map[g].proc, &cpus); else { @@ -1117,15 +1115,10 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) ha_cpuset_clr(&cpus_copy, n); ha_cpuset_set(&cpu_map[g].proc, n); } - } - } else { - /* first tgroup, iterate on threads. E.g. cpu-map 1/1-4 0-3 */ - for (g = 0; g < MAX_TGROUPS; g++) { - /* No mapping for this tgroup */ - if (!(tgroup & (1UL << g))) - continue; - - ha_cpuset_assign(&cpus_copy, &cpus); + } else { + /* a thread set is specified, apply the + * CPU set to these threads. + */ for (j = n = 0; j < MAX_THREADS_PER_GROUP; j++) { /* No mapping for this thread */ if (!(thread & (1UL << j)))