MINOR: thread: rely on the cpuset functions to count bound CPUs
let's just clean up the thread_cpus_enabled() code a little bit by removing the OS-specific code and rely on ha_cpuset_detect_bound() instead. On macos we continue to use sysconf() for now.
This commit is contained in:
parent
32bb68e736
commit
05a4efb102
21
src/thread.c
21
src/thread.c
@ -27,10 +27,6 @@
|
|||||||
#ifdef USE_CPU_AFFINITY
|
#ifdef USE_CPU_AFFINITY
|
||||||
# include <sched.h>
|
# include <sched.h>
|
||||||
# if defined(__FreeBSD__) || defined(__DragonFly__)
|
# if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
# include <sys/param.h>
|
|
||||||
# ifdef __FreeBSD__
|
|
||||||
# include <sys/cpuset.h>
|
|
||||||
# endif
|
|
||||||
# include <pthread_np.h>
|
# include <pthread_np.h>
|
||||||
# endif
|
# endif
|
||||||
# ifdef __APPLE__
|
# ifdef __APPLE__
|
||||||
@ -380,20 +376,13 @@ void ha_rwlock_init(HA_RWLOCK_T *l)
|
|||||||
static int thread_cpus_enabled()
|
static int thread_cpus_enabled()
|
||||||
{
|
{
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
|
||||||
#ifdef USE_CPU_AFFINITY
|
#ifdef USE_CPU_AFFINITY
|
||||||
#if defined(__linux__) && defined(CPU_COUNT)
|
struct hap_cpuset set = { };
|
||||||
cpu_set_t mask;
|
|
||||||
|
|
||||||
if (sched_getaffinity(0, sizeof(mask), &mask) == 0)
|
ret = ha_cpuset_detect_bound(&set);
|
||||||
ret = CPU_COUNT(&mask);
|
#if defined(__APPLE__)
|
||||||
#elif defined(__FreeBSD__) && defined(USE_CPU_AFFINITY)
|
if (!ret)
|
||||||
cpuset_t cpuset;
|
ret = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
if (cpuset_getaffinity(CPU_LEVEL_CPUSET, CPU_WHICH_PID, -1,
|
|
||||||
sizeof(cpuset), &cpuset) == 0)
|
|
||||||
ret = CPU_COUNT(&cpuset);
|
|
||||||
#elif defined(__APPLE__)
|
|
||||||
ret = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
ret = MAX(ret, 1);
|
ret = MAX(ret, 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user