From: Brad Smith <brad@comstyle.com>
To: git@vger.kernel.org
Subject: [PATCH] thread-utils.c: detect online CPU count on OpenBSD / NetBSD
Date: Fri, 9 May 2025 02:13:13 -0400 [thread overview]
Message-ID: <aB2c-W0V83aVDpZr@humpty.home.comstyle.com> (raw)
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>
---
thread-utils.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
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;
--
2.49.0
next reply other threads:[~2025-05-09 6:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-09 6:13 Brad Smith [this message]
2025-05-09 8:36 ` [PATCH] thread-utils.c: detect online CPU count on OpenBSD / NetBSD Patrick Steinhardt
2025-05-31 20:18 ` Brad Smith
2025-06-01 2:14 ` Collin Funk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aB2c-W0V83aVDpZr@humpty.home.comstyle.com \
--to=brad@comstyle.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).