Skip to content

Commit c9258d3

Browse files
committed
powerpc/smp: Dynamically build Powerpc topology
JIRA: https://issues.redhat.com/browse/RHEL-118964 Conflicts: Minor context diff in one hunk. commit c469757 Author: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Date: Thu Dec 14 23:37:15 2023 +0530 powerpc/smp: Dynamically build Powerpc topology Currently there are four Powerpc specific sched topologies. These are all statically defined. However not all these topologies are used by all Powerpc systems. To avoid unnecessary degenerations by the scheduler, masks and flags are compared. However if the sched topologies are build dynamically then the code is simpler and there are greater chances of avoiding degenerations. Note: Even X86 builds its sched topologies dynamically and proposed changes are very similar to the way X86 is building its topologies. Signed-off-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20231214180720.310852-6-srikar@linux.vnet.ibm.com Signed-off-by: Phil Auld <pauld@redhat.com>
1 parent 24f80a4 commit c9258d3

File tree

1 file changed

+28
-50
lines changed

1 file changed

+28
-50
lines changed

arch/powerpc/kernel/smp.c

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,6 @@ EXPORT_PER_CPU_SYMBOL(cpu_l2_cache_map);
9595
EXPORT_PER_CPU_SYMBOL(cpu_core_map);
9696
EXPORT_SYMBOL_GPL(has_big_cores);
9797

98-
enum {
99-
#ifdef CONFIG_SCHED_SMT
100-
smt_idx,
101-
#endif
102-
cache_idx,
103-
mc_idx,
104-
die_idx,
105-
};
106-
10798
#define MAX_THREAD_LIST_SIZE 8
10899
#define THREAD_GROUP_SHARE_L1 1
109100
#define THREAD_GROUP_SHARE_L2_L3 2
@@ -1080,16 +1071,6 @@ static const struct cpumask *cpu_mc_mask(int cpu)
10801071
return cpu_coregroup_mask(cpu);
10811072
}
10821073

1083-
static struct sched_domain_topology_level powerpc_topology[] = {
1084-
#ifdef CONFIG_SCHED_SMT
1085-
{ cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
1086-
#endif
1087-
{ shared_cache_mask, powerpc_shared_cache_flags, SD_INIT_NAME(CACHE) },
1088-
{ cpu_mc_mask, powerpc_shared_proc_flags, SD_INIT_NAME(MC) },
1089-
{ cpu_cpu_mask, powerpc_shared_proc_flags, SD_INIT_NAME(PKG) },
1090-
{ NULL, },
1091-
};
1092-
10931074
static int __init init_big_cores(void)
10941075
{
10951076
int cpu;
@@ -1720,46 +1701,45 @@ int setup_profiling_timer(unsigned int multiplier)
17201701
return 0;
17211702
}
17221703

1723-
static void __init fixup_topology(void)
1704+
static struct sched_domain_topology_level powerpc_topology[6];
1705+
1706+
static void __init build_sched_topology(void)
17241707
{
1725-
int i;
1708+
int i = 0;
17261709

17271710
if (is_shared_processor() && has_big_cores)
17281711
static_branch_enable(&splpar_asym_pack);
17291712

17301713
#ifdef CONFIG_SCHED_SMT
17311714
if (has_big_cores) {
17321715
pr_info("Big cores detected but using small core scheduling\n");
1733-
powerpc_topology[smt_idx].mask = smallcore_smt_mask;
1716+
powerpc_topology[i++] = (struct sched_domain_topology_level){
1717+
smallcore_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT)
1718+
};
1719+
} else {
1720+
powerpc_topology[i++] = (struct sched_domain_topology_level){
1721+
cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT)
1722+
};
17341723
}
17351724
#endif
1725+
if (shared_caches) {
1726+
powerpc_topology[i++] = (struct sched_domain_topology_level){
1727+
shared_cache_mask, powerpc_shared_cache_flags, SD_INIT_NAME(CACHE)
1728+
};
1729+
}
1730+
if (has_coregroup_support()) {
1731+
powerpc_topology[i++] = (struct sched_domain_topology_level){
1732+
cpu_mc_mask, powerpc_shared_proc_flags, SD_INIT_NAME(MC)
1733+
};
1734+
}
1735+
powerpc_topology[i++] = (struct sched_domain_topology_level){
1736+
cpu_cpu_mask, powerpc_shared_proc_flags, SD_INIT_NAME(PKG)
1737+
};
17361738

1737-
if (!has_coregroup_support())
1738-
powerpc_topology[mc_idx].mask = powerpc_topology[cache_idx].mask;
1739-
1740-
/*
1741-
* Try to consolidate topology levels here instead of
1742-
* allowing scheduler to degenerate.
1743-
* - Dont consolidate if masks are different.
1744-
* - Dont consolidate if sd_flags exists and are different.
1745-
*/
1746-
for (i = 1; i <= die_idx; i++) {
1747-
if (powerpc_topology[i].mask != powerpc_topology[i - 1].mask)
1748-
continue;
1749-
1750-
if (powerpc_topology[i].sd_flags && powerpc_topology[i - 1].sd_flags &&
1751-
powerpc_topology[i].sd_flags != powerpc_topology[i - 1].sd_flags)
1752-
continue;
1753-
1754-
if (!powerpc_topology[i - 1].sd_flags)
1755-
powerpc_topology[i - 1].sd_flags = powerpc_topology[i].sd_flags;
1739+
/* There must be one trailing NULL entry left. */
1740+
BUG_ON(i >= ARRAY_SIZE(powerpc_topology) - 1);
17561741

1757-
powerpc_topology[i].mask = powerpc_topology[i + 1].mask;
1758-
powerpc_topology[i].sd_flags = powerpc_topology[i + 1].sd_flags;
1759-
#ifdef CONFIG_SCHED_DEBUG
1760-
powerpc_topology[i].name = powerpc_topology[i + 1].name;
1761-
#endif
1762-
}
1742+
set_sched_topology(powerpc_topology);
17631743
}
17641744

17651745
void __init smp_cpus_done(unsigned int max_cpus)
@@ -1774,9 +1754,7 @@ void __init smp_cpus_done(unsigned int max_cpus)
17741754
smp_ops->bringup_done();
17751755

17761756
dump_numa_cpu_topology();
1777-
1778-
fixup_topology();
1779-
set_sched_topology(powerpc_topology);
1757+
build_sched_topology();
17801758
}
17811759

17821760
/*

0 commit comments

Comments
 (0)