3

I am trying to understand how many processors are supported by Linux Kernel.

grep NR_CPUS /boot/config-`uname -r`

Will give me the maximum number of processors supported by kernel, which I can override using kernel command line parameter nr_cpus.

To find number of online cpus, i can use num_online_cpus() function

Then what is nr_cpu_ids?

#include <linux/kernel.h>
#include <linux/module.h>

MODULE_LICENSE("GPL");


static int __init test_hello_init(void)
{
    pr_info("%s: In init NR_CPUs=%d, nr_cpu_ids=%d\n", __func__, NR_CPUS, nr_cpu_ids);
    pr_info("Number of cpus available:%d\n", num_online_cpus());
    return -1;
}

static void __exit test_hello_exit(void)
{
    pr_info("%s: In exit\n", __func__);
}

module_init(test_hello_init);
module_exit(test_hello_exit);

[11548.627338] test_hello_init: In init NR_CPUs=8192, nr_cpu_ids=128
[11548.627340] Number of cpus available:6

What is the difference between NR_CPUs and ncr_cpu_ids. Are they not same?

md.jamal
  • 4,067
  • 8
  • 45
  • 108

1 Answers1

5

nr_cpu_ids is the total number of CPUs or processors in the machine while NR_CPUS is the total number of CPUs the Linux O/S can handle.

Yunnosch
  • 26,130
  • 9
  • 42
  • 54
xman
  • 51
  • 1
  • 6