mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs
@ 2026-10-12 10:20 Shrikanth Hegde
  2026-10-12 10:20 ` [PATCH 1/4] powerpc/topology: Introduce llc_override debug knob Shrikanth Hegde
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Shrikanth Hegde @ 2026-10-12 10:20 UTC (permalink / raw)
  To: maddy, linuxppc-dev, peterz, tim.c.chen
  Cc: sshegde, christophe.leroy, linux-kernel, ritesh.list,
	kprateek.nayak, yu.c.chen, vineethr, vincent.guittot, srikar,
	npiggin, mpe

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/cover.1778703694.git.tim.c.chen@linux.intel.com/

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

-- 
2.52.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/4] powerpc/topology: Introduce llc_override debug knob
  2026-10-12 10:20 [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs Shrikanth Hegde
@ 2026-10-12 10:20 ` Shrikanth Hegde
  2026-10-12 12:14   ` Srikar Dronamraju
  2026-10-12 10:20 ` [PATCH 2/4] powerpc/topology: Add docs for llc_override Shrikanth Hegde
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Shrikanth Hegde @ 2026-10-12 10:20 UTC (permalink / raw)
  To: maddy, linuxppc-dev, peterz, tim.c.chen
  Cc: sshegde, christophe.leroy, linux-kernel, ritesh.list,
	kprateek.nayak, yu.c.chen, vineethr, vincent.guittot, srikar,
	npiggin, mpe

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.

Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
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(+)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 6a5a5469aaae..433757511adb 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -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);
-- 
2.52.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 2/4] powerpc/topology: Add docs for llc_override
  2026-10-12 10:20 [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs Shrikanth Hegde
  2026-10-12 10:20 ` [PATCH 1/4] powerpc/topology: Introduce llc_override debug knob Shrikanth Hegde
@ 2026-10-12 10:20 ` Shrikanth Hegde
  2026-10-12 10:20 ` [PATCH 3/4] powerpc/topology: Update mc/pkg flags based on llc_override Shrikanth Hegde
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Shrikanth Hegde @ 2026-10-12 10:20 UTC (permalink / raw)
  To: maddy, linuxppc-dev, peterz, tim.c.chen
  Cc: sshegde, christophe.leroy, linux-kernel, ritesh.list,
	kprateek.nayak, yu.c.chen, vineethr, vincent.guittot, srikar,
	npiggin, mpe

Provide documentation for the newly introduced debug knob
named as llc_override.

This may help one if they want to experiment with cache aware
scheduling.

Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
 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

diff --git a/Documentation/arch/powerpc/index.rst b/Documentation/arch/powerpc/index.rst
index 40419bea8e10..0f4caf50a9e7 100644
--- a/Documentation/arch/powerpc/index.rst
+++ b/Documentation/arch/powerpc/index.rst
@@ -33,6 +33,7 @@ powerpc
     qe_firmware
     syscall64-abi
     transactional_memory
+    topology
     ultravisor
     vas-api
     vcpudispatch_stats
diff --git a/Documentation/arch/powerpc/topology.rst b/Documentation/arch/powerpc/topology.rst
new file mode 100644
index 000000000000..9ed3cf7ade69
--- /dev/null
+++ b/Documentation/arch/powerpc/topology.rst
@@ -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.
-- 
2.52.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 3/4] powerpc/topology: Update mc/pkg flags based on llc_override
  2026-10-12 10:20 [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs Shrikanth Hegde
  2026-10-12 10:20 ` [PATCH 1/4] powerpc/topology: Introduce llc_override debug knob Shrikanth Hegde
  2026-10-12 10:20 ` [PATCH 2/4] powerpc/topology: Add docs for llc_override Shrikanth Hegde
@ 2026-10-12 10:20 ` Shrikanth Hegde
  2026-10-12 10:20 ` [PATCH 4/4] powerpc/topology: Rebuild sched domains on llc_override change Shrikanth Hegde
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Shrikanth Hegde @ 2026-10-12 10:20 UTC (permalink / raw)
  To: maddy, linuxppc-dev, peterz, tim.c.chen
  Cc: sshegde, christophe.leroy, linux-kernel, ritesh.list,
	kprateek.nayak, yu.c.chen, vineethr, vincent.guittot, srikar,
	npiggin, mpe

Update 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.

Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
 arch/powerpc/kernel/smp.c | 63 +++++++++++++++++++++++++--------------
 1 file changed, 40 insertions(+), 23 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 433757511adb..4b6512d25f73 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -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)
 {
-- 
2.52.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 4/4] powerpc/topology: Rebuild sched domains on llc_override change
  2026-10-12 10:20 [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs Shrikanth Hegde
                   ` (2 preceding siblings ...)
  2026-10-12 10:20 ` [PATCH 3/4] powerpc/topology: Update mc/pkg flags based on llc_override Shrikanth Hegde
@ 2026-10-12 10:20 ` Shrikanth Hegde
  2026-10-12 12:19 ` [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs Srikar Dronamraju
  2026-10-12 21:15 ` Tim Chen
  5 siblings, 0 replies; 13+ messages in thread
From: Shrikanth Hegde @ 2026-10-12 10:20 UTC (permalink / raw)
  To: maddy, linuxppc-dev, peterz, tim.c.chen
  Cc: sshegde, christophe.leroy, linux-kernel, ritesh.list,
	kprateek.nayak, yu.c.chen, vineethr, vincent.guittot, srikar,
	npiggin, mpe

On 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_override
SD_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_override
SD_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

Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
 arch/powerpc/kernel/smp.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 4b6512d25f73..6a4ee7d3b8e5 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -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);
-- 
2.52.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] powerpc/topology: Introduce llc_override debug knob
  2026-10-12 10:20 ` [PATCH 1/4] powerpc/topology: Introduce llc_override debug knob Shrikanth Hegde
@ 2026-10-12 12:14   ` Srikar Dronamraju
  2026-10-12 14:10     ` Shrikanth Hegde
  0 siblings, 1 reply; 13+ messages in thread
From: Srikar Dronamraju @ 2026-10-12 12:14 UTC (permalink / raw)
  To: Shrikanth Hegde
  Cc: maddy, linuxppc-dev, peterz, tim.c.chen, christophe.leroy,
	linux-kernel, ritesh.list, kprateek.nayak, yu.c.chen, vineethr,
	vincent.guittot, npiggin, mpe

* Shrikanth Hegde <sshegde@linux.ibm.com> [2026-10-12 15:50:34]:

Hi Shrikanth,

> 
> 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.
> 

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.

> 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 <sshegde@linux.ibm.com>
> ---
> 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(+)
> 
> diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
> index 6a5a5469aaae..433757511adb 100644
> --- a/arch/powerpc/kernel/smp.c
> +++ b/arch/powerpc/kernel/smp.c
> @@ -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,
> +};
> +

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.


-- 
Thanks and Regards
Srikar Dronamraju

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs
  2026-10-12 10:20 [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs Shrikanth Hegde
                   ` (3 preceding siblings ...)
  2026-10-12 10:20 ` [PATCH 4/4] powerpc/topology: Rebuild sched domains on llc_override change Shrikanth Hegde
@ 2026-10-12 12:19 ` Srikar Dronamraju
  2026-10-12 14:14   ` Shrikanth Hegde
  2026-10-12 21:15 ` Tim Chen
  5 siblings, 1 reply; 13+ messages in thread
From: Srikar Dronamraju @ 2026-10-12 12:19 UTC (permalink / raw)
  To: Shrikanth Hegde
  Cc: maddy, linuxppc-dev, peterz, tim.c.chen, christophe.leroy,
	linux-kernel, ritesh.list, kprateek.nayak, yu.c.chen, vineethr,
	vincent.guittot, npiggin, mpe

* Shrikanth Hegde <sshegde@linux.ibm.com> [2026-10-12 15:50:33]:


Hi Shrikanth,

> 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.
> 

Can we add a reference to the earlier attempt to try MCLLC a few years back.

-- 
Thanks and Regards
Srikar Dronamraju

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/4] powerpc/topology: Introduce llc_override debug knob
  2026-10-12 12:14   ` Srikar Dronamraju
@ 2026-10-12 14:10     ` Shrikanth Hegde
  0 siblings, 0 replies; 13+ messages in thread
From: Shrikanth Hegde @ 2026-10-12 14:10 UTC (permalink / raw)
  To: Srikar Dronamraju
  Cc: maddy, linuxppc-dev, peterz, tim.c.chen, christophe.leroy,
	linux-kernel, ritesh.list, kprateek.nayak, yu.c.chen, vineethr,
	vincent.guittot, npiggin, mpe

Hi Srikar. Thanks for taking a look at the patches.
    
>>   #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.
> 
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.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs
  2026-10-12 12:19 ` [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs Srikar Dronamraju
@ 2026-10-12 14:14   ` Shrikanth Hegde
  0 siblings, 0 replies; 13+ messages in thread
From: Shrikanth Hegde @ 2026-10-12 14:14 UTC (permalink / raw)
  To: Srikar Dronamraju
  Cc: maddy, linuxppc-dev, peterz, tim.c.chen, christophe.leroy,
	linux-kernel, ritesh.list, kprateek.nayak, yu.c.chen, vineethr,
	vincent.guittot, npiggin, mpe



On 10/12/26 5:49 PM, Srikar Dronamraju wrote:
> * Shrikanth Hegde <sshegde@linux.ibm.com> [2026-10-12 15:50:33]:
> 
> 
> Hi Shrikanth,
> 
>> 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.
>>
> 
> 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/1617341874-1205-1-git-send-email-ego@linux.vnet.ibm.com/

But I couldn't find an email id of Gautham which won't bounce. Based on what i know :)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs
  2026-10-12 10:20 [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs Shrikanth Hegde
                   ` (4 preceding siblings ...)
  2026-10-12 12:19 ` [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs Srikar Dronamraju
@ 2026-10-12 21:15 ` Tim Chen
  2026-10-13  9:58   ` Shrikanth Hegde
  2026-10-13 10:05   ` Chen, Yu C
  5 siblings, 2 replies; 13+ messages in thread
From: Tim Chen @ 2026-10-12 21:15 UTC (permalink / raw)
  To: Shrikanth Hegde, maddy, linuxppc-dev, peterz
  Cc: christophe.leroy, linux-kernel, ritesh.list, kprateek.nayak,
	yu.c.chen, vineethr, vincent.guittot, srikar, npiggin, mpe

On Mon, 2026-10-12 at 15:50 +0530, Shrikanth Hegde wrote:
> 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/cover.1778703694.git.tim.c.chen@linux.intel.com/

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.

> 
> 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.

> 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.

A selftest would be great and much welcomed.  

Tim

> 
> 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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs
  2026-10-12 21:15 ` Tim Chen
@ 2026-10-13  9:58   ` Shrikanth Hegde
  2026-10-13 20:44     ` Tim Chen
  2026-10-13 10:05   ` Chen, Yu C
  1 sibling, 1 reply; 13+ messages in thread
From: Shrikanth Hegde @ 2026-10-13  9:58 UTC (permalink / raw)
  To: Tim Chen, maddy, linuxppc-dev, peterz
  Cc: christophe.leroy, linux-kernel, ritesh.list, kprateek.nayak,
	yu.c.chen, vineethr, vincent.guittot, srikar, npiggin, mpe

Hi Tim, Thanks for taking a look and findings.

On 10/13/26 2:45 AM, Tim Chen wrote:
> On Mon, 2026-10-12 at 15:50 +0530, Shrikanth Hegde wrote:
>> 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/cover.1778703694.git.tim.c.chen@linux.intel.com/
> 
> 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.
> 

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(-)

diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h
index 44ec416fa489..f4555632e692 100644
--- a/arch/powerpc/include/asm/topology.h
+++ b/arch/powerpc/include/asm/topology.h
@@ -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>
diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
index 6a4ee7d3b8e5..139c54fc3e2d 100644
--- a/arch/powerpc/kernel/smp.c
+++ b/arch/powerpc/kernel/smp.c
@@ -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();
  	}
  
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 7b91cae4a59c..4d7e2ee841a9 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -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
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index dd2b1d70ec9d..63c9bca4c5eb 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -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
-- 
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?
>>
>> 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.
> 
>> 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.
> 
> 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!.

> Tim
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs
  2026-10-12 21:15 ` Tim Chen
  2026-10-13  9:58   ` Shrikanth Hegde
@ 2026-10-13 10:05   ` Chen, Yu C
  1 sibling, 0 replies; 13+ messages in thread
From: Chen, Yu C @ 2026-10-13 10:05 UTC (permalink / raw)
  To: Tim Chen, Shrikanth Hegde
  Cc: christophe.leroy, linux-kernel, ritesh.list, kprateek.nayak,
	vineethr, vincent.guittot, srikar, npiggin, mpe, maddy,
	linuxppc-dev, peterz

On 10/13/2026 5:15 AM, Tim Chen wrote:
> On Mon, 2026-10-12 at 15:50 +0530, Shrikanth Hegde wrote:

[ ... ]

>>
>> 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.
> 
>> 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.
> 
> 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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs
  2026-10-13  9:58   ` Shrikanth Hegde
@ 2026-10-13 20:44     ` Tim Chen
  0 siblings, 0 replies; 13+ messages in thread
From: Tim Chen @ 2026-10-13 20:44 UTC (permalink / raw)
  To: Shrikanth Hegde, maddy, linuxppc-dev, peterz
  Cc: christophe.leroy, linux-kernel, ritesh.list, kprateek.nayak,
	yu.c.chen, vineethr, vincent.guittot, srikar, npiggin, mpe

On Tue, 2026-10-13 at 15:28 +0530, Shrikanth Hegde wrote:
> 

[snip]

> 
> 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(-)
> 
> diff --git a/arch/powerpc/include/asm/topology.h b/arch/powerpc/include/asm/topology.h
> index 44ec416fa489..f4555632e692 100644
> --- a/arch/powerpc/include/asm/topology.h
> +++ b/arch/powerpc/include/asm/topology.h
> @@ -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().

>   
>   #ifdef CONFIG_PPC64
>   #include <asm/smp.h>
> diff --git a/arch/powerpc/kernel/smp.c b/arch/powerpc/kernel/smp.c
> index 6a4ee7d3b8e5..139c54fc3e2d 100644
> --- a/arch/powerpc/kernel/smp.c
> +++ b/arch/powerpc/kernel/smp.c
> @@ -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);
> +	}
> +}
> +

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.

>   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();

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

>   		rebuild_sched_domains();
>   	}
>   
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 7b91cae4a59c..4d7e2ee841a9 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -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
> diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
> index dd2b1d70ec9d..63c9bca4c5eb 100644
> --- a/kernel/sched/topology.c
> +++ b/kernel/sched/topology.c
> @@ -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

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-10-13 20:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-12 10:20 [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs Shrikanth Hegde
2026-10-12 10:20 ` [PATCH 1/4] powerpc/topology: Introduce llc_override debug knob Shrikanth Hegde
2026-10-12 12:14   ` Srikar Dronamraju
2026-10-12 14:10     ` Shrikanth Hegde
2026-10-12 10:20 ` [PATCH 2/4] powerpc/topology: Add docs for llc_override Shrikanth Hegde
2026-10-12 10:20 ` [PATCH 3/4] powerpc/topology: Update mc/pkg flags based on llc_override Shrikanth Hegde
2026-10-12 10:20 ` [PATCH 4/4] powerpc/topology: Rebuild sched domains on llc_override change Shrikanth Hegde
2026-10-12 12:19 ` [PATCH 0/4] powerpc/topology: Introduce llc_override debugfs Srikar Dronamraju
2026-10-12 14:14   ` Shrikanth Hegde
2026-10-12 21:15 ` Tim Chen
2026-10-13  9:58   ` Shrikanth Hegde
2026-10-13 20:44     ` Tim Chen
2026-10-13 10:05   ` Chen, Yu C

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®