From 46453d3f7d09c56b07a1b3745f1a2d24c5650c15 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Thu, 11 Apr 2019 00:06:47 +0200 Subject: [PATCH] MINOR: threads: Implement thread_cpus_enabled() for FreeBSD. 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/hathreads.c b/src/hathreads.c index 1826f9201..686edca8e 100644 --- a/src/hathreads.c +++ b/src/hathreads.c @@ -19,6 +19,10 @@ #include #endif +#ifdef __FreeBSD__ +#include +#endif + #include #include #include @@ -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);