]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: cpu-map: fix thread 1's affinity affecting all threads
authorWilly Tarreau <w@1wt.eu>
Mon, 22 Aug 2022 08:38:00 +0000 (10:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 22 Aug 2022 08:38:00 +0000 (10:38 +0200)
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.

src/cfgparse-global.c

index 43aded112aded4fc38be08afc6dabd5748775a58..a7c1a40eadf68c75fdd9c83ce06e3704ce23f22e 100644 (file)
@@ -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)))