[PATCH] linux: fix accuracy of get_nprocs and get_nprocs_conf [BZ #28865]

Florian Weimer fweimer@redhat.com
Mon Feb 7 11:44:05 GMT 2022


* Adhemerval Zanella via Libc-alpha:

> On 05/02/2022 18:24, Dmitry V. Levin wrote:
>> get_nprocs() and get_nprocs_conf() use various methods to obtain an
>> accurate number of processors.  Re-introduce __get_nprocs_sched() as
>> a source of information, and fix the order in which these methods are
>> used to return the most accurate information.  The primary source of
>> information used in both functions remains unchanged.
>> 
>> This also changes __get_nprocs_sched() error return value from 2 to 0,
>> but all its users are already prepared to handle that.
>> 
>> Old behavior:
>>   get_nprocs:
>>     /sys/devices/system/cpu/online -> /proc/stat -> 2
>>   get_nprocs_conf:
>>     /sys/devices/system/cpu/ -> /proc/stat -> 2
>> 
>> New behavior:
>>   get_nprocs:
>>     /sys/devices/system/cpu/online -> sched_getaffinity -> /proc/stat -> 2
>>   get_nprocs_conf:
>>     /sys/devices/system/cpu/ -> /proc/stat -> sched_getaffinity -> 2
>> 
>> Fixes: 342298278e ("linux: Revert the use of sched_getaffinity on get_nproc")
>> Closes: BZ #28865
>
> I think we are circling back on this, on BZ#27645 [1] we changed get_nprocs
> to use sched_getaffinity and then we have to revert it with BZ#28310 [2] because
> it introduced regression on some monitoring tools [3].

But I think using sched_getaffinity as a fallback when /sys and /proc
are not available makes somse.  It's different form what we did
temporarily (sched_getaffinity first).

Thanks,
Florian



More information about the Libc-alpha mailing list