Skip to content

Commit 6c17ea1

Browse files
Nysal Jan K.Ampe
authored andcommitted
cpu/SMT: Enable SMT only if a core is online
If a core is offline then enabling SMT should not online CPUs of this core. By enabling SMT, what is intended is either changing the SMT value from "off" to "on" or setting the SMT level (threads per core) from a lower to higher value. On PowerPC the ppc64_cpu utility can be used, among other things, to perform the following functions: ppc64_cpu --cores-on # Get the number of online cores ppc64_cpu --cores-on=X # Put exactly X cores online ppc64_cpu --offline-cores=X[,Y,...] # Put specified cores offline ppc64_cpu --smt={on|off|value} # Enable, disable or change SMT level If the user has decided to offline certain cores, enabling SMT should not online CPUs in those cores. This patch fixes the issue and changes the behaviour as described, by introducing an arch specific function topology_is_core_online(). It is currently implemented only for PowerPC. Fixes: 73c58e7 ("powerpc: Add HOTPLUG_SMT support") Reported-by: Tyrel Datwyler <tyreld@linux.ibm.com> Closes: https://groups.google.com/g/powerpc-utils-devel/c/wrwVzAAnRlI/m/5KJSoqP4BAAJ Signed-off-by: Nysal Jan K.A <nysal@linux.ibm.com> Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20240731030126.956210-2-nysal@linux.ibm.com
1 parent e7e846d commit 6c17ea1

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Documentation/ABI/testing/sysfs-devices-system-cpu

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ Description: Control Symmetric Multi Threading (SMT)
562562
================ =========================================
563563

564564
If control status is "forceoff" or "notsupported" writes
565-
are rejected.
565+
are rejected. Note that enabling SMT on PowerPC skips
566+
offline cores.
566567

567568
What: /sys/devices/system/cpu/cpuX/power/energy_perf_bias
568569
Date: March 2019

kernel/cpu.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,16 @@ int cpuhp_smt_disable(enum cpuhp_smt_control ctrlval)
26892689
return ret;
26902690
}
26912691

2692+
/**
2693+
* Check if the core a CPU belongs to is online
2694+
*/
2695+
#if !defined(topology_is_core_online)
2696+
static inline bool topology_is_core_online(unsigned int cpu)
2697+
{
2698+
return true;
2699+
}
2700+
#endif
2701+
26922702
int cpuhp_smt_enable(void)
26932703
{
26942704
int cpu, ret = 0;
@@ -2699,7 +2709,7 @@ int cpuhp_smt_enable(void)
26992709
/* Skip online CPUs and CPUs on offline nodes */
27002710
if (cpu_online(cpu) || !node_online(cpu_to_node(cpu)))
27012711
continue;
2702-
if (!cpu_smt_thread_allowed(cpu))
2712+
if (!cpu_smt_thread_allowed(cpu) || !topology_is_core_online(cpu))
27032713
continue;
27042714
ret = _cpu_up(cpu, 0, CPUHP_ONLINE);
27052715
if (ret)

0 commit comments

Comments
 (0)