Skip to content

Commit 8f37961

Browse files
pdxChenIngo Molnar
authored andcommitted
sched/core, x86/topology: Fix NUMA in package topology bug
Current code can call set_cpu_sibling_map() and invoke sched_set_topology() more than once (e.g. on CPU hot plug). When this happens after sched_init_smp() has been called, we lose the NUMA topology extension to sched_domain_topology in sched_init_numa(). This results in incorrect topology when the sched domain is rebuilt. This patch fixes the bug and issues warning if we call sched_set_topology() after sched_init_smp(). Signed-off-by: Tim Chen <[email protected]> Signed-off-by: Srinivas Pandruvada <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/1474485552-141429-2-git-send-email-srinivas.pandruvada@linux.intel.com Signed-off-by: Ingo Molnar <[email protected]>
1 parent 536e0e8 commit 8f37961

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

arch/x86/kernel/smpboot.c

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ static bool match_die(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)
471471
return false;
472472
}
473473

474-
static struct sched_domain_topology_level numa_inside_package_topology[] = {
474+
static struct sched_domain_topology_level x86_numa_in_package_topology[] = {
475475
#ifdef CONFIG_SCHED_SMT
476476
{ cpu_smt_mask, cpu_smt_flags, SD_INIT_NAME(SMT) },
477477
#endif
@@ -480,22 +480,23 @@ static struct sched_domain_topology_level numa_inside_package_topology[] = {
480480
#endif
481481
{ NULL, },
482482
};
483+
484+
static struct sched_domain_topology_level x86_topology[] = {
485+
#ifdef CONFIG_SCHED_SMT
486+
{ cpu_smt_mask, cpu_smt_flags, SD_INIT_NAME(SMT) },
487+
#endif
488+
#ifdef CONFIG_SCHED_MC
489+
{ cpu_coregroup_mask, cpu_core_flags, SD_INIT_NAME(MC) },
490+
#endif
491+
{ cpu_cpu_mask, SD_INIT_NAME(DIE) },
492+
{ NULL, },
493+
};
494+
483495
/*
484-
* set_sched_topology() sets the topology internal to a CPU. The
485-
* NUMA topologies are layered on top of it to build the full
486-
* system topology.
487-
*
488-
* If NUMA nodes are observed to occur within a CPU package, this
489-
* function should be called. It forces the sched domain code to
490-
* only use the SMT level for the CPU portion of the topology.
491-
* This essentially falls back to relying on NUMA information
492-
* from the SRAT table to describe the entire system topology
493-
* (except for hyperthreads).
496+
* Set if a package/die has multiple NUMA nodes inside.
497+
* AMD Magny-Cours and Intel Cluster-on-Die have this.
494498
*/
495-
static void primarily_use_numa_for_topology(void)
496-
{
497-
set_sched_topology(numa_inside_package_topology);
498-
}
499+
static bool x86_has_numa_in_package;
499500

500501
void set_cpu_sibling_map(int cpu)
501502
{
@@ -558,7 +559,7 @@ void set_cpu_sibling_map(int cpu)
558559
c->booted_cores = cpu_data(i).booted_cores;
559560
}
560561
if (match_die(c, o) && !topology_same_node(c, o))
561-
primarily_use_numa_for_topology();
562+
x86_has_numa_in_package = true;
562563
}
563564

564565
threads = cpumask_weight(topology_sibling_cpumask(cpu));
@@ -1304,6 +1305,16 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
13041305
zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL);
13051306
zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL);
13061307
}
1308+
1309+
/*
1310+
* Set 'default' x86 topology, this matches default_topology() in that
1311+
* it has NUMA nodes as a topology level. See also
1312+
* native_smp_cpus_done().
1313+
*
1314+
* Must be done before set_cpus_sibling_map() is ran.
1315+
*/
1316+
set_sched_topology(x86_topology);
1317+
13071318
set_cpu_sibling_map(0);
13081319

13091320
switch (smp_sanity_check(max_cpus)) {
@@ -1370,6 +1381,9 @@ void __init native_smp_cpus_done(unsigned int max_cpus)
13701381
{
13711382
pr_debug("Boot done\n");
13721383

1384+
if (x86_has_numa_in_package)
1385+
set_sched_topology(x86_numa_in_package_topology);
1386+
13731387
nmi_selftest();
13741388
impress_friends();
13751389
setup_ioapic_dest();

kernel/sched/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6552,6 +6552,9 @@ static struct sched_domain_topology_level *sched_domain_topology =
65526552

65536553
void set_sched_topology(struct sched_domain_topology_level *tl)
65546554
{
6555+
if (WARN_ON_ONCE(sched_smp_initialized))
6556+
return;
6557+
65556558
sched_domain_topology = tl;
65566559
}
65576560

0 commit comments

Comments
 (0)