Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1395459

[PATCH 01/10] x86: Add topology_max_smt_threads()

From Andi Kleen <andi@firstfloor.org>
Newsgroups linux.kernel
Subject [PATCH 01/10] x86: Add topology_max_smt_threads()
Date 2016-05-06 01:10 +0200
Message-ID <rvAz7-1bh-3@gated-at.bofh.it> (permalink)
References <rvAz7-1bh-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Andi Kleen <ak@linux.intel.com>

For SMT specific workarounds it is useful to know if SMT is active
on any online CPU in the system. This currently requires a loop
over all online CPUs.

Add a global variable that is updated with the maximum number
of smt threads on any CPU on online/offline, and use it for
topology_max_smt_threads()

The single call is easier to use than a loop.

Not exported to user space because user space already can use
the existing sibling interfaces to find this out.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 arch/x86/include/asm/topology.h |  5 +++++
 arch/x86/kernel/smpboot.c       | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h
index 7f991bd5031b..4707555f209e 100644
--- a/arch/x86/include/asm/topology.h
+++ b/arch/x86/include/asm/topology.h
@@ -129,6 +129,10 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);
 
 extern unsigned int __max_logical_packages;
 #define topology_max_packages()			(__max_logical_packages)
+
+extern int max_smt_threads;
+#define topology_max_smt_threads()		max_smt_threads
+
 int topology_update_package_map(unsigned int apicid, unsigned int cpu);
 extern int topology_phys_to_logical_pkg(unsigned int pkg);
 #else
@@ -136,6 +140,7 @@ extern int topology_phys_to_logical_pkg(unsigned int pkg);
 static inline int
 topology_update_package_map(unsigned int apicid, unsigned int cpu) { return 0; }
 static inline int topology_phys_to_logical_pkg(unsigned int pkg) { return 0; }
+#define topology_max_smt_threads()		1
 #endif
 
 static inline void arch_fix_phys_package_id(int num, u32 slot)
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index a2065d3b3b39..6e5a721857f5 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -105,6 +105,9 @@ static unsigned int max_physical_pkg_id __read_mostly;
 unsigned int __max_logical_packages __read_mostly;
 EXPORT_SYMBOL(__max_logical_packages);
 
+/* Maximum number of SMT threads on any online core */
+int max_smt_threads __read_mostly;
+
 static inline void smpboot_setup_warm_reset_vector(unsigned long start_eip)
 {
 	unsigned long flags;
@@ -489,6 +492,7 @@ void set_cpu_sibling_map(int cpu)
 	struct cpuinfo_x86 *c = &cpu_data(cpu);
 	struct cpuinfo_x86 *o;
 	int i;
+	int threads;
 
 	cpumask_set_cpu(cpu, cpu_sibling_setup_mask);
 
@@ -545,6 +549,10 @@ void set_cpu_sibling_map(int cpu)
 		if (match_die(c, o) && !topology_same_node(c, o))
 			primarily_use_numa_for_topology();
 	}
+
+	threads = cpumask_weight(topology_sibling_cpumask(cpu));
+	if (threads > max_smt_threads)
+		max_smt_threads = threads;
 }
 
 /* maps the cpu to the sched domain representing multi-core */
@@ -1436,6 +1444,21 @@ __init void prefill_possible_map(void)
 
 #ifdef CONFIG_HOTPLUG_CPU
 
+/* Recompute SMT state for all CPUs on offline */
+static void recompute_smt_state(void)
+{
+	int max_threads;
+	int cpu;
+
+	max_threads = 0;
+	for_each_online_cpu (cpu) {
+		int threads = cpumask_weight(topology_sibling_cpumask(cpu));
+		if (threads > max_threads)
+			max_threads = threads;
+	}
+	max_smt_threads = max_threads;
+}
+
 static void remove_siblinginfo(int cpu)
 {
 	int sibling;
@@ -1460,6 +1483,7 @@ static void remove_siblinginfo(int cpu)
 	c->phys_proc_id = 0;
 	c->cpu_core_id = 0;
 	cpumask_clear_cpu(cpu, cpu_sibling_setup_mask);
+	recompute_smt_state();
 }
 
 static void remove_cpu_from_maps(int cpu)
-- 
2.5.5

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH 01/10] x86: Add topology_max_smt_threads() Andi Kleen <andi@firstfloor.org> - 2016-05-06 01:10 +0200
  Re: [PATCH 01/10] x86: Add topology_max_smt_threads() Peter Zijlstra <peterz@infradead.org> - 2016-05-06 12:20 +0200
    Re: [PATCH 01/10] x86: Add topology_max_smt_threads() Thomas Gleixner <tglx@linutronix.de> - 2016-05-06 12:50 +0200
      [UPDATED PATCH 01/10] x86: Add topology_max_smt_threads() Andi Kleen <andi@firstfloor.org> - 2016-05-06 19:30 +0200
        Re: [UPDATED PATCH 01/10] x86: Add topology_max_smt_threads() Thomas Gleixner <tglx@linutronix.de> - 2016-05-07 10:20 +0200
        Re: [UPDATED PATCH 01/10] x86: Add topology_max_smt_threads() Ingo Molnar <mingo@kernel.org> - 2016-05-12 10:10 +0200

csiph-web