Skip to contentSkip to conversation

arm: platsmp: Allow secondary cpu hotplug with maxcpus=1

PATCH Superseded Stephen Boyd 3 participants 4 messages Jun 29, 2011 – Jun 30, 2011

Subsystems (10)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: platsmp: Allow secondary cpu hotplug with maxcpus=1

If an ARM system has multiple cpus in the same socket and the kernel is booted with maxcpus=1, secondary cpus are possible but not present due to how platform_smp_prepare_cpus() is called. Fix this by always calling platform_smp_prepare_cpus() as long as max_cpus is non-zero (0 means no SMP) to allow platform code to decide if any non-boot cpus are present in the system. Since all current platform code doesn't support physical hotplug we have a situation where possible == present and thus we can simply copy the possible map to the present map.

With this patch it's possible to boot an ARM system with maxcpus=1 on the command line and then hotplug in secondary cpus via sysfs. This is more in line with how x86 works with maxcpus=1 on the command line.

---

This patch was tested along with an MSM patch:

https://lkml.org/lkml/2011/4/7/354

I don't have any non-MSM hardware to test on so Acks and tested-bys are welcome.

 arch/arm/kernel/smp.c             |    3 +--
 arch/arm/mach-exynos4/platsmp.c   |    5 +----
 arch/arm/mach-msm/platsmp.c       |    5 +----
 arch/arm/mach-omap2/omap-smp.c    |    5 +----
 arch/arm/mach-realview/platsmp.c  |    5 +----
 arch/arm/mach-shmobile/platsmp.c  |    5 +----
 arch/arm/mach-tegra/platsmp.c     |    5 +----
 arch/arm/mach-ux500/platsmp.c     |    5 +----
 arch/arm/mach-vexpress/ct-ca9x4.c |    5 +----
 9 files changed, 9 insertions(+), 34 deletions(-)
arch/arm/kernel/smp.c +1 -2
index e7f92a4..fbaa24a 100644
@@ -365,8 +365,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
 	 */
 	if (max_cpus > ncores)
 		max_cpus = ncores;
-
-	if (max_cpus > 1) {
+	if (ncores > 1 && max_cpus) {
 		/*
 		 * Enable the local timer or broadcast device for the
 		 * boot CPU, but only if we have more than one CPU.
arch/arm/mach-exynos4/platsmp.c +1 -4
index c5e65a0..3f870d2 100644
@@ -154,14 +154,11 @@ void __init smp_init_cpus(void)
 
 void __init platform_smp_prepare_cpus(unsigned int max_cpus)
 {
-	int i;
-
 	/*
 	 * Initialise the present map, which describes the set of CPUs
 	 * actually populated at the present time.
 	 */
-	for (i = 0; i < max_cpus; i++)
-		set_cpu_present(i, true);
+	init_cpu_present(&cpu_possible_map);
 
 	scu_enable(scu_base_addr());
 
arch/arm/mach-msm/platsmp.c +1 -4
index 2034098..84e293f 100644
@@ -157,12 +157,9 @@ void __init smp_init_cpus(void)
 
 void __init platform_smp_prepare_cpus(unsigned int max_cpus)
 {
-	int i;
-
 	/*
 	 * Initialise the present map, which describes the set of CPUs
 	 * actually populated at the present time.
 	 */
-	for (i = 0; i < max_cpus; i++)
-		set_cpu_present(i, true);
+	init_cpu_present(&cpu_possible_map);
 }
arch/arm/mach-omap2/omap-smp.c +1 -4
index ecfe93c..5895d19 100644
@@ -125,14 +125,11 @@ void __init smp_init_cpus(void)
 
 void __init platform_smp_prepare_cpus(unsigned int max_cpus)
 {
-	int i;
-
 	/*
 	 * Initialise the present map, which describes the set of CPUs
 	 * actually populated at the present time.
 	 */
-	for (i = 0; i < max_cpus; i++)
-		set_cpu_present(i, true);
+	init_cpu_present(&cpu_possible_map);
 
 	/*
 	 * Initialise the SCU and wake up the secondary core using
arch/arm/mach-realview/platsmp.c +1 -4
index 963bf0d..00666be 100644
@@ -68,14 +68,11 @@ void __init smp_init_cpus(void)
 
 void __init platform_smp_prepare_cpus(unsigned int max_cpus)
 {
-	int i;
-
 	/*
 	 * Initialise the present map, which describes the set of CPUs
 	 * actually populated at the present time.
 	 */
-	for (i = 0; i < max_cpus; i++)
-		set_cpu_present(i, true);
+	init_cpu_present(&cpu_possible_map);
 
 	scu_enable(scu_base_addr());
 
arch/arm/mach-shmobile/platsmp.c +1 -4
index f3888fe..ca5b523 100644
@@ -64,10 +64,7 @@ void __init smp_init_cpus(void)
 
 void __init platform_smp_prepare_cpus(unsigned int max_cpus)
 {
-	int i;
-
-	for (i = 0; i < max_cpus; i++)
-		set_cpu_present(i, true);
+	init_cpu_present(&cpu_possible_map);
 
 	shmobile_smp_prepare_cpus();
 }
arch/arm/mach-tegra/platsmp.c +1 -4
index b8ae3c9..f11426a 100644
@@ -129,14 +129,11 @@ void __init smp_init_cpus(void)
 
 void __init platform_smp_prepare_cpus(unsigned int max_cpus)
 {
-	int i;
-
 	/*
 	 * Initialise the present map, which describes the set of CPUs
 	 * actually populated at the present time.
 	 */
-	for (i = 0; i < max_cpus; i++)
-		set_cpu_present(i, true);
+	init_cpu_present(&cpu_possible_map);
 
 	scu_enable(scu_base);
 }
arch/arm/mach-ux500/platsmp.c +1 -4
index 0c527fe..4509b7d 100644
@@ -172,14 +172,11 @@ void __init smp_init_cpus(void)
 
 void __init platform_smp_prepare_cpus(unsigned int max_cpus)
 {
-	int i;
-
 	/*
 	 * Initialise the present map, which describes the set of CPUs
 	 * actually populated@the present time.
 	 */
-	for (i = 0; i < max_cpus; i++)
-		set_cpu_present(i, true);
+	init_cpu_present(&cpu_possible_map);
 
 	scu_enable(scu_base_addr());
 	wakeup_secondary();
arch/arm/mach-vexpress/ct-ca9x4.c +1 -4
index 765a71f..c7cd438 100644
@@ -229,10 +229,7 @@ static void ct_ca9x4_init_cpu_map(void)
 
 static void ct_ca9x4_smp_enable(unsigned int max_cpus)
 {
-	int i;
-	for (i = 0; i < max_cpus; i++)
-		set_cpu_present(i, true);
-
+	init_cpu_present(&cpu_possible_map);
 	scu_enable(MMIO_P2V(A9_MPCORE_SCU));
 }
 #endif
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Stephen Boyd

If an ARM system has multiple cpus in the same socket and the kernel is booted with maxcpus=1, secondary cpus are possible but not present due to how platform_smp_prepare_cpus() is called. Fix this by always calling platform_smp_prepare_cpus() as long as max_cpus is non-zero (0 means no SMP) to allow platform code to decide if any non-boot cpus are present in the system. Since all current platform code doesn't support physical hotplug we have a situation where possible == present and thus we can simply copy the possible map to the present map.

Quoted 6 lines

With this patch it's possible to boot an ARM system with maxcpus=1 on the command line and then hotplug in secondary cpus via sysfs. This is more in line with how x86 works with maxcpus=1 on the command line.

#2 lore raw
In reply to Stephen Boyd

arch/arm/mach-exynos4/platsmp.c void __init smp_init_cpus(void) · line 161

Quoted 11 lines · Stephen Boyd

void __init platform_smp_prepare_cpus(unsigned int max_cpus) {

arch/arm/mach-exynos4/platsmp.c +1 -4
-	int i;
-
 	/*
 	 * Initialise the present map, which describes the set of CPUs
 	 * actually populated at the present time.
 	 */
-	for (i = 0; i < max_cpus; i++)
-		set_cpu_present(i, true);
+	init_cpu_present(&cpu_possible_map);

Ok, if we're now doing this in every platform, it might as well go into arch/arm/kernel/smp.c - platforms can re-initialize the present map in this callback if they need to do something different.

#3 lore raw
Quoted 15 lines · Russell King - ARM Linux

arch/arm/mach-exynos4/platsmp.c void __init smp_init_cpus(void) · line 161

Quoted 11 lines · Stephen Boyd

void __init platform_smp_prepare_cpus(unsigned int max_cpus) {

arch/arm/mach-exynos4/platsmp.c +1 -4
-	int i;
-
 	/*
 	 * Initialise the present map, which describes the set of CPUs
 	 * actually populated at the present time.
 	 */
-	for (i = 0; i < max_cpus; i++)
-		set_cpu_present(i, true);
+	init_cpu_present(&cpu_possible_map);

Ok, if we're now doing this in every platform, it might as well go into arch/arm/kernel/smp.c - platforms can re-initialize the present map in this callback if they need to do something different.

That sounds better. V2 coming soon.

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.