]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: threads: Fix pthread_setaffinity_np on FreeBSD.
authorOlivier Houchard <ohouchard@haproxy.com>
Fri, 1 Dec 2017 17:19:43 +0000 (18:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 2 Dec 2017 13:23:12 +0000 (14:23 +0100)
As with the call to cpuset_setaffinity(), FreeBSD expects the argument to
pthread_setaffinity_np() to be a cpuset_t, not an unsigned long, so the call
was silently failing.

This should probably be backported to 1.8.

src/haproxy.c

index e842673ea352be4086e9c03291cd160ea95ce2ca..df8d34e7404d01271b9b18d7540c72b2f48571ed 100644 (file)
@@ -2915,10 +2915,24 @@ int main(int argc, char **argv)
                                global.cpu_map.thread[relative_pid-1][i] &= global.cpu_map.proc[relative_pid-1];
 
                        if (i < LONGBITS &&       /* only the first 32/64 threads may be pinned */
-                           global.cpu_map.thread[relative_pid-1][i]) /* only do this if the thread has a THREAD map */
+                           global.cpu_map.thread[relative_pid-1][i]) {/* only do this if the thread has a THREAD map */
+#if defined(__FreeBSD__) || defined(__NetBSD__)
+                               cpuset_t cpuset;
+#else
+                               cpu_set_t cpuset;
+#endif
+                               int j;
+                               unsigned long cpu_map = global.cpu_map.thread[relative_pid-1][i];
+
+                               CPU_ZERO(&cpuset);
+
+                               while ((j = ffsl(cpu_map)) > 0) {
+                                       CPU_SET(j - 1, &cpuset);
+                                       cpu_map &= ~(1 << (j - 1));
+                               }
                                pthread_setaffinity_np(threads[i],
-                                                      sizeof(unsigned long),
-                                                      (void *)&global.cpu_map.thread[relative_pid-1][i]);
+                                                      sizeof(cpuset), &cpuset);
+                       }
                }
 #endif /* !USE_CPU_AFFINITY */