Skip to contentSkip to conversation

ARM: kernel: DT cpu map validity check helper function

PATCH New Hiroshi Doyu 3 participants 5 messages Jan 14, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ARM: kernel: DT cpu map validity check helper function

From: Lorenzo Pieralisi <[email protected]>

Since the introduction of /cpu nodes bindings for ARM and the corresponding parse function arm_dt_init_cpu_maps(), the cpu_logical_map and the number of possible CPUs are set according to the DT /cpu nodes entries. Currently most of the existing ARM SMP platforms detect the number of cores through HW probing in their .smp_init_cpus functions and set the possible CPU mask accordingly.
This method should be upgraded so that the CPU counting mechanism will be based on DT, keeping legacy HW probing mechanism as a fall back solution.

In order to implement this fall back solution mechanism, the ARM DT code should provide a helper function to platforms to check if the cpu map has been properly initialized through DT. If the check fails the platform will resort to legacy HW based cores counting mechanism.

This patch implements a helper function that platforms can call to check whether DT based cpu map initialization and cores count were completed successfully.

---
 arch/arm/include/asm/prom.h |   10 ++++++++++
 arch/arm/kernel/devtree.c   |    6 ++++++
 2 files changed, 16 insertions(+)
arch/arm/include/asm/prom.h +10 -0
index a219227..487614a 100644
@@ -18,6 +18,15 @@
 extern struct machine_desc *setup_machine_fdt(unsigned int dt_phys);
 extern void arm_dt_memblock_reserve(void);
 extern void __init arm_dt_init_cpu_maps(void);
+/*
+ * Return true if cpu map initialization has been
+ * carried out correctly from DT
+ */
+static inline bool __init arm_dt_cpu_map_valid(void)
+{
+	extern bool valid_dt_cpu_map;
+	return valid_dt_cpu_map;
+}
 
 #else /* CONFIG_OF */
 
@@ -28,6 +37,7 @@ static inline struct machine_desc *setup_machine_fdt(unsigned int dt_phys)
 
 static inline void arm_dt_memblock_reserve(void) { }
 static inline void arm_dt_init_cpu_maps(void) { }
+static inline bool __init arm_dt_cpu_map_valid(void) { return false; }
 
 #endif /* CONFIG_OF */
 #endif /* ASMARM_PROM_H */
arch/arm/kernel/devtree.c +6 -0
index 70f1bde..4d8d1ec 100644
@@ -64,6 +64,11 @@ void __init arm_dt_memblock_reserve(void)
 }
 
 /*
+ * Export DT cpu map validity flag to platforms
+ */
+bool valid_dt_cpu_map __initdata;
+
+/*
  * arm_dt_init_cpu_maps - Function retrieves cpu nodes from the device tree
  * and builds the cpu logical map array containing MPIDR values related to
  * logical cpus
@@ -158,6 +163,7 @@ void __init arm_dt_init_cpu_maps(void)
 	 * a reg property, the DT CPU list can be considered valid and the
 	 * logical map created in smp_setup_processor_id() can be overridden
 	 */
+	valid_dt_cpu_map = true;
 	for (i = 0; i < cpuidx; i++) {
 		set_cpu_possible(i, true);
 		cpu_logical_map(i) = tmp_map[i];
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 2/2 ARM: tegra: Use DT /cpu node to detect number of CPU core

SCU based detection only works with Cortex-A9 MP and it doesn't support ones with multiple clusters. The only way to detect number of CPU core correctly is with DT /cpu node. If DT /cpu node based detection fails, we just simply fall back a single core in Tegra SoCs.

---
Based on the discussion:
http://lists.infradead.org/pipermail/linux-arm-kernel/2013-January/140608.html

---
 arch/arm/mach-tegra/platsmp.c |   17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
arch/arm/mach-tegra/platsmp.c +3 -14
index 6867030..456e7cc 100644
@@ -24,6 +24,7 @@
 #include <asm/mach-types.h>
 #include <asm/smp_scu.h>
 #include <asm/smp_plat.h>
+#include <asm/prom.h>
 
 #include <mach/powergate.h>
 
@@ -177,22 +178,10 @@ done:
 	return status;
 }
 
-/*
- * Initialise the CPU possible map early - this describes the CPUs
- * which may be present or become present in the system.
- */
 static void __init tegra_smp_init_cpus(void)
 {
-	unsigned int i, ncores = scu_get_core_count(scu_base);
-
-	if (ncores > nr_cpu_ids) {
-		pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
-			ncores, nr_cpu_ids);
-		ncores = nr_cpu_ids;
-	}
-
-	for (i = 0; i < ncores; i++)
-		set_cpu_possible(i, true);
+	if (!arm_dt_cpu_map_valid())
+		set_cpu_possible(0, true);
 
 	set_smp_cross_call(gic_raise_softirq);
 }
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/2 ARM: tegra: Use DT /cpu node to detect number of CPU core

arch/arm/mach-tegra/platsmp.c done: · line 184

Quoted 2 lines · Hiroshi Doyu
arch/arm/mach-tegra/platsmp.c +2 -0
+	if (!arm_dt_cpu_map_valid())
+		set_cpu_possible(0, true);

You don't need to do any of this (and, therefore, I don't think you even need the first patch.)

The generic boot code will set CPU0 as possible, present and online. Think about it: you're booting on that very CPU so it better be possible, present and online. If it isn't, what CPU is executing your code?

arm_dt_init_cpu_maps() will only ever set _additional_ CPUs in the possible map.

Ergo, by the time the above code is run, CPU0 will already be marked as possible. Therefore, the above code and arm_dt_cpu_map_valid() is not required.

#3 lore raw

PATCH 2/2 ARM: tegra: Use DT /cpu node to detect number of CPU core

Hi Russell,

Russell King - ARM Linux <[email protected]> wrote @ Mon, 14 Jan 2013 10:27:20 +0100:

Quoted 11 lines · Hiroshi Doyu

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (!arm_dt_cpu_map_valid())
+		set_cpu_possible(0, true);

You don't need to do any of this (and, therefore, I don't think you even need the first patch.)

The generic boot code will set CPU0 as possible, present and online. Think about it: you're booting on that very CPU so it better be possible, present and online. If it isn't, what CPU is executing your code?

Quoted 6 lines

arm_dt_init_cpu_maps() will only ever set _additional_ CPUs in the possible map.

Ergo, by the time the above code is run, CPU0 will already be marked as possible. Therefore, the above code and arm_dt_cpu_map_valid() is not required.

Right.

In Tegra, we've decided to not use SCU based detection at all any more and to continue with a single core even when DT cpu detection fails. For Tegra, "arm_dt_cpu_map_valid()" is not necessary. For other SoCs, this would be necessary when they want to detect again with SCU.

Now this original Tegra patch would be independet of the 1st patch as below:

Quoted 1 line

From 36061aff7a772524a1d1785884889619042d4445 Mon Sep 17 00:00:00 2001

From: Hiroshi Doyu <[email protected]>
Date: Mon, 26 Nov 2012 12:25:14 +0200
Subject: [PATCH 1/1] ARM: tegra: Use DT /cpu node to detect number of CPU
core

SCU based detection only works with Cortex-A9 MP and it doesn't support ones with multiple clusters. The only way to detect number of CPU core correctly is with DT /cpu node.

Tegra SoCs decided to use DT detection as the only way and to not use SCU based detection at all. Even if DT /cpu node based detection fails, it continues with a single core

---
Based on the discussion:
http://lists.infradead.org/pipermail/linux-arm-kernel/2013-January/140608.html

---
 arch/arm/mach-tegra/platsmp.c |   15 ---------------
 1 file changed, 15 deletions(-)
arch/arm/mach-tegra/platsmp.c +0 -15
index 6867030..689ee4b 100644
@@ -177,23 +177,8 @@ done:
 	return status;
 }
 
-/*
- * Initialise the CPU possible map early - this describes the CPUs
- * which may be present or become present in the system.
- */
 static void __init tegra_smp_init_cpus(void)
 {
-	unsigned int i, ncores = scu_get_core_count(scu_base);
-
-	if (ncores > nr_cpu_ids) {
-		pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
-			ncores, nr_cpu_ids);
-		ncores = nr_cpu_ids;
-	}
-
-	for (i = 0; i < ncores; i++)
-		set_cpu_possible(i, true);
-
 	set_smp_cross_call(gic_raise_softirq);
 }
 
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH 2/2 ARM: tegra: Use DT /cpu node to detect number of CPU core

Quoted 22 lines · Hiroshi Doyu

Hi Russell,

Russell King - ARM Linux <[email protected]> wrote @ Mon, 14 Jan 2013 10:27:20 +0100:

Quoted 11 lines · Hiroshi Doyu

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (!arm_dt_cpu_map_valid())
+		set_cpu_possible(0, true);

You don't need to do any of this (and, therefore, I don't think you even need the first patch.)

The generic boot code will set CPU0 as possible, present and online. Think about it: you're booting on that very CPU so it better be possible, present and online. If it isn't, what CPU is executing your code?

Quoted 6 lines

arm_dt_init_cpu_maps() will only ever set _additional_ CPUs in the possible map.

Ergo, by the time the above code is run, CPU0 will already be marked as possible. Therefore, the above code and arm_dt_cpu_map_valid() is not required.

Quoted 7 lines

Right.

In Tegra, we've decided to not use SCU based detection at all any more and to continue with a single core even when DT cpu detection fails. For Tegra, "arm_dt_cpu_map_valid()" is not necessary. For other SoCs, this would be necessary when they want to detect again with SCU.

Correct. I will keep my patch around and repost it if and when we want other platforms to rely on legacy HW number of cores count discovery.

Given that's going to be temporary legacy code anyway, I hope we won't need it at all.

Lorenzo