Skip to content

Commit 3825346

Browse files
mpeKAGA-KOKO
authored andcommitted
cpu/SMT: Create topology_smt_thread_allowed()
Some architectures allows partial SMT states, i.e. when not all SMT threads are brought online. To support that, add an architecture helper which checks whether a given CPU is allowed to be brought online depending on how many SMT threads are currently enabled. Since this is only applicable to architecture supporting partial SMT, only these architectures should select the new configuration variable CONFIG_SMT_NUM_THREADS_DYNAMIC. For the other architectures, not supporting the partial SMT states, there is no need to define topology_cpu_smt_allowed(), the generic code assumed that all the threads are allowed or only the primary ones. Call the helper from cpu_smt_enable(), and cpu_smt_allowed() when SMT is enabled, to check if the particular thread should be onlined. Notably, also call it from cpu_smt_disable() if CPU_SMT_ENABLED, to allow offlining some threads to move from a higher to lower number of threads online. [ ldufour: Slightly reword the commit's description ] [ ldufour: Introduce CONFIG_SMT_NUM_THREADS_DYNAMIC ] Suggested-by: Thomas Gleixner <tglx@linutronix.de> 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-7-ldufour@linux.ibm.com
1 parent 91b4a7d commit 3825346

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

arch/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ config ARCH_HAS_SUBPAGE_FAULTS
3434
config HOTPLUG_SMT
3535
bool
3636

37+
config SMT_NUM_THREADS_DYNAMIC
38+
bool
39+
3740
# Selected by HOTPLUG_CORE_SYNC_DEAD or HOTPLUG_CORE_SYNC_FULL
3841
config HOTPLUG_CORE_SYNC
3942
bool

kernel/cpu.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,23 @@ static int __init smt_cmdline_disable(char *str)
645645
}
646646
early_param("nosmt", smt_cmdline_disable);
647647

648+
/*
649+
* For Archicture supporting partial SMT states check if the thread is allowed.
650+
* Otherwise this has already been checked through cpu_smt_max_threads when
651+
* setting the SMT level.
652+
*/
653+
static inline bool cpu_smt_thread_allowed(unsigned int cpu)
654+
{
655+
#ifdef CONFIG_SMT_NUM_THREADS_DYNAMIC
656+
return topology_smt_thread_allowed(cpu);
657+
#else
658+
return true;
659+
#endif
660+
}
661+
648662
static inline bool cpu_smt_allowed(unsigned int cpu)
649663
{
650-
if (cpu_smt_control == CPU_SMT_ENABLED)
664+
if (cpu_smt_control == CPU_SMT_ENABLED && cpu_smt_thread_allowed(cpu))
651665
return true;
652666

653667
if (topology_is_primary_thread(cpu))
@@ -2642,6 +2656,12 @@ int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval)
26422656
for_each_online_cpu(cpu) {
26432657
if (topology_is_primary_thread(cpu))
26442658
continue;
2659+
/*
2660+
* Disable can be called with CPU_SMT_ENABLED when changing
2661+
* from a higher to lower number of SMT threads per core.
2662+
*/
2663+
if (ctrlval == CPU_SMT_ENABLED && cpu_smt_thread_allowed(cpu))
2664+
continue;
26452665
ret = cpu_down_maps_locked(cpu, CPUHP_OFFLINE);
26462666
if (ret)
26472667
break;
@@ -2676,6 +2696,8 @@ int cpuhp_smt_enable(void)
26762696
/* Skip online CPUs and CPUs on offline nodes */
26772697
if (cpu_online(cpu) || !node_online(cpu_to_node(cpu)))
26782698
continue;
2699+
if (!cpu_smt_thread_allowed(cpu))
2700+
continue;
26792701
ret = _cpu_up(cpu, 0, CPUHP_ONLINE);
26802702
if (ret)
26812703
break;

0 commit comments

Comments
 (0)