public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "steffen at sdaoden dot eu" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug libc/30135] New: sysconf: _SC_NPROCESSORS*: tweak?
Date: Sat, 18 Feb 2023 20:25:32 +0000	[thread overview]
Message-ID: <bug-30135-131@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=30135

            Bug ID: 30135
           Summary: sysconf: _SC_NPROCESSORS*: tweak?
           Product: glibc
           Version: 2.36
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: steffen at sdaoden dot eu
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

#?0|kent:tmp$ cat t.c
#include <stdio.h>
#include <unistd.h>
int main(void){
        long c,o;
        c = sysconf(_SC_NPROCESSORS_CONF);
        o = sysconf(_SC_NPROCESSORS_ONLN);
        printf("c=%ld o=%ld\n", c, o);
        return 0;
}


On bare metal:

#?0|kent:tmp$ tcc -run t.c
c=8 o=4
#?0|kent:tmp$ nproc
4

But in a box with cgroup-limited CPUs:

bash-5.2$ tcc -run t.c
c=4 o=4
bash-5.2$ nproc
3


Could this be a "bug" in the C library, as this checks
/sys/devices/system/cpu/online, /proc/stat, and only
then (iirc now) uses sched_getaffinity.  It documents
get_nprocs(3) as "number of processors currently
available in the system".

But POSIX standardized these[1] as _SC_NPROCESSORS_CONF
+ _SC_NPROCESSORS_ONLN for sysconf(3) as well as
NPROCESSORS_CONF and NPROCESSORS_ONLN for getconf(1),
saying

  ...
    The maximum number of execution units | _SC_NPROCESSORS_ONLN
    currently available to run threads† |
  ....
    † The nature of an execution unit and the precise conditions
    under which an execution unit is considered to be available,
    or can be made available, or how many threads it can execute
    in parallel, are implementation-defined.

Which is not the same.  Implementation-defined though.
But i mean if it is easy to give correct results for an execution
context (i would).

  [1] https://austingroupbugs.net/view.php?id=339

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2023-02-18 20:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-18 20:25 steffen at sdaoden dot eu [this message]
2023-02-18 20:26 ` [Bug libc/30135] " steffen at sdaoden dot eu
2023-02-20 20:28 ` adhemerval.zanella at linaro dot org
2023-02-20 20:50 ` steffen at sdaoden dot eu
2023-02-20 22:46 ` adhemerval.zanella at linaro dot org
2023-02-20 23:47 ` steffen at sdaoden dot eu
2023-02-21  8:59 ` sam at gentoo dot org
2023-02-21 10:25 ` fweimer at redhat dot com
2023-02-21 17:31 ` steffen at sdaoden dot eu

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=bug-30135-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).