]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: thread: rely on the cpuset functions to count bound CPUs
authorWilly Tarreau <w@1wt.eu>
Tue, 11 Jul 2023 15:03:09 +0000 (17:03 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 14 Mar 2025 17:30:30 +0000 (18:30 +0100)
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

index e54a32ef93e0d6bb2b7e271c534f87ccb46054a4..7796d5c5e8c55c483c061b09c5c77d063f84ee3e 100644 (file)
 #ifdef USE_CPU_AFFINITY
 #  include <sched.h>
 #  if defined(__FreeBSD__) || defined(__DragonFly__)
-#    include <sys/param.h>
-#    ifdef __FreeBSD__
-#      include <sys/cpuset.h>
-#    endif
 #    include <pthread_np.h>
 #  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;
-
-       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);
+       struct hap_cpuset set = { };
+
+       ret = ha_cpuset_detect_bound(&set);
+#if defined(__APPLE__)
+       if (!ret)
+               ret = (int)sysconf(_SC_NPROCESSORS_ONLN);
 #endif
 #endif
        ret = MAX(ret, 1);