open-watcom / open-watcom-v2

Open Watcom V2.0 - Source code repository, Wiki, Latest Binary build, Archived builds including all installers for download.
Other
991 stars 163 forks source link

output of sysconf(_SC_NPROCESSORS_CONF) is incorrect #1325

Closed jmalak closed 3 months ago

jmalak commented 3 months ago
The output of sysconf(_SC_NPROCESSORS_CONF) and sysconf(_SC_NPROCESSORS_ONLN) is same and is correct only for sysconf(_SC_NPROCESSORS_ONLN). POSIX define output for both as Value Description
_SC_NPROCESSORS_CONF Maximum number of execution units that can be made available to run threads
_SC_NPROCESSORS_ONLN Maximum number of execution units currently available to run threads

the system call sched_getaffinity is used for both now, but value returned by it is valid only for _SC_NPROCESSORS_ONLN.

It is necessary to design new processing for _SC_NPROCESSORS_CONF to get proper value which represent real CPU count.

jmalak commented 3 months ago

I add new implementation for sysconf(_SC_NPROCESSORS_CONF). It looks like correct value is only available in kernel, because there can be also some hot-plugin CPU's that this value is not static. Such kernel information is available by sysfs /sys/devices/system/cpu/present. New implementation check info in this file and get number of really available CPU's (including hot-plugin CPU's if it is used).