Skip to content

Commit f54d443

Browse files
KAGA-KOKOPeter Zijlstra
authored andcommitted
x86/apic: Provide cpu_primary_thread mask
Make the primary thread tracking CPU mask based in preparation for simpler handling of parallel bootup. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Michael Kelley <mikelley@microsoft.com> Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name> Tested-by: Helge Deller <deller@gmx.de> # parisc Tested-by: Guilherme G. Piccoli <gpiccoli@igalia.com> # Steam Deck Link: https://lore.kernel.org/r/20230512205257.186599880@linutronix.de
1 parent 8b5a0f9 commit f54d443

4 files changed

Lines changed: 27 additions & 26 deletions

File tree

arch/x86/include/asm/apic.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,8 @@ extern int default_check_phys_apicid_present(int phys_apicid);
506506
#endif /* CONFIG_X86_LOCAL_APIC */
507507

508508
#ifdef CONFIG_SMP
509-
bool apic_id_is_primary_thread(unsigned int id);
510509
void apic_smt_update(void);
511510
#else
512-
static inline bool apic_id_is_primary_thread(unsigned int id) { return false; }
513511
static inline void apic_smt_update(void) { }
514512
#endif
515513

arch/x86/include/asm/topology.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
* CONFIG_NUMA.
3232
*/
3333
#include <linux/numa.h>
34+
#include <linux/cpumask.h>
3435

3536
#ifdef CONFIG_NUMA
36-
#include <linux/cpumask.h>
3737

3838
#include <asm/mpspec.h>
3939
#include <asm/percpu.h>
@@ -139,9 +139,20 @@ static inline int topology_max_smt_threads(void)
139139
int topology_update_package_map(unsigned int apicid, unsigned int cpu);
140140
int topology_update_die_map(unsigned int dieid, unsigned int cpu);
141141
int topology_phys_to_logical_pkg(unsigned int pkg);
142-
bool topology_is_primary_thread(unsigned int cpu);
143142
bool topology_smt_supported(void);
144-
#else
143+
144+
extern struct cpumask __cpu_primary_thread_mask;
145+
#define cpu_primary_thread_mask ((const struct cpumask *)&__cpu_primary_thread_mask)
146+
147+
/**
148+
* topology_is_primary_thread - Check whether CPU is the primary SMT thread
149+
* @cpu: CPU to check
150+
*/
151+
static inline bool topology_is_primary_thread(unsigned int cpu)
152+
{
153+
return cpumask_test_cpu(cpu, cpu_primary_thread_mask);
154+
}
155+
#else /* CONFIG_SMP */
145156
#define topology_max_packages() (1)
146157
static inline int
147158
topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; }
@@ -152,7 +163,7 @@ static inline int topology_max_die_per_package(void) { return 1; }
152163
static inline int topology_max_smt_threads(void) { return 1; }
153164
static inline bool topology_is_primary_thread(unsigned int cpu) { return true; }
154165
static inline bool topology_smt_supported(void) { return false; }
155-
#endif
166+
#endif /* !CONFIG_SMP */
156167

157168
static inline void arch_fix_phys_package_id(int num, u32 slot)
158169
{

arch/x86/kernel/apic/apic.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,20 +2386,16 @@ bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
23862386
}
23872387

23882388
#ifdef CONFIG_SMP
2389-
/**
2390-
* apic_id_is_primary_thread - Check whether APIC ID belongs to a primary thread
2391-
* @apicid: APIC ID to check
2392-
*/
2393-
bool apic_id_is_primary_thread(unsigned int apicid)
2389+
static void cpu_mark_primary_thread(unsigned int cpu, unsigned int apicid)
23942390
{
2395-
u32 mask;
2396-
2397-
if (smp_num_siblings == 1)
2398-
return true;
23992391
/* Isolate the SMT bit(s) in the APICID and check for 0 */
2400-
mask = (1U << (fls(smp_num_siblings) - 1)) - 1;
2401-
return !(apicid & mask);
2392+
u32 mask = (1U << (fls(smp_num_siblings) - 1)) - 1;
2393+
2394+
if (smp_num_siblings == 1 || !(apicid & mask))
2395+
cpumask_set_cpu(cpu, &__cpu_primary_thread_mask);
24022396
}
2397+
#else
2398+
static inline void cpu_mark_primary_thread(unsigned int cpu, unsigned int apicid) { }
24032399
#endif
24042400

24052401
/*
@@ -2544,6 +2540,8 @@ int generic_processor_info(int apicid, int version)
25442540
set_cpu_present(cpu, true);
25452541
num_processors++;
25462542

2543+
cpu_mark_primary_thread(cpu, apicid);
2544+
25472545
return cpu;
25482546
}
25492547

arch/x86/kernel/smpboot.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ EXPORT_PER_CPU_SYMBOL(cpu_die_map);
102102
DEFINE_PER_CPU_READ_MOSTLY(struct cpuinfo_x86, cpu_info);
103103
EXPORT_PER_CPU_SYMBOL(cpu_info);
104104

105+
/* CPUs which are the primary SMT threads */
106+
struct cpumask __cpu_primary_thread_mask __read_mostly;
107+
105108
/* Representing CPUs for which sibling maps can be computed */
106109
static cpumask_var_t cpu_sibling_setup_mask;
107110

@@ -276,15 +279,6 @@ static void notrace start_secondary(void *unused)
276279
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
277280
}
278281

279-
/**
280-
* topology_is_primary_thread - Check whether CPU is the primary SMT thread
281-
* @cpu: CPU to check
282-
*/
283-
bool topology_is_primary_thread(unsigned int cpu)
284-
{
285-
return apic_id_is_primary_thread(per_cpu(x86_cpu_to_apicid, cpu));
286-
}
287-
288282
/**
289283
* topology_smt_supported - Check whether SMT is supported by the CPUs
290284
*/

0 commit comments

Comments
 (0)