mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
To: musl@lists.openwall.com, Michael Jeanson <mjeanson@efficios.com>,
	Richard Purdie <richard.purdie@linuxfoundation.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Subject: Re: sysconf(_SC_NPROCESSORS_CONF) returns the wrong value
Date: Sat, 16 Mar 2019 10:28:19 -0400	[thread overview]
Message-ID: <20190316142819.GE6994@joraj-alpa> (raw)
In-Reply-To: <20190316022534.GN26605@port70.net>

> > A simple command line to show this:
> > 
> >   taskset -c 0 nproc --all
> > 
> > This is equivalent to asking sysconf(__SC_NPROCESSORS_CONF).
> 
> the right way to check the sysconf from a shell is getconf

It was only to provide an easy reproducer. But you are right in that nproc
does not expose the complete picture. Thanks for taking the time to reproduce
the base problem.

I mixed up the  _NPROCESSORS_ONLN result for glibc, it should have been 4 in the
previous email since there is 4 online cpu even if we have sched_affinity only
set for cpu0. (nproc was not proving my point for the _NPROCESSORS_ONLN value)

As you know, you can take a cpu offline easily, but we still need to account for
it in userspace tracing since it can be put back online (see Mathieu Desnoyers
answer in this thread).

  echo 0 > /sys/devices/system/cpu/cpu3/online

Now on a glibc system:

  $ taskset -c 0 getconf -a |grep NPROC
  _NPROCESSORS_CONF                  4
  _NPROCESSORS_ONLN                  3

This is why we use _NPROCESSORS_CONF and expect it to represent the complete
picture. We do not care much for _NPROCESSORS_ONLN or affinity. This is why the
use of "nproc --all" was sufficient for me (I was wrong).

> 
> on glibc system
> $ taskset -c 0 getconf -a |grep NPROC
> _NPROCESSORS_CONF                  8
> _NPROCESSORS_ONLN                  8
> 
> on musl
> $ taskset -c 0 getconf -a |grep NPROC
> _NPROCESSORS_CONF                  1
> _NPROCESSORS_ONLN                  1
> 
> so both values differ (plain nproc returns the affinity number,
> *_ONLN is all the cpus that the kernel schedules to, *_CONF
> includes offline cpus that may be hotplugged)
> 
> these are documented linux extensions so i think musl should follow
> the linux sysconf man page. (but the semantics is not entirely clear
> e.g. there is /sys/devices/system/cpu/possible which can have larger
> number than echo /sys/devices/system/cpu/cpu[0-9]* |wc -w which is
> what glibc seems to be doing for *_CONF)
> 
> i think we need to know why does a process care if musl returns
> the wrong number? or what are the valid uses of such a number?
> (there are heterogeous systems like arm big-little, numa systems
> with many sockets, containers, virtualization,.. how deep may a
> user process need to go down in this rabbit hole?)

I'll refer you to Mathieu Desnoyers answer regarding that. (same thread).
It should be approved shortly by a moderator.

Cheers

-- 
Jonathan Rajotte-Julien
EfficiOS


  parent reply	other threads:[~2019-03-16 14:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-15 21:02 Jonathan Rajotte-Julien
2019-03-16  2:25 ` Szabolcs Nagy
2019-03-16 13:58   ` Mathieu Desnoyers
2019-03-16 14:28   ` Jonathan Rajotte-Julien [this message]
2019-03-19 19:11   ` Florian Weimer
2019-03-26 16:23   ` Jonathan Rajotte-Julien
2019-03-26 17:45     ` Szabolcs Nagy
2019-03-26 18:01       ` Mathieu Desnoyers
2019-04-02 19:02         ` Szabolcs Nagy
2019-04-02 22:38           ` Mathieu Desnoyers

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=20190316142819.GE6994@joraj-alpa \
    --to=jonathan.rajotte-julien@efficios.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mjeanson@efficios.com \
    --cc=musl@lists.openwall.com \
    --cc=richard.purdie@linuxfoundation.org \
    /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).