public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Cc: Nicolas Saenz Julienne <nsaenzju@redhat.com>,
	Florian Weimer <fweimer@redhat.com>
Subject: [PATCH 1/3] misc: Add __get_nprocs_sched
Date: Mon,  6 Sep 2021 15:11:31 -0300	[thread overview]
Message-ID: <20210906181133.1401140-2-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20210906181133.1401140-1-adhemerval.zanella@linaro.org>

This is an internal function meant to return the number of avaliable
processor where the process can scheduled, different than the
__get_nprocs which returns a the system available online CPU.

The Linux implementation currently only calls __get_nprocs(), which
in tuns calls sched_getaffinity.
---
 include/sys/sysinfo.h                 | 7 ++++++-
 malloc/arena.c                        | 2 +-
 misc/getsysstats.c                    | 6 ++++++
 sysdeps/mach/getsysstats.c            | 6 ++++++
 sysdeps/unix/sysv/linux/getsysstats.c | 6 ++++++
 5 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/include/sys/sysinfo.h b/include/sys/sysinfo.h
index 7388356a19..c490561581 100644
--- a/include/sys/sysinfo.h
+++ b/include/sys/sysinfo.h
@@ -9,10 +9,15 @@
 extern int __get_nprocs_conf (void);
 libc_hidden_proto (__get_nprocs_conf)
 
-/* Return number of available processors.  */
+/* Return number of available processors (not all of them will be
+   available to the caller process).  */
 extern int __get_nprocs (void);
 libc_hidden_proto (__get_nprocs)
 
+/* Return the number of available processors which the process can
+   be scheduled.  */
+extern int __get_nprocs_sched (void) attribute_hidden;
+
 /* Return number of physical pages of memory in the system.  */
 extern long int __get_phys_pages (void);
 libc_hidden_proto (__get_phys_pages)
diff --git a/malloc/arena.c b/malloc/arena.c
index 4c398753ae..78ef4cf18c 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -878,7 +878,7 @@ arena_get2 (size_t size, mstate avoid_arena)
             narenas_limit = mp_.arena_max;
           else if (narenas > mp_.arena_test)
             {
-              int n = __get_nprocs ();
+              int n = __get_nprocs_sched ();
 
               if (n >= 1)
                 narenas_limit = NARENAS_FROM_NCORES (n);
diff --git a/misc/getsysstats.c b/misc/getsysstats.c
index 2986d62247..5cbba0f9bd 100644
--- a/misc/getsysstats.c
+++ b/misc/getsysstats.c
@@ -44,6 +44,12 @@ weak_alias (__get_nprocs, get_nprocs)
 link_warning (get_nprocs, "warning: get_nprocs will always return 1")
 
 
+int
+__get_nprocs_sched (void)
+{
+  return 1;
+}
+
 long int
 __get_phys_pages (void)
 {
diff --git a/sysdeps/mach/getsysstats.c b/sysdeps/mach/getsysstats.c
index 1267f39da2..cc8023f979 100644
--- a/sysdeps/mach/getsysstats.c
+++ b/sysdeps/mach/getsysstats.c
@@ -62,6 +62,12 @@ __get_nprocs (void)
 libc_hidden_def (__get_nprocs)
 weak_alias (__get_nprocs, get_nprocs)
 
+int
+__get_nprocs_sched (void)
+{
+  return __get_nprocs ();
+}
+
 /* Return the number of physical pages on the system. */
 long int
 __get_phys_pages (void)
diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
index 8a5d342f0c..e9c0dc4d83 100644
--- a/sysdeps/unix/sysv/linux/getsysstats.c
+++ b/sysdeps/unix/sysv/linux/getsysstats.c
@@ -87,6 +87,12 @@ __get_nprocs (void)
 libc_hidden_def (__get_nprocs)
 weak_alias (__get_nprocs, get_nprocs)
 
+int
+__get_nprocs_sched (void)
+{
+  return __get_nprocs ();
+}
+
 
 /* On some architectures it is possible to distinguish between configured
    and active cpus.  */
-- 
2.30.2


  reply	other threads:[~2021-09-06 18:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-06 18:11 [PATCH 0/3] Revert the use of sched_getaffinity on get_nproc Adhemerval Zanella
2021-09-06 18:11 ` Adhemerval Zanella [this message]
2021-09-06 18:11 ` [PATCH 2/3] linux: Simplify get_nprocs Adhemerval Zanella
2021-09-07  9:30   ` Florian Weimer
2021-09-07 12:05     ` Adhemerval Zanella
2021-09-07  9:44   ` Florian Weimer
2021-09-06 18:11 ` [PATCH 3/3] linux: Revert the use of sched_getaffinity on get_nproc (BZ #28310) Adhemerval Zanella
2021-09-07  9:45   ` Florian Weimer
2021-09-07 12:12     ` Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210906181133.1401140-2-adhemerval.zanella@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=nsaenzju@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).