mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2025-01-27 01:39:20 +07: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>
90 lines
2.0 KiB
C
90 lines
2.0 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright (C) 2012 Regents of the University of California
|
|
*/
|
|
|
|
#ifndef _ASM_RISCV_SMP_H
|
|
#define _ASM_RISCV_SMP_H
|
|
|
|
#include <linux/cpumask.h>
|
|
#include <linux/irqreturn.h>
|
|
#include <linux/thread_info.h>
|
|
|
|
#define INVALID_HARTID ULONG_MAX
|
|
|
|
struct seq_file;
|
|
extern unsigned long boot_cpu_hartid;
|
|
|
|
#ifdef CONFIG_SMP
|
|
/*
|
|
* Mapping between linux logical cpu index and hartid.
|
|
*/
|
|
extern unsigned long __cpuid_to_hartid_map[NR_CPUS];
|
|
#define cpuid_to_hartid_map(cpu) __cpuid_to_hartid_map[cpu]
|
|
|
|
/* print IPI stats */
|
|
void show_ipi_stats(struct seq_file *p, int prec);
|
|
|
|
/* SMP initialization hook for setup_arch */
|
|
void __init setup_smp(void);
|
|
|
|
/* Hook for the generic smp_call_function_many() routine. */
|
|
void arch_send_call_function_ipi_mask(struct cpumask *mask);
|
|
|
|
/* Hook for the generic smp_call_function_single() routine. */
|
|
void arch_send_call_function_single_ipi(int cpu);
|
|
|
|
int riscv_hartid_to_cpuid(int hartid);
|
|
void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
|
|
|
|
/*
|
|
* Obtains the hart ID of the currently executing task. This relies on
|
|
* THREAD_INFO_IN_TASK, but we define that unconditionally.
|
|
*/
|
|
#define raw_smp_processor_id() (current_thread_info()->cpu)
|
|
|
|
#if defined CONFIG_HOTPLUG_CPU
|
|
int __cpu_disable(void);
|
|
void __cpu_die(unsigned int cpu);
|
|
void cpu_stop(void);
|
|
#else
|
|
#endif /* CONFIG_HOTPLUG_CPU */
|
|
|
|
#else
|
|
|
|
static inline void show_ipi_stats(struct seq_file *p, int prec)
|
|
{
|
|
}
|
|
|
|
static inline int riscv_hartid_to_cpuid(int hartid)
|
|
{
|
|
if (hartid == boot_cpu_hartid)
|
|
return 0;
|
|
|
|
return -1;
|
|
}
|
|
static inline unsigned long cpuid_to_hartid_map(int cpu)
|
|
{
|
|
return boot_cpu_hartid;
|
|
}
|
|
|
|
static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,
|
|
struct cpumask *out)
|
|
{
|
|
cpumask_clear(out);
|
|
cpumask_set_cpu(boot_cpu_hartid, out);
|
|
}
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
#if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
|
|
bool cpu_has_hotplug(unsigned int cpu);
|
|
#else
|
|
static inline bool cpu_has_hotplug(unsigned int cpu)
|
|
{
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
#endif /* _ASM_RISCV_SMP_H */
|