]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: init: Fix CPU affinity setting on FreeBSD.
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 16 Aug 2017 15:29:11 +0000 (17:29 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 17 Aug 2017 16:39:52 +0000 (18:39 +0200)
Use a cpuset_t instead of assuming the cpu mask is an unsigned long.
This should fix setting the CPU affinity on FreeBSD >= 11.

This patch should be backported to stable releases.

src/haproxy.c

index 7af4ab479c761a43b2fa64d2124388dbf5c21fc3..30e850c4ac4719b71adccb3b6bd41248ef5bb470 100644 (file)
@@ -2558,7 +2558,18 @@ int main(int argc, char **argv)
                    proc < LONGBITS &&       /* only the first 32/64 processes may be pinned */
                    global.cpu_map[proc])    /* only do this if the process has a CPU map */
 #ifdef __FreeBSD__
-                       cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(unsigned long), (void *)&global.cpu_map[proc]);
+               {
+                       cpuset_t cpuset;
+                       int i;
+                       unsigned long cpu_map = global.cpu_map[proc];
+
+                       CPU_ZERO(&cpuset);
+                       while ((i = ffsl(cpu_map)) > 0) {
+                               CPU_SET(i - 1, &cpuset);
+                               cpu_map &= ~(1 << (i - 1));
+                       }
+                       ret = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(cpuset), &cpuset);
+               }
 #else
                        sched_setaffinity(0, sizeof(unsigned long), (void *)&global.cpu_map[proc]);
 #endif