Hi Willy,

Added support for cpu-map feature on FreeBSD.
It works, but only as long as the as the number of CPU's doesnt rise to high <=64. While the cpuset_t supports up to 256 bits.

Maybe a better solution would be to create a separate function like done here http://lxr.nginx.org/source/src/os/unix/ngx_setaffinity.c though not sure thats needed..

Also i'm not sure you will like the IFDEF __FREEBSD__ thats used.?. I couldnt find any other way to properly determine the correct function to use though.

Hope its ok as is, and you can merge it?

Thanks in advance,
PiBa-NL
From dda0dac1eb3be4bcb9d58e43744ebb16ba5d69d7 Mon Sep 17 00:00:00 2001
From: Pieter Baauw <piba.nl....@gmail.com>
Date: Thu, 17 Sep 2015 21:26:40 +0200
Subject: [PATCH] MINOR: support cpu-map feature through the compile option
 USE_CPU_AFFINITY on FreeBSD

---
 src/haproxy.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/haproxy.c b/src/haproxy.c
index ae790c4..681109d 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -50,6 +50,10 @@
 #define __USE_GNU
 #include <sched.h>
 #undef __USE_GNU
+#ifdef __FreeBSD__
+#include <sys/param.h>
+#include <sys/cpuset.h>
+#endif
 #endif
 
 #ifdef DEBUG_FULL
@@ -1780,8 +1784,12 @@ int main(int argc, char **argv)
                if (proc < global.nbproc &&  /* child */
                    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]);
+#else
                        sched_setaffinity(0, sizeof(unsigned long), (void 
*)&global.cpu_map[proc]);
 #endif
+#endif
                /* close the pidfile both in children and father */
                if (pidfd >= 0) {
                        //lseek(pidfd, 0, SEEK_SET);  /* debug: emulate eglibc 
bug */
-- 
1.9.5.msysgit.1

Reply via email to