From 05a4efb1028fab549b4f5b237187e95a703eb9a7 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 11 Jul 2023 17:03:09 +0200 Subject: [PATCH] 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. --- src/thread.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/thread.c b/src/thread.c index e54a32ef9..7796d5c5e 100644 --- a/src/thread.c +++ b/src/thread.c @@ -27,10 +27,6 @@ #ifdef USE_CPU_AFFINITY # include # if defined(__FreeBSD__) || defined(__DragonFly__) -# include -# ifdef __FreeBSD__ -# include -# endif # include # endif # ifdef __APPLE__ @@ -380,20 +376,13 @@ void ha_rwlock_init(HA_RWLOCK_T *l) static int thread_cpus_enabled() { int ret = 1; - #ifdef USE_CPU_AFFINITY -#if defined(__linux__) && defined(CPU_COUNT) - cpu_set_t mask; + struct hap_cpuset set = { }; - 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); -#elif defined(__APPLE__) - ret = (int)sysconf(_SC_NPROCESSORS_ONLN); + ret = ha_cpuset_detect_bound(&set); +#if defined(__APPLE__) + if (!ret) + ret = (int)sysconf(_SC_NPROCESSORS_ONLN); #endif #endif ret = MAX(ret, 1);