sched: ttwu_queue_cond: perform queued wakeups across different L2 caches
Subsystems (3)
RFC PATCH 1/1 sched: ttwu_queue_cond: perform queued wakeups across different L2 caches
Skipping queued wakeups for all logical CPUs sharing an LLC means that on a 192 cores AMD EPYC 9654 96-Core Processor (over 2 sockets), groups of 8 cores (16 hardware threads) end up grabbing runqueue locks of other runqueues within the same group for each wakeup, causing contention on the runqueue locks.
Improve this by only considering hardware threads sharing an L2 cache as candidates for skipping use of the queued wakeups.
This results in the following benchmark improvements:
hackbench -g 32 -f 20 --threads --pipe -l 480000 -s 100
from 49s to 34s. (30% speedup)
And similarly with perf bench:
perf bench sched messaging -g 32 -p -t -l 100000
from 10.9s to 7.4s (32% speedup)
This was developed as part of the investigation into a weird regression reported by AMD where adding a raw spinlock in the scheduler context switch accelerated hackbench. It turned out that changing this raw spinlock for a loop of 10000x cpu_relax within do_idle() had similar benefits.
This patch achieves a similar effect without busy waiting nor changing anything about runqueue selection on wakeup. It considers that only hardware threads sharing an L2 cache should skip the queued try-to-wakeup and directly grab the target runqueue lock, rather than allowing all hardware threads sharing an LLC to do so.
I would be interested to hear feedback about performance impact of this patch (improvement or regression) on other workloads and hardware, especially for Intel CPUs. One thing that we might want to empirically figure out from the topology is whether there is a maximum number of hardware threads within an LLC below which it would make sense to use the LLC rather than L2 as group within which queued wakeups can be skipped.
[ Only tested on AMD CPUs so far. ]
--- arch/Kconfig | 6 ++++++ arch/x86/Kconfig | 1 + drivers/base/Kconfig | 1 + include/linux/sched/topology.h | 3 ++- kernel/sched/core.c | 26 +++++++++++++++++++++++--- 5 files changed, 33 insertions(+), 4 deletions(-)
arch/Kconfig +6 -0
@@ -340,6 +340,12 @@ config HAVE_ASM_MODVERSIONS <asm/asm-prototypes.h> to support the module versioning for symbols exported from assembly code. +config HAVE_CLUSTERGROUP + bool + help + This symbol should be selected by an architecture if it + implements CPU clustergroup. + config HAVE_REGS_AND_STACK_ACCESS_API bool help
arch/x86/Kconfig +1 -0
@@ -299,6 +299,7 @@ config X86 select FUNCTION_ALIGNMENT_4B imply IMA_SECURE_AND_OR_TRUSTED_BOOT if EFI select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE + select HAVE_CLUSTERGROUP config INSTRUCTION_DECODER def_bool y
drivers/base/Kconfig +1 -0
@@ -218,6 +218,7 @@ config DMA_FENCE_TRACE config GENERIC_ARCH_TOPOLOGY bool + select HAVE_CLUSTERGROUP help Enable support for architectures common topology code: e.g., parsing CPU capacity information from DT, usage of such information for
include/linux/sched/topology.h +2 -1
@@ -178,7 +178,8 @@ extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],cpumask_var_t *alloc_sched_domains (unsigned int ndoms);void free_sched_domains (cpumask_var_t doms[],unsigned int ndoms); -bool cpus_share_cache (int this_cpu,int that_cpu); +bool cpus_share_cluster (int this_cpu,int that_cpu);/* Share L2. */ +bool cpus_share_cache (int this_cpu,int that_cpu);/* Share LLC. */ typedef const struct cpumask *(*sched_domain_mask_f )(int cpu);typedef int (*sched_domain_flags_f )(void );
kernel/sched/core.c +23 -3
@@ -3904,13 +3904,33 @@ void wake_up_if_idle(int cpu)rcu_read_unlock (); } +/* +* Query whether CPUs share LLC. +*/ bool cpus_share_cache (int this_cpu,int that_cpu) +{ +return per_cpu (sd_llc_id, this_cpu) ==per_cpu (sd_llc_id, that_cpu); +} + +#ifdef CONFIG_HAVE_CLUSTERGROUP +/* +* Query whether CPUs share L2 cache. +*/ +bool cpus_share_cluster (int this_cpu,int that_cpu) {if (this_cpu == that_cpu)return true; - -return per_cpu (sd_llc_id, this_cpu) ==per_cpu (sd_llc_id, that_cpu); +return cpumask_test_cpu (that_cpu,cpu_clustergroup_mask (this_cpu)); +} +#else +/* +* Fall-back on querying whether CPUs share LLC. +*/ +bool cpus_share_cluster (int this_cpu,int that_cpu) +{ +return cpus_share_cache (this_cpu, that_cpu); } +#endif static inline bool ttwu_queue_cond (struct task_struct *p,int cpu) {
@@ -3929,7 +3949,7 @@ static inline bool ttwu_queue_cond(struct task_struct *p, int cpu)* If the CPU does not share cache, then queue the task on the * remote rqs wakelist to avoid accessing remote data. */ -if (!cpus_share_cache (smp_processor_id (), cpu)) +if (!cpus_share_cluster (smp_processor_id (), cpu))return true;if (cpu ==smp_processor_id ())
Signature · 1 line
2.39.2
Vincent Guittot
maintainerQuoted 114 lines · Mathieu Desnoyers
Skipping queued wakeups for all logical CPUs sharing an LLC means that on a 192 cores AMD EPYC 9654 96-Core Processor (over 2 sockets), groups of 8 cores (16 hardware threads) end up grabbing runqueue locks of other runqueues within the same group for each wakeup, causing contention on the runqueue locks.
Improve this by only considering hardware threads sharing an L2 cache as candidates for skipping use of the queued wakeups.
This results in the following benchmark improvements:
hackbench -g 32 -f 20 --threads --pipe -l 480000 -s 100from 49s to 34s. (30% speedup)
And similarly with perf bench:
perf bench sched messaging -g 32 -p -t -l 100000
from 10.9s to 7.4s (32% speedup)
This was developed as part of the investigation into a weird regression reported by AMD where adding a raw spinlock in the scheduler context switch accelerated hackbench. It turned out that changing this raw spinlock for a loop of 10000x
cpu_relaxwithindo_idle()had similar benefits.This patch achieves a similar effect without busy waiting nor changing anything about runqueue selection on wakeup. It considers that only hardware threads sharing an L2 cache should skip the queued try-to-wakeup and directly grab the target runqueue lock, rather than allowing all hardware threads sharing an LLC to do so.
I would be interested to hear feedback about performance impact of this patch (improvement or regression) on other workloads and hardware, especially for Intel CPUs. One thing that we might want to empirically figure out from the topology is whether there is a maximum number of hardware threads within an LLC below which it would make sense to use the LLC rather than L2 as group within which queued wakeups can be skipped.
[ Only tested on AMD CPUs so far. ]
Signed-off-by Mathieu Desnoyers <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Valentin Schneider <[email protected]>Cc Steven Rostedt <[email protected]>Cc Ben Segall <[email protected]>Cc Mel Gorman <[email protected]>Cc Daniel Bristot de Oliveira <[email protected]>Cc Vincent Guittot <[email protected]>Cc Juri Lelli <[email protected]>Cc Swapnil Sapkal <[email protected]>Cc Aaron Lu <[email protected]>--- arch/Kconfig | 6 ++++++ arch/x86/Kconfig | 1 + drivers/base/Kconfig | 1 + include/linux/sched/topology.h | 3 ++- kernel/sched/core.c | 26 +++++++++++++++++++++++--- 5 files changed, 33 insertions(+), 4 deletions(-)arch/Kconfig +6
-0@@ -340,6 +340,12 @@ config HAVE_ASM_MODVERSIONS <asm/asm-prototypes.h> to support the module versioning for symbols exported from assembly code. +config HAVE_CLUSTERGROUP + bool + help + This symbol should be selected by an architecture if it + implements CPU clustergroup. + config HAVE_REGS_AND_STACK_ACCESS_API bool helparch/x86/Kconfig +1
-0@@ -299,6 +299,7 @@ config X86 select FUNCTION_ALIGNMENT_4B imply IMA_SECURE_AND_OR_TRUSTED_BOOT if EFI select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE + select HAVE_CLUSTERGROUP config INSTRUCTION_DECODER def_bool ydrivers/base/Kconfig +1
-0@@ -218,6 +218,7 @@ config DMA_FENCE_TRACE config GENERIC_ARCH_TOPOLOGY bool + select HAVE_CLUSTERGROUP help Enable support for architectures common topology code: e.g., parsing CPU capacity information from DT, usage of such information forinclude/linux/sched/topology.h +0
-0
include/linux/sched/topology.h extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], · line 182
Quoted 6 lines
include/linux/sched/topology.h +2
-1@@ -178,7 +178,8 @@ extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],cpumask_var_t *alloc_sched_domains (unsigned int ndoms);void free_sched_domains (cpumask_var_t doms[],unsigned int ndoms); -bool cpus_share_cache (int this_cpu,int that_cpu); +bool cpus_share_cluster (int this_cpu,int that_cpu);/* Share L2. */ +bool cpus_share_cache (int this_cpu,int that_cpu);/* Share LLC. */
I think that Yicong is doing what you want with cpus_share_lowest_cache() which points to cluster when available or LLC otherwise
https://lore.kernel.org/lkml/[email protected]/t/#m0ab9fa0fe0c3779b9bbadcfbc1b643dce7cb7618
Quoted 55 lines
include/linux/sched/topology.h +0
-0typedef const struct cpumask *(*sched_domain_mask_f )(int cpu);typedef int (*sched_domain_flags_f )(void );kernel/sched/core.c +23
-4@@ -3904,13 +3904,33 @@ void wake_up_if_idle(int cpu)rcu_read_unlock (); } +/* +* Query whether CPUs share LLC. +*/ bool cpus_share_cache (int this_cpu,int that_cpu) +{ +return per_cpu (sd_llc_id, this_cpu) ==per_cpu (sd_llc_id, that_cpu); +} + +#ifdef CONFIG_HAVE_CLUSTERGROUP +/* +* Query whether CPUs share L2 cache. +*/ +bool cpus_share_cluster (int this_cpu,int that_cpu) {if (this_cpu == that_cpu)return true; - -return per_cpu (sd_llc_id, this_cpu) ==per_cpu (sd_llc_id, that_cpu); +return cpumask_test_cpu (that_cpu,cpu_clustergroup_mask (this_cpu)); +} +#else +/* +* Fall-back on querying whether CPUs share LLC. +*/ +bool cpus_share_cluster (int this_cpu,int that_cpu) +{ +return cpus_share_cache (this_cpu, that_cpu); } +#endif static inline bool ttwu_queue_cond (struct task_struct *p,int cpu) {@@ -3929,7 +3949,7 @@ static inline bool ttwu_queue_cond(struct task_struct *p, int cpu)* If the CPU does not share cache, then queue the task on the * remote rqs wakelist to avoid accessing remote data. */ -if (!cpus_share_cache (smp_processor_id (), cpu)) +if (!cpus_share_cluster (smp_processor_id (), cpu))return true;if (cpu ==smp_processor_id ()) --2.39.2
Quoted 8 lines · Vincent Guittot
Quoted 6 lines · Mathieu Desnoyers
Skipping queued wakeups for all logical CPUs sharing an LLC means that on a 192 cores AMD EPYC 9654 96-Core Processor (over 2 sockets), groups of 8 cores (16 hardware threads) end up grabbing runqueue locks of other runqueues within the same group for each wakeup, causing contention on the runqueue locks.
[...]
Quoted 10 lines
include/linux/sched/topology.h extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], · line 182
Quoted 4 lines
include/linux/sched/topology.h +2
-1-bool cpus_share_cache (int this_cpu,int that_cpu); +bool cpus_share_cluster (int this_cpu,int that_cpu);/* Share L2. */ +bool cpus_share_cache (int this_cpu,int that_cpu);/* Share LLC. */ I think that Yicong is doing what you want with
cpus_share_lowest_cache()which points to cluster when available or LLC otherwise
https://lore.kernel.org/lkml/[email protected]/t/#m0ab9fa0fe0c3779b9bbadcfbc1b643dce7cb7618
AFAIU (please correct me if I'm wrong) my AMD EPYC machine has sockets consisting of 12 clusters, each cluster having its own L3 cache.
What I am trying to achieve here is really to implement "cpus_share_l2": I want this to match only when the cpus have a common L2 cache. L3 appears to be a group which is either:
- too large (16 hw threads) or
- have a too high access latency.
I'm not certain which (or if both) of those reasons explain why grouping by L2 is better here.
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Quoted 23 lines · Mathieu Desnoyers
Quoted 8 lines · Vincent Guittot
Quoted 6 lines · Mathieu Desnoyers
Skipping queued wakeups for all logical CPUs sharing an LLC means that on a 192 cores AMD EPYC 9654 96-Core Processor (over 2 sockets), groups of 8 cores (16 hardware threads) end up grabbing runqueue locks of other runqueues within the same group for each wakeup, causing contention on the runqueue locks.
[...]
Quoted 10 lines
include/linux/sched/topology.h extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], · line 182
Quoted 4 lines
include/linux/sched/topology.h +2
-1-bool cpus_share_cache (int this_cpu,int that_cpu); +bool cpus_share_cluster(int this_cpu, int that_cpu); /* Share L2. */ +bool cpus_share_cache(int this_cpu, int that_cpu); /* Share LLC. */I think that Yicong is doing what you want with
cpus_share_lowest_cache()which points to cluster when available or LLC otherwise
https://lore.kernel.org/lkml/[email protected]/t/#m0ab9fa0fe0c3779b9bbadcfbc1b643dce7cb7618AFAIU (please correct me if I'm wrong) my AMD EPYC machine has sockets consisting of 12 clusters, each cluster having its own L3 cache.
Quoted 7 lines
What I am trying to achieve here is really to implement "
cpus_share_l2": I want this to match only when the cpus have a common L2 cache. L3 appears to be a group which is either:- too large (16 hw threads) or
- have a too high access latency.I'm not certain which (or if both) of those reasons explain why grouping by L2 is better here.
Re-reading the patch you pointed me to, I notice:
"+ * Whether CPUs are share lowest cache, which means LLC on non-cluster
+ * machines and LLC tag or L2 on machines with clusters."
So this "share lowest cache" really means lowest in terms of number, e.g. L2 < L3, and not "lowest in the hierarchy" as is "closest to memory", correct ?
Thanks,
Mathieu
Quoted 5 lines
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Vincent Guittot
maintainerQuoted 36 lines · Mathieu Desnoyers
Quoted 28 lines · Mathieu Desnoyers
Quoted 8 lines · Vincent Guittot
Quoted 6 lines · Mathieu Desnoyers
Skipping queued wakeups for all logical CPUs sharing an LLC means that on a 192 cores AMD EPYC 9654 96-Core Processor (over 2 sockets), groups of 8 cores (16 hardware threads) end up grabbing runqueue locks of other runqueues within the same group for each wakeup, causing contention on the runqueue locks.
[...]
Quoted 10 lines
include/linux/sched/topology.h extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], · line 182
Quoted 4 lines
include/linux/sched/topology.h +2
-1-bool cpus_share_cache (int this_cpu,int that_cpu); +bool cpus_share_cluster (int this_cpu,int that_cpu);/* Share L2. */ +bool cpus_share_cache (int this_cpu,int that_cpu);/* Share LLC. */ I think that Yicong is doing what you want with
cpus_share_lowest_cache()which points to cluster when available or LLC otherwise
https://lore.kernel.org/lkml/[email protected]/t/#m0ab9fa0fe0c3779b9bbadcfbc1b643dce7cb7618AFAIU (please correct me if I'm wrong) my AMD EPYC machine has sockets consisting of 12 clusters, each cluster having its own L3 cache.
What I am trying to achieve here is really to implement "
cpus_share_l2":
I want this to match only when the cpus have a common L2 cache. L3 appears to be a group which is either:Quoted 5 lines
- too large (16 hw threads) or
- have a too high access latency.I'm not certain which (or if both) of those reasons explain why grouping by L2 is better here.
Quoted 8 lines
Re-reading the patch you pointed me to, I notice:
"+ * Whether CPUs are share lowest cache, which means LLC on non-cluster
+ * machines and LLC tag or L2 on machines with clusters."So this "share lowest cache" really means lowest in terms of number, e.g. L2 < L3, and not "lowest in the hierarchy" as is "closest to memory", correct ?
Yes
Quoted 16 lines
Thanks,
Mathieu
Quoted 5 lines
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
K Prateek Nayak
reviewerHello Vincent, Mathieu,
Quoted 119 lines · Vincent Guittot
Quoted 117 lines · Mathieu Desnoyers
Skipping queued wakeups for all logical CPUs sharing an LLC means that on a 192 cores AMD EPYC 9654 96-Core Processor (over 2 sockets), groups of 8 cores (16 hardware threads) end up grabbing runqueue locks of other runqueues within the same group for each wakeup, causing contention on the runqueue locks.
Improve this by only considering hardware threads sharing an L2 cache as candidates for skipping use of the queued wakeups.
This results in the following benchmark improvements:
hackbench -g 32 -f 20 --threads --pipe -l 480000 -s 100from 49s to 34s. (30% speedup)
And similarly with perf bench:
perf bench sched messaging -g 32 -p -t -l 100000
from 10.9s to 7.4s (32% speedup)
This was developed as part of the investigation into a weird regression reported by AMD where adding a raw spinlock in the scheduler context switch accelerated hackbench. It turned out that changing this raw spinlock for a loop of 10000x
cpu_relaxwithindo_idle()had similar benefits.This patch achieves a similar effect without busy waiting nor changing anything about runqueue selection on wakeup. It considers that only hardware threads sharing an L2 cache should skip the queued try-to-wakeup and directly grab the target runqueue lock, rather than allowing all hardware threads sharing an LLC to do so.
I would be interested to hear feedback about performance impact of this patch (improvement or regression) on other workloads and hardware, especially for Intel CPUs. One thing that we might want to empirically figure out from the topology is whether there is a maximum number of hardware threads within an LLC below which it would make sense to use the LLC rather than L2 as group within which queued wakeups can be skipped.
[ Only tested on AMD CPUs so far. ]
Signed-off-by Mathieu Desnoyers <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Valentin Schneider <[email protected]>Cc Steven Rostedt <[email protected]>Cc Ben Segall <[email protected]>Cc Mel Gorman <[email protected]>Cc Daniel Bristot de Oliveira <[email protected]>Cc Vincent Guittot <[email protected]>Cc Juri Lelli <[email protected]>Cc Swapnil Sapkal <[email protected]>Cc Aaron Lu <[email protected]>--- arch/Kconfig | 6 ++++++ arch/x86/Kconfig | 1 + drivers/base/Kconfig | 1 + include/linux/sched/topology.h | 3 ++- kernel/sched/core.c | 26 +++++++++++++++++++++++--- 5 files changed, 33 insertions(+), 4 deletions(-)arch/Kconfig +6
-0@@ -340,6 +340,12 @@ config HAVE_ASM_MODVERSIONS <asm/asm-prototypes.h> to support the module versioning for symbols exported from assembly code. +config HAVE_CLUSTERGROUP + bool + help + This symbol should be selected by an architecture if it + implements CPU clustergroup. + config HAVE_REGS_AND_STACK_ACCESS_API bool helparch/x86/Kconfig +1
-0@@ -299,6 +299,7 @@ config X86 select FUNCTION_ALIGNMENT_4B imply IMA_SECURE_AND_OR_TRUSTED_BOOT if EFI select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE + select HAVE_CLUSTERGROUP config INSTRUCTION_DECODER def_bool ydrivers/base/Kconfig +1
-0@@ -218,6 +218,7 @@ config DMA_FENCE_TRACE config GENERIC_ARCH_TOPOLOGY bool + select HAVE_CLUSTERGROUP help Enable support for architectures common topology code: e.g., parsing CPU capacity information from DT, usage of such information forinclude/linux/sched/topology.h +0
-0@@ -178,7 +178,8 @@ extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],cpumask_var_t *alloc_sched_domains (unsigned int ndoms);void free_sched_domains (cpumask_var_t doms[],unsigned int ndoms);
Quoted 8 lines
include/linux/sched/topology.h extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], · line 182
Quoted 3 lines
include/linux/sched/topology.h +2
-1-bool cpus_share_cache (int this_cpu,int that_cpu); +bool cpus_share_cluster (int this_cpu,int that_cpu);/* Share L2. */ +bool cpus_share_cache (int this_cpu,int that_cpu);/* Share LLC. */ I think that Yicong is doing what you want with
cpus_share_lowest_cache()which points to cluster when available or LLC otherwise
https://lore.kernel.org/lkml/[email protected]/t/#m0ab9fa0fe0c3779b9bbadcfbc1b643dce7cb7618
Please correct me if I'm wrong, but with Yicong's latest version
(https://lore.kernel.org/lkml/[email protected]/)
"sd_share_id" will follow "sd_llc_id" if the SD_CLUSTER domain is degenerated, which is the case with any system where CLUSTER domain is same as SMT domain.
On logging the cpu and sd_share_id on my 3rd Gen EPYC system I see,
CPU(0) sd_share_id(0)
CPU(1) sd_share_id(0)
CPU(2) sd_share_id(0)
CPU(3) sd_share_id(0)
CPU(4) sd_share_id(0)
CPU(5) sd_share_id(0)
CPU(6) sd_share_id(0)
CPU(7) sd_share_id(0)
CPU(8) sd_share_id(8)
CPU(9) sd_share_id(8)
...
CPU(127) sd_share_id(120)
CPU(128) sd_share_id(0)
CPU(129) sd_share_id(0)
CPU(130) sd_share_id(0)
CPU(131) sd_share_id(0)
CPU(132) sd_share_id(0)
CPU(133) sd_share_id(0)
CPU(134) sd_share_id(0)
CPU(135) sd_share_id(0)
CPU(136) sd_share_id(8)
..."sd_share_id" follows the "sd_llc_id" since CLUSTER domain is degenerated.
# echo Y > /sys/kernel/debug/sched/verbose
# cat /sys/kernel/debug/sched/domains/cpu0/domain*/flags
SD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_SHARE_CPUCAPACITY SD_SHARE_PKG_RESOURCES SD_PREFER_SIBLING # SMT Domain
SD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_SHARE_PKG_RESOURCES SD_PREFER_SIBLING # MC Domain
SD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_PREFER_SIBLING # DIE Domain
SD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_SERIALIZE SD_OVERLAP SD_NUMA # NUMA DomainBut I believe Mathieu's case would require falling back to "core_id" if the cluster domain has degenerated.
--
Thanks and Regards,
Prateek
Quoted 171 lines · K Prateek Nayak
Hello Vincent, Mathieu,
Quoted 119 lines · Vincent Guittot
Quoted 117 lines · Mathieu Desnoyers
Skipping queued wakeups for all logical CPUs sharing an LLC means that on a 192 cores AMD EPYC 9654 96-Core Processor (over 2 sockets), groups of 8 cores (16 hardware threads) end up grabbing runqueue locks of other runqueues within the same group for each wakeup, causing contention on the runqueue locks.
Improve this by only considering hardware threads sharing an L2 cache as candidates for skipping use of the queued wakeups.
This results in the following benchmark improvements:
hackbench -g 32 -f 20 --threads --pipe -l 480000 -s 100from 49s to 34s. (30% speedup)
And similarly with perf bench:
perf bench sched messaging -g 32 -p -t -l 100000
from 10.9s to 7.4s (32% speedup)
This was developed as part of the investigation into a weird regression reported by AMD where adding a raw spinlock in the scheduler context switch accelerated hackbench. It turned out that changing this raw spinlock for a loop of 10000x
cpu_relaxwithindo_idle()had similar benefits.This patch achieves a similar effect without busy waiting nor changing anything about runqueue selection on wakeup. It considers that only hardware threads sharing an L2 cache should skip the queued try-to-wakeup and directly grab the target runqueue lock, rather than allowing all hardware threads sharing an LLC to do so.
I would be interested to hear feedback about performance impact of this patch (improvement or regression) on other workloads and hardware, especially for Intel CPUs. One thing that we might want to empirically figure out from the topology is whether there is a maximum number of hardware threads within an LLC below which it would make sense to use the LLC rather than L2 as group within which queued wakeups can be skipped.
[ Only tested on AMD CPUs so far. ]
Signed-off-by Mathieu Desnoyers <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Valentin Schneider <[email protected]>Cc Steven Rostedt <[email protected]>Cc Ben Segall <[email protected]>Cc Mel Gorman <[email protected]>Cc Daniel Bristot de Oliveira <[email protected]>Cc Vincent Guittot <[email protected]>Cc Juri Lelli <[email protected]>Cc Swapnil Sapkal <[email protected]>Cc Aaron Lu <[email protected]>--- arch/Kconfig | 6 ++++++ arch/x86/Kconfig | 1 + drivers/base/Kconfig | 1 + include/linux/sched/topology.h | 3 ++- kernel/sched/core.c | 26 +++++++++++++++++++++++--- 5 files changed, 33 insertions(+), 4 deletions(-)arch/Kconfig +6
-0@@ -340,6 +340,12 @@ config HAVE_ASM_MODVERSIONS <asm/asm-prototypes.h> to support the module versioning for symbols exported from assembly code. +config HAVE_CLUSTERGROUP + bool + help + This symbol should be selected by an architecture if it + implements CPU clustergroup. + config HAVE_REGS_AND_STACK_ACCESS_API bool helparch/x86/Kconfig +1
-0@@ -299,6 +299,7 @@ config X86 select FUNCTION_ALIGNMENT_4B imply IMA_SECURE_AND_OR_TRUSTED_BOOT if EFI select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE + select HAVE_CLUSTERGROUP config INSTRUCTION_DECODER def_bool ydrivers/base/Kconfig +1
-0@@ -218,6 +218,7 @@ config DMA_FENCE_TRACE config GENERIC_ARCH_TOPOLOGY bool + select HAVE_CLUSTERGROUP help Enable support for architectures common topology code: e.g., parsing CPU capacity information from DT, usage of such information forinclude/linux/sched/topology.h +0
-0@@ -178,7 +178,8 @@ extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],cpumask_var_t *alloc_sched_domains (unsigned int ndoms);void free_sched_domains (cpumask_var_t doms[],unsigned int ndoms);Quoted 8 lines
include/linux/sched/topology.h extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[], · line 182
Quoted 3 lines
include/linux/sched/topology.h +2
-1-bool cpus_share_cache (int this_cpu,int that_cpu); +bool cpus_share_cluster (int this_cpu,int that_cpu);/* Share L2. */ +bool cpus_share_cache (int this_cpu,int that_cpu);/* Share LLC. */ I think that Yicong is doing what you want with
cpus_share_lowest_cache()which points to cluster when available or LLC otherwise
https://lore.kernel.org/lkml/[email protected]/t/#m0ab9fa0fe0c3779b9bbadcfbc1b643dce7cb7618Please correct me if I'm wrong, but with Yicong's latest version
(https://lore.kernel.org/lkml/[email protected]/)
"sd_share_id" will follow "sd_llc_id" if theSD_CLUSTERdomain is degenerated, which is the case with any system where CLUSTER domain is same as SMT domain.On logging the cpu and
sd_share_idon my 3rd Gen EPYC system I see,CPU(0) sd_share_id(0) CPU(1) sd_share_id(0) CPU(2) sd_share_id(0) CPU(3) sd_share_id(0) CPU(4) sd_share_id(0) CPU(5) sd_share_id(0) CPU(6) sd_share_id(0) CPU(7) sd_share_id(0) CPU(8) sd_share_id(8) CPU(9) sd_share_id(8) ... CPU(127) sd_share_id(120) CPU(128) sd_share_id(0) CPU(129) sd_share_id(0) CPU(130) sd_share_id(0) CPU(131) sd_share_id(0) CPU(132) sd_share_id(0) CPU(133) sd_share_id(0) CPU(134) sd_share_id(0) CPU(135) sd_share_id(0) CPU(136) sd_share_id(8) ..."
sd_share_id" follows the "sd_llc_id" since CLUSTER domain is degenerated.# echo Y > /sys/kernel/debug/sched/verbose # cat /sys/kernel/debug/sched/domains/cpu0/domain*/flags SD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_SHARE_CPUCAPACITY SD_SHARE_PKG_RESOURCES SD_PREFER_SIBLING # SMT Domain SD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_SHARE_PKG_RESOURCES SD_PREFER_SIBLING # MC Domain SD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_PREFER_SIBLING # DIE Domain SD_BALANCE_NEWIDLE SD_BALANCE_EXEC SD_BALANCE_FORK SD_WAKE_AFFINE SD_SERIALIZE SD_OVERLAP SD_NUMA # NUMA Domain
Quoted 2 lines
But I believe Mathieu's case would require falling back to "
core_id" if the cluster domain has degenerated.
Yes, I've noticed the same thing on my system. I'm preparing an updated patchset which renames cpus_share_cache() to cpus_share_llc(), and introduces a new cpus_share_l2c() based on a new sd_l2c_id per-cpu variable derived from topology_cluster_cpumask(). It seems to work fine so far.
Thanks,
Mathieu
Quoted 4 lines
--
Thanks and Regards,
Prateek
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com