Skip to content

Commit c52787b

Browse files
balbir-awsKAGA-KOKO
authored andcommitted
x86/smp: Add a per-cpu view of SMT state
A new field smt_active in cpuinfo_x86 identifies if the current core/cpu is in SMT mode or not. This is helpful when the system has some of its cores with threads offlined and can be used for cases where action is taken based on the state of SMT. The upcoming support for paranoid L1D flush will make use of this information. Suggested-by: Thomas Gleixner <[email protected]> Signed-off-by: Balbir Singh <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ff11764 commit c52787b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

arch/x86/include/asm/processor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ struct cpuinfo_x86 {
136136
u16 logical_die_id;
137137
/* Index into per_cpu list: */
138138
u16 cpu_index;
139+
/* Is SMT active on this core? */
140+
bool smt_active;
139141
u32 microcode;
140142
/* Address space bits used by the cache internally */
141143
u8 x86_cache_bits;

arch/x86/kernel/smpboot.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@ void set_cpu_sibling_map(int cpu)
610610
if (threads > __max_smt_threads)
611611
__max_smt_threads = threads;
612612

613+
for_each_cpu(i, topology_sibling_cpumask(cpu))
614+
cpu_data(i).smt_active = threads > 1;
615+
613616
/*
614617
* This needs a separate iteration over the cpus because we rely on all
615618
* topology_sibling_cpumask links to be set-up.
@@ -1552,8 +1555,13 @@ static void remove_siblinginfo(int cpu)
15521555

15531556
for_each_cpu(sibling, topology_die_cpumask(cpu))
15541557
cpumask_clear_cpu(cpu, topology_die_cpumask(sibling));
1555-
for_each_cpu(sibling, topology_sibling_cpumask(cpu))
1558+
1559+
for_each_cpu(sibling, topology_sibling_cpumask(cpu)) {
15561560
cpumask_clear_cpu(cpu, topology_sibling_cpumask(sibling));
1561+
if (cpumask_weight(topology_sibling_cpumask(sibling)) == 1)
1562+
cpu_data(sibling).smt_active = false;
1563+
}
1564+
15571565
for_each_cpu(sibling, cpu_llc_shared_mask(cpu))
15581566
cpumask_clear_cpu(cpu, cpu_llc_shared_mask(sibling));
15591567
cpumask_clear(cpu_llc_shared_mask(cpu));

0 commit comments

Comments
 (0)