This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: What *is* the API for sched_getaffinity? Should sched_getaffinity always succeed when using cpu_set_t?
- From: "Carlos O'Donell" <carlos at redhat dot com>
- To: KOSAKI Motohiro <kosaki dot motohiro at gmail dot com>
- Cc: libc-alpha <libc-alpha at sourceware dot org>
- Date: Thu, 18 Jul 2013 05:36:04 -0400
- Subject: Re: What *is* the API for sched_getaffinity? Should sched_getaffinity always succeed when using cpu_set_t?
- References: <51E42BFE dot 7000301 at redhat dot com> <51E4A0BB dot 2070802 at gmail dot com> <51E4A123 dot 9070001 at gmail dot com> <51E6F3ED dot 8000502 at redhat dot com> <51E6F956 dot 5050902 at gmail dot com> <51E714DE dot 6060802 at redhat dot com> <CAHGf_=oZW3kNA3V-9u+BZNs3tL3JKCsO2a0Q6f0iJzo=N4Wb8w at mail dot gmail dot com>
On 07/17/2013 06:56 PM, KOSAKI Motohiro wrote:
>> Just to clarify:
>>
>> kernel/sched/core.c:
>> ...
>> 3714 SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len,
>> 3715 unsigned long __user *, user_mask_ptr)
>> ...
>> 3720 if ((len * BITS_PER_BYTE) < nr_cpu_ids)
>> 3721 return -EINVAL;
>>
>> This code causes EINVAL to be returned when the length of the userspace
>> buffer is smaller than the size of the mask for ONLINE cpus.
>
> No. nr_cpu_ids mean possible cpus. This code mean, if user buffer is less than
> possible cpus, sched_getaffinity() always return EINVAL.
> I agree this name is not fully clear. ;-)
This is disappointing because the kernel's sched_getaffinity could work
with online cpus here and it would save space and map conveniently
to sysconf(_SC_NPROCESSORS_ONLN).
However, glibc would have to handle two distinct behaviours at that point,
so there is no real benefit.
I think we need _SC_NPROCESSORS_MAX_NP, otherwise users have no useful
way to determine the maximum number of possible cpus.
Cheers,
Carlos.