]> git.ipfire.org Git - thirdparty/git.git/commitdiff
thread-utils.c: detect online CPU count on OpenBSD / NetBSD
authorBrad Smith <brad@comstyle.com>
Fri, 9 May 2025 06:13:13 +0000 (02:13 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 Jun 2025 00:15:13 +0000 (17:15 -0700)
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>
thread-utils.c

index 1f89ffab4c32bc02b5d955851401628a5b9a540e..374890e6b05b6937e6f7d0450a258a882f225f3a 100644 (file)
@@ -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;