]> Savannah Git Hosting - gnulib.git/commitdiff
nproc: Ensure nproc(NPROC_ALL) ≥ nproc(NPROC_CURRENT) with glibc ≥ 2.26.
authorBruno Haible <bruno@clisp.org>
Mon, 10 Jun 2019 20:11:11 +0000 (22:11 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 10 Jun 2019 20:11:11 +0000 (22:11 +0200)
Reported by Nikita Ermakov <arei@altlinux.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2019-06/msg00003.html>.

* lib/nproc.c (num_processors_ignoring_omp): Treat a return value of
sysconf (_SC_NPROCESSORS_CONF) == 2 like a return value == 1.

ChangeLog
lib/nproc.c

index 217779ef3dfd3638c9bc52245314a1194b2c056f..18aecf7d2de5786f35bff8cd91a02748e4700246 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-06-10  Bruno Haible  <bruno@clisp.org>
+
+       nproc: Ensure nproc(NPROC_ALL) ≥ nproc(NPROC_CURRENT) with glibc ≥ 2.26.
+       Reported by Nikita Ermakov <arei@altlinux.org> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2019-06/msg00003.html>.
+       * lib/nproc.c (num_processors_ignoring_omp): Treat a return value of
+       sysconf (_SC_NPROCESSORS_CONF) == 2 like a return value == 1.
+
 2019-06-10  Bruno Haible  <bruno@clisp.org>
 
        posix_spawn_file_actions_addchdir: Fix possible use-after-free bug.
index 77b876027120718a30b4285e929764385bf9f30e..b11690b570d821cacd2a24e2f6d139187d99c6d5 100644 (file)
@@ -216,8 +216,9 @@ num_processors_ignoring_omp (enum nproc_query query)
      Note! On Linux systems with glibc, the first and second number come from
      the /sys and /proc file systems (see
      glibc/sysdeps/unix/sysv/linux/getsysstats.c).
-     In some situations these file systems are not mounted, and the sysconf
-     call returns 1, which does not reflect the reality.  */
+     In some situations these file systems are not mounted, and the sysconf call
+     returns 1 or 2 (<https://sourceware.org/bugzilla/show_bug.cgi?id=21542>),
+     which does not reflect the reality.  */
 
   if (query == NPROC_CURRENT)
     {
@@ -249,13 +250,13 @@ num_processors_ignoring_omp (enum nproc_query query)
         /* On Linux systems with glibc, this information comes from the /sys and
            /proc file systems (see glibc/sysdeps/unix/sysv/linux/getsysstats.c).
            In some situations these file systems are not mounted, and the
-           sysconf call returns 1.  But we wish to guarantee that
+           sysconf call returns 1 or 2.  But we wish to guarantee that
            num_processors (NPROC_ALL) >= num_processors (NPROC_CURRENT).  */
-        if (nprocs == 1)
+        if (nprocs == 1 || nprocs == 2)
           {
             unsigned long nprocs_current = num_processors_via_affinity_mask ();
 
-            if (nprocs_current > 0)
+            if (/* nprocs_current > 0 && */ nprocs_current > nprocs)
               nprocs = nprocs_current;
           }
 # endif