]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: fix a 100% cpu usage with cpu-map and nbthread/nbproc
authorCyril Bonté <cyril.bonte@free.fr>
Mon, 12 Mar 2018 20:47:39 +0000 (21:47 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 12 Mar 2018 21:52:24 +0000 (22:52 +0100)
Krishna Kumar reported a 100% cpu usage with a configuration using
cpu-map and a high number of threads,

Indeed, this minimal configuration to reproduce the issue :
  global
    nbthread 40
    cpu-map auto:1/1-40 0-39

  frontend test
    bind :8000

This is due to a wrong type in a shift operator (int vs unsigned long int),
causing an endless loop while applying the cpu affinity on threads. The same
issue may also occur with nbproc under FreeBSD. This commit addresses both
cases.

This patch must be backported to 1.8.

src/haproxy.c

index 8785b9f94990b52c59b9e57e0e06b858513a2690..0c823c49791960555b8c12e1d493046f785fc9d5 100644 (file)
@@ -2837,7 +2837,7 @@ int main(int argc, char **argv)
                        CPU_ZERO(&cpuset);
                        while ((i = ffsl(cpu_map)) > 0) {
                                CPU_SET(i - 1, &cpuset);
-                               cpu_map &= ~(1 << (i - 1));
+                               cpu_map &= ~(1UL << (i - 1));
                        }
                        ret = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(cpuset), &cpuset);
                }
@@ -3037,7 +3037,7 @@ int main(int argc, char **argv)
 
                                while ((j = ffsl(cpu_map)) > 0) {
                                        CPU_SET(j - 1, &cpuset);
-                                       cpu_map &= ~(1 << (j - 1));
+                                       cpu_map &= ~(1UL << (j - 1));
                                }
                                pthread_setaffinity_np(threads[i],
                                                       sizeof(cpuset), &cpuset);