summaryrefslogtreecommitdiff
path: root/lib/nproc.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2019-06-10 22:11:11 +0200
committerBruno Haible <bruno@clisp.org>2019-06-10 22:11:11 +0200
commit5dd3e60c55345c3c477492323a4395799e30e02b (patch)
treef9b8796304bf4c0f4b3c3878fa71a9c76d327574 /lib/nproc.c
parentb827d8a6fab0c25eaf0c59b94c5bbef00efeeae5 (diff)
downloadgnulib-5dd3e60c55345c3c477492323a4395799e30e02b.tar.gz
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.
Diffstat (limited to 'lib/nproc.c')
-rw-r--r--lib/nproc.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/nproc.c b/lib/nproc.c
index 77b8760271..b11690b570 100644
--- a/lib/nproc.c
+++ b/lib/nproc.c
@@ -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