From 682e7d78fb98d6298926e88e5093e2172488ea6f Mon Sep 17 00:00:00 2001 From: Laurent Dufour Date: Thu, 1 Jun 2023 18:02:55 +0200 Subject: [PATCH] Consider the SMT level specify at boot time This allows PPC kernel to boot with a SMT level different from 1 or threads per core value. Signed-off-by: Laurent Dufour --- arch/powerpc/kernel/smp.c | 2 +- include/linux/cpu_smt.h | 6 ++++-- kernel/cpu.c | 9 +++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c index eed20b9253b7..ec8ccf3d6294 100644 --- a/arch/powerpc/kernel/smp.c +++ b/arch/powerpc/kernel/smp.c @@ -1156,7 +1156,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus) smp_ops->probe(); // Initalise the generic SMT topology support - cpu_smt_check_topology(threads_per_core); + cpu_smt_check_topology(smt_enabled_at_boot, threads_per_core); } void smp_prepare_boot_cpu(void) diff --git a/include/linux/cpu_smt.h b/include/linux/cpu_smt.h index 8d4ae26047c9..b5f13acb323f 100644 --- a/include/linux/cpu_smt.h +++ b/include/linux/cpu_smt.h @@ -14,7 +14,8 @@ enum cpuhp_smt_control { extern enum cpuhp_smt_control cpu_smt_control; extern unsigned int cpu_smt_num_threads; extern void cpu_smt_disable(bool force); -extern void cpu_smt_check_topology(unsigned int num_threads); +extern void cpu_smt_check_topology(unsigned int num_threads, + unsigned int max_threads); extern bool cpu_smt_possible(void); extern int cpuhp_smt_enable(void); extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval); @@ -22,7 +23,8 @@ extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval); # define cpu_smt_control (CPU_SMT_NOT_IMPLEMENTED) # define cpu_smt_num_threads 1 static inline void cpu_smt_disable(bool force) { } -static inline void cpu_smt_check_topology(unsigned int num_threads) { } +static inline void cpu_smt_check_topology(unsigned int num_threads, + unsigned int max_threads) { } static inline bool cpu_smt_possible(void) { return false; } static inline int cpuhp_smt_enable(void) { return 0; } static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; } diff --git a/kernel/cpu.c b/kernel/cpu.c index aca23c7b4547..268d386bd4e7 100644 --- a/kernel/cpu.c +++ b/kernel/cpu.c @@ -435,12 +435,17 @@ void __init cpu_smt_disable(bool force) * The decision whether SMT is supported can only be done after the full * CPU identification. Called from architecture code. */ -void __init cpu_smt_check_topology(unsigned int num_threads) +void __init cpu_smt_check_topology(unsigned int num_threads, + unsigned int max_threads) { if (!topology_smt_supported()) cpu_smt_control = CPU_SMT_NOT_SUPPORTED; - cpu_smt_max_threads = num_threads; + cpu_smt_max_threads = max_threads; + + WARN_ON(num_threads > max_threads); + if (num_threads > max_threads) + num_threads = max_threads; // May already be disabled by nosmt command line parameter if (cpu_smt_control != CPU_SMT_ENABLED) -- 2.40.1