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
Cc: Michael Jeanson <mjeanson@efficios.com>,
	Richard Purdie <richard.purdie@linuxfoundation.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Subject: sysconf(_SC_NPROCESSORS_CONF) returns the wrong value
Date: Fri, 15 Mar 2019 17:02:02 -0400	[thread overview]
Message-ID: <20190315210202.GD6994@joraj-alpa> (raw)

Hi all,

We are currently in the process of making sure that lttng [1] (linux tracer) run
smoothly on system using musl (Yocto, Alpine etc.). Most things work
fine. Still, we currently have tests that are failing due to an issue regarding
the reported number of configured processors on the system (__SC_NPROCESSORS_CONF).
Note that users of LTTng are also affected by this if they chose to modify the
sched affinity of their instrumented apps. This is relatively a big deal for us.

Long story short, we start an app with "taskset -c 0" and we need to allocate
data structure internally but using the number of configured processors not the
number of online processors. To do so we call sysconf(__SC_NPROCESSORS_CONF).
Slight problem: the value returned is the _SC_NPROCESSORS_ONLN value instead of
__SC_NPROCESSORS_CONF.

From src/conf/sysconf.c:196

 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;

A simple command line to show this:

  taskset -c 0 nproc --all

This is equivalent to asking sysconf(__SC_NPROCESSORS_CONF).

On 4 cpu system using glibc:

  $ taskset -c 0 nproc --all
  4

On the same system using musl:

  $ taskset -c 0 nproc --all
  1

And as for _SC_NPROCESSORS_ONLN, we can use:

  taskset -c 0 nproc

Using glibc:
  $ taskset -c 0 nproc
  1

Using musl:
  $ taskset -c 0 nproc
  1

No problem there.

Not sure where to go from there. We will probably end-up having a fallback for
musl that will probably consist of parsing /sys/ like glibc does.

Still we wanted to get your feedback on the matter.

Cheers

-- 
Jonathan Rajotte-Julien
EfficiOS


             reply	other threads:[~2019-03-15 21:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-15 21:02 Jonathan Rajotte-Julien [this message]
2019-03-16  2:25 ` Szabolcs Nagy
2019-03-16 13:58   ` Mathieu Desnoyers
2019-03-16 14:28   ` Jonathan Rajotte-Julien
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=20190315210202.GD6994@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).