Merge branch 'x86-topology-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / arch / x86 / kernel / smpboot.c
index 1af7a2d89419b627137f8a778e82997dc7e162fd..f78801114ee1ce829837c5a1e3147cf119f6c1d0 100644 (file)
@@ -89,6 +89,10 @@ EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
 DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
 EXPORT_PER_CPU_SYMBOL(cpu_core_map);
 
+/* representing HT, core, and die siblings of each logical CPU */
+DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);
+EXPORT_PER_CPU_SYMBOL(cpu_die_map);
+
 DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
 
 /* Per CPU bogomips and other parameters */
@@ -99,6 +103,7 @@ EXPORT_PER_CPU_SYMBOL(cpu_info);
 unsigned int __max_logical_packages __read_mostly;
 EXPORT_SYMBOL(__max_logical_packages);
 static unsigned int logical_packages __read_mostly;
+static unsigned int logical_die __read_mostly;
 
 /* Maximum number of SMT threads on any online core */
 int __read_mostly __max_smt_threads = 1;
@@ -306,6 +311,26 @@ int topology_phys_to_logical_pkg(unsigned int phys_pkg)
        return -1;
 }
 EXPORT_SYMBOL(topology_phys_to_logical_pkg);
+/**
+ * topology_phys_to_logical_die - Map a physical die id to logical
+ *
+ * Returns logical die id or -1 if not found
+ */
+int topology_phys_to_logical_die(unsigned int die_id, unsigned int cur_cpu)
+{
+       int cpu;
+       int proc_id = cpu_data(cur_cpu).phys_proc_id;
+
+       for_each_possible_cpu(cpu) {
+               struct cpuinfo_x86 *c = &cpu_data(cpu);
+
+               if (c->initialized && c->cpu_die_id == die_id &&
+                   c->phys_proc_id == proc_id)
+                       return c->logical_die_id;
+       }
+       return -1;
+}
+EXPORT_SYMBOL(topology_phys_to_logical_die);
 
 /**
  * topology_update_package_map - Update the physical to logical package map
@@ -330,6 +355,29 @@ found:
        cpu_data(cpu).logical_proc_id = new;
        return 0;
 }
+/**
+ * topology_update_die_map - Update the physical to logical die map
+ * @die:       The die id as retrieved via CPUID
+ * @cpu:       The cpu for which this is updated
+ */
+int topology_update_die_map(unsigned int die, unsigned int cpu)
+{
+       int new;
+
+       /* Already available somewhere? */
+       new = topology_phys_to_logical_die(die, cpu);
+       if (new >= 0)
+               goto found;
+
+       new = logical_die++;
+       if (new != die) {
+               pr_info("CPU %u Converting physical %u to logical die %u\n",
+                       cpu, die, new);
+       }
+found:
+       cpu_data(cpu).logical_die_id = new;
+       return 0;
+}
 
 void __init smp_store_boot_cpu_info(void)
 {
@@ -339,6 +387,7 @@ void __init smp_store_boot_cpu_info(void)
        *c = boot_cpu_data;
        c->cpu_index = id;
        topology_update_package_map(c->phys_proc_id, id);
+       topology_update_die_map(c->cpu_die_id, id);
        c->initialized = true;
 }
 
@@ -393,6 +442,7 @@ static bool match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)
                int cpu1 = c->cpu_index, cpu2 = o->cpu_index;
 
                if (c->phys_proc_id == o->phys_proc_id &&
+                   c->cpu_die_id == o->cpu_die_id &&
                    per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2)) {
                        if (c->cpu_core_id == o->cpu_core_id)
                                return topology_sane(c, o, "smt");
@@ -404,6 +454,7 @@ static bool match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)
                }
 
        } else if (c->phys_proc_id == o->phys_proc_id &&
+                  c->cpu_die_id == o->cpu_die_id &&
                   c->cpu_core_id == o->cpu_core_id) {
                return topology_sane(c, o, "smt");
        }
@@ -466,6 +517,15 @@ static bool match_pkg(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)
        return false;
 }
 
+static bool match_die(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)
+{
+       if ((c->phys_proc_id == o->phys_proc_id) &&
+               (c->cpu_die_id == o->cpu_die_id))
+               return true;
+       return false;
+}
+
+
 #if defined(CONFIG_SCHED_SMT) || defined(CONFIG_SCHED_MC)
 static inline int x86_sched_itmt_flags(void)
 {
@@ -528,6 +588,7 @@ void set_cpu_sibling_map(int cpu)
                cpumask_set_cpu(cpu, topology_sibling_cpumask(cpu));
                cpumask_set_cpu(cpu, cpu_llc_shared_mask(cpu));
                cpumask_set_cpu(cpu, topology_core_cpumask(cpu));
+               cpumask_set_cpu(cpu, topology_die_cpumask(cpu));
                c->booted_cores = 1;
                return;
        }
@@ -576,6 +637,9 @@ void set_cpu_sibling_map(int cpu)
                }
                if (match_pkg(c, o) && !topology_same_node(c, o))
                        x86_has_numa_in_package = true;
+
+               if ((i == cpu) || (has_mp && match_die(c, o)))
+                       link_mask(topology_die_cpumask, cpu, i);
        }
 
        threads = cpumask_weight(topology_sibling_cpumask(cpu));
@@ -1180,6 +1244,7 @@ static __init void disable_smp(void)
                physid_set_mask_of_physid(0, &phys_cpu_present_map);
        cpumask_set_cpu(0, topology_sibling_cpumask(0));
        cpumask_set_cpu(0, topology_core_cpumask(0));
+       cpumask_set_cpu(0, topology_die_cpumask(0));
 }
 
 /*
@@ -1275,6 +1340,7 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
        for_each_possible_cpu(i) {
                zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL);
                zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL);
+               zalloc_cpumask_var(&per_cpu(cpu_die_map, i), GFP_KERNEL);
                zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL);
        }
 
@@ -1495,6 +1561,8 @@ static void remove_siblinginfo(int cpu)
                        cpu_data(sibling).booted_cores--;
        }
 
+       for_each_cpu(sibling, topology_die_cpumask(cpu))
+               cpumask_clear_cpu(cpu, topology_die_cpumask(sibling));
        for_each_cpu(sibling, topology_sibling_cpumask(cpu))
                cpumask_clear_cpu(cpu, topology_sibling_cpumask(sibling));
        for_each_cpu(sibling, cpu_llc_shared_mask(cpu))
@@ -1502,6 +1570,7 @@ static void remove_siblinginfo(int cpu)
        cpumask_clear(cpu_llc_shared_mask(cpu));
        cpumask_clear(topology_sibling_cpumask(cpu));
        cpumask_clear(topology_core_cpumask(cpu));
+       cpumask_clear(topology_die_cpumask(cpu));
        c->cpu_core_id = 0;
        c->booted_cores = 0;
        cpumask_clear_cpu(cpu, cpu_sibling_setup_mask);