Skip to content

Commit 8f2d6c4

Browse files
author
Peter Zijlstra
committed
x86/sched: Rewrite topology setup
Instead of having a number of fixed topologies to pick from; build one on the fly. This is both simpler now and simpler to extend in the future. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/20230601153522.GB559993%40hirez.programming.kicks-ass.net
1 parent 1c06918 commit 8f2d6c4

File tree

1 file changed

+43
-51
lines changed

1 file changed

+43
-51
lines changed

arch/x86/kernel/smpboot.c

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -563,50 +563,57 @@ static int x86_cluster_flags(void)
563563
#endif
564564
#endif
565565

566-
static struct sched_domain_topology_level x86_numa_in_package_topology[] = {
567-
#ifdef CONFIG_SCHED_SMT
568-
{ cpu_smt_mask, x86_smt_flags, SD_INIT_NAME(SMT) },
569-
#endif
570-
#ifdef CONFIG_SCHED_CLUSTER
571-
{ cpu_clustergroup_mask, x86_cluster_flags, SD_INIT_NAME(CLS) },
572-
#endif
573-
#ifdef CONFIG_SCHED_MC
574-
{ cpu_coregroup_mask, x86_core_flags, SD_INIT_NAME(MC) },
575-
#endif
576-
{ NULL, },
577-
};
566+
/*
567+
* Set if a package/die has multiple NUMA nodes inside.
568+
* AMD Magny-Cours, Intel Cluster-on-Die, and Intel
569+
* Sub-NUMA Clustering have this.
570+
*/
571+
static bool x86_has_numa_in_package;
578572

579-
static struct sched_domain_topology_level x86_hybrid_topology[] = {
580-
#ifdef CONFIG_SCHED_SMT
581-
{ cpu_smt_mask, x86_smt_flags, SD_INIT_NAME(SMT) },
582-
#endif
583-
#ifdef CONFIG_SCHED_MC
584-
{ cpu_coregroup_mask, x86_core_flags, SD_INIT_NAME(MC) },
585-
#endif
586-
{ cpu_cpu_mask, x86_sched_itmt_flags, SD_INIT_NAME(DIE) },
587-
{ NULL, },
588-
};
573+
static struct sched_domain_topology_level x86_topology[6];
574+
575+
static void __init build_sched_topology(void)
576+
{
577+
int i = 0;
589578

590-
static struct sched_domain_topology_level x86_topology[] = {
591579
#ifdef CONFIG_SCHED_SMT
592-
{ cpu_smt_mask, x86_smt_flags, SD_INIT_NAME(SMT) },
580+
x86_topology[i++] = (struct sched_domain_topology_level){
581+
cpu_smt_mask, x86_smt_flags, SD_INIT_NAME(SMT)
582+
};
593583
#endif
594584
#ifdef CONFIG_SCHED_CLUSTER
595-
{ cpu_clustergroup_mask, x86_cluster_flags, SD_INIT_NAME(CLS) },
585+
/*
586+
* For now, skip the cluster domain on Hybrid.
587+
*/
588+
if (!cpu_feature_enabled(X86_FEATURE_HYBRID_CPU)) {
589+
x86_topology[i++] = (struct sched_domain_topology_level){
590+
cpu_clustergroup_mask, x86_cluster_flags, SD_INIT_NAME(CLS)
591+
};
592+
}
596593
#endif
597594
#ifdef CONFIG_SCHED_MC
598-
{ cpu_coregroup_mask, x86_core_flags, SD_INIT_NAME(MC) },
595+
x86_topology[i++] = (struct sched_domain_topology_level){
596+
cpu_coregroup_mask, x86_core_flags, SD_INIT_NAME(MC)
597+
};
599598
#endif
600-
{ cpu_cpu_mask, SD_INIT_NAME(DIE) },
601-
{ NULL, },
602-
};
599+
/*
600+
* When there is NUMA topology inside the package skip the DIE domain
601+
* since the NUMA domains will auto-magically create the right spanning
602+
* domains based on the SLIT.
603+
*/
604+
if (!x86_has_numa_in_package) {
605+
x86_topology[i++] = (struct sched_domain_topology_level){
606+
cpu_cpu_mask, SD_INIT_NAME(DIE)
607+
};
608+
}
603609

604-
/*
605-
* Set if a package/die has multiple NUMA nodes inside.
606-
* AMD Magny-Cours, Intel Cluster-on-Die, and Intel
607-
* Sub-NUMA Clustering have this.
608-
*/
609-
static bool x86_has_numa_in_package;
610+
/*
611+
* There must be one trailing NULL entry left.
612+
*/
613+
BUG_ON(i >= ARRAY_SIZE(x86_topology)-1);
614+
615+
set_sched_topology(x86_topology);
616+
}
610617

611618
void set_cpu_sibling_map(int cpu)
612619
{
@@ -1390,15 +1397,6 @@ void __init smp_prepare_cpus_common(void)
13901397
zalloc_cpumask_var(&per_cpu(cpu_l2c_shared_map, i), GFP_KERNEL);
13911398
}
13921399

1393-
/*
1394-
* Set 'default' x86 topology, this matches default_topology() in that
1395-
* it has NUMA nodes as a topology level. See also
1396-
* native_smp_cpus_done().
1397-
*
1398-
* Must be done before set_cpus_sibling_map() is ran.
1399-
*/
1400-
set_sched_topology(x86_topology);
1401-
14021400
set_cpu_sibling_map(0);
14031401
}
14041402

@@ -1490,13 +1488,7 @@ void __init native_smp_cpus_done(unsigned int max_cpus)
14901488
pr_debug("Boot done\n");
14911489

14921490
calculate_max_logical_packages();
1493-
1494-
/* XXX for now assume numa-in-package and hybrid don't overlap */
1495-
if (x86_has_numa_in_package)
1496-
set_sched_topology(x86_numa_in_package_topology);
1497-
if (cpu_feature_enabled(X86_FEATURE_HYBRID_CPU))
1498-
set_sched_topology(x86_hybrid_topology);
1499-
1491+
build_sched_topology();
15001492
nmi_selftest();
15011493
impress_friends();
15021494
cache_aps_init();

0 commit comments

Comments
 (0)