* get_nprocs question @ 2004-03-16 6:23 Andreas Jaeger 2004-03-16 20:05 ` Andreas Jaeger 0 siblings, 1 reply; 5+ messages in thread From: Andreas Jaeger @ 2004-03-16 6:23 UTC (permalink / raw) To: Glibc hackers [-- Attachment #1: Type: text/plain, Size: 663 bytes --] What exactly is the semantics of get_nprocs, the manual states: The @code{get_nprocs} function returns the number of available processors. Does available mean the number of all processors the kernel runs on? Or does it mean the number of CPUs upon which the process and its children will be permitted to execute? In the latter case we can use the sched_getaffinity system call for get_nprocs if it's available. If this is ok, I'll prepare a patch... Andreas -- Andreas Jaeger, aj@suse.de, http://www.suse.de/~aj SuSE Linux AG, Maxfeldstr. 5, 90409 Nürnberg, Germany GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126 [-- Attachment #2: Type: application/pgp-signature, Size: 188 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: get_nprocs question 2004-03-16 6:23 get_nprocs question Andreas Jaeger @ 2004-03-16 20:05 ` Andreas Jaeger 2004-03-16 20:12 ` Ulrich Drepper 0 siblings, 1 reply; 5+ messages in thread From: Andreas Jaeger @ 2004-03-16 20:05 UTC (permalink / raw) To: Glibc hackers [-- Attachment #1: Type: text/plain, Size: 2616 bytes --] Andreas Jaeger <aj@suse.de> writes: > What exactly is the semantics of get_nprocs, the manual states: > The @code{get_nprocs} function returns the number of available processors. > > Does available mean the number of all processors the kernel runs on? > Or does it mean the number of CPUs upon which the process and its > children will be permitted to execute? > > In the latter case we can use the sched_getaffinity system call for > get_nprocs if it's available. If this is ok, I'll prepare a patch... Here's the proposed patch. Is this ok? Andreas 2004-03-16 Andreas Jaeger <aj@suse.de> Andi Kleen <ak@suse.de> * sysdeps/unix/sysv/linux/getsysstats.c (popcnt): New. (__get_nprocs): Use sched_getaffinity to get number of processors. ============================================================ Index: sysdeps/unix/sysv/linux/getsysstats.c --- sysdeps/unix/sysv/linux/getsysstats.c 4 Sep 2003 08:25:11 -0000 1.27 +++ sysdeps/unix/sysv/linux/getsysstats.c 16 Mar 2004 20:04:23 -0000 @@ -1,5 +1,5 @@ /* Determine various system internal values, Linux version. - Copyright (C) 1996-2001, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1996-2001, 2002, 2003, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. @@ -133,6 +133,26 @@ get_proc_path (char *buffer, size_t bufs while (0) #endif +static unsigned char pop4 [16] = +{ + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 +}; + +/* Population count: count number of bits set. */ +static int +popcnt (unsigned char *buffer, int num) +{ + int count = 0; + int i; + for (i = 0; i < num; i++) + { + unsigned char w = buffer[i]; + count += pop4[w >> 4] + pop4[w & 0xF]; + } + return count; +} + + int __get_nprocs () { @@ -141,7 +161,17 @@ __get_nprocs () const char *proc_path; int result = 1; - /* XXX Here will come a test for the new system call. */ +#ifdef __NR_sched_getaffinity + cpu_set_t cpuset; + + result = INLINE_SYSCALL (sched_getaffinity, 3, __getpid(), sizeof (cpu_set_t), + &cpuset); + if (result != -1) + { + return popcnt ((unsigned char *) &cpuset, result); + } + +#endif /* Get mount point of proc filesystem. */ proc_path = get_proc_path (buffer, sizeof buffer); -- Andreas Jaeger, aj@suse.de, http://www.suse.de/~aj SuSE Linux AG, Maxfeldstr. 5, 90409 Nürnberg, Germany GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126 [-- Attachment #2: Type: application/pgp-signature, Size: 188 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: get_nprocs question 2004-03-16 20:05 ` Andreas Jaeger @ 2004-03-16 20:12 ` Ulrich Drepper 2004-03-17 5:33 ` Andreas Jaeger 0 siblings, 1 reply; 5+ messages in thread From: Ulrich Drepper @ 2004-03-16 20:12 UTC (permalink / raw) To: Andreas Jaeger; +Cc: Glibc hackers Andreas Jaeger wrote: > Here's the proposed patch. Is this ok? No. The value returned never had a thread-specific value but with getaffinity it would have. The definition should stay as it it, the affinity issue reducing the possible number of processors the process/thread can run on is a different issue which needs a different set of interfaces. -- ⧠Ulrich Drepper ⧠Red Hat, Inc. ⧠444 Castro St ⧠Mountain View, CA â ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: get_nprocs question 2004-03-16 20:12 ` Ulrich Drepper @ 2004-03-17 5:33 ` Andreas Jaeger 2004-03-17 5:50 ` Ulrich Drepper 0 siblings, 1 reply; 5+ messages in thread From: Andreas Jaeger @ 2004-03-17 5:33 UTC (permalink / raw) To: Ulrich Drepper; +Cc: Glibc hackers [-- Attachment #1: Type: text/plain, Size: 1008 bytes --] Ulrich Drepper <drepper@redhat.com> writes: > Andreas Jaeger wrote: > >> Here's the proposed patch. Is this ok? > > No. The value returned never had a thread-specific value but with > getaffinity it would have. The definition should stay as it it, the > affinity issue reducing the possible number of processors the > process/thread can run on is a different issue which needs a different > set of interfaces. OK, then just one more question: What is the difference between these two: /* Return number of configured processors. */ extern int get_nprocs_conf (void) __THROW; /* Return number of available processors. */ extern int get_nprocs (void) __THROW; How can configured be different from available? My change above would make it different but perhaps not as desired... Andreas -- Andreas Jaeger, aj@suse.de, http://www.suse.de/~aj SuSE Linux AG, Maxfeldstr. 5, 90409 Nürnberg, Germany GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126 [-- Attachment #2: Type: application/pgp-signature, Size: 188 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: get_nprocs question 2004-03-17 5:33 ` Andreas Jaeger @ 2004-03-17 5:50 ` Ulrich Drepper 0 siblings, 0 replies; 5+ messages in thread From: Ulrich Drepper @ 2004-03-17 5:50 UTC (permalink / raw) To: Andreas Jaeger; +Cc: Glibc hackers Andreas Jaeger wrote: > OK, then just one more question: What is the difference between these > two: > > /* Return number of configured processors. */ > extern int get_nprocs_conf (void) __THROW; > > /* Return number of available processors. */ > extern int get_nprocs (void) __THROW; The number of processors the OS knows or knew about need not be the same as the number which is currently in use by any process. This is all from long before there was affinity. Processors can be disabled (think hotplug). The SPARC kernel always had the distinction, x86 and may others don't. -- ⧠Ulrich Drepper ⧠Red Hat, Inc. ⧠444 Castro St ⧠Mountain View, CA â ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-03-17 5:50 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2004-03-16 6:23 get_nprocs question Andreas Jaeger 2004-03-16 20:05 ` Andreas Jaeger 2004-03-16 20:12 ` Ulrich Drepper 2004-03-17 5:33 ` Andreas Jaeger 2004-03-17 5:50 ` Ulrich Drepper
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).