From: Brad Smith Date: Fri, 9 May 2025 06:13:13 +0000 (-0400) Subject: thread-utils.c: detect online CPU count on OpenBSD / NetBSD X-Git-Tag: v2.50.0-rc1~1^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f1a09dbb643c8669928ee32337ff92370fc1157;p=thirdparty%2Fgit.git 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 Reviewed-by: Collin Funk Signed-off-by: Junio C Hamano --- diff --git a/thread-utils.c b/thread-utils.c index 1f89ffab4c..374890e6b0 100644 --- a/thread-utils.c +++ b/thread-utils.c @@ -46,11 +46,11 @@ int online_cpus(void) mib[0] = CTL_HW; # ifdef HW_AVAILCPU mib[1] = HW_AVAILCPU; - len = sizeof(cpucount); - if (!sysctl(mib, 2, &cpucount, &len, NULL, 0)) - return cpucount; -# endif /* HW_AVAILCPU */ +# elif defined(HW_NCPUONLINE) + mib[1] = HW_NCPUONLINE; +# else mib[1] = HW_NCPU; +# endif /* HW_AVAILCPU */ len = sizeof(cpucount); if (!sysctl(mib, 2, &cpucount, &len, NULL, 0)) return cpucount;