git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] thread-utils.c: detect online CPU count on OpenBSD / NetBSD

From
Brad Smith <brad@comstyle.com>
Date
May 31, 2025, 20:18 UTC
Message-ID
<f929a4b5-1011-42dd-ad86-bb654d170db2@comstyle.com>
In-Reply-To
<aB2c-W0V83aVDpZr@humpty.home.comstyle.com>
ping.
On 2025-05-09 2:13 a.m., Brad Smith wrote:
Show 30 quoted lines
> 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;
Previous: Patrick SteinhardtNext: Collin Funk
Message 3 of 4 in “thread-utils.c: detect online CPU count on OpenBSD / NetBSD”
  1. thread-utils.c: detect online CPU count on OpenBSD / NetBSDBrad Smith, May 9, 2025
  2. Patrick SteinhardtMay 9, 2025
  3. Brad SmithMay 31, 2025
  4. Collin FunkJun 1, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.