Skip to content

Commit ed44a56

Browse files
ChangSeokBaebp3tk0v
authored andcommitted
x86/cpu/topology: Make primary thread mask available with SMP=n
cpu_primary_thread_mask is only defined when CONFIG_SMP=y. However, even in UP kernels there is always exactly one CPU, which can reasonably be treated as the primary thread. Historically, topology_is_primary_thread() always returned true with CONFIG_SMP=n. A recent commit: 4b455f5 ("cpu/SMT: Provide a default topology_is_primary_thread()") replaced it with a generic implementation with the note: "When disabling SMT, the primary thread of the SMT will remain enabled/active. Architectures that have a special primary thread (e.g. x86) need to override this function. ..." For consistency and clarity, make the primary thread mask available regardless of SMP, similar to cpu_possible_mask and cpu_present_mask. Move __cpu_primary_thread_mask into common code to prevent build issues. Let cpu_mark_primary_thread() configure the mask even for UP kernels, alongside other masks. Then, topology_is_primary_thread() can consistently reference it. Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Tony Luck <tony.luck@intel.com> Link: https://lore.kernel.org/r/20250320234104.8288-1-chang.seok.bae@intel.com
1 parent 3a86608 commit ed44a56

4 files changed

Lines changed: 9 additions & 13 deletions

File tree

arch/x86/include/asm/topology.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ static inline unsigned int topology_amd_nodes_per_pkg(void)
218218
return __amd_nodes_per_pkg;
219219
}
220220

221+
#else /* CONFIG_SMP */
222+
static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
223+
static inline int topology_max_smt_threads(void) { return 1; }
224+
static inline unsigned int topology_amd_nodes_per_pkg(void) { return 1; }
225+
#endif /* !CONFIG_SMP */
226+
221227
extern struct cpumask __cpu_primary_thread_mask;
222228
#define cpu_primary_thread_mask ((const struct cpumask *)&__cpu_primary_thread_mask)
223229

@@ -241,12 +247,6 @@ static inline bool topology_is_core_online(unsigned int cpu)
241247
}
242248
#define topology_is_core_online topology_is_core_online
243249

244-
#else /* CONFIG_SMP */
245-
static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
246-
static inline int topology_max_smt_threads(void) { return 1; }
247-
static inline unsigned int topology_amd_nodes_per_pkg(void) { return 1; }
248-
#endif /* !CONFIG_SMP */
249-
250250
static inline void arch_fix_phys_package_id(int num, u32 slot)
251251
{
252252
}

arch/x86/kernel/cpu/topology.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,11 @@ bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
7575
return phys_id == (u64)cpuid_to_apicid[cpu];
7676
}
7777

78-
#ifdef CONFIG_SMP
7978
static void cpu_mark_primary_thread(unsigned int cpu, unsigned int apicid)
8079
{
8180
if (!(apicid & (__max_threads_per_core - 1)))
8281
cpumask_set_cpu(cpu, &__cpu_primary_thread_mask);
8382
}
84-
#else
85-
static inline void cpu_mark_primary_thread(unsigned int cpu, unsigned int apicid) { }
86-
#endif
8783

8884
/*
8985
* Convert the APIC ID to a domain level ID by masking out the low bits

arch/x86/kernel/cpu/topology_common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ EXPORT_SYMBOL_GPL(x86_topo_system);
1616
unsigned int __amd_nodes_per_pkg __ro_after_init;
1717
EXPORT_SYMBOL_GPL(__amd_nodes_per_pkg);
1818

19+
/* CPUs which are the primary SMT threads */
20+
struct cpumask __cpu_primary_thread_mask __read_mostly;
21+
1922
void topology_set_dom(struct topo_scan *tscan, enum x86_topology_domains dom,
2023
unsigned int shift, unsigned int ncpus)
2124
{

arch/x86/kernel/smpboot.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ EXPORT_PER_CPU_SYMBOL(cpu_core_map);
103103
DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);
104104
EXPORT_PER_CPU_SYMBOL(cpu_die_map);
105105

106-
/* CPUs which are the primary SMT threads */
107-
struct cpumask __cpu_primary_thread_mask __read_mostly;
108-
109106
/* Representing CPUs for which sibling maps can be computed */
110107
static cpumask_var_t cpu_sibling_setup_mask;
111108

0 commit comments

Comments
 (0)