public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/28865] New: linux: _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN are inaccurate without /sys and /proc
@ 2022-02-05 19:43 ldv at sourceware dot org
  2022-02-08 22:24 ` [Bug libc/28865] " cvs-commit at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ldv at sourceware dot org @ 2022-02-05 19:43 UTC (permalink / raw)
  To: glibc-bugs

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

            Bug ID: 28865
           Summary: linux: _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN
                    are inaccurate without /sys and /proc
           Product: glibc
           Version: 2.35
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: ldv at sourceware dot org
                CC: adhemerval.zanella at linaro dot org, drepper.fsp at gmail dot com,
                    glebfm at altlinux dot org
  Target Milestone: ---
             Flags: security-

Commit 342298278e ("linux: Revert the use of sched_getaffinity on get_nproc")
aka glibc-2.35~480 introduced a regression in environments where neither
/sys/devices/system/cpu/ nor /proc/stat is available:

$ nproc
128
$ getconf -a | grep _NPROCESSORS_
_NPROCESSORS_CONF                  2
_NPROCESSORS_ONLN                  2

This happened because that commit made get_nprocs() and get_nprocs_conf()
bluntly return 2 when neither /sys/devices/system/cpu/ nor /proc/stat is
available.

I suggest changing these functions to check various sources of information in
the following order:

get_nprocs: /sys/devices/system/cpu/online -> sched_getaffinity -> /proc/stat
-> 2
get_nprocs_conf: /sys/devices/system/cpu/ -> /proc/stat -> sched_getaffinity ->
2

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

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

* [Bug libc/28865] linux: _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN are inaccurate without /sys and /proc
  2022-02-05 19:43 [Bug libc/28865] New: linux: _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN are inaccurate without /sys and /proc ldv at sourceware dot org
@ 2022-02-08 22:24 ` cvs-commit at gcc dot gnu.org
  2022-02-08 22:27 ` ldv at sourceware dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-08 22:24 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #1 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Dmitry Levin <ldv@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e1d32b836410767270a3adf1f82b1a47e6e4cd51

commit e1d32b836410767270a3adf1f82b1a47e6e4cd51
Author: Dmitry V. Levin <ldv@altlinux.org>
Date:   Sat Feb 5 08:00:00 2022 +0000

    linux: fix accuracy of get_nprocs and get_nprocs_conf [BZ #28865]

    get_nprocs() and get_nprocs_conf() use various methods to obtain an
    accurate number of processors.  Re-introduce __get_nprocs_sched() as
    a source of information, and fix the order in which these methods are
    used to return the most accurate information.  The primary source of
    information used in both functions remains unchanged.

    This also changes __get_nprocs_sched() error return value from 2 to 0,
    but all its users are already prepared to handle that.

    Old fallback order:
      get_nprocs:
        /sys/devices/system/cpu/online -> /proc/stat -> 2
      get_nprocs_conf:
        /sys/devices/system/cpu/ -> /proc/stat -> 2

    New fallback order:
      get_nprocs:
        /sys/devices/system/cpu/online -> /proc/stat -> sched_getaffinity -> 2
      get_nprocs_conf:
        /sys/devices/system/cpu/ -> /proc/stat -> sched_getaffinity -> 2

    Fixes: 342298278e ("linux: Revert the use of sched_getaffinity on
get_nproc")
    Closes: BZ #28865
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

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

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

* [Bug libc/28865] linux: _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN are inaccurate without /sys and /proc
  2022-02-05 19:43 [Bug libc/28865] New: linux: _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN are inaccurate without /sys and /proc ldv at sourceware dot org
  2022-02-08 22:24 ` [Bug libc/28865] " cvs-commit at gcc dot gnu.org
@ 2022-02-08 22:27 ` ldv at sourceware dot org
  2022-02-08 22:34 ` cvs-commit at gcc dot gnu.org
  2022-02-08 22:34 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ldv at sourceware dot org @ 2022-02-08 22:27 UTC (permalink / raw)
  To: glibc-bugs

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

Dmitry V. Levin <ldv at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |2.36
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
           Assignee|unassigned at sourceware dot org   |ldv at sourceware dot org

--- Comment #2 from Dmitry V. Levin <ldv at sourceware dot org> ---
Fixed in 2.36.

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

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

* [Bug libc/28865] linux: _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN are inaccurate without /sys and /proc
  2022-02-05 19:43 [Bug libc/28865] New: linux: _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN are inaccurate without /sys and /proc ldv at sourceware dot org
  2022-02-08 22:24 ` [Bug libc/28865] " cvs-commit at gcc dot gnu.org
  2022-02-08 22:27 ` ldv at sourceware dot org
@ 2022-02-08 22:34 ` cvs-commit at gcc dot gnu.org
  2022-02-08 22:34 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-08 22:34 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #3 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The release/2.34/master branch has been updated by Dmitry Levin
<ldv@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=007e054d786be340699c634e3a3b30ab1fde1a7a

commit 007e054d786be340699c634e3a3b30ab1fde1a7a
Author: Dmitry V. Levin <ldv@altlinux.org>
Date:   Sat Feb 5 08:00:00 2022 +0000

    linux: fix accuracy of get_nprocs and get_nprocs_conf [BZ #28865]

    get_nprocs() and get_nprocs_conf() use various methods to obtain an
    accurate number of processors.  Re-introduce __get_nprocs_sched() as
    a source of information, and fix the order in which these methods are
    used to return the most accurate information.  The primary source of
    information used in both functions remains unchanged.

    This also changes __get_nprocs_sched() error return value from 2 to 0,
    but all its users are already prepared to handle that.

    Old fallback order:
      get_nprocs:
        /sys/devices/system/cpu/online -> /proc/stat -> 2
      get_nprocs_conf:
        /sys/devices/system/cpu/ -> /proc/stat -> 2

    New fallback order:
      get_nprocs:
        /sys/devices/system/cpu/online -> /proc/stat -> sched_getaffinity -> 2
      get_nprocs_conf:
        /sys/devices/system/cpu/ -> /proc/stat -> sched_getaffinity -> 2

    Fixes: 342298278e ("linux: Revert the use of sched_getaffinity on
get_nproc")
    Closes: BZ #28865
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

    (cherry picked from commit e1d32b836410767270a3adf1f82b1a47e6e4cd51)

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

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

* [Bug libc/28865] linux: _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN are inaccurate without /sys and /proc
  2022-02-05 19:43 [Bug libc/28865] New: linux: _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN are inaccurate without /sys and /proc ldv at sourceware dot org
                   ` (2 preceding siblings ...)
  2022-02-08 22:34 ` cvs-commit at gcc dot gnu.org
@ 2022-02-08 22:34 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-08 22:34 UTC (permalink / raw)
  To: glibc-bugs

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

--- Comment #4 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The release/2.35/master branch has been updated by Dmitry Levin
<ldv@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=491f2ef1f0ff849490f374917957018d07ee0586

commit 491f2ef1f0ff849490f374917957018d07ee0586
Author: Dmitry V. Levin <ldv@altlinux.org>
Date:   Sat Feb 5 08:00:00 2022 +0000

    linux: fix accuracy of get_nprocs and get_nprocs_conf [BZ #28865]

    get_nprocs() and get_nprocs_conf() use various methods to obtain an
    accurate number of processors.  Re-introduce __get_nprocs_sched() as
    a source of information, and fix the order in which these methods are
    used to return the most accurate information.  The primary source of
    information used in both functions remains unchanged.

    This also changes __get_nprocs_sched() error return value from 2 to 0,
    but all its users are already prepared to handle that.

    Old fallback order:
      get_nprocs:
        /sys/devices/system/cpu/online -> /proc/stat -> 2
      get_nprocs_conf:
        /sys/devices/system/cpu/ -> /proc/stat -> 2

    New fallback order:
      get_nprocs:
        /sys/devices/system/cpu/online -> /proc/stat -> sched_getaffinity -> 2
      get_nprocs_conf:
        /sys/devices/system/cpu/ -> /proc/stat -> sched_getaffinity -> 2

    Fixes: 342298278e ("linux: Revert the use of sched_getaffinity on
get_nproc")
    Closes: BZ #28865
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

    (cherry picked from commit e1d32b836410767270a3adf1f82b1a47e6e4cd51)

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

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

end of thread, other threads:[~2022-02-08 22:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-05 19:43 [Bug libc/28865] New: linux: _SC_NPROCESSORS_CONF and _SC_NPROCESSORS_ONLN are inaccurate without /sys and /proc ldv at sourceware dot org
2022-02-08 22:24 ` [Bug libc/28865] " cvs-commit at gcc dot gnu.org
2022-02-08 22:27 ` ldv at sourceware dot org
2022-02-08 22:34 ` cvs-commit at gcc dot gnu.org
2022-02-08 22:34 ` cvs-commit at gcc dot gnu.org

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