Reputation: 63
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
Reputation: 21817
You can use nr_cpu_ids variable which is set by all architectures during kernel boot up and initialization.
Upvotes: 3
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
Reputation: 85
Personally, I cat /proc/cpuinfo to learn about the CPUs on a machine.
Upvotes: -2
Reputation: 530
Try:
$lscpu
This gives me information about CPUs, as well as architecture, etc...
Upvotes: -2