public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/30135] New: sysconf: _SC_NPROCESSORS*: tweak?
@ 2023-02-18 20:25 steffen at sdaoden dot eu
  2023-02-18 20:26 ` [Bug libc/30135] " steffen at sdaoden dot eu
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: steffen at sdaoden dot eu @ 2023-02-18 20:25 UTC (permalink / raw)
  To: glibc-bugs

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-02-21 17:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-18 20:25 [Bug libc/30135] New: sysconf: _SC_NPROCESSORS*: tweak? steffen at sdaoden dot eu
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

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).