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:
Output:
References:
https://stackoverflow.com/questions/43171805/find-number-of-cpus-in-linux-kernel
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); | |
Output:
References:
https://stackoverflow.com/questions/43171805/find-number-of-cpus-in-linux-kernel
Comments
Post a Comment