94084c
commit e870aac8974cda746157a5a3c9f452ccd70da29b
94084c
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
94084c
Date:   Mon Sep 6 12:22:54 2021 -0300
94084c
94084c
    misc: Add __get_nprocs_sched
94084c
    
94084c
    This is an internal function meant to return the number of avaliable
94084c
    processor where the process can scheduled, different than the
94084c
    __get_nprocs which returns a the system available online CPU.
94084c
    
94084c
    The Linux implementation currently only calls __get_nprocs(), which
94084c
    in tuns calls sched_getaffinity.
94084c
    
94084c
    Reviewed-by: Florian Weimer <fweimer@redhat.com>
94084c
    (cherry picked from commit 11a02b035b464ab6813676adfd19c4a59c36d907)
94084c
94084c
diff --git a/include/sys/sysinfo.h b/include/sys/sysinfo.h
94084c
index 7388356a19269335..c490561581733038 100644
94084c
--- a/include/sys/sysinfo.h
94084c
+++ b/include/sys/sysinfo.h
94084c
@@ -9,10 +9,15 @@
94084c
 extern int __get_nprocs_conf (void);
94084c
 libc_hidden_proto (__get_nprocs_conf)
94084c
 
94084c
-/* Return number of available processors.  */
94084c
+/* Return number of available processors (not all of them will be
94084c
+   available to the caller process).  */
94084c
 extern int __get_nprocs (void);
94084c
 libc_hidden_proto (__get_nprocs)
94084c
 
94084c
+/* Return the number of available processors which the process can
94084c
+   be scheduled.  */
94084c
+extern int __get_nprocs_sched (void) attribute_hidden;
94084c
+
94084c
 /* Return number of physical pages of memory in the system.  */
94084c
 extern long int __get_phys_pages (void);
94084c
 libc_hidden_proto (__get_phys_pages)
94084c
diff --git a/malloc/arena.c b/malloc/arena.c
94084c
index 667484630ed0afa5..f1f0af86489d0063 100644
94084c
--- a/malloc/arena.c
94084c
+++ b/malloc/arena.c
94084c
@@ -879,7 +879,7 @@ arena_get2 (size_t size, mstate avoid_arena)
94084c
             narenas_limit = mp_.arena_max;
94084c
           else if (narenas > mp_.arena_test)
94084c
             {
94084c
-              int n = __get_nprocs ();
94084c
+              int n = __get_nprocs_sched ();
94084c
 
94084c
               if (n >= 1)
94084c
                 narenas_limit = NARENAS_FROM_NCORES (n);
94084c
diff --git a/misc/getsysstats.c b/misc/getsysstats.c
94084c
index 0eedface6d2b0f75..57d93601e21265d7 100644
94084c
--- a/misc/getsysstats.c
94084c
+++ b/misc/getsysstats.c
94084c
@@ -45,6 +45,12 @@ weak_alias (__get_nprocs, get_nprocs)
94084c
 link_warning (get_nprocs, "warning: get_nprocs will always return 1")
94084c
 
94084c
 
94084c
+int
94084c
+__get_nprocs_sched (void)
94084c
+{
94084c
+  return 1;
94084c
+}
94084c
+
94084c
 long int
94084c
 __get_phys_pages (void)
94084c
 {
94084c
diff --git a/sysdeps/mach/getsysstats.c b/sysdeps/mach/getsysstats.c
94084c
index 1267f39da26aee38..cc8023f979bf6f74 100644
94084c
--- a/sysdeps/mach/getsysstats.c
94084c
+++ b/sysdeps/mach/getsysstats.c
94084c
@@ -62,6 +62,12 @@ __get_nprocs (void)
94084c
 libc_hidden_def (__get_nprocs)
94084c
 weak_alias (__get_nprocs, get_nprocs)
94084c
 
94084c
+int
94084c
+__get_nprocs_sched (void)
94084c
+{
94084c
+  return __get_nprocs ();
94084c
+}
94084c
+
94084c
 /* Return the number of physical pages on the system. */
94084c
 long int
94084c
 __get_phys_pages (void)
94084c
diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
94084c
index 1391e360b8f8e86c..120ce1bb756b09cc 100644
94084c
--- a/sysdeps/unix/sysv/linux/getsysstats.c
94084c
+++ b/sysdeps/unix/sysv/linux/getsysstats.c
94084c
@@ -88,6 +88,12 @@ __get_nprocs (void)
94084c
 libc_hidden_def (__get_nprocs)
94084c
 weak_alias (__get_nprocs, get_nprocs)
94084c
 
94084c
+int
94084c
+__get_nprocs_sched (void)
94084c
+{
94084c
+  return __get_nprocs ();
94084c
+}
94084c
+
94084c
 
94084c
 /* On some architectures it is possible to distinguish between configured
94084c
    and active cpus.  */