@@ -729,6 +729,36 @@ const struct cpumask *cpu_clustergroup_mask(int cpu)
return &cpu_topology[cpu].cluster_sibling;
}
+#ifdef CONFIG_HOTPLUG_SMT
+
+/* Maximum threads number per-Core */
+static unsigned int topology_smt_num_threads = 1;
+
+void __init topology_smt_set_num_threads(unsigned int num_threads)
+{
+ topology_smt_num_threads = num_threads;
+}
+
+unsigned int __init topology_smt_get_num_threads(void)
+{
+ return topology_smt_num_threads;
+}
+
+/*
+ * On SMT Hotplug the primary thread of the SMT won't be disabled. For x86 they
+ * seem to have a primary thread for special purpose. For other arthitectures
+ * like arm64 there's no such restriction for a primary thread, so make the
+ * first thread in the SMT as the primary thread.
+ */
+bool topology_is_primary_thread(unsigned int cpu)
+{
+ if (cpu == cpumask_first(topology_sibling_cpumask(cpu)))
+ return true;
+
+ return false;
+}
+#endif
+
void update_siblings_masks(unsigned int cpuid)
{
struct cpu_topology *cpu_topo, *cpuid_topo = &cpu_topology[cpuid];
@@ -841,6 +871,14 @@ void __init init_cpu_topology(void)
reset_cpu_topology();
}
+ /*
+ * By this stage we get to know whether we support SMT or not, update
+ * the information for the core. We don't support
+ * CONFIG_SMT_NUM_THREADS_DYNAMIC so make the max_threads == num_threads.
+ */
+ cpu_smt_set_num_threads(topology_smt_get_num_threads(),
+ topology_smt_get_num_threads());
+
for_each_possible_cpu(cpu) {
ret = fetch_cache_info(cpu);
if (!ret)
@@ -92,6 +92,20 @@ void update_siblings_masks(unsigned int cpu);
void remove_cpu_topology(unsigned int cpuid);
void reset_cpu_topology(void);
int parse_acpi_topology(void);
+
+#ifdef CONFIG_HOTPLUG_SMT
+bool topology_is_primary_thread(unsigned int cpu);
+void topology_smt_set_num_threads(unsigned int num_threads);
+unsigned int topology_smt_get_num_threads(void);
+#else
+static inline bool topology_is_primary_thread(unsigned int cpu) { return false; }
+static inline void topology_smt_set_num_threads(unsigned int num_threads) { }
+static inline unsigned int topology_smt_get_num_threads(void)
+{
+ return 1;
+}
+#endif
+
#endif
#endif /* _LINUX_ARCH_TOPOLOGY_H_ */