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.
This commit is contained in:
Olivier Houchard 2019-04-11 00:06:47 +02:00
parent 526dc95eb9
commit 46453d3f7d

View File

@ -19,6 +19,10 @@
#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);