Linux Module to print number of CPU's

We can look at /proc/cpuinfo to find out the number of processors present in Linux from user space.


What if we want to find out the number of cpus in kernel module. num_online_cpus() function can give the number of CPU's which are online.

Code:


#include <linux/module.h> /* for MODULE_*. module_* */
#include <linux/printk.h> /* for pr_* */
#include <linux/cpumask.h> /* for num_online_cpus */
static int __init mod_init(void)
{
pr_info("number of online cpus is %d\n", num_online_cpus());
return 0;
}
static void __exit mod_exit(void)
{
}
module_init(mod_init);
module_exit(mod_exit);
MODULE_LICENSE("GPL");
view raw online_cpus.c hosted with ❤ by GitHub

Output:


References:

https://stackoverflow.com/questions/43171805/find-number-of-cpus-in-linux-kernel

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

PR, PN and PV Variable in Yocto