Skip to content

Commit 447ae4a

Browse files
mpeKAGA-KOKO
authored andcommitted
cpu/SMT: Store the current/max number of threads
Some architectures allow partial SMT states at boot time, ie. when not all SMT threads are brought online. To support that the SMT code needs to know the maximum number of SMT threads, and also the currently configured number. The architecture code knows the max number of threads, so have the architecture code pass that value to cpu_smt_set_num_threads(). Note that although topology_max_smt_threads() exists, it is not configured early enough to be used here. As architecture, like PowerPC, allows the threads number to be set through the kernel command line, also pass that value. [ ldufour: Slightly reword the commit message ] [ ldufour: Rename cpu_smt_check_topology and add a num_threads argument ] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Laurent Dufour <ldufour@linux.ibm.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Zhang Rui <rui.zhang@intel.com> Link: https://lore.kernel.org/r/20230705145143.40545-5-ldufour@linux.ibm.com
1 parent c53361c commit 447ae4a

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

arch/x86/kernel/cpu/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2317,7 +2317,7 @@ void __init arch_cpu_finalize_init(void)
23172317
* identify_boot_cpu() initialized SMT support information, let the
23182318
* core code know.
23192319
*/
2320-
cpu_smt_check_topology();
2320+
cpu_smt_set_num_threads(smp_num_siblings, smp_num_siblings);
23212321

23222322
if (!IS_ENABLED(CONFIG_SMP)) {
23232323
pr_info("CPU: ");

include/linux/cpu_smt.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ enum cpuhp_smt_control {
1212

1313
#if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT)
1414
extern enum cpuhp_smt_control cpu_smt_control;
15+
extern unsigned int cpu_smt_num_threads;
1516
extern void cpu_smt_disable(bool force);
16-
extern void cpu_smt_check_topology(void);
17+
extern void cpu_smt_set_num_threads(unsigned int num_threads,
18+
unsigned int max_threads);
1719
extern bool cpu_smt_possible(void);
1820
extern int cpuhp_smt_enable(void);
1921
extern int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval);
2022
#else
2123
# define cpu_smt_control (CPU_SMT_NOT_IMPLEMENTED)
24+
# define cpu_smt_num_threads 1
2225
static inline void cpu_smt_disable(bool force) { }
23-
static inline void cpu_smt_check_topology(void) { }
26+
static inline void cpu_smt_set_num_threads(unsigned int num_threads,
27+
unsigned int max_threads) { }
2428
static inline bool cpu_smt_possible(void) { return false; }
2529
static inline int cpuhp_smt_enable(void) { return 0; }
2630
static inline int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval) { return 0; }

kernel/cpu.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ void __weak arch_smt_update(void) { }
594594
#ifdef CONFIG_HOTPLUG_SMT
595595

596596
enum cpuhp_smt_control cpu_smt_control __read_mostly = CPU_SMT_ENABLED;
597+
static unsigned int cpu_smt_max_threads __ro_after_init;
598+
unsigned int cpu_smt_num_threads __read_mostly = UINT_MAX;
597599

598600
void __init cpu_smt_disable(bool force)
599601
{
@@ -607,16 +609,33 @@ void __init cpu_smt_disable(bool force)
607609
pr_info("SMT: disabled\n");
608610
cpu_smt_control = CPU_SMT_DISABLED;
609611
}
612+
cpu_smt_num_threads = 1;
610613
}
611614

612615
/*
613616
* The decision whether SMT is supported can only be done after the full
614617
* CPU identification. Called from architecture code.
615618
*/
616-
void __init cpu_smt_check_topology(void)
619+
void __init cpu_smt_set_num_threads(unsigned int num_threads,
620+
unsigned int max_threads)
617621
{
622+
WARN_ON(!num_threads || (num_threads > max_threads));
623+
618624
if (!topology_smt_supported())
619625
cpu_smt_control = CPU_SMT_NOT_SUPPORTED;
626+
627+
cpu_smt_max_threads = max_threads;
628+
629+
/*
630+
* If SMT has been disabled via the kernel command line or SMT is
631+
* not supported, set cpu_smt_num_threads to 1 for consistency.
632+
* If enabled, take the architecture requested number of threads
633+
* to bring up into account.
634+
*/
635+
if (cpu_smt_control != CPU_SMT_ENABLED)
636+
cpu_smt_num_threads = 1;
637+
else if (num_threads < cpu_smt_num_threads)
638+
cpu_smt_num_threads = num_threads;
620639
}
621640

622641
static int __init smt_cmdline_disable(char *str)

0 commit comments

Comments
 (0)