Skip to contentSkip to conversation

Use num_possible_cpus() instead of direct use of NR_CPUS.

PATCH In review Ameen 3 participants 3 messages Jan 10, 2016 – Jan 11, 2016

lore
Share & tools
lore

Ameen

author
#0 lore raw

PATCH 2/2 Use num_possible_cpus() instead of direct use of NR_CPUS.

WARNING: usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus()..

---
 kernel/smp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/smp.c +2 -2
index d903c02..94033ac 100644
@@ -549,13 +549,13 @@ static int __init maxcpus(char *str)
 early_param("maxcpus", maxcpus);
 
 /* Setup number of possible processor ids */
-int nr_cpu_ids __read_mostly = NR_CPUS;
+int nr_cpu_ids __read_mostly = num_possible_cpus();
 EXPORT_SYMBOL(nr_cpu_ids);
 
 /* An arch may set nr_cpu_ids earlier if needed, so this would be redundant */
 void __init setup_nr_cpu_ids(void)
 {
-	nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1;
+	nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),num_possible_cpus()) + 1;
 }
 
 void __weak smp_announce(void)
Signature · 1 line
2.5.0
#1 lore raw
Quoted 1 line · Ameen

WARNING: usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus()..

Is that a checkpatch warning? Notice the word "often". You need to provide info why it's the case here (and I doubt the change will be corect in this case).

Quoted 26 lines
---
 kernel/smp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/smp.c +2 -2
index d903c02..94033ac 100644
@@ -549,13 +549,13 @@ static int __init maxcpus(char *str)
 early_param("maxcpus", maxcpus);
 
 /* Setup number of possible processor ids */
-int nr_cpu_ids __read_mostly = NR_CPUS;
+int nr_cpu_ids __read_mostly = num_possible_cpus();
 EXPORT_SYMBOL(nr_cpu_ids);
 
 /* An arch may set nr_cpu_ids earlier if needed, so this would be redundant */
 void __init setup_nr_cpu_ids(void)
 {
-	nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1;
+	nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),num_possible_cpus()) + 1;
 }
 
 void __weak smp_announce(void)
#2 lore raw
Quoted 5 lines · Vlastimil Babka
Quoted 1 line · Ameen

WARNING: usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus()..

Is that a checkpatch warning? Notice the word "often". You need to provide info why it's the case here (and I doubt the change will be corect in this case).

Yeah, this is terminally broken.