mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 00:04:15 +08:00
f1e58583b9
This patch enable support for cpu hotplug in RISC-V. It uses SBI HSM extension to online/offline any hart. As a result, the harts are returned to firmware once they are offline. If the harts are brought online afterwards, they re-enter Linux kernel as if a secondary hart booted for the first time. All booting requirements are honored during this process. Tested both on QEMU and HighFive Unleashed board with. Test result follows. --------------------------------------------------- Offline cpu 2 --------------------------------------------------- $ echo 0 > /sys/devices/system/cpu/cpu2/online [ 32.828684] CPU2: off $ cat /proc/cpuinfo processor : 0 hart : 0 isa : rv64imafdcsu mmu : sv48 processor : 1 hart : 1 isa : rv64imafdcsu mmu : sv48 processor : 3 hart : 3 isa : rv64imafdcsu mmu : sv48 processor : 4 hart : 4 isa : rv64imafdcsu mmu : sv48 processor : 5 hart : 5 isa : rv64imafdcsu mmu : sv48 processor : 6 hart : 6 isa : rv64imafdcsu mmu : sv48 processor : 7 hart : 7 isa : rv64imafdcsu mmu : sv48 --------------------------------------------------- online cpu 2 --------------------------------------------------- $ echo 1 > /sys/devices/system/cpu/cpu2/online $ cat /proc/cpuinfo processor : 0 hart : 0 isa : rv64imafdcsu mmu : sv48 processor : 1 hart : 1 isa : rv64imafdcsu mmu : sv48 processor : 2 hart : 2 isa : rv64imafdcsu mmu : sv48 processor : 3 hart : 3 isa : rv64imafdcsu mmu : sv48 processor : 4 hart : 4 isa : rv64imafdcsu mmu : sv48 processor : 5 hart : 5 isa : rv64imafdcsu mmu : sv48 processor : 6 hart : 6 isa : rv64imafdcsu mmu : sv48 processor : 7 hart : 7 isa : rv64imafdcsu mmu : sv48 Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
88 lines
1.6 KiB
C
88 lines
1.6 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (C) 2020 Western Digital Corporation or its affiliates.
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/err.h>
|
|
#include <linux/irq.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/sched/hotplug.h>
|
|
#include <asm/irq.h>
|
|
#include <asm/cpu_ops.h>
|
|
#include <asm/sbi.h>
|
|
|
|
void cpu_stop(void);
|
|
void arch_cpu_idle_dead(void)
|
|
{
|
|
cpu_stop();
|
|
}
|
|
|
|
bool cpu_has_hotplug(unsigned int cpu)
|
|
{
|
|
if (cpu_ops[cpu]->cpu_stop)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
/*
|
|
* __cpu_disable runs on the processor to be shutdown.
|
|
*/
|
|
int __cpu_disable(void)
|
|
{
|
|
int ret = 0;
|
|
unsigned int cpu = smp_processor_id();
|
|
|
|
if (!cpu_ops[cpu] || !cpu_ops[cpu]->cpu_stop)
|
|
return -EOPNOTSUPP;
|
|
|
|
if (cpu_ops[cpu]->cpu_disable)
|
|
ret = cpu_ops[cpu]->cpu_disable(cpu);
|
|
|
|
if (ret)
|
|
return ret;
|
|
|
|
remove_cpu_topology(cpu);
|
|
set_cpu_online(cpu, false);
|
|
irq_migrate_all_off_this_cpu();
|
|
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Called on the thread which is asking for a CPU to be shutdown.
|
|
*/
|
|
void __cpu_die(unsigned int cpu)
|
|
{
|
|
int ret = 0;
|
|
|
|
if (!cpu_wait_death(cpu, 5)) {
|
|
pr_err("CPU %u: didn't die\n", cpu);
|
|
return;
|
|
}
|
|
pr_notice("CPU%u: off\n", cpu);
|
|
|
|
/* Verify from the firmware if the cpu is really stopped*/
|
|
if (cpu_ops[cpu]->cpu_is_stopped)
|
|
ret = cpu_ops[cpu]->cpu_is_stopped(cpu);
|
|
if (ret)
|
|
pr_warn("CPU%d may not have stopped: %d\n", cpu, ret);
|
|
}
|
|
|
|
/*
|
|
* Called from the idle thread for the CPU which has been shutdown.
|
|
*/
|
|
void cpu_stop(void)
|
|
{
|
|
idle_task_exit();
|
|
|
|
(void)cpu_report_death();
|
|
|
|
cpu_ops[smp_processor_id()]->cpu_stop();
|
|
/* It should never reach here */
|
|
BUG();
|
|
}
|