[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Fix num_processors_ignoring_omp.
From: |
Nikita Ermakov |
Subject: |
[PATCH] Fix num_processors_ignoring_omp. |
Date: |
Tue, 4 Jun 2019 15:43:06 +0300 |
From: Nikita Ermakov <address@hidden>
- Update comments to correspond closed glibc bug #21542.
- In case of failed _SC_NPROCESSORS_CONF use the maximum between
nprocs_current and nprocs to meet the requirements of
num_processors (NPROC_ALL) >= num_processors (NPROC_CURRENT).
---
lib/nproc.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)
diff --git a/lib/nproc.c b/lib/nproc.c
index 77b876027..a550711b4 100644
--- a/lib/nproc.c
+++ b/lib/nproc.c
@@ -217,17 +217,14 @@ num_processors_ignoring_omp (enum nproc_query query)
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. */
+ call returns 1 or 2, which does not reflect the reality. */
+ unsigned long nprocs_current = num_processors_via_affinity_mask ();
if (query == NPROC_CURRENT)
{
/* Try the modern affinity mask system call. */
- {
- unsigned long nprocs = num_processors_via_affinity_mask ();
-
- if (nprocs > 0)
- return nprocs;
- }
+ if (nprocs_current > 0)
+ return nprocs_current;
#if defined _SC_NPROCESSORS_ONLN
{ /* This works on glibc, Mac OS X 10.5, FreeBSD, AIX, OSF/1, Solaris,
@@ -249,15 +246,10 @@ 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)
- {
- unsigned long nprocs_current = num_processors_via_affinity_mask ();
-
- if (nprocs_current > 0)
- nprocs = nprocs_current;
- }
+ if (nprocs_current > nprocs)
+ nprocs = nprocs_current;
# endif
if (nprocs > 0)
--
2.19.2
- [PATCH] Fix num_processors_ignoring_omp.,
Nikita Ermakov <=