Relevant blog entry is https://landley.net/notes-2022.html#26-07-2022

> Meanwhile, I found out that musl has a bug! The nproc command has two
> modes, the default shows available processors (as modified by taskset),
> and nproc --all shows installed processors (whether or not the current process
> can schedule on them). One codepath is _SC_NPROCESSORS_CONF and the other
> is _SC_NPROCESSORS_ONLN. Except musl does ONLN for both, it hasn't got the
> second codepath, which according to strace is checking /sys/devices/system/cpu
> in glibc, and the bionic source has a comment saying that /proc/cpuinfo
> works fine on x86 but arm is broken because arm filters out the
> taskset-unavailable processors from that, so you have to look at the sysfs
> one to work around the arm bug.

And then me ruminating that mkroot is all single processor emulations so testing
this is once again a design issue...

Pretty sure I poked Rich about it at the time, but I just I confirmed that musl
still has the bug in today's git. And the above bionic note is apparently why my
code is looking at sysfs to get the data, and "strace nproc --all" on debian
says that's what they're doing too, and ltrace says it's doing the getconf() so
yes glibc is also doing it.

Musl will apparently allow itself to read data out of /proc, or at least there's
13 hits in the current codebase, but has zero instances of reading out of /sys.

Rob

On 5/2/24 11:20, enh wrote:
> (to be fair, i was shocked the first time i had to deal with an
> Android device where these weren't both the same...)
> 
> On Thu, May 2, 2024 at 9:18 AM enh <e...@google.com> wrote:
>>
>> /facepalm
>>
>> maybe move your hand-written version into portability just for musl,
>> and everyone with a working libc just uses sysconf()?
>>
>> On Tue, Apr 30, 2024 at 8:26 PM Rob Landley <r...@landley.net> wrote:
>> >
>> > On 4/29/24 16:56, enh via Toybox wrote:
>> > > isn't nproc(1) just a call to sysconf(3) with either
>> > > _SC_NPROCESSORS_ONLN for regular behavior, or _SC_NPROCESSORS_CONF for
>> > > --all?
>> >
>> > From musl src/conf/sysconf.c:
>> >
>> >         case JT_NPROCESSORS_CONF & 255:
>> >         case JT_NPROCESSORS_ONLN & 255: ;
>> >                 unsigned char set[128] = {1};
>> >                 int i, cnt;
>> >                 __syscall(SYS_sched_getaffinity, 0, sizeof set, set);
>> >                 for (i=cnt=0; i<sizeof set; i++)
>> >                         for (; set[i]; set[i]&=set[i]-1, cnt++);
>> >                 return cnt;
>> >
>> > Musl returns the same thing for "conf" and "online".
>> >
>> > Rob
_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to