Re: libcruft/sysconf_cpus.c patch

"Indan Zupancic" <[email protected]> Tue, 23 Nov 2010 19:37:36 +0100 (CET)
Newsgroups gmane.linux.lib.dietlibc
Message-ID <[email protected]>
(Bela forgot to CC the list.)

On Tue, November 23, 2010 19:11, Bela Lubkin wrote:
> Indan Zupancic wrote:
>
>> You can use sched_getaffinity() to figure out the number of cpus.
>> Just count the number of bits set. Advantage of this is that it
>> gives the number of useable cpus, not the theoretical maximum.
>> Disadvantage is that it only works for Linux 2.6.
>
> It'll also be wrong if you were exec'd by someone who used
> sched_setaffinity() to restrict your horizons.

Not really. The manpage says:

        - _SC_NPROCESSORS_CONF
              The number of processors configured.

        - _SC_NPROCESSORS_ONLN
              The number of processors currently online (available).

I'd argue that for ONLN returning the number of available cpus is the
correct thing to do.

Anyway, if you don't want that, and also want to support CONF you can
save the original mask, then figure out the number of cpus with
sched_setaffinity(), before restoring the original. Though that is
more bother than really worth it.

> Anyway, I haven't noticed sched_[gs]etaffinity() support in dietlibc!

The kernel supports it, it's a system call, so adding it to dietlibc
is trivial.

> Writing a fully working /proc version isn't hard... stand by.
>
> Felix von Leitner wrote:
>
>> Maybe we should use /proc/stat.  There is no sysctl for this,
>> unfortunately, and it's not in the ELF auxvec.  Too bad, really.
>
> That seems to be what glibc does (from strace(), not source: I don't
> know what other strategies might be hiding in #ifdefs...)
>
>> I'd prefer a way that works if /proc if not mounted.
>
> Yeah, these are all still /proc-dependent, which isn't great...
>
>>Bela<
>

Regards,

Indan