Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <tglx@linutronix.de>
Signed-off-by: Balbir Singh <sblbir@amazon.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20210108121056.21940-2-sblbir@amazon.com

authored by

Balbir Singh and committed by
Thomas Gleixner
c52787b5 ff117646

+11 -1
+2
arch/x86/include/asm/processor.h
··· 136 136 u16 logical_die_id; 137 137 /* Index into per_cpu list: */ 138 138 u16 cpu_index; 139 + /* Is SMT active on this core? */ 140 + bool smt_active; 139 141 u32 microcode; 140 142 /* Address space bits used by the cache internally */ 141 143 u8 x86_cache_bits;
+9 -1
arch/x86/kernel/smpboot.c
··· 610 610 if (threads > __max_smt_threads) 611 611 __max_smt_threads = threads; 612 612 613 + for_each_cpu(i, topology_sibling_cpumask(cpu)) 614 + cpu_data(i).smt_active = threads > 1; 615 + 613 616 /* 614 617 * This needs a separate iteration over the cpus because we rely on all 615 618 * topology_sibling_cpumask links to be set-up. ··· 1555 1552 1556 1553 for_each_cpu(sibling, topology_die_cpumask(cpu)) 1557 1554 cpumask_clear_cpu(cpu, topology_die_cpumask(sibling)); 1558 - for_each_cpu(sibling, topology_sibling_cpumask(cpu)) 1555 + 1556 + for_each_cpu(sibling, topology_sibling_cpumask(cpu)) { 1559 1557 cpumask_clear_cpu(cpu, topology_sibling_cpumask(sibling)); 1558 + if (cpumask_weight(topology_sibling_cpumask(sibling)) == 1) 1559 + cpu_data(sibling).smt_active = false; 1560 + } 1561 + 1560 1562 for_each_cpu(sibling, cpu_llc_shared_mask(cpu)) 1561 1563 cpumask_clear_cpu(cpu, cpu_llc_shared_mask(sibling)); 1562 1564 cpumask_clear(cpu_llc_shared_mask(cpu));