[PATCH] glibc: Remove CPU set size checking from affinity functions [BZ #19143]

Michael Kerrisk (man-pages) mtk.manpages@gmail.com
Thu Mar 10 20:06:00 GMT 2016


Hi Florian,

On 10 March 2016 at 21:03, Florian Weimer <fweimer@redhat.com> wrote:
> On 03/10/2016 06:07 PM, Michael Kerrisk (man-pages) wrote:
>> 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 looks reasonable, thanks.

Thanks for checking it!

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