public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* getting processor numbers
@ 2007-04-03 16:54 Ulrich Drepper
  2007-04-03 17:30 ` linux-os (Dick Johnson)
                   ` (4 more replies)
  0 siblings, 5 replies; 56+ messages in thread
From: Ulrich Drepper @ 2007-04-03 16:54 UTC (permalink / raw)
  To: Linux Kernel, Andrew Morton

[-- Attachment #1: Type: text/plain, Size: 1710 bytes --]

More and more code depends on knowing the number of processors in the
system to efficiently scale the code.  E.g., in OpenMP it is used by
default to determine how many threads to create.  Creating more threads
than there are processors/cores doesn't make sense.

glibc for a long time provides functionality to retrieve the number
through sysconf() and this is what fortunately most programs use.  The
problem is that we are currently using /proc/cpuinfo since this is all
there was available at that time.  Creating /proc/cpuinfo takes the
kernel quite a long time, unfortunately (I think Jakub said it is mainly
the interrupt information).

The alternative today is to use /sys/devices/system/cpu and count the
number of cpu* directories in it.  This is somewhat faster.  But there
would be another possibility: simply stat /sys/devices/system/cpu and
use st_nlink - 2.

This last step unfortunately it made impossible by recent changes:

  http://article.gmane.org/gmane.linux.kernel/413178

I would like to propose changing that patch, move the sched_*
pseudo-files in some other directly and permanently ban putting any new
file into /sys/devices/system/cpu.

To get some numbers, you can try

  http://people.redhat.com/drepper/nproc-timing.c

The numbers I see on x86-64:

cpuinfo 10145810 cycles for 100 accesses
readdir /sys 3113870 cycles for 100 accesses
stat /sys 741070 cycles for 100 accesses

Note that for the first two methods I skipped the actual parsing part.
This means in the real solution the gap between those two and the simple
stat() call is even bigger.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 251 bytes --]

^ permalink raw reply	[flat|nested] 56+ messages in thread

end of thread, other threads:[~2007-04-04 14:53 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-03 16:54 getting processor numbers Ulrich Drepper
2007-04-03 17:30 ` linux-os (Dick Johnson)
2007-04-03 17:37   ` Ulrich Drepper
2007-04-03 17:56 ` Dr. David Alan Gilbert
2007-04-03 18:11 ` Andi Kleen
2007-04-03 17:17   ` Ulrich Drepper
2007-04-03 17:22     ` Alan Cox
2007-04-03 17:30       ` Andi Kleen
2007-04-03 20:24         ` Jeremy Fitzhardinge
2007-04-03 17:27     ` Andi Kleen
2007-04-03 17:30       ` Ulrich Drepper
2007-04-03 17:35         ` Andi Kleen
2007-04-03 17:45           ` Ulrich Drepper
2007-04-03 17:58             ` Andi Kleen
2007-04-03 18:05               ` Ulrich Drepper
2007-04-03 18:11                 ` Andi Kleen
2007-04-03 18:21                   ` Ulrich Drepper
2007-04-03 17:44         ` Siddha, Suresh B
2007-04-03 17:59           ` Ulrich Drepper
2007-04-03 19:40             ` Jakub Jelinek
2007-04-03 20:13             ` Ingo Oeser
2007-04-03 23:38               ` J.A. Magallón
2007-04-03 19:55           ` Ulrich Drepper
2007-04-03 20:13             ` Siddha, Suresh B
2007-04-03 20:19               ` Ulrich Drepper
2007-04-03 20:32                 ` Eric Dumazet
2007-04-03 20:20             ` Nathan Lynch
2007-04-03 19:15 ` Davide Libenzi
2007-04-03 19:32   ` Ulrich Drepper
2007-04-04  0:31     ` H. Peter Anvin
2007-04-04  0:35       ` Jeremy Fitzhardinge
2007-04-04  0:38         ` H. Peter Anvin
2007-04-04  5:09           ` Eric Dumazet
2007-04-04  5:16             ` H. Peter Anvin
2007-04-04  5:22               ` Jeremy Fitzhardinge
2007-04-04  5:40                 ` H. Peter Anvin
2007-04-04  5:46                   ` Eric Dumazet
2007-04-04  5:29               ` Eric Dumazet
2007-04-03 20:16 ` Andrew Morton
     [not found]   ` <4612BB89.8040102@redhat.com>
     [not found]     ` <20070403141348.9bcdb13e.akpm@linux-foundation.org>
2007-04-03 22:13       ` Ulrich Drepper
2007-04-03 22:48         ` Andrew Morton
2007-04-03 23:00           ` Ulrich Drepper
2007-04-03 23:23             ` Andrew Morton
2007-04-03 23:54               ` Ulrich Drepper
2007-04-04  2:55               ` Paul Jackson
2007-04-04  8:39               ` Oleg Nesterov
2007-04-04  9:39                 ` Ingo Molnar
2007-04-04  8:57                   ` Oleg Nesterov
2007-04-04 10:01                     ` Ingo Molnar
2007-04-04  2:58             ` Paul Jackson
2007-04-04  3:04             ` Paul Jackson
2007-04-04  2:52           ` Paul Jackson
2007-04-04  2:04   ` Paul Jackson
2007-04-04  6:47     ` Jakub Jelinek
2007-04-04  7:02       ` Paul Jackson
2007-04-04 14:51       ` Cliff Wickman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox