[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1627953123-24248-2-git-send-email-guoren@kernel.org>
Date: Tue, 3 Aug 2021 09:12:03 +0800
From: guoren@...nel.org
To: anup.patel@....com, atish.patra@....com, palmerdabbelt@...gle.com,
tglx@...utronix.de, maz@...nel.org, guoren@...nel.org
Cc: linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org,
Guo Ren <guoren@...ux.alibaba.com>
Subject: [PATCH 2/2] riscv: Improve status in cpu sections of device-tree for cpuhotplug usage
From: Guo Ren <guoren@...ux.alibaba.com>
If we define cpu sections with first okay & second fail:
cpus {
#address-cells = <1>;
#size-cells = <0>;
timebase-frequency = <3000000>;
cpu@0 {
device_type = "cpu";
reg = <0>;
status = "okay";
...
};
cpu@1 {
device_type = "cpu";
reg = <1>;
status = "fail";
...
};
};
Currently, we only get cpu0 without cpu1 in the shell:
$ ls /sys/bus/cpu/devices/
cpu0
But it should be cpu0 online and cpu1 offline, then we could let
cpu1 online later by shell. This patch fixup the problem and let
us could make cpu1 online in the shell later after system boot:
$ ls /sys/bus/cpu/devices/
cpu0 cpu1
$ cat /sys/bus/cpu/devices/cpu0/online
1
$ cat /sys/bus/cpu/devices/cpu1/online
0
$ echo 224 > /sys/bus/cpu/devices/cpu1/hotplug/target
(cat /sys/devices/system/cpu/hotplug/states "224: online")
$ cat /sys/bus/cpu/devices/cpu1/online
1
Signed-off-by: Guo Ren <guoren@...ux.alibaba.com>
Cc: Anup Patel <anup.patel@....com>
Cc: Atish Patra <atish.patra@....com>
Cc: Palmer Dabbelt <palmerdabbelt@...gle.com>
---
arch/riscv/kernel/cpu.c | 5 -----
arch/riscv/kernel/smpboot.c | 11 +++++++++++
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c
index 6d59e69..14f63fd 100644
--- a/arch/riscv/kernel/cpu.c
+++ b/arch/riscv/kernel/cpu.c
@@ -27,11 +27,6 @@ int riscv_of_processor_hartid(struct device_node *node)
return -ENODEV;
}
- if (!of_device_is_available(node)) {
- pr_info("CPU with hartid=%d is not available\n", hart);
- return -ENODEV;
- }
-
if (of_property_read_string(node, "riscv,isa", &isa)) {
pr_warn("CPU with hartid=%d has no \"riscv,isa\" property\n", hart);
return -ENODEV;
diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
index bd82375..c3b620b 100644
--- a/arch/riscv/kernel/smpboot.c
+++ b/arch/riscv/kernel/smpboot.c
@@ -37,6 +37,7 @@
#include "head.h"
static DECLARE_COMPLETION(cpu_running);
+static struct cpumask cpu_delay_available_mask = { CPU_BITS_NONE };
void __init smp_prepare_boot_cpu(void)
{
@@ -99,6 +100,11 @@ void __init setup_smp(void)
break;
}
+ if (!of_device_is_available(dn))
+ pr_info("CPU with hartid=%d is not available\n", hart);
+ else
+ cpumask_set_cpu(cpuid, &cpu_delay_available_mask);
+
cpuid_to_hartid_map(cpuid) = hart;
early_map_cpu_to_node(cpuid, of_node_to_nid(dn));
cpuid++;
@@ -131,6 +137,11 @@ int __cpu_up(unsigned int cpu, struct task_struct *tidle)
int ret = 0;
tidle->thread_info.cpu = cpu;
+ if (!cpumask_test_cpu(cpu, &cpu_delay_available_mask)) {
+ cpumask_set_cpu(cpu, &cpu_delay_available_mask);
+ return -EIO;
+ }
+
ret = start_secondary_cpu(cpu, tidle);
if (!ret) {
wait_for_completion_timeout(&cpu_running,
--
2.7.4
Powered by blists - more mailing lists