user3105001
user3105001

Reputation: 63

Find number of CPUs in linux kernel

I want detect number of CPUs in linux kernel and write a sys_call that find it.

cpuinfo_x86 gives features of one CPU and cpu_detect fills it but how to find number of CPUs to detect?

Upvotes: 5

Views: 8242

Answers (4)

0xAX
0xAX

Reputation: 21817

You can use nr_cpu_ids variable which is set by all architectures during kernel boot up and initialization.

Upvotes: 3

Arulpandiyan Vadivel
Arulpandiyan Vadivel

Reputation: 417

Using the MACRO NR_CPUS we can find the number of CPU. This Macro should not be used in early_init sequence Since mostly NR_CPUS will not be initialized as it is run time macro.

or you can use num_online_cpus() function to get the number of cpus online.

you can find more options in include/linux/cpumask.h header to find availability of CPUS in various kinds.

Upvotes: 6

rreck
rreck

Reputation: 85

Personally, I cat /proc/cpuinfo to learn about the CPUs on a machine.

Upvotes: -2

jedruniu
jedruniu

Reputation: 530

Try:

$lscpu

This gives me information about CPUs, as well as architecture, etc...

Upvotes: -2

Related Questions