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