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:14:45 -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:
>> Thank you for the clarification.
>>
>> I think I see what you mean.
>>
>> There is no race.
>>
>> (1) No race in sched_getaffinity internally.
>>
>> 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. ;-)
OK, thank you for clarifying. In which case all of my further assumptions
are wrong.
> btw, we don't call memset(0) for clearing rest buffer because backward
> compatibility. gibc need to clear it if needed.
glibc will clear it.
>> You might have an empty socket with no configured CPU and
>> that would contribute towards possible cpus, but not configured
>> or online cpus.
>
> If 'configured' is such mean, you are correct. And then, we need to fix glibc
> manual for clarify.
I can fix the glibc manual. A 'configured' CPU is one that the OS
can bring online.
>> It really seems to me that we need _SC_NPROCESSORS_MAX_NP to
>> indicate the physical maximum number of CPUs the OS can connect
>> given a particular topology, and it can return -1 to indicate
>> it is completely a dynamic topology in which case all we can
>> do is call sched_getaffinity with higher and higher buffers
>> to find the current maximum (and we can't cache it).
>
> Right.
>
>> Does that clarify why I think we may need _SC_NPROCESSORS_MAX_NP?
>
> Yes, completely. My question was, current glibc manual describe
> sysconf (_SC_NPROCESSORS_CONF) mean "To determine the number of
> processors available to the system one can run". And, if "can" mean
> hot plugging, it should
> be possible cpus. It was my point.
No, it needs clarification. I will fix the manual.
Either way the question remains:
(1) Should glibc's sched_getaffinity never fail?
or
(2) Should glibc's sched_getaffinity fail with EINVAL when the size
of the cpu set is smaller than the size of the affinity mask for
all possible cpus?
I believe that a call to sched_getaffinity should not fail.
What do you think?
Cheers,
Carlos.