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: Alexander Monakov <amonakov at ispras dot ru>
- Cc: KOSAKI Motohiro <kosaki dot motohiro at gmail dot com>, chrubis at suse dot cz, libc-alpha <libc-alpha at sourceware dot org>
- Date: Fri, 19 Jul 2013 00:58:48 -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> <20130716110445 dot GA20826 at rei> <CAHGf_=qxR-abdjwmJUw8vApSioDhKhvsc54Yx-fpw5V-whpioQ at mail dot gmail dot com> <51E5DCB2 dot 1070305 at gmail dot com> <20130717100527 dot GA24881 at rei> <51E6EA7E dot 6050601 at gmail dot com> <20130718110505 dot GA32439 at rei> <51E85763 dot 5090809 at gmail dot com> <51E8691C dot 6040609 at redhat dot com> <alpine dot LNX dot 2 dot 00 dot 1307190814340 dot 1061 at monopod dot intra dot ispras dot ru>
On 07/19/2013 12:26 AM, Alexander Monakov wrote:
> On 07/18/2013 05:00 PM, KOSAKI Motohiro wrote:
>>> Why application should think the cpus are 8? I mean cpu offlining is typically
>>> not short term.
> [snip]
> On Thu, 18 Jul 2013, Carlos O'Donell wrote:
>> The manual is wrong.
>>
>> You should use _SC_NPROCESSORS_ONLN.
>>
>> The manual should be fixed.
>>
>> There is no reason to recommend using configured processors to
>> assist in achieving maximum parallelism performance.
>
> Is that really so? IIUC, on ARM, Linux kernel can dynamically bring CPUs
> online/offline in response to load as a power saving measure, and for example
> if you run 'top' you'll see the reported number of CPUs fluctuate.
>
> So using the number of CPUs that are online *right now* does not seem
> appropriate, because on an otherwise idle system a just-started application
> will see just one CPU as online.
That's a good point.
However the application can't tell the difference between offline and
reserved for something else, and offline ready for use. The system
might be partitioned.
The application only knows that _SC_NPROCESSORS_ONLN are online now,
and creating more threads than that might just result in wasted cycles
contended for locks.
Therefore on ARM the Linux kernel can either report the CPU offline
and expect an intelligent application *not* to spin up lots of threads,
or just report those CPUs as online (but in deep sleep, potentially off).
I think that on ARM, with CPUs offline, _SC_NPROCESSORS_ONLN should
still count those CPUs if they are going to be put back online once
load goes up.
Keep in mind that _SC_NPROCESSORS_ONLN means the number of processors
available for scheduling tasks, and a sleeping CPU that will be brought
online when load goes up should IMO count.
Unless someone has a different argument?
Cheers,
Carlos.