Skip to contentSkip to conversation

arm64: Support hard limit of cpu count by nr_cpus

PATCH New Kefeng Wang 3 participants 11 messages Aug 5, 2016 – Aug 9, 2016 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: Support hard limit of cpu count by nr_cpus

Enable the hard limit of cpu count by nr_cpus on arm64. The code is borrowed from MIPS.

---
 arch/arm64/kernel/setup.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm64/kernel/setup.c +16 -0
index 536dce2..597b777 100644
@@ -224,6 +224,21 @@ static void __init request_standard_resources(void)
 
 u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID };
 
+static void __init prefill_possible_map(void)
+{
+	int i, possible = num_possible_cpus();
+
+	if (possible > nr_cpu_ids)
+		possible = nr_cpu_ids;
+
+	for (i = 0; i < possible; i++)
+		set_cpu_possible(i, true);
+	for (; i < NR_CPUS; i++)
+		set_cpu_possible(i, false);
+
+	nr_cpu_ids = possible;
+}
+
 void __init setup_arch(char **cmdline_p)
 {
 	pr_info("Boot CPU: AArch64 Processor [%08x]\n", read_cpuid_id());
@@ -285,6 +300,7 @@ void __init setup_arch(char **cmdline_p)
 	cpu_read_bootcpu_ops();
 	smp_init_cpus();
 	smp_build_mpidr_hash();
+	prefill_possible_map();
 
 #ifdef CONFIG_VT
 #if defined(CONFIG_VGA_CONSOLE)
Signature · 1 line
1.7.12.4
#1 lore raw

PATCH 1/1 arm64: Support hard limit of cpu count by nr_cpus

Quoted 21 lines · Kefeng Wang

Enable the hard limit of cpu count by nr_cpus on arm64. The code is borrowed from MIPS.

---
 arch/arm64/kernel/setup.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm64/kernel/setup.c +4 -0
index 536dce2..597b777 100644
@@ -224,6 +224,21 @@ static void __init request_standard_resources(void)
 
 u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID };
 
+static void __init prefill_possible_map(void)
+{
+	int i, possible = num_possible_cpus();
+

arch/arm64/kernel/setup.c static void __init request_standard_resources(void) · line 240

Quoted 10 lines
arch/arm64/kernel/setup.c +10 -0
+	if (possible > nr_cpu_ids)
+		possible = nr_cpu_ids;
+
+	for (i = 0; i < possible; i++)
+		set_cpu_possible(i, true);
+	for (; i < NR_CPUS; i++)
+		set_cpu_possible(i, false);
+
+	nr_cpu_ids = possible;
+}

Shouldn't we just avoid marking those CPUs as possible in smp_cpu_setup, rather than rewriting things later on?

Also, can you explain exactly what functionality is missing at the moment, please? I assume it's the nr_cpus= option not working correctly?

Will

#2 lore raw

PATCH 1/1 arm64: Support hard limit of cpu count by nr_cpus

Quoted 27 lines · Will Deacon
Quoted 26 lines · Kefeng Wang

Enable the hard limit of cpu count by nr_cpus on arm64. The code is borrowed from MIPS.

---
 arch/arm64/kernel/setup.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm64/kernel/setup.c +9 -0
index 536dce2..597b777 100644
@@ -224,6 +224,21 @@ static void __init request_standard_resources(void)
 
 u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID };
 
+static void __init prefill_possible_map(void)
+{
+	int i, possible = num_possible_cpus();
+
+	if (possible > nr_cpu_ids)
+		possible = nr_cpu_ids;
+
+	for (i = 0; i < possible; i++)
+		set_cpu_possible(i, true);
Quoted 8 lines

arch/arm64/kernel/setup.c static void __init request_standard_resources(void) · line 240

Quoted 5 lines
arch/arm64/kernel/setup.c +5 -0
+	for (; i < NR_CPUS; i++)
+		set_cpu_possible(i, false);
+
+	nr_cpu_ids = possible;
+}

Shouldn't we just avoid marking those CPUs as possible in smp_cpu_setup, rather than rewriting things later on?

How about this one,

Quoted 1 line

From 0965eebecbc5aea0473df0cb45d32b2fccf72a9a Mon Sep 17 00:00:00 2001

From: Kefeng Wang <[email protected]>
Date: Fri, 5 Aug 2016 17:44:33 +0800
Subject: [PATCH v2] arm64: Support hard limit of cpu count by nr_cpus

Enable the hard limit of cpu count by set boot options nr_cpus=x on arm64.

---
 arch/arm64/kernel/smp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/kernel/smp.c +4 -1
index 76a6d92..0ac3ff5 100644
@@ -496,7 +496,10 @@ static int __init smp_cpu_setup(int cpu)
 	if (cpu_ops[cpu]->cpu_init(cpu))
 		return -ENODEV;
 
-	set_cpu_possible(cpu, true);
+	if (cpu < nr_cpu_ids)
+		set_cpu_possible(cpu, true);
+	else
+		return -EINVAL;
 
 	return 0;
 }
Signature · 1 line
1.7.12.4
Quoted 3 lines

Also, can you explain exactly what functionality is missing at the moment, please? I assume it's the nr_cpus= option not working correctly?

Yes. they use same bootargs nr_cpus=1 on both arm64 and x86, but find it can't work in arm64.

Quoted 5 lines

Will

.

#3 lore raw

PATCH 1/1 arm64: Support hard limit of cpu count by nr_cpus

Quoted 61 lines · Kefeng Wang
Quoted 27 lines · Will Deacon
Quoted 26 lines · Kefeng Wang

Enable the hard limit of cpu count by nr_cpus on arm64. The code is borrowed from MIPS.

---
 arch/arm64/kernel/setup.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm64/kernel/setup.c +9 -0
index 536dce2..597b777 100644
@@ -224,6 +224,21 @@ static void __init request_standard_resources(void)
 
 u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID };
 
+static void __init prefill_possible_map(void)
+{
+	int i, possible = num_possible_cpus();
+
+	if (possible > nr_cpu_ids)
+		possible = nr_cpu_ids;
+
+	for (i = 0; i < possible; i++)
+		set_cpu_possible(i, true);
Quoted 8 lines

arch/arm64/kernel/setup.c static void __init request_standard_resources(void) · line 240

Quoted 5 lines
arch/arm64/kernel/setup.c +5 -0
+	for (; i < NR_CPUS; i++)
+		set_cpu_possible(i, false);
+
+	nr_cpu_ids = possible;
+}

Shouldn't we just avoid marking those CPUs as possible in smp_cpu_setup, rather than rewriting things later on?

How about this one,

From 0965eebecbc5aea0473df0cb45d32b2fccf72a9a Mon Sep 17 00:00:00 2001
From: Kefeng Wang <[email protected]>
Date: Fri, 5 Aug 2016 17:44:33 +0800
Subject: [PATCH v2] arm64: Support hard limit of cpu count by nr_cpus

Enable the hard limit of cpu count by set boot options nr_cpus=x on arm64.

---
 arch/arm64/kernel/smp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/kernel/smp.c +0 -0
index 76a6d92..0ac3ff5 100644
@@ -496,7 +496,10 @@ static int __init smp_cpu_setup(int cpu)
 	if (cpu_ops[cpu]->cpu_init(cpu))

arch/arm64/kernel/smp.c static int __init smp_cpu_setup(int cpu) · line 505

Quoted 10 lines
arch/arm64/kernel/smp.c +4 -1
 		return -ENODEV;
 
-	set_cpu_possible(cpu, true);
+	if (cpu < nr_cpu_ids)
+		set_cpu_possible(cpu, true);
+	else
+		return -EINVAL;
 
 	return 0;
 }

Or is this even better ?

arch/arm64/kernel/smp.c +3 -3
index 490db85..dbd6a5e 100644
@@ -659,9 +659,9 @@ void __init smp_init_cpus(void)
                 acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
                                       acpi_parse_gic_cpu_interface, 0);
  
-       if (cpu_count > NR_CPUS)
+       if (cpu_count > nr_cpu_ids)
                 pr_warn("no. of cores (%d) greater than configured maximum of %d - clipping\n",
-                       cpu_count, NR_CPUS);
+                       cpu_count, nr_cpu_ids);
  
         if (!bootcpu_valid) {
                 pr_err("missing boot CPU MPIDR, not enabling secondaries\n");
@@ -675,7 +675,7 @@ void __init smp_init_cpus(void)
          * with entries in cpu_logical_map while initializing the cpus.
          * If the cpu set-up fails, invalidate the cpu_logical_map entry.
          */
-       for (i = 1; i < NR_CPUS; i++) {
+       for (i = 1; i < nr_cpu_ids; i++) {
                 if (cpu_logical_map(i) != INVALID_HWID) {
                         if (smp_cpu_setup(i))
                                 cpu_logical_map(i) = INVALID_HWID;

Cheers
Suzuki

#4 lore raw

PATCH 1/1 arm64: Support hard limit of cpu count by nr_cpus

Quoted 8 lines · Suzuki K Poulose
Quoted 7 lines · Kefeng Wang
Quoted 4 lines · Will Deacon
Quoted 3 lines · Kefeng Wang

Enable the hard limit of cpu count by nr_cpus on arm64. The code is borrowed from MIPS.

[...]

Quoted 2 lines

Or is this even better ?

Agree, and let's show a better warning.

arch/arm64/kernel/smp.c void __init smp_init_cpus(void) · line 663

Quoted 12 lines
arch/arm64/kernel/smp.c +1 -1
index 490db85..dbd6a5e 100644
@@ -659,9 +659,9 @@ void __init smp_init_cpus(void)
                acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
                                      acpi_parse_gic_cpu_interface, 0);
 
-       if (cpu_count > NR_CPUS)
+       if (cpu_count > nr_cpu_ids)
                pr_warn("no. of cores (%d) greater than configured maximum of %d - clipping\n",

change to pr_warn("%d cores exceeds configured maximum of %d - clipping\n",

Thanks,
Kefeng

Quoted 21 lines
arch/arm64/kernel/smp.c +2 -2
-                       cpu_count, NR_CPUS);
+                       cpu_count, nr_cpu_ids);
 
        if (!bootcpu_valid) {
                pr_err("missing boot CPU MPIDR, not enabling secondaries\n");
@@ -675,7 +675,7 @@ void __init smp_init_cpus(void)
         * with entries in cpu_logical_map while initializing the cpus.
         * If the cpu set-up fails, invalidate the cpu_logical_map entry.
         */
-       for (i = 1; i < NR_CPUS; i++) {
+       for (i = 1; i < nr_cpu_ids; i++) {
                if (cpu_logical_map(i) != INVALID_HWID) {
                        if (smp_cpu_setup(i))
                                cpu_logical_map(i) = INVALID_HWID;

Cheers
Suzuki

.

#5 lore raw

PATCH v2 1/1 arm64: Support hard limit of cpu count by nr_cpus

In reply to Suzuki K Poulose

Enable the hard limit of cpu count by set boot options nr_cpus=x on arm64, and show a better warning when cpu number exceeds the limit.

---

Changed since v1:
- clip cpu number in smp_init_cpus suggested-by Will and Suzuki, and update the warning.

 arch/arm64/kernel/smp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/kernel/smp.c +4 -4
index 76a6d92..cbfc31c 100644
@@ -661,9 +661,9 @@ void __init smp_init_cpus(void)
 		acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
 				      acpi_parse_gic_cpu_interface, 0);
 
-	if (cpu_count > NR_CPUS)
-		pr_warn("no. of cores (%d) greater than configured maximum of %d - clipping\n",
-			cpu_count, NR_CPUS);
+	if (cpu_count > nr_cpu_ids)
+		pr_warn("%d cores exceeds configured maximum of %d - clipping\n",
+			cpu_count, nr_cpu_ids);
 
 	if (!bootcpu_valid) {
 		pr_err("missing boot CPU MPIDR, not enabling secondaries\n");
@@ -677,7 +677,7 @@ void __init smp_init_cpus(void)
 	 * with entries in cpu_logical_map while initializing the cpus.
 	 * If the cpu set-up fails, invalidate the cpu_logical_map entry.
 	 */
-	for (i = 1; i < NR_CPUS; i++) {
+	for (i = 1; i < nr_cpu_ids; i++) {
 		if (cpu_logical_map(i) != INVALID_HWID) {
 			if (smp_cpu_setup(i))
 				cpu_logical_map(i) = INVALID_HWID;
Signature · 1 line
1.7.12.4
#6 lore raw

PATCH v2 1/1 arm64: Support hard limit of cpu count by nr_cpus

Quoted 19 lines · Kefeng Wang

Enable the hard limit of cpu count by set boot options nr_cpus=x on arm64, and show a better warning when cpu number exceeds the limit.

---

Changed since v1:
- clip cpu number in smp_init_cpus suggested-by Will and Suzuki, and update the warning.

 arch/arm64/kernel/smp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/kernel/smp.c +0 -0
index 76a6d92..cbfc31c 100644

arch/arm64/kernel/smp.c void __init smp_init_cpus(void) · line 666

Quoted 9 lines
arch/arm64/kernel/smp.c +3 -3
@@ -661,9 +661,9 @@ void __init smp_init_cpus(void)
 		acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
 				      acpi_parse_gic_cpu_interface, 0);
 
-	if (cpu_count > NR_CPUS)
-		pr_warn("no. of cores (%d) greater than configured maximum of %d - clipping\n",
-			cpu_count, NR_CPUS);
+	if (cpu_count > nr_cpu_ids)
+		pr_warn("%d cores exceeds configured maximum of %d - clipping\n",
+			cpu_count, nr_cpu_ids);

I think we should leave the message as it was, and is better than what you have changed it to.

With that change,

#7 lore raw

PATCH v2 1/1 arm64: Support hard limit of cpu count by nr_cpus

Quoted 23 lines · Suzuki K Poulose
Quoted 22 lines · Kefeng Wang

Enable the hard limit of cpu count by set boot options nr_cpus=x on arm64, and show a better warning when cpu number exceeds the limit.

---

Changed since v1:
- clip cpu number in smp_init_cpus suggested-by Will and Suzuki, and update the warning.

 arch/arm64/kernel/smp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/kernel/smp.c +0 -0
index 76a6d92..cbfc31c 100644
@@ -661,9 +661,9 @@ void __init smp_init_cpus(void)
         acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
                       acpi_parse_gic_cpu_interface, 0);
 
Quoted 9 lines

arch/arm64/kernel/smp.c void __init smp_init_cpus(void) · line 666

Quoted 6 lines
arch/arm64/kernel/smp.c +3 -3
-    if (cpu_count > NR_CPUS)
-        pr_warn("no. of cores (%d) greater than configured maximum of %d - clipping\n",
-            cpu_count, NR_CPUS);
+    if (cpu_count > nr_cpu_ids)
+        pr_warn("%d cores exceeds configured maximum of %d - clipping\n",
+            cpu_count, nr_cpu_ids);

I think we should leave the message as it was, and is better than what you have changed it to.

The old message is OF only and the old logic shows message when the first cpu number greater than NR_CPUS. But now the cpu_count is the total cpu counts(get from DT or ACPI), so I change the message.

Quoted 9 lines

With that change,

.

#8 lore raw

PATCH v2 1/1 arm64: Support hard limit of cpu count by nr_cpus

Quoted 36 lines · Kefeng Wang
Quoted 23 lines · Suzuki K Poulose
Quoted 22 lines · Kefeng Wang

Enable the hard limit of cpu count by set boot options nr_cpus=x on arm64, and show a better warning when cpu number exceeds the limit.

---

Changed since v1:
- clip cpu number in smp_init_cpus suggested-by Will and Suzuki, and update the warning.

 arch/arm64/kernel/smp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/kernel/smp.c +0 -0
index 76a6d92..cbfc31c 100644
@@ -661,9 +661,9 @@ void __init smp_init_cpus(void)
         acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
                       acpi_parse_gic_cpu_interface, 0);
 
Quoted 9 lines

arch/arm64/kernel/smp.c void __init smp_init_cpus(void) · line 666

Quoted 6 lines
arch/arm64/kernel/smp.c +3 -3
-    if (cpu_count > NR_CPUS)
-        pr_warn("no. of cores (%d) greater than configured maximum of %d - clipping\n",
-            cpu_count, NR_CPUS);
+    if (cpu_count > nr_cpu_ids)
+        pr_warn("%d cores exceeds configured maximum of %d - clipping\n",
+            cpu_count, nr_cpu_ids);

I think we should leave the message as it was, and is better than what you have changed it to.

Quoted 1 line

The old message is OF only and the old logic shows message when the first cpu number greater than NR_CPUS.

I think you misunderstood "of" (as in plain english) with OF (as in Open Firmware). To avoid the confusion, how about making it :

"Number of cores (%d) exceeds configured maximum of %d - clipping\n" ?

Certainly a message like :

"5 cores exceeds configured maximum of %d..." doesn't look nice.

Suzuki

Quoted 13 lines

But now the cpu_count is the total cpu counts(get from DT or ACPI), so I change the message.

Quoted 9 lines

With that change,

.

#9 lore raw

PATCH v2 1/1 arm64: Support hard limit of cpu count by nr_cpus

Quoted 37 lines · Suzuki K Poulose
Quoted 36 lines · Kefeng Wang
Quoted 32 lines · Suzuki K Poulose
Quoted 19 lines · Kefeng Wang

Enable the hard limit of cpu count by set boot options nr_cpus=x on arm64, and show a better warning when cpu number exceeds the limit.

---

Changed since v1:
- clip cpu number in smp_init_cpus suggested-by Will and Suzuki, and update the warning.

 arch/arm64/kernel/smp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/kernel/smp.c +0 -0
index 76a6d92..cbfc31c 100644

arch/arm64/kernel/smp.c void __init smp_init_cpus(void) · line 666

Quoted 9 lines
arch/arm64/kernel/smp.c +3 -3
@@ -661,9 +661,9 @@ void __init smp_init_cpus(void)
         acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
                       acpi_parse_gic_cpu_interface, 0);
 
-    if (cpu_count > NR_CPUS)
-        pr_warn("no. of cores (%d) greater than configured maximum of %d - clipping\n",
-            cpu_count, NR_CPUS);
+    if (cpu_count > nr_cpu_ids)
+        pr_warn("%d cores exceeds configured maximum of %d - clipping\n",
+            cpu_count, nr_cpu_ids);

I think we should leave the message as it was, and is better than what you have changed it to.

Quoted 6 lines
Quoted 1 line

The old message is OF only and the old logic shows message when the first cpu number greater than NR_CPUS.

I think you misunderstood "of" (as in plain english) with OF (as in Open Firmware). To avoid the confusion, how about making it :

"Number of cores (%d) exceeds configured maximum of %d - clipping\n" ?

Er, I do misunderstood it, my bad, will use this one, thanks :)

Kefeng

Quoted 25 lines

Certainly a message like :

"5 cores exceeds configured maximum of %d..." doesn't look nice.

Suzuki

Quoted 13 lines

But now the cpu_count is the total cpu counts(get from DT or ACPI), so I change the message.

Quoted 9 lines

With that change,

.

.

#10 lore raw

PATCH v3 1/1 arm64: Support hard limit of cpu count by nr_cpus

In reply to Suzuki K Poulose

Enable the hard limit of cpu count by set boot options nr_cpus=x on arm64, and make a minor change about message when total number of cpu exceeds the limit.

---

Change since v2:
- change the warning message suggested-by Suzuki, and Suzuki's reviewed-by Change since v1:
- clip cpu number in smp_init_cpus suggested-by Will and Suzuki, and update the warning.

 arch/arm64/kernel/smp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/kernel/smp.c +4 -4
index 76a6d92..d93d433 100644
@@ -661,9 +661,9 @@ void __init smp_init_cpus(void)
 		acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
 				      acpi_parse_gic_cpu_interface, 0);
 
-	if (cpu_count > NR_CPUS)
-		pr_warn("no. of cores (%d) greater than configured maximum of %d - clipping\n",
-			cpu_count, NR_CPUS);
+	if (cpu_count > nr_cpu_ids)
+		pr_warn("Number of cores (%d) exceeds configured maximum of %d - clipping\n",
+			cpu_count, nr_cpu_ids);
 
 	if (!bootcpu_valid) {
 		pr_err("missing boot CPU MPIDR, not enabling secondaries\n");
@@ -677,7 +677,7 @@ void __init smp_init_cpus(void)
 	 * with entries in cpu_logical_map while initializing the cpus.
 	 * If the cpu set-up fails, invalidate the cpu_logical_map entry.
 	 */
-	for (i = 1; i < NR_CPUS; i++) {
+	for (i = 1; i < nr_cpu_ids; i++) {
 		if (cpu_logical_map(i) != INVALID_HWID) {
 			if (smp_cpu_setup(i))
 				cpu_logical_map(i) = INVALID_HWID;
Signature · 1 line
1.7.12.4