Skip to content

Commit 4b455f5

Browse files
Yicong Yangctmarinas
authored andcommitted
cpu/SMT: Provide a default topology_is_primary_thread()
Currently if architectures want to support HOTPLUG_SMT they need to provide a topology_is_primary_thread() telling the framework which thread in the SMT cannot offline. However arm64 doesn't have a restriction on which thread in the SMT cannot offline, a simplest choice is that just make 1st thread as the "primary" thread. So just make this as the default implementation in the framework and let architectures like x86 that have special primary thread to override this function (which they've already done). There's no need to provide a stub function if !CONFIG_SMP or !CONFIG_HOTPLUG_SMT. In such case the testing CPU is already the 1st CPU in the SMT so it's always the primary thread. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Pierre Gondois <pierre.gondois@arm.com> Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> Link: https://lore.kernel.org/r/20250311075143.61078-2-yangyicong@huawei.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 0ad2507 commit 4b455f5

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

arch/powerpc/include/asm/topology.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ static inline bool topology_is_primary_thread(unsigned int cpu)
152152
{
153153
return cpu == cpu_first_thread_sibling(cpu);
154154
}
155+
#define topology_is_primary_thread topology_is_primary_thread
155156

156157
static inline bool topology_smt_thread_allowed(unsigned int cpu)
157158
{

arch/x86/include/asm/topology.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ static inline bool topology_is_primary_thread(unsigned int cpu)
229229
{
230230
return cpumask_test_cpu(cpu, cpu_primary_thread_mask);
231231
}
232+
#define topology_is_primary_thread topology_is_primary_thread
232233

233234
#else /* CONFIG_SMP */
234235
static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
235236
static inline int topology_max_smt_threads(void) { return 1; }
236-
static inline bool topology_is_primary_thread(unsigned int cpu) { return true; }
237237
static inline unsigned int topology_amd_nodes_per_pkg(void) { return 1; }
238238
#endif /* !CONFIG_SMP */
239239

include/linux/topology.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,29 @@ static inline const struct cpumask *cpu_smt_mask(int cpu)
240240
}
241241
#endif
242242

243+
#ifndef topology_is_primary_thread
244+
245+
static inline bool topology_is_primary_thread(unsigned int cpu)
246+
{
247+
/*
248+
* When disabling SMT, the primary thread of the SMT will remain
249+
* enabled/active. Architectures that have a special primary thread
250+
* (e.g. x86) need to override this function. Otherwise the first
251+
* thread in the SMT can be made the primary thread.
252+
*
253+
* The sibling cpumask of an offline CPU always contains the CPU
254+
* itself on architectures using the implementation of
255+
* CONFIG_GENERIC_ARCH_TOPOLOGY for building their topology.
256+
* Other architectures not using CONFIG_GENERIC_ARCH_TOPOLOGY for
257+
* building their topology have to check whether to use this default
258+
* implementation or to override it.
259+
*/
260+
return cpu == cpumask_first(topology_sibling_cpumask(cpu));
261+
}
262+
#define topology_is_primary_thread topology_is_primary_thread
263+
264+
#endif
265+
243266
static inline const struct cpumask *cpu_cpu_mask(int cpu)
244267
{
245268
return cpumask_of_node(cpu_to_node(cpu));

0 commit comments

Comments
 (0)