5

How can I determine the number of CPUs on an OpenBSD system, using either system tools or C code?

The technique I know of to count CPUs on other BSD platforms -- checking /var/run/dmesg.boot for certain strings, doesn't always seem to work.

More context: Unfortunately, I don't have an OpenBSD system available to play around with. I am trying to address the OpenBSD-specific test failures for a Perl module.

mob
  • 183
  • 1
  • 7

4 Answers4

10

On OpenBSD you have:

sysctl hw.ncpu

or

sysctl hw.ncpufound

As explained in sysctl(3), ncpu is the number of CPU used by system and ncpufound is the number of CPU found by the system.

By the way, devio.us provides free shell account on OpenBSD servers.

Paul
  • 3,037
  • 6
  • 27
  • 40
Benoit
  • 3,549
  • 1
  • 19
  • 17
  • Thanks for the great tip about `devio.us`! That will make it easier to answer all my other OpenBSD questions. – mob Nov 23 '10 at 21:46
4

On FreeBSD, it's

sysctl -n hw.ncpu

and on Darwin

sysctl -n hw.availcpu

So perhaps it's similar? There is a system call, I think, but I'd poke around with the command line first.

poolie
  • 1,165
  • 1
  • 9
  • 17
2

The internet tells me to try this

dmesg | grep -i CPU

or

sysctl -a | egrep -i 'hw.machine|hw.model|hw.ncpu'

is cpuinfo available?? I know you can have it on BSD variants..

Arenstar
  • 3,602
  • 2
  • 25
  • 34
1

In 6.4 ncpuonline was added and as of 7.0 sysctl(2) states:

HW_NCPU (hw.ncpu)
    The number of CPUs configured.
HW_NCPUFOUND (hw.ncpufound)
    The number of CPUs found.
HW_NCPUONLINE (hw.ncpuonline)
    The number of CPUs online.

Further information on ncpuonline is available in revision (openbsd-cvs).

Paul
  • 3,037
  • 6
  • 27
  • 40