mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: __sched_cpucount returns garbage
Date: Tue, 2 Dec 2014 19:11:15 -0500	[thread overview]
Message-ID: <20141203001115.GC4574@brightrain.aerifal.cx> (raw)
In-Reply-To: <20141130113846.GC9258@port70.net>

On Sun, Nov 30, 2014 at 12:38:46PM +0100, Szabolcs Nagy wrote:
> * Isaac Dunham <ibid.ag@gmail.com> [2014-11-29 15:36:33 -0800]:
> > I noticed that nproc ended up on the toybox TODO list (via Tizen), and went
> > poking about via strace and ltrace to see where it got the cpu count from.
> > 
> > In the process, I discovered that __sched_cpucount is returning garbage;
> 
> works here as expected:
> 
> #define _GNU_SOURCE
> #include <sched.h>
> int main()
> {
> 	cpu_set_t s = {0};
> 	CPU_SET(3, &s);
> 	CPU_SET(7, &s);
> 	CPU_SET(24, &s);
> 	return __sched_cpucount(sizeof s, &s);
> }
> 
> returns 3
> 
> > on Alpine Linux on my N270-based netbook (1 physical core but 
> > hyperthreading makes it look like 2),
> > nproc
> > outputs a random number of CPUs ranging from 413 to 472.
> 
> see where the cpu_set_t argument comes from
> (most likely sched_getaffinity syscall)
> then see why that is broken
> 
> __sched_cpucount just counts bit flags

Is it possible that the macros from sched.h are using it wrong, or
that nproc is using __sched_cpucount directly rather than using the
sched.h macros and expecting different behavior from it (perhaps a
mismatch between the musl and glibc behavior, like counting bits vs
bytes vs longs)?

Rich


  reply	other threads:[~2014-12-03  0:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-29 23:36 Isaac Dunham
2014-11-30 11:38 ` Szabolcs Nagy
2014-12-03  0:11   ` Rich Felker [this message]
2014-12-03  1:33     ` Isaac Dunham
2014-12-03  2:48       ` Rich Felker
2014-12-03  3:19         ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141203001115.GC4574@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).