]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: threads: Implement thread_cpus_enabled() for FreeBSD.
authorOlivier Houchard <cognet@ci0.org>
Wed, 10 Apr 2019 22:06:47 +0000 (00:06 +0200)
committerOlivier Houchard <cognet@ci0.org>
Wed, 10 Apr 2019 22:09:22 +0000 (00:09 +0200)
Use cpuset_getaffinity() to implement thread_cpus_enabled() on FreeBSD, so
that we can know the number of CPUs available, and automatically launch as
much threads if nbthread isn't specified.

src/hathreads.c

index 1826f9201fc289efb7325af4bf5315c28d33096a..686edca8e4cd4bd70288fca0a0574d844bd92dbf 100644 (file)
 #include <sched.h>
 #endif
 
+#ifdef __FreeBSD__
+#include <sys/cpuset.h>
+#endif
+
 #include <common/cfgparse.h>
 #include <common/hathreads.h>
 #include <common/standard.h>
@@ -122,6 +126,11 @@ static int thread_cpus_enabled()
 
        if (sched_getaffinity(0, sizeof(mask), &mask) == 0)
                ret = CPU_COUNT(&mask);
+#elif defined(__FreeBSD__) && defined(USE_CPU_AFFINITY)
+       cpuset_t cpuset;
+       if (cpuset_getaffinity(CPU_LEVEL_CPUSET, CPU_WHICH_PID, -1,
+           sizeof(cpuset), &cpuset) == 0)
+               ret = CPU_COUNT(&cpuset);
 #endif
 #endif
        ret = MAX(ret, 1);