thread-utils.c: detect online CPU count on OpenBSD / NetBSD
OpenBSD / NetBSD use HW_NCPUONLINE to detect the online CPU count. OpenBSD ships with SMT disabled on X86 systems so HW_NCPU would provide double the number of CPUs as opposed to the proper online count. Signed-off-by: Brad Smith <brad@comstyle.com> Reviewed-by: Collin Funk <collin.funk1@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brad Smith committed
May 9, 2025 at 02:13 UTC
7f1a09dbb643c8669928ee32337ff92370fc1157
1 file changed
+4
-4
thread-utils.c
+4
-4
@@ -46,11 +46,11 @@ int online_cpus(void)
46
mib[0] = CTL_HW;
47
# ifdef HW_AVAILCPU
48
mib[1] = HW_AVAILCPU;
49
- len = sizeof(cpucount);
50
- if (!sysctl(mib, 2, &cpucount, &len, NULL, 0))
51
- return cpucount;
52
-# endif /* HW_AVAILCPU */
49
+# elif defined(HW_NCPUONLINE)
50
+ mib[1] = HW_NCPUONLINE;
51
+# else
52
mib[1] = HW_NCPU;
53
+# endif /* HW_AVAILCPU */
54
len = sizeof(cpucount);
55
if (!sysctl(mib, 2, &cpucount, &len, NULL, 0))
56
return cpucount;