I was browsing Linux kernel code to understand the nr_cpus
boot parameter.
As per the documentation,
(https://www.kernel.org/doc/Documentation/kernel-parameters.txt)
[SMP] Maximum number of processors that an SMP kernel
could support. nr_cpus=n : n >= 1 limits the kernel to
supporting 'n' processors. Later in runtime you can not
use hotplug cpu feature to put more cpu back to online.
just like you compile the kernel NR_CPUS=n
In the smp.c
code, the value is set to nr_cpu_ids
which is then used everywhere in kernel.
http://lxr.free-electrons.com/source/kernel/smp.c
527 static int __init nrcpus(char *str)
528 {
529 int nr_cpus;
530
531 get_option(&str, &nr_cpus);
532 if (nr_cpus > 0 && nr_cpus < nr_cpu_ids)
533 nr_cpu_ids = nr_cpus;
534
535 return 0;
536 }
537
538 early_param("nr_cpus", nrcpus);
What I do not understand the nr_cpu_ids is also set by setup_nr_cpu_ids.
555 /* An arch may set nr_cpu_ids earlier if needed, so this would be redundant */
556 void __init setup_nr_cpu_ids(void)
557 {
558 nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1;
559 }
Initially, I thought this is called before the early_param
invocation. After adding logs, I found that setup_nr_cpu_ids()
is called after nr_cpus()
. nr_cpu_ids
is always set to the value sets in setup_nr_cpu_ids()
in stead of nr_cpus()
. I even verified its value in smp_init()
.
Can anybody please clarify if my observation is correct or not?
What is the exact usage of nr_cpu_ids
?