]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cpu-topo: add detection of online CPUs on FreeBSD
authorWilly Tarreau <w@1wt.eu>
Thu, 20 Jul 2023 14:16:05 +0000 (16:16 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 14 Mar 2025 17:30:30 +0000 (18:30 +0100)
On FreeBSD we can detect online CPUs at least by doing the bitwise-OR of
the CPUs of all domains, so we're using this and adding this detection
to ha_cpuset_detect_online(). If we find simpler later, we can always
rework it, but it's reasonably inexpensive since we only check existing
domains.

src/cpu_topo.c

index ddf45e6fff61ea1be210e111dcc71247baa5e4b1..3b1d29b8d4c7393d6c280075acafd0f5f1cfe9f8 100644 (file)
@@ -35,7 +35,30 @@ int ha_cpuset_detect_online(struct hap_cpuset *set)
                        ha_cpuset_zero(set);
        }
 
-#else // !__linux__
+#elif defined(__FreeBSD__)
+
+       struct hap_cpuset node_cpu_set;
+       int ndomains, domain;
+       size_t len = sizeof(ndomains);
+
+       ha_cpuset_zero(set);
+
+       /* retrieve the union of NUMA nodes as online CPUs */
+       if (sysctlbyname("vm.ndomains", &ndomains, &len, NULL, 0) == 0) {
+               BUG_ON(ndomains > MAXMEMDOM);
+
+               for (domain = 0; domain < ndomains; domain++) {
+                       ha_cpuset_zero(&node_cpu_set);
+
+                       if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_DOMAIN, domain,
+                                              sizeof(node_cpu_set.cpuset), &node_cpu_set.cpuset) == -1)
+                               continue;
+
+                       ha_cpuset_or(set, &node_cpu_set);
+               }
+       }
+
+#else // !__linux__, !__FreeBSD__
 
        ha_cpuset_zero(set);