Skip to contentSkip to conversation

ARC: setup cpu possible mask according to status field in dts

RFC In review Eugeniy Paltsev 2 participants 2 messages Dec 22, 2017 – Jan 5, 2018 Synopsys ARC architecture

lore
Share & tools
lore
#0 lore raw

RFC 1/1 ARC: setup cpu possible mask according to status field in dts

As we have option in u-boot to set CPU mask for running linux, we want to pass information to kernel about CPU cores should be brought up.

So we patch kernel dtb in u-boot to set CPUs status.

On linux boot we setup cpu possible mask according to status field in each cpu node. It is generic method according to ePAPR:
status - a standard property describing the state of a CPU. This property shall be present for nodes representing CPUs in a symmetric multiprocessing (SMP) configuration. For a CPU node the meaning of the "okay" and "disabled" values are as follows:
"okay" - The CPU is running; "disabled" - The CPU is in a quiescent state."

Also we setup MCIP debug mask according cpu possible mask.

Signed-off-by Eugeniy Paltsev <Eugeniy.Paltsev at synopsys.com>
---
 arch/arc/kernel/mcip.c | 10 ++++++++--
 arch/arc/kernel/smp.c  | 30 ++++++++++++++++++++++++++----
 2 files changed, 34 insertions(+), 6 deletions(-)
arch/arc/kernel/mcip.c +8 -2
index f61a52b..246481d 100644
@@ -89,6 +89,8 @@ static void mcip_ipi_clear(int irq)
 static void mcip_probe_n_setup(void)
 {
 	struct mcip_bcr mp;
+	u32 mcip_mask = 0;
+	int i;
 
 	READ_BCR(ARC_REG_MCIP_BCR, mp);
 
@@ -102,9 +104,13 @@ static void mcip_probe_n_setup(void)
 
 	cpuinfo_arc700[0].extn.gfrc = mp.gfrc;
 
+	for (i = 0; i < NR_CPUS; i++)
+		if (cpu_possible(i))
+			mcip_mask |= BIT(i);
+
 	if (mp.dbg) {
-		__mcip_cmd_data(CMD_DEBUG_SET_SELECT, 0, 0xf);
-		__mcip_cmd_data(CMD_DEBUG_SET_MASK, 0xf, 0xf);
+		__mcip_cmd_data(CMD_DEBUG_SET_SELECT, 0, mcip_mask);
+		__mcip_cmd_data(CMD_DEBUG_SET_MASK, 0xf, mcip_mask);
 	}
 }
 
arch/arc/kernel/smp.c +26 -4
index efe8b42..ee8b20a 100644
@@ -24,6 +24,8 @@
 #include <linux/reboot.h>
 #include <linux/irqdomain.h>
 #include <linux/export.h>
+#include <linux/of_fdt.h>
+#include <linux/libfdt.h>
 
 #include <asm/processor.h>
 #include <asm/setup.h>
@@ -47,6 +49,29 @@ void __init smp_prepare_boot_cpu(void)
 {
 }
 
+/* Mark cpu as possible if cpu status is "okay" or status absents */
+void __init smp_init_cpumask(void)
+{
+	const struct fdt_property *prop;
+	char fdt_cpu_path[25];
+	unsigned int i, oft;
+
+	for (i = 0; i < NR_CPUS; i++) {
+		sprintf(fdt_cpu_path, "/cpus/cpu@%u", i);
+		oft = fdt_path_offset(initial_boot_params, fdt_cpu_path);
+		prop = fdt_get_property(initial_boot_params, oft, "status", NULL);
+
+		/* No status property == status OK */
+		if (!prop) {
+			set_cpu_possible(i, true);
+			continue;
+		}
+
+		if (!strcmp("okay", prop->data))
+			set_cpu_possible(i, true);
+	}
+}
+
 /*
  * Called from setup_arch() before calling setup_processor()
  *
@@ -58,10 +83,7 @@ void __init smp_prepare_boot_cpu(void)
  */
 void __init smp_init_cpus(void)
 {
-	unsigned int i;
-
-	for (i = 0; i < NR_CPUS; i++)
-		set_cpu_possible(i, true);
+	smp_init_cpumask();
 
 	if (plat_smp_ops.init_early_smp)
 		plat_smp_ops.init_early_smp();
Signature · 1 line
2.9.3
#1 lore raw
Quoted 15 lines · Eugeniy Paltsev

As we have option in u-boot to set CPU mask for running linux, we want to pass information to kernel about CPU cores should be brought up.

So we patch kernel dtb in u-boot to set CPUs status.

On linux boot we setup cpu possible mask according to status field in each cpu node. It is generic method according to ePAPR:
status - a standard property describing the state of a CPU. This property shall be present for nodes representing CPUs in a symmetric multiprocessing (SMP) configuration. For a CPU node the meaning of the "okay" and "disabled" values are as follows:
"okay" - The CPU is running; "disabled" - The CPU is in a quiescent state."

Quoted 1 line

Also we setup MCIP debug mask according cpu possible mask.

Idea seems fine to me- and this MCIP things has been pain for Alexey on and off.

arch/arc/kernel/mcip.c static void mcip_probe_n_setup(void) · line 110

Quoted 10 lines

[snip]

arch/arc/kernel/mcip.c +4 -0
@@ -102,9 +104,13 @@ static void mcip_probe_n_setup(void)
 
  	cpuinfo_arc700[0].extn.gfrc = mp.gfrc;
 
+	for (i = 0; i < NR_CPUS; i++)
+		if (cpu_possible(i))
+			mcip_mask |= BIT(i);
+

Can you use existing helpers from include/linux/cpumask.h ?
They likely also handle the case of NR_CPUS > 32 which our code doesn't (although granted this is unlikely for ARC for now)

Quoted 14 lines

[snip]

arch/arc/kernel/smp.c +12 -0
+/* Mark cpu as possible if cpu status is "okay" or status absents */
+void __init smp_init_cpumask(void)
+{
+	const struct fdt_property *prop;
+	char fdt_cpu_path[25];
+	unsigned int i, oft;
+
+	for (i = 0; i < NR_CPUS; i++) {
+		sprintf(fdt_cpu_path, "/cpus/cpu@%u", i);
+		oft = fdt_path_offset(initial_boot_params, fdt_cpu_path);
+		prop = fdt_get_property(initial_boot_params, oft, "status", NULL);
+

arch/arc/kernel/smp.c void __init smp_prepare_boot_cpu(void) · line 73

Quoted 10 lines
arch/arc/kernel/smp.c +10 -0
+		/* No status property == status OK */
+		if (!prop) {
+			set_cpu_possible(i, true);
+			continue;
+		}
+
+		if (!strcmp("okay", prop->data))
+			set_cpu_possible(i, true);
+	}
+}

So it seems DT / ePar also provides for present-cpus / possible-cpus which is what EZChip folks use (see arch/arc/plat-eznps/smp.c)
It seems that is a better mechanism rather than annotating each CPU node's status (atleast it seems better for 4K CPUs which is what these guys have) If you agree we should pull that code out into here and remove their init_early_smp hook !

-Vineet