powerpc/topology: Introduce llc_override debugfs
Subsystems (3)
Shrikanth Hegde
reviewercover powerpc/topology: Introduce llc_override debugfs
There is a new feature in scheduler called as Cache Aware Scheduling [1]. It tries to keep related tasks within the same LLC domain while keeping the system reasonably balanced.
Cache Aware Scheduling assumes that the scheduler LLC domain is large enough to be a useful placement target. This is true on many systems where an LLC spans several cores, but not on PowerPC systems where the scheduler-visible LLC is at the SMT level. In that case, sd_llc_size is effectively the SMT width.
This becomes visible in the capacity check:
return !fits_capacity((mm->sc_stat.nr_running_avg * cpu_smt_num_threads),
scale * per_cpu(sd_llc_size, cpu));As a result, Cache aware scheduling may be enabled but has no room to operate.
Hence provide a debugfs option to set LLC at specific domain so that one can try experiment their workload with cache aware scheduling. This also provides ways to explore it on system with SMT=4 to see if there are any opportunities to improve or uncover bugs if there is any.
Note it is a debug option and it is recommended to keep it disabled. There is no performance guarantees across different values.
[1]: https://lore.kernel.org/all/[email protected]/
Tim, Chenyu, Peter,
Are there any selftest or patches which is used for functional validation of cache aware scheduling? per-LLC occupancy in /proc/{PID}/schedstat may not tell the full story when there are multiple processes and multiple LLC's.
Atleast for functional verification, we might need one if there is not one already. The reason being,
- At present, we may need a custom workload. hackbench/schbench are wakeup intensive and typically bail out even before load balance.
- stress-ng is per process. So doesn't get cache aware scheduling.
- A selftest could spwan specific number of threads till llc size etc and ensure packing happens till core_count(llc_size) by default. This could also be used for tunable verfifications.
- Provide an ability to observe how much of the workload was contained within the LLC due to cache aware scheduling or number of load balances stopped due to preferred llc.
These are some initial thoughts I had. If it sounds ok, I can try to add a new selftest/kunit test.
Shrikanth Hegde (4):
powerpc/topology: Introduce llc_override debug knob powerpc/topology: Add docs for llc_override powerpc/topology: Update mc/pkg flags based on llc_override powerpc/topology: Rebuild sched domains on llc_override change
Documentation/arch/powerpc/index.rst | 1 + Documentation/arch/powerpc/topology.rst | 27 +++++ arch/powerpc/kernel/smp.c | 128 +++++++++++++++++++++++- 3 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 Documentation/arch/powerpc/topology.rst
Signature · 1 line
2.52.0
Shrikanth Hegde
reviewerPATCH 1/4 powerpc/topology: Introduce llc_override debug knob
There is a new feature in scheduler called as Cache Aware Scheduling. It tries to keep related tasks within the same LLC domain while keeping the system reasonably balanced.
Cache Aware Scheduling assumes that the scheduler LLC domain is large enough to be a useful placement target. This is true on many systems where an LLC spans several cores, but not on PowerPC systems where the scheduler-visible LLC is at the SMT level.
In that case, sd_llc_size is effectively the SMT width.
This becomes visible in the capacity check:
!fits_capacity((mm->sc_stat.nr_running_avg * cpu_smt_num_threads),
scale * per_cpu(sd_llc_size, cpu));As a result, it may be enabled but has no room to operate. Hence provide a debugfs option one can set to try experiment their workload with cache aware scheduling. This also provides ways to explore it on system with SMT=4 to see if there are any opportunities to improve or uncover bugs if there is any.
This does not change the hardware cache topology. It only changes the sched-domain level at which SD_SHARE_LLC is set.
Initially start with,
- New debugs file called llc_override. It can be set/get on /sys/kernel/debug/powerpc/llc_override
- Adds parser logic for the debug knob.
There is no point in setting NUMA as the LLC domain. So give option until pkg to experiment with.
Actual flag manipulations and rebuilding sched domains are introduced in subsequent patches.
---
PS: Split is deliberate. If squashing all this into one patch helps,
let me know.
arch/powerpc/kernel/smp.c | 90 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+)
arch/powerpc/kernel/smp.c +90 -0
@@ -36,6 +36,7 @@#include <linux/pgtable.h> #include <linux/clockchips.h> #include <linux/kexec.h> +#include <linux/debugfs.h> #include <asm/ptrace.h> #include <linux/atomic.h>
@@ -1826,3 +1827,92 @@ void __noreturn arch_cpu_idle_dead(void) }#endif + +enum llc_override_values { +LLC_OVERRIDE_DISABLED , +LLC_OVERRIDE_SMT , +LLC_OVERRIDE_MC , +LLC_OVERRIDE_PKG , +}; + +static int llc_override; +static int llc_override_changed; +static DEFINE_MUTEX (llc_override_mutex); + +static const char *const llc_override_str[] = { + [LLC_OVERRIDE_DISABLED ] ="0" , + [LLC_OVERRIDE_SMT ] ="smt" , + [LLC_OVERRIDE_MC ] ="mc" , + [LLC_OVERRIDE_PKG ] ="pkg" , +}; + +static ssize_t llc_override_get (struct file *file,char __user *ubuf, +size_t count,loff_t *ppos) +{ +int override; +char buf[8 ]; +int len; + + override =READ_ONCE (llc_override); + len =scnprintf (buf,sizeof (buf),"%s\n" , llc_override_str[override]); +return simple_read_from_buffer (ubuf, count, ppos, buf, len); +} + +static ssize_t llc_override_set (struct file *file,const char __user *ubuf, +size_t count,loff_t *ppos) +{ +char buf[8 ]; +int override; + +if (!count || count >=sizeof (buf)) +return -EINVAL ; + +if (copy_from_user (buf, ubuf, count)) +return -EFAULT ; + + buf[count] ='\0' ; +strim (buf); + +if (!strcmp (buf,"0" )) + override =LLC_OVERRIDE_DISABLED ; +else if (!strcasecmp (buf,"smt" )) + override =LLC_OVERRIDE_SMT ; +else if (!strcasecmp (buf,"mc" )) + override =LLC_OVERRIDE_MC ; +else if (!strcasecmp (buf,"pkg" )) + override =LLC_OVERRIDE_PKG ; +else +return -EINVAL ; + +if (override ==LLC_OVERRIDE_MC && !has_coregroup_support ()) +return -EINVAL ; + +mutex_lock (&llc_override_mutex); + +if (override !=READ_ONCE (llc_override)) { +WRITE_ONCE (llc_override, override); +WRITE_ONCE (llc_override_changed,1 ); +pr_info ("sched LLC override set to %s\n" , + llc_override_str[override]); + +/* Will be calling rebuild sched domain in later patches */ + } + +mutex_unlock (&llc_override_mutex); +return count; +} + +static const struct file_operations llc_override_fops = { + .open = simple_open, + .read = llc_override_get, + .write = llc_override_set, + .llseek = default_llseek, +}; + +static __init int llc_override_debugfs_init (void ) +{ +debugfs_create_file ("llc_override" ,0600 , arch_debugfs_dir,NULL , + &llc_override_fops); +return 0 ; +} +device_initcall (llc_override_debugfs_init);
Signature · 1 line
2.52.0
Re: [PATCH 1/4] powerpc/topology: Introduce llc_override debug knob
* Shrikanth Hegde <[email protected]> [2026-10-12 15:50:34]:
Hi Shrikanth,
Quoted 7 lines
As a result, it may be enabled but has no room to operate. Hence provide a debugfs option one can set to try experiment their workload with cache aware scheduling. This also provides ways to explore it on system with SMT=4 to see if there are any opportunities to improve or uncover bugs if there is any.
Quoted 8 lines
This does not change the hardware cache topology. It only changes the sched-domain level at which
SD_SHARE_LLCis set.Initially start with,
- New debugs file calledllc_override. It can be set/get on/sys/kernel/debug/powerpc/llc_override
- Adds parser logic for the debug knob.
This is a good way to allow experimenting to know if a software override of the LLC esp given the latency numbers within hemisphere and chip.
Quoted 28 lines
There is no point in setting NUMA as the LLC domain. So give option until pkg to experiment with.
Actual flag manipulations and rebuilding sched domains are introduced in subsequent patches.
Signed-off-by Shrikanth Hegde <[email protected]>---
PS: Split is deliberate. If squashing all this into one patch helps,
let me know.arch/powerpc/kernel/smp.c | 90 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+)arch/powerpc/kernel/smp.c +1
-0@@ -36,6 +36,7 @@#include <linux/pgtable.h> #include <linux/clockchips.h> #include <linux/kexec.h> +#include <linux/debugfs.h> #include <asm/ptrace.h> #include <linux/atomic.h> @@ -1826,3 +1827,92 @@ void __noreturn arch_cpu_idle_dead(void) }
arch/powerpc/kernel/smp.c void __noreturn arch_cpu_idle_dead(void) · line 1837
Quoted 10 lines
arch/powerpc/kernel/smp.c +8
-0#endif + +enum llc_override_values { +LLC_OVERRIDE_DISABLED , +LLC_OVERRIDE_SMT , +LLC_OVERRIDE_MC , +LLC_OVERRIDE_PKG , +}; +
For the current experiments, would it help to keep it simple and have just SMT and MC. I mean we can include disabled and pkg based on our experiments.
Signature · 2 lines
Thanks and Regards Srikar Dronamraju
Shrikanth Hegde
reviewerRe: [PATCH 1/4] powerpc/topology: Introduce llc_override debug knob
Hi Srikar. Thanks for taking a look at the patches.
Quoted 4 lines
Quoted 4 lines
#endifarch/powerpc/kernel/smp.c +3
-0+ +enum llc_override_values { +LLC_OVERRIDE_DISABLED ,
Quoted 9 lines
arch/powerpc/kernel/smp.c void __noreturn arch_cpu_idle_dead(void) · line 1837
Quoted 5 lines
arch/powerpc/kernel/smp.c +5
-0+LLC_OVERRIDE_SMT , +LLC_OVERRIDE_MC , + LLC_OVERRIDE_PKG, +}; +For the current experiments, would it help to keep it simple and have just SMT and MC. I mean we can include disabled and pkg based on our experiments.
I think we should keep disabled. So it is clear when disabled, there is no adverse effect of it.
I think keeping pkg for experimentation seems okay. If not necessary we can remove it later. Having at pkg gives you to try increased number of cores in a llc. So it may be a useful too IMHO.
Shrikanth Hegde
reviewerPATCH 2/4 powerpc/topology: Add docs for llc_override
In reply to Shrikanth HegdeProvide documentation for the newly introduced debug knob named as llc_override.
This may help one if they want to experiment with cache aware scheduling.
--- Documentation/arch/powerpc/index.rst | 1 + Documentation/arch/powerpc/topology.rst | 27 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 Documentation/arch/powerpc/topology.rst
Documentation/arch/powerpc/index.rst +1 -0
@@ -33,6 +33,7 @@ powerpc qe_firmware syscall64-abi transactional_memory + topology ultravisor vas-api vcpudispatch_stats
Documentation/arch/powerpc/topology.rst new file +27 -0
@@ -0,0 +1,27 @@ +.. SPDX-License-Identifier: GPL-2.0 +.. _topology: + + +llc_override +============== + +Override the scheduler-visible LLC domain on PowerPC. + +Having LLC(last level cache) at MC/PKG helps to experiment with new +scheduler feature called cache aware scheduling which expects LLC to have +at least more than 1 core. Scheduler uses notion of LLC for wakeup and +load balancing decisions. + +Accepted values are: + + 0 Disable the override and use the platform default. + smt LLC will be at SMT domain. + mc LLC will be at MC domain, including at SMT domains. + pkg LLC will be at PKG domain, including at MC and SMT domains, + +Writing a new value rebuilds the scheduler domains. One can check the +domain flags and look for SD_SHARE_LLC to confirm if it took effect. + +Note that this doesn't change HW cache topology. It is only a debug knob +to experiment with scheduler related functionalities. So set it to sensible +values. Also note that there is no performance guarantees across the values.
Signature · 1 line
2.52.0
Shrikanth Hegde
reviewerPATCH 3/4 powerpc/topology: Update mc/pkg flags based on llc_override
In reply to Shrikanth HegdeUpdate the flags passed for building the scheduler topology.
SD_SHARE_LLC is used to determine the highest domain where the LLC is. Also when set at a particular domain, all the child domains are expected to have it set as well.
--- arch/powerpc/kernel/smp.c | 63 +++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 23 deletions(-)
arch/powerpc/kernel/smp.c +40 -23
@@ -141,6 +141,24 @@ volatile unsigned int cpu_callin_map[NR_CPUS];int smt_enabled_at_boot =1 ; +enum llc_override_values { +LLC_OVERRIDE_DISABLED , +LLC_OVERRIDE_SMT , +LLC_OVERRIDE_MC , +LLC_OVERRIDE_PKG , +}; + +static int llc_override; +static int llc_override_changed; +static DEFINE_MUTEX (llc_override_mutex); + +static const char *const llc_override_str[] = { + [LLC_OVERRIDE_DISABLED ] ="0" , + [LLC_OVERRIDE_SMT ] ="smt" , + [LLC_OVERRIDE_MC ] ="mc" , + [LLC_OVERRIDE_PKG ] ="pkg" , +}; +/* * Returns 1 if the specified cpu should be brought up during boot. * Used to inhibit booting threads if they've been disabled or
@@ -1022,14 +1040,31 @@ static int powerpc_shared_cache_flags(void)return SD_SHARE_LLC ; } -static int powerpc_shared_proc_flags (void ) +static int powerpc_mc_flags (void ) { +int flags =0 ; +if (static_branch_unlikely (&splpar_asym_pack)) -return SD_ASYM_PACKING ; + flags |=SD_ASYM_PACKING ; -return 0 ; +if (READ_ONCE (llc_override) >=LLC_OVERRIDE_MC ) + flags |=SD_SHARE_LLC ; + +return flags; } +static int powerpc_pkg_flags (void ) +{ +int flags =0 ; + +if (static_branch_unlikely (&splpar_asym_pack)) + flags |=SD_ASYM_PACKING ; + +if (READ_ONCE (llc_override) >=LLC_OVERRIDE_PKG ) + flags |=SD_SHARE_LLC ; + +return flags; +}/* * We can't just pass cpu_l2_cache_mask() directly because * returns a non-const pointer and the compiler barfs on that.
@@ -1737,10 +1772,10 @@ static void __init build_sched_topology(void)if (has_coregroup_support ()) { powerpc_topology[i++] = -SDTL_INIT (tl_mc_mask, powerpc_shared_proc_flags,MC ); +SDTL_INIT (tl_mc_mask, powerpc_mc_flags,MC ); } - powerpc_topology[i++] =SDTL_INIT (tl_pkg_mask, powerpc_shared_proc_flags,PKG ); + powerpc_topology[i++] =SDTL_INIT (tl_pkg_mask, powerpc_pkg_flags,PKG );/* There must be one trailing NULL entry left. */ BUG_ON (i >=ARRAY_SIZE (powerpc_topology) -1 );
@@ -1828,24 +1863,6 @@ void __noreturn arch_cpu_idle_dead(void)#endif -enum llc_override_values { -LLC_OVERRIDE_DISABLED , -LLC_OVERRIDE_SMT , -LLC_OVERRIDE_MC , -LLC_OVERRIDE_PKG , -}; - -static int llc_override; -static int llc_override_changed; -static DEFINE_MUTEX (llc_override_mutex); - -static const char *const llc_override_str[] = { - [LLC_OVERRIDE_DISABLED ] ="0" , - [LLC_OVERRIDE_SMT ] ="smt" , - [LLC_OVERRIDE_MC ] ="mc" , - [LLC_OVERRIDE_PKG ] ="pkg" , -}; -static ssize_t llc_override_get (struct file *file,char __user *ubuf,size_t count,loff_t *ppos) {
Signature · 1 line
2.52.0
Shrikanth Hegde
reviewerPATCH 4/4 powerpc/topology: Rebuild sched domains on llc_override change
In reply to Shrikanth HegdeOn changing the llc_override, rebuild the sched domains.
For the rebuild to happen, indicate it to the scheduler that complete rebuild of the sched domains need to happen via arch_update_cpu_topology().
With this, llc_override functionality is complete.
For example, on CPU10,
domain0/name:SMT
domain1/name:MC
domain2/name:PKG
echo 0 > /sys/kernel/debug/powerpc/llc_overrideSD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_SHARE_CPUCAPACITY SD_SHARE_LLC SD_PREFER_SIBLING SD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_PREFER_SIBLING SD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_PREFER_SIBLING
echo mc > /sys/kernel/debug/powerpc/llc_overrideSD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_SHARE_CPUCAPACITY SD_SHARE_LLC SD_PREFER_SIBLING SD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_SHARE_LLC SD_PREFER_SIBLING SD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_PREFER_SIBLING
--- arch/powerpc/kernel/smp.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
arch/powerpc/kernel/smp.c +13 -2
@@ -37,6 +37,7 @@#include <linux/clockchips.h> #include <linux/kexec.h> #include <linux/debugfs.h> +#include <linux/cpuset.h> #include <asm/ptrace.h> #include <linux/atomic.h>
@@ -1863,6 +1864,16 @@ void __noreturn arch_cpu_idle_dead(void)#endif +int arch_update_cpu_topology (void ) +{ +if (READ_ONCE (llc_override_changed)) { +WRITE_ONCE (llc_override_changed,0 ); +return 1 ; + } + +return 0 ; +} +static ssize_t llc_override_get (struct file *file,char __user *ubuf,size_t count,loff_t *ppos) {
@@ -1909,10 +1920,10 @@ static ssize_t llc_override_set(struct file *file, const char __user *ubuf,if (override !=READ_ONCE (llc_override)) {WRITE_ONCE (llc_override, override);WRITE_ONCE (llc_override_changed,1 ); -pr_info ("sched LLC override set to %s\n" , +pr_info ("sched LLC override set to %s. Rebuilding sched domains\n" , llc_override_str[override]); -/* Will be calling rebuild sched domain in later patches */ +rebuild_sched_domains (); }mutex_unlock (&llc_override_mutex);
Signature · 1 line
2.52.0
* Shrikanth Hegde <[email protected]> [2026-10-12 15:50:33]:
Hi Shrikanth,
Quoted 9 lines
There is a new feature in scheduler called as Cache Aware Scheduling [1]. It tries to keep related tasks within the same LLC domain while keeping the system reasonably balanced.
Cache Aware Scheduling assumes that the scheduler LLC domain is large enough to be a useful placement target. This is true on many systems where an LLC spans several cores, but not on PowerPC systems where the scheduler-visible LLC is at the SMT level. In that case,
sd_llc_sizeis effectively the SMT width.
Can we add a reference to the earlier attempt to try MCLLC a few years back.
Signature · 2 lines
Thanks and Regards Srikar Dronamraju
Shrikanth Hegde
reviewerQuoted 9 lines · Srikar Dronamraju
* Shrikanth Hegde <[email protected]> [2026-10-12 15:50:33]:
Hi Shrikanth,
Quoted 4 lines
There is a new feature in scheduler called as Cache Aware Scheduling [1]. It tries to keep related tasks within the same LLC domain while keeping the system reasonably balanced.
Quoted 8 lines
Quoted 5 lines
Cache Aware Scheduling assumes that the scheduler LLC domain is large enough to be a useful placement target. This is true on many systems where an LLC spans several cores, but not on PowerPC systems where the scheduler-visible LLC is at the SMT level. In that case,
sd_llc_sizeis effectively the SMT width.Can we add a reference to the earlier attempt to try MCLLC a few years back.
Ah yes. will add it.
It is this one.
https://lore.kernel.org/all/[email protected]/
But I couldn't find an email id of Gautham which won't bounce. Based on what i know :)
Quoted 20 lines · Shrikanth Hegde
There is a new feature in scheduler called as Cache Aware Scheduling [1]. It tries to keep related tasks within the same LLC domain while keeping the system reasonably balanced.
Cache Aware Scheduling assumes that the scheduler LLC domain is large enough to be a useful placement target. This is true on many systems where an LLC spans several cores, but not on PowerPC systems where the scheduler-visible LLC is at the SMT level. In that case,
sd_llc_sizeis effectively the SMT width.This becomes visible in the capacity check:
return !fits_capacity((mm->sc_stat.nr_running_avg * cpu_smt_num_threads), scale * per_cpu(sd_llc_size, cpu));As a result, Cache aware scheduling may be enabled but has no room to operate.
Hence provide a debugfs option to set LLC at specific domain so that one can try experiment their workload with cache aware scheduling. This also provides ways to explore it on system with SMT=4 to see if there are any opportunities to improve or uncover bugs if there is any.
Quoted 4 lines
Note it is a debug option and it is recommended to keep it disabled. There is no performance guarantees across different values.
Shrikanth,
This is an interesting idea. One question from a quick look at the code.
The override moves sd_llc, sd_llc_size and sd_llc_shared, but not sd_llc_id. The id comes from arch_llc_mask(), which is cpu_l2_cache_mask() on powerpc, so after your patches it is still unique per core. It is also sticky: build_sched_domains() assigns it only when it is -1, and it is reset only on CPU offline. So a rebuild from the knob keeps the old ids.
Cache aware scheduling uses this id as the identity of an LLC:p->preferred_llc, nr_pref_dst_llc/llc_counts[], and the llc_id(cpu) == llc_id(grp->cpu) check in task_cache_work(). In that loop the occupancy is now summed over the MC span, but the id check rarely matches and is broken.
To make this work, arch_llc_mask() needs to follow the override, and the llc ids need to be reset when the topology is forced to rebuild.
Quoted 4 lines
Tim, Chenyu, Peter,
Are there any selftest or patches which is used for functional validation of cache aware scheduling?
We haven't created one. We validate mostly with workloads such as hackbench, schbench and yogini (which can vary the number of threads over time and track CPU assignment). I agree they are not ideal for functional checks of the load balance path.
Quoted 14 lines
per-LLC occupancy in
/proc/{PID}/schedstatmay not tell the full story when there are multiple processes and multiple LLC's.Atleast for functional verification, we might need one if there is not one already. The reason being,
- At present, we may need a custom workload. hackbench/schbench are wakeup intensive and typically bail out even before load balance.
- stress-ng is per process. So doesn't get cache aware scheduling.
- A selftest could spwan specific number of threads till llc size etc and ensure packing happens tillcore_count(llc_size)by default. This could also be used for tunable verfifications.
- Provide an ability to observe how much of the workload was contained within the LLC due to cache aware scheduling or number of load balances stopped due to preferred llc.
A selftest would be great and much welcomed.
Tim
Quoted 15 lines
These are some initial thoughts I had. If it sounds ok, I can try to add a new selftest/kunit test.
Shrikanth Hegde (4):
powerpc/topology: Introducellc_overridedebug knob powerpc/topology: Add docs forllc_overridepowerpc/topology: Update mc/pkg flags based onllc_overridepowerpc/topology: Rebuild sched domains onllc_overridechangeDocumentation/arch/powerpc/index.rst | 1 + Documentation/arch/powerpc/topology.rst | 27 +++++ arch/powerpc/kernel/smp.c | 128 +++++++++++++++++++++++- 3 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 Documentation/arch/powerpc/topology.rst
Shrikanth Hegde
reviewerHi Tim, Thanks for taking a look and findings.
Quoted 37 lines · Tim Chen
Quoted 20 lines · Shrikanth Hegde
There is a new feature in scheduler called as Cache Aware Scheduling [1]. It tries to keep related tasks within the same LLC domain while keeping the system reasonably balanced.
Cache Aware Scheduling assumes that the scheduler LLC domain is large enough to be a useful placement target. This is true on many systems where an LLC spans several cores, but not on PowerPC systems where the scheduler-visible LLC is at the SMT level. In that case,
sd_llc_sizeis effectively the SMT width.This becomes visible in the capacity check:
return !fits_capacity((mm->sc_stat.nr_running_avg * cpu_smt_num_threads), scale * per_cpu(sd_llc_size, cpu));As a result, Cache aware scheduling may be enabled but has no room to operate.
Hence provide a debugfs option to set LLC at specific domain so that one can try experiment their workload with cache aware scheduling. This also provides ways to explore it on system with SMT=4 to see if there are any opportunities to improve or uncover bugs if there is any.
Quoted 4 lines
Note it is a debug option and it is recommended to keep it disabled. There is no performance guarantees across different values.
Shrikanth,
This is an interesting idea. One question from a quick look at the code.
The override moves
sd_llc,sd_llc_sizeandsd_llc_shared, but notsd_llc_id. The id comes fromarch_llc_mask(), which iscpu_l2_cache_mask()on powerpc, so after your patches it is still unique per core. It is also sticky:build_sched_domains()assigns it only when it is -1, and it is reset only on CPU offline. So a rebuild from the knob keeps the old ids.
Quoted 9 lines
Cache aware scheduling uses this id as the identity of an LLC:
p->preferred_llc, nr_pref_dst_llc/llc_counts[], and thellc_id(cpu)==llc_id(grp->cpu)check intask_cache_work(). In that loop the occupancy is now summed over the MC span, but the id check rarely matches and is broken.To make this work,
arch_llc_mask()needs to follow the override, and the llc ids need to be reset when the topology is forced to rebuild.
Thanks for catching this. I missed to see that.
One way to fix it is with a change like below.
But more thoughts after the patch.
--- arch/powerpc/include/asm/topology.h | 7 +------ arch/powerpc/kernel/smp.c | 23 +++++++++++++++++++++++ include/linux/sched.h | 2 +- kernel/sched/topology.c | 7 +++++++ 4 files changed, 32 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/topology.h +1 -6
@@ -135,12 +135,7 @@ struct cpumask *cpu_coregroup_mask(int cpu);const struct cpumask *cpu_die_mask (int cpu);int cpu_die_id (int cpu); -/* -* Points to where the LLC is. On power9 this will point at CACHE -* domain, On others it will point to SMT domain. In all cases -* cpu_l2_cache_mask points to where LLC is -*/ -#define arch_llc_mask (cpu) cpu_l2_cache_mask(cpu) +const struct cpumask *arch_llc_mask (int cpu);#ifdef CONFIG_PPC64 #include <asm/smp.h>
arch/powerpc/kernel/smp.c +23 -0
@@ -1864,6 +1864,28 @@ void __noreturn arch_cpu_idle_dead(void)#endif +/* +* Points to where the LLC is. On power9 this will point at CACHE +* domain, On others it will point to SMT domain. In all cases +* cpu_l2_cache_mask points to where LLC is. +* +* If there is llc_override debug knob, return appropriate mask +*/ +const struct cpumask *arch_llc_mask (int cpu) +{ +switch (READ_ONCE (llc_override)) { +case LLC_OVERRIDE_SMT : +return cpu_smt_mask (cpu); +case LLC_OVERRIDE_MC : +return cpu_coregroup_mask (cpu); +case LLC_OVERRIDE_PKG : +return cpu_die_mask (cpu); +case LLC_OVERRIDE_DISABLED : +default : +return cpu_l2_cache_mask (cpu); + } +} +int arch_update_cpu_topology (void ) {if (READ_ONCE (llc_override_changed)) {
@@ -1923,6 +1945,7 @@ static ssize_t llc_override_set(struct file *file, const char __user *ubuf,pr_info ("sched LLC override set to %s. Rebuilding sched domains\n" , llc_override_str[override]); +sched_reset_llc_id ();rebuild_sched_domains (); }
include/linux/sched.h +1 -1
@@ -2505,5 +2505,5 @@ extern void migrate_enable(void);#endif /* MODULE */ DEFINE_LOCK_GUARD_0(migrate, migrate_disable(), migrate_enable()) - +void sched_reset_llc_id (void );#endif
kernel/sched/topology.c +7 -0
@@ -3087,6 +3087,13 @@ void sched_domains_free_llc_id(int cpu)sched_domains_mutex_unlock (); } +void sched_reset_llc_id (void ) +{ +int cpu; + +for_each_online_cpu (cpu) +sched_domains_free_llc_id (cpu); +}/* * Build sched domains for a given set of CPUs and attach the sched domains * to the individual CPUs
Signature · 21 lines
2.52.0 Another way to avoid all this is with kernel parameter i think. That would fix the LLC at specific domain and this reset/rebuild of llc_id won't be necessary. If one is happy to change the debugfs, i guess they would okay with rebooting the kernel with specific parameter too. And at this point, I think that would mean the code will be arch/powerpc/ contained too. (Yes, that would need updating arch_llc_mask, but no need to do the rebuilding the sd_llc_id stuff) So two ways. - debugfs way with above changes. - kernel parameters way. Tim, Peter, Maddy, What do you guys suggest?
Quoted 25 lines
Quoted 4 lines
Tim, Chenyu, Peter,
Are there any selftest or patches which is used for functional validation of cache aware scheduling?We haven't created one. We validate mostly with workloads such as hackbench, schbench and yogini (which can vary the number of threads over time and track CPU assignment). I agree they are not ideal for functional checks of the load balance path.
Quoted 14 lines
per-LLC occupancy in
/proc/{PID}/schedstatmay not tell the full story when there are multiple processes and multiple LLC's.Atleast for functional verification, we might need one if there is not one already. The reason being,
- At present, we may need a custom workload. hackbench/schbench are wakeup intensive and typically bail out even before load balance.
- stress-ng is per process. So doesn't get cache aware scheduling.
- A selftest could spwan specific number of threads till llc size etc and ensure packing happens tillcore_count(llc_size)by default. This could also be used for tunable verfifications.
- Provide an ability to observe how much of the workload was contained within the LLC due to cache aware scheduling or number of load balances stopped due to preferred llc.
Quoted 2 lines
A selftest would be great and much welcomed.
Cool. Will give it a try. but only after start implementing will come to know the challenges. LLM's are there to help anyway!.
Quoted 2 lines
Tim
Quoted 1 line · Shrikanth Hegde
[snip]
Quoted 16 lines
One way to fix it is with a change like below.
But more thoughts after the patch.--- arch/powerpc/include/asm/topology.h | 7 +------ arch/powerpc/kernel/smp.c | 23 +++++++++++++++++++++++ include/linux/sched.h | 2 +- kernel/sched/topology.c | 7 +++++++ 4 files changed, 32 insertions(+), 7 deletions(-)arch/powerpc/include/asm/topology.h +0
-0
arch/powerpc/include/asm/topology.h struct cpumask *cpu_coregroup_mask(int cpu); · line 138
Quoted 10 lines
arch/powerpc/include/asm/topology.h +1
-6@@ -135,12 +135,7 @@ struct cpumask *cpu_coregroup_mask(int cpu);const struct cpumask *cpu_die_mask (int cpu);int cpu_die_id (int cpu); -/* -* Points to where the LLC is. On power9 this will point at CACHE -* domain, On others it will point to SMT domain. In all cases -* cpu_l2_cache_mask points to where LLC is -*/ -#define arch_llc_mask (cpu) cpu_l2_cache_mask(cpu) +const struct cpumask *arch_llc_mask (int cpu);
You will need to add
#define arch_llc_mask arch_llc_mask
here.
Otherwise kernel/sched/topology.c looks for a macro:
# ifndef arch_llc_mask #define arch_llc_mask(cpu) cpu_coregroup_mask(cpu) # endif
With the #define gone, the generic code falls back to cpu_coregroup_mask().
Quoted 23 lines
arch/powerpc/include/asm/topology.h +0
-0#ifdef CONFIG_PPC64 #include <asm/smp.h> arch/powerpc/kernel/smp.c +12
-0@@ -1864,6 +1864,28 @@ void __noreturn arch_cpu_idle_dead(void)#endif +/* +* Points to where the LLC is. On power9 this will point at CACHE +* domain, On others it will point to SMT domain. In all cases +* cpu_l2_cache_mask points to where LLC is. +* +* If there is llc_override debug knob, return appropriate mask +*/ +const struct cpumask *arch_llc_mask (int cpu) +{ +switch (READ_ONCE (llc_override)) { +case LLC_OVERRIDE_SMT : +return cpu_smt_mask (cpu);
arch/powerpc/kernel/smp.c void __noreturn arch_cpu_idle_dead(void) · line 1888
Quoted 10 lines
arch/powerpc/kernel/smp.c +10
-0+case LLC_OVERRIDE_MC : +return cpu_coregroup_mask (cpu); +case LLC_OVERRIDE_PKG : +return cpu_die_mask (cpu); +case LLC_OVERRIDE_DISABLED : +default : +return cpu_l2_cache_mask (cpu); + } +} +
The mask here has to match the span of the highest SD_SHARE_LLC domain, and there seems to be some mismatches.
- PKG: On power pc, seems like cpu_die_mask() returns cpu_coregroup_map when coregroups are supported,
if (has_coregroup_support()) return per_cpu(cpu_coregroup_map, cpu); else return cpu_node_mask(cpu);
so this is the MC span while sd_llc sits at PKG. It should be cpu_node_mask(), the same as tl_pkg_mask().
- SMT: patch 3 adds SD_SHARE_LLC only to MC/PKG, so for "smt" the flags are as before. I think it is possible for P9 to have shared_caches between two cores:
/*
* P9 has a slightly odd architecture where pairs of cores share an L2 cache.
* This topology makes it *much* cheaper to migrate tasks between adjacent cores
* since the migrated task remains cache hot. We want to take advantage of this
* at the scheduler level so an extra topology level is required. */
the CACHE level also has SD_SHARE_LLC, and highest_flag_domain() picks it, so sd_llc spans cpu_l2_cache_map. shared_caches is only set when that map is wider
than the core's threads, e.g. a P9 core pair sharing an L2:
CPU: 0 1 2 3 | 4 5 6 7
cpu_smt_mask(): core A | core B
sd_llc (CACHE): 0-7 The ids follow cpu_smt_mask(), so 0-3 and 4-7 get different ids while sd_llc and sd_llc_size cover all eight, and cpus_share_cache(0, 4) is false, which is incorrect.
arch/powerpc/kernel/smp.c static ssize_t llc_override_set(struct file *file, const char __user *ubuf, · line 1948
Quoted 8 lines
arch/powerpc/kernel/smp.c +1
-0int arch_update_cpu_topology (void ) {if (READ_ONCE (llc_override_changed)) {@@ -1923,6 +1945,7 @@ static ssize_t llc_override_set(struct file *file, const char __user *ubuf,pr_info ("sched LLC override set to %s. Rebuilding sched domains\n" , llc_override_str[override]); +sched_reset_llc_id ();
The reset here seems racy without taking cpus_read_lock, and taking sched_domains_mutex for each CPU and you could have a cpu hot plug event or cpu set rebuild in between.
That's why I would go with the boot parameter. The llc ids are assigned once, with the right mask, so there is nothing to reset or rebuild, no change to kernel/sched/, and everything stays in arch/powerpc. Since this is an experiment knob, needing a reboot to change it is a small cost, and every run starts from a clean state.
Tim
Quoted 32 lines
arch/powerpc/kernel/smp.c +0
-0rebuild_sched_domains (); }include/linux/sched.h +1
-1@@ -2505,5 +2505,5 @@ extern void migrate_enable(void);#endif /* MODULE */ DEFINE_LOCK_GUARD_0(migrate, migrate_disable(), migrate_enable()) - +void sched_reset_llc_id (void );#endif kernel/sched/topology.c +7
-0@@ -3087,6 +3087,13 @@ void sched_domains_free_llc_id(int cpu)sched_domains_mutex_unlock (); } +void sched_reset_llc_id (void ) +{ +int cpu; + +for_each_online_cpu (cpu) +sched_domains_free_llc_id (cpu); +}/* * Build sched domains for a given set of CPUs and attach the sched domains * to the individual CPUs
Shrikanth Hegde
reviewerQuoted 24 lines · Tim Chen
Quoted 1 line · Shrikanth Hegde
[snip]
Quoted 19 lines
One way to fix it is with a change like below.
But more thoughts after the patch.--- arch/powerpc/include/asm/topology.h | 7 +------ arch/powerpc/kernel/smp.c | 23 +++++++++++++++++++++++ include/linux/sched.h | 2 +- kernel/sched/topology.c | 7 +++++++ 4 files changed, 32 insertions(+), 7 deletions(-)arch/powerpc/include/asm/topology.h +0
-0@@ -135,12 +135,7 @@ struct cpumask *cpu_coregroup_mask(int cpu);const struct cpumask *cpu_die_mask (int cpu);int cpu_die_id (int cpu);
Quoted 10 lines
arch/powerpc/include/asm/topology.h struct cpumask *cpu_coregroup_mask(int cpu); · line 138
Quoted 7 lines
arch/powerpc/include/asm/topology.h +1
-6-/* -* Points to where the LLC is. On power9 this will point at CACHE -* domain, On others it will point to SMT domain. In all cases -* cpu_l2_cache_mask points to where LLC is -*/ -#define arch_llc_mask (cpu) cpu_l2_cache_mask(cpu) +const struct cpumask *arch_llc_mask (int cpu);You will need to add
#definearch_llc_maskarch_llc_mask
Yes.
Quoted 52 lines
here.
Otherwise
kernel/sched/topology.clooks for a macro:# ifndef arch_llc_mask #define arch_llc_mask(cpu) cpu_coregroup_mask(cpu) # endifWith the #define gone, the generic code falls back to
cpu_coregroup_mask().Quoted 23 lines
arch/powerpc/include/asm/topology.h +0
-0#ifdef CONFIG_PPC64 #include <asm/smp.h> arch/powerpc/kernel/smp.c +12
-0@@ -1864,6 +1864,28 @@ void __noreturn arch_cpu_idle_dead(void)#endif +/* +* Points to where the LLC is. On power9 this will point at CACHE +* domain, On others it will point to SMT domain. In all cases +* cpu_l2_cache_mask points to where LLC is. +* +* If there is llc_override debug knob, return appropriate mask +*/ +const struct cpumask *arch_llc_mask (int cpu) +{ +switch (READ_ONCE (llc_override)) { +case LLC_OVERRIDE_SMT : +return cpu_smt_mask (cpu);arch/powerpc/kernel/smp.c void __noreturn arch_cpu_idle_dead(void) · line 1888
Quoted 10 lines
arch/powerpc/kernel/smp.c +10
-0+case LLC_OVERRIDE_MC : +return cpu_coregroup_mask (cpu); +case LLC_OVERRIDE_PKG : +return cpu_die_mask (cpu); +case LLC_OVERRIDE_DISABLED : +default : +return cpu_l2_cache_mask (cpu); + } +} +The mask here has to match the span of the highest
SD_SHARE_LLCdomain, and there seems to be some mismatches.- PKG: On power pc, seems like
cpu_die_mask()returnscpu_coregroup_mapwhen coregroups are supported,
Quoted 8 lines
if (has_coregroup_support()) return per_cpu(cpu_coregroup_map, cpu); else return cpu_node_mask(cpu);so this is the MC span while
sd_llcsits at PKG. It should becpu_node_mask(), the same astl_pkg_mask().
facepalm :/
Quoted 15 lines
- SMT: patch 3 adds
SD_SHARE_LLConly to MC/PKG, so for "smt" the flags are as before. I think it is possible for P9 to haveshared_cachesbetween two cores:/*
* P9 has a slightly odd architecture where pairs of cores share an L2 cache.
* This topology makes it *much* cheaper to migrate tasks between adjacent cores
* since the migrated task remains cache hot. We want to take advantage of this
* at the scheduler level so an extra topology level is required. */the CACHE level also has
SD_SHARE_LLC, andhighest_flag_domain()picks it, sosd_llcspanscpu_l2_cache_map.shared_cachesis only set when that map is wider
than the core's threads, e.g. a P9 core pair sharing an L2:
Quoted 8 lines
CPU: 0 1 2 3 | 4 5 6 7 cpu_smt_mask(): core A | core B sd_llc (CACHE): 0-7The ids follow
cpu_smt_mask(), so 0-3 and 4-7 get different ids whilesd_llcandsd_llc_sizecover all eight, andcpus_share_cache(0, 4)is false, which is incorrect.
Yes. I doubt anyone wants to try this experiment on Power9. But yes, functionally updating the flags is needed.
@srikar,
That is also the reason for having the disabled. By default on P9, llc will be at CACHE domain. But, one may want to experiment with =smt which i doubt anyone will ever do.
Quoted 13 lines
arch/powerpc/kernel/smp.c static ssize_t llc_override_set(struct file *file, const char __user *ubuf, · line 1948
Quoted 8 lines
arch/powerpc/kernel/smp.c +1
-0int arch_update_cpu_topology (void ) {if (READ_ONCE (llc_override_changed)) {@@ -1923,6 +1945,7 @@ static ssize_t llc_override_set(struct file *file, const char __user *ubuf,pr_info ("sched LLC override set to %s. Rebuilding sched domains\n" , llc_override_str[override]); +sched_reset_llc_id ();The reset here seems racy without taking
cpus_read_lock, and takingsched_domains_mutexfor each CPU and you could have a cpu hot plug event or cpu set rebuild in between.
Quoted 7 lines
That's why I would go with the boot parameter. The llc ids are assigned once, with the right mask, so there is nothing to reset or rebuild, no change to
kernel/sched/, and everything stays inarch/powerpc. Since this is an experiment knob, needing a reboot to change it is a small cost, and every run starts from a clean state.Tim
Yes. That is what i prefer at this moment too. It will be cleaner. Only thing is, need to get the masks right in different domains.
Quoted 33 lines
Quoted 33 lines
arch/powerpc/kernel/smp.c +0
-0rebuild_sched_domains (); }include/linux/sched.h +1
-1@@ -2505,5 +2505,5 @@ extern void migrate_enable(void);#endif /* MODULE */ DEFINE_LOCK_GUARD_0(migrate, migrate_disable(), migrate_enable()) - +void sched_reset_llc_id (void );#endif kernel/sched/topology.c +7
-0@@ -3087,6 +3087,13 @@ void sched_domains_free_llc_id(int cpu)sched_domains_mutex_unlock (); } +void sched_reset_llc_id (void ) +{ +int cpu; + +for_each_online_cpu (cpu) +sched_domains_free_llc_id (cpu); +}/* * Build sched domains for a given set of CPUs and attach the sched domains * to the individual CPUs
Quoted 28 lines · Shrikanth Hegde
Quoted 18 lines · Tim Chen
Quoted 1 line · Shrikanth Hegde
- SMT: patch 3 adds
SD_SHARE_LLConly to MC/PKG, so for "smt" the flags are as before. I think it is possible for P9 to haveshared_cachesbetween two cores:/*
* P9 has a slightly odd architecture where pairs of cores share an L2 cache.
* This topology makes it *much* cheaper to migrate tasks between adjacent cores
* since the migrated task remains cache hot. We want to take advantage of this
* at the scheduler level so an extra topology level is required. */the CACHE level also has
SD_SHARE_LLC, andhighest_flag_domain()picks it, sosd_llcspanscpu_l2_cache_map.shared_cachesis only set when that map is wider
than the core's threads, e.g. a P9 core pair sharing an L2:Quoted 8 lines
CPU: 0 1 2 3 | 4 5 6 7 cpu_smt_mask(): core A | core B sd_llc (CACHE): 0-7The ids follow
cpu_smt_mask(), so 0-3 and 4-7 get different ids whilesd_llcandsd_llc_sizecover all eight, andcpus_share_cache(0, 4)is false, which is incorrect.
Quoted 8 lines
Yes. I doubt anyone wants to try this experiment on Power9. But yes, functionally updating the flags is needed.
@srikar,
That is also the reason for having the disabled. By default on P9, llc will be at CACHE domain. But, one may want to experiment with =smt which i doubt anyone will ever do.
I think P9 is a very valid point, but I don't think we should look at disable as an option just for this.
I would say, lets keep it simple now, just have an option rather a toggle to have LLC as MC/PKG for experimentation purpose. Switch the toggle and it does back to regular LLC mode. Also we don't know how the future Power Systems LLCs will look like. So keeping it a simple toggle, will reduce pain and increase our flexibility for the future.
Whether the toggle will switch to MC or PKG could be decided based on the experiment results.
Signature · 2 lines
Thanks and Regards Srikar Dronamraju
Shrikanth Hegde
reviewerQuoted 42 lines · Srikar Dronamraju
Quoted 28 lines · Shrikanth Hegde
Quoted 18 lines · Tim Chen
Quoted 1 line · Shrikanth Hegde
- SMT: patch 3 adds
SD_SHARE_LLConly to MC/PKG, so for "smt" the flags are as before. I think it is possible for P9 to haveshared_cachesbetween two cores:/*
* P9 has a slightly odd architecture where pairs of cores share an L2 cache.
* This topology makes it *much* cheaper to migrate tasks between adjacent cores
* since the migrated task remains cache hot. We want to take advantage of this
* at the scheduler level so an extra topology level is required. */the CACHE level also has
SD_SHARE_LLC, andhighest_flag_domain()picks it, sosd_llcspanscpu_l2_cache_map.shared_cachesis only set when that map is wider
than the core's threads, e.g. a P9 core pair sharing an L2:Quoted 8 lines
CPU: 0 1 2 3 | 4 5 6 7
cpu_smt_mask(): core A | core B
sd_llc(CACHE): 0-7The ids follow
cpu_smt_mask(), so 0-3 and 4-7 get different ids whilesd_llcandsd_llc_sizecover all eight, andcpus_share_cache(0, 4)is false, which is incorrect.Quoted 8 lines
Yes. I doubt anyone wants to try this experiment on Power9. But yes, functionally updating the flags is needed.
@srikar,
That is also the reason for having the disabled. By default on P9, llc will be at CACHE domain. But, one may want to experiment with =smt which i doubt anyone will ever do.I think P9 is a very valid point, but I don't think we should look at disable as an option just for this.
Quoted 9 lines
I would say, lets keep it simple now, just have an option rather a toggle to have LLC as MC/PKG for experimentation purpose. Switch the toggle and it does back to regular LLC mode. Also we don't know how the future Power Systems LLCs will look like. So keeping it a simple toggle, will reduce pain and increase our flexibility for the future.
Whether the toggle will switch to MC or PKG could be decided based on the experiment results.
Ok. So kernel parameter "llc_override=mc/pkg" exclusively for ppc.
llc_override=mc means LLC is at MC.
llc_override=pkg means LLC is at PKG.
No kernel parameter means no change.
Hope that sounds good.
Also this new kernel parameter sounds a distant relative of split_llc.
Quoted 1 line · Tim Chen
On Mon, 2026-10-12 at 15:50 +0530, Shrikanth Hegde wrote:
[ ... ]
Quoted 25 lines
Quoted 4 lines
Tim, Chenyu, Peter,
Are there any selftest or patches which is used for functional validation of cache aware scheduling?We haven't created one. We validate mostly with workloads such as hackbench, schbench and yogini (which can vary the number of threads over time and track CPU assignment). I agree they are not ideal for functional checks of the load balance path.
Quoted 14 lines
per-LLC occupancy in
/proc/{PID}/schedstatmay not tell the full story when there are multiple processes and multiple LLC's.Atleast for functional verification, we might need one if there is not one already. The reason being,
- At present, we may need a custom workload. hackbench/schbench are wakeup intensive and typically bail out even before load balance.
- stress-ng is per process. So doesn't get cache aware scheduling.
- A selftest could spwan specific number of threads till llc size etc and ensure packing happens tillcore_count(llc_size)by default. This could also be used for tunable verfifications.
- Provide an ability to observe how much of the workload was contained within the LLC due to cache aware scheduling or number of load balances stopped due to preferred llc.
Quoted 2 lines
A selftest would be great and much welcomed.
Yes, that would be very useful. For functional testing, previously we asked AI to generate a trial test script to launch a random number of while(1) tests and watch their occupancy on each LLC.
thanks,
Chenyu