https://github.com/ziglang/zig/blob/caa008505729f9511f6f0b070636013e9597b3f7/std/os/index.zig#L2763
Reading man sysctlbyname, I see that on Macos:
hw.ncpu
The number of cpus. This attribute is deprecated and it is recom-
mended that hw.logicalcpu, hw.logicalcpu_max, hw.physicalcpu, or
hw.physicalcpu_max be used instead.
hw.logicalcpu
The number of logical processors available in the current power
management mode.
hw.logicalcpu_max
The maximum number of logical processors that could be available
this boot.
hw.physicalcpu
The number of physical processors available in the current power
management mode.
hw.physicalcpu_max
The maximum number of physical processors that could be available
this boot.
I agree hw.ncpu is the wrong choice but something to consider is that sysconf(_SC_NPROCESSORS_ONLN) on macos gets it wrong too, it calls sysctl("hw.ncpu"):
hw.activecpu is probably (arguably) the right choice, it reflects the kernel's idea of online logical CPUs.
Most helpful comment
I agree
hw.ncpuis the wrong choice but something to consider is thatsysconf(_SC_NPROCESSORS_ONLN)on macos gets it wrong too, it callssysctl("hw.ncpu"):https://github.com/unofficial-opensource-apple/Libc/blob/aec41eec4ba22ce5873263632f3724b4be89bd5e/gen/FreeBSD/sysconf.c#L590-L600
hw.activecpuis probably (arguably) the right choice, it reflects the kernel's idea of online logical CPUs.