Zig: Use of deprecated hw.ncpu

Created on 16 Jul 2018  路  1Comment  路  Source: ziglang/zig

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.
bug

Most helpful comment

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"):

https://github.com/unofficial-opensource-apple/Libc/blob/aec41eec4ba22ce5873263632f3724b4be89bd5e/gen/FreeBSD/sysconf.c#L590-L600

hw.activecpu is probably (arguably) the right choice, it reflects the kernel's idea of online logical CPUs.

>All comments

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"):

https://github.com/unofficial-opensource-apple/Libc/blob/aec41eec4ba22ce5873263632f3724b4be89bd5e/gen/FreeBSD/sysconf.c#L590-L600

hw.activecpu is probably (arguably) the right choice, it reflects the kernel's idea of online logical CPUs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bheads picture bheads  路  3Comments

komuw picture komuw  路  3Comments

andrewrk picture andrewrk  路  3Comments

S0urc3C0de picture S0urc3C0de  路  3Comments

andersfr picture andersfr  路  3Comments