[PATCH] glibc: Remove CPU set size checking from affinity functions [BZ #19143]
Michael Kerrisk (man-pages)
mtk.manpages@gmail.com
Thu Mar 10 17:07:00 GMT 2016
Hello Florian.
On 03/10/2016 12:20 PM, Florian Weimer wrote:
> On 03/08/2016 08:42 PM, Michael Kerrisk (man-pages) wrote:
>
>>> One caveat is that sched_getaffinity can set bits beyond the requested
>>> allocation size (in bits) because the kernel gets a padded CPU vector
>>> and sees a few additional bits.
>>
>> I'm not quite clear on this point. Does it get a padded CPU vector
>> because CPU_ALLOC() might allocate a vector of size larger than the
>> user requested?
>
> Yes, this is the problem, combined with CPU_ALLOC_SIZE returning the
> larger size (which is unavoidable).
Thanks for the clarification. I added this paragraph:
Be aware that CPU_ALLOC(3) may allocate a slightly larger CPU
set than requested (because CPU sets are implemented as bit
masks allocated in units of sizeof(long)). Consequently,
sched_getaffinity() can set bits beyond the requested allocaâ
tion size, because the kernel sees a few additional bits.
Therefore, the caller should iterate over the bits in the
returned set, counting those which are set, and stop upon
reaching the value returned by CPU_COUNT(3) (rather than iterâ
ating over the number of bits requested to be allocated).
> This whole interface could have been designed much better (compare
> select to epoll, for instance).
Indeed!
Cheers,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
More information about the Libc-alpha
mailing list