sched/fair: Prefer fully-idle SMT cores in asym-capacity idle selection
PATCH 1/1 sched/fair: Prefer fully-idle SMT cores in asym-capacity idle selection
On systems with asymmetric CPU capacity (e.g., ACPI/CPPC reporting different per-core frequencies), the wakeup path uses select_idle_capacity() and prioritizes idle CPUs with higher capacity for better task placement. However, when those CPUs belong to SMT cores, their effective capacity can be much lower than the nominal capacity when the sibling thread is busy: SMT siblings compete for shared resources, so a "high capacity" CPU that is idle but whose sibling is busy does not deliver its full capacity. This effective capacity reduction cannot be modeled by the static capacity value alone.
Introduce SMT awareness in the asym-capacity idle selection policy: when SMT is active prefer fully-idle SMT cores over partially-idle ones. A two-phase selection first tries only CPUs on fully idle cores, then falls back to any idle CPU if none fit.
Prioritizing fully-idle SMT cores yields better task placement because the effective capacity of partially-idle SMT cores is reduced; always preferring them when available leads to more accurate capacity usage on task wakeup.
On an SMT system with asymmetric CPU capacities, SMT-aware idle selection has been shown to improve throughput by around 15-18% for CPU-bound workloads, running an amount of tasks equal to the amount of SMT cores.
--- kernel/sched/fair.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
kernel/sched/fair.c +21 -3
@@ -7945,9 +7945,13 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool* Scan the asym_capacity domain for idle CPUs; pick the first idle one on which * the task fits. If no CPU is big enough, but there are idle ones, try to * maximize capacity. +* +* When @smt_idle_only is true (asym + SMT), only consider CPUs on cores whose +* SMT siblings are all idle, to avoid stacking and sharing SMT resources. */ static int -select_idle_capacity (struct task_struct *p,struct sched_domain *sd,int target) +select_idle_capacity (struct task_struct *p,struct sched_domain *sd,int target, +bool smt_idle_only) {unsigned long task_util, util_min, util_max, best_cap =0 ;int fits, best_fits =0 ;
@@ -7967,6 +7971,9 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)if (!choose_idle_cpu (cpu, p))continue ; +if (smt_idle_only && !is_core_idle (cpu)) +continue ; + fits =util_fits_cpu (task_util, util_min, util_max, cpu);/* This CPU fits with all requirements */
@@ -8102,8 +8109,19 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)* capacity path. */ if (sd) { - i =select_idle_capacity (p, sd, target); -return ((unsigned )i < nr_cpumask_bits) ? i : target; +/* +* When asym + SMT and the hint says idle cores exist, +* try idle cores first to avoid stacking on SMT; else +* scan all idle CPUs. +*/ +if (sched_smt_active () &&test_idle_cores (target)) { + i =select_idle_capacity (p, sd, target, true); +if ((unsigned int )i >= nr_cpumask_bits) + i =select_idle_capacity (p, sd, target, false); + }else { + i =select_idle_capacity (p, sd, target, false); + } +return ((unsigned int )i < nr_cpumask_bits) ? i : target; } }
Signature · 1 line
2.53.0
Vincent Guittot
maintainerQuoted 5 lines · Andrea Righi
On systems with asymmetric CPU capacity (e.g., ACPI/CPPC reporting different per-core frequencies), the wakeup path uses
select_idle_capacity()and prioritizes idle CPUs with higher capacity for better task placement. However, when those CPUs belong to SMT cores,
Interesting, which kind of system has both SMT and SD_ASYM_CPUCAPACITY ? I thought both were never set simultaneously and SD_ASYM_PACKING was used for system involving SMT like x86
Quoted 60 lines
their effective capacity can be much lower than the nominal capacity when the sibling thread is busy: SMT siblings compete for shared resources, so a "high capacity" CPU that is idle but whose sibling is busy does not deliver its full capacity. This effective capacity reduction cannot be modeled by the static capacity value alone.
Introduce SMT awareness in the asym-capacity idle selection policy: when SMT is active prefer fully-idle SMT cores over partially-idle ones. A two-phase selection first tries only CPUs on fully idle cores, then falls back to any idle CPU if none fit.
Prioritizing fully-idle SMT cores yields better task placement because the effective capacity of partially-idle SMT cores is reduced; always preferring them when available leads to more accurate capacity usage on task wakeup.
On an SMT system with asymmetric CPU capacities, SMT-aware idle selection has been shown to improve throughput by around 15-18% for CPU-bound workloads, running an amount of tasks equal to the amount of SMT cores.
Signed-off-by Andrea Righi <[email protected]>--- kernel/sched/fair.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)kernel/sched/fair.c +8
-2@@ -7945,9 +7945,13 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool* Scan the asym_capacity domain for idle CPUs; pick the first idle one on which * the task fits. If no CPU is big enough, but there are idle ones, try to * maximize capacity. +* +* When @smt_idle_only is true (asym + SMT), only consider CPUs on cores whose +* SMT siblings are all idle, to avoid stacking and sharing SMT resources. */ static int -select_idle_capacity (struct task_struct *p,struct sched_domain *sd,int target) +select_idle_capacity (struct task_struct *p,struct sched_domain *sd,int target, +bool smt_idle_only) {unsigned long task_util, util_min, util_max, best_cap =0 ;int fits, best_fits =0 ;@@ -7967,6 +7971,9 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)if (!choose_idle_cpu (cpu, p))continue ; +if (smt_idle_only && !is_core_idle (cpu)) +continue ; + fits =util_fits_cpu (task_util, util_min, util_max, cpu);/* This CPU fits with all requirements */ @@ -8102,8 +8109,19 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)* capacity path. */ if (sd) { - i =select_idle_capacity (p, sd, target);
kernel/sched/fair.c static int select_idle_sibling(struct task_struct *p, int prev, int target) · line 8120
Quoted 10 lines
kernel/sched/fair.c +9
-1-return ((unsigned )i < nr_cpumask_bits) ? i : target; +/* +* When asym + SMT and the hint says idle cores exist, +* try idle cores first to avoid stacking on SMT; else +* scan all idle CPUs. +*/ +if (sched_smt_active () &&test_idle_cores (target)) { + i =select_idle_capacity (p, sd, target, true); +if ((unsigned int )i >= nr_cpumask_bits) + i =select_idle_capacity (p, sd, target, false);
Can't you make it one pass in select_idle_capacity ?
Quoted 10 lines
kernel/sched/fair.c +4
-1+ }else { + i =select_idle_capacity (p, sd, target, false); + } +return ((unsigned int )i < nr_cpumask_bits) ? i : target; } } --2.53.0
Hi Vincent,
Quoted 10 lines · Vincent Guittot
Quoted 5 lines · Andrea Righi
On systems with asymmetric CPU capacity (e.g., ACPI/CPPC reporting different per-core frequencies), the wakeup path uses
select_idle_capacity()and prioritizes idle CPUs with higher capacity for better task placement. However, when those CPUs belong to SMT cores,Interesting, which kind of system has both SMT and
SD_ASYM_CPUCAPACITY? I thought both were never set simultaneously andSD_ASYM_PACKINGwas used for system involving SMT like x86
It's an NVIDIA platform (not publicly available yet), where the firmware exposes different CPU capacities and has SMT enabled, so both SD_ASYM_CPUCAPACITY and SMT are present. I'm not sure whether the final firmware release will keep this exact configuration (there's a good chance it will), so I'm targeting it to be prepared.
Quoted 65 lines
Quoted 65 lines
their effective capacity can be much lower than the nominal capacity when the sibling thread is busy: SMT siblings compete for shared resources, so a "high capacity" CPU that is idle but whose sibling is busy does not deliver its full capacity. This effective capacity reduction cannot be modeled by the static capacity value alone.
Introduce SMT awareness in the asym-capacity idle selection policy: when SMT is active prefer fully-idle SMT cores over partially-idle ones. A two-phase selection first tries only CPUs on fully idle cores, then falls back to any idle CPU if none fit.
Prioritizing fully-idle SMT cores yields better task placement because the effective capacity of partially-idle SMT cores is reduced; always preferring them when available leads to more accurate capacity usage on task wakeup.
On an SMT system with asymmetric CPU capacities, SMT-aware idle selection has been shown to improve throughput by around 15-18% for CPU-bound workloads, running an amount of tasks equal to the amount of SMT cores.
Signed-off-by Andrea Righi <[email protected]>--- kernel/sched/fair.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)kernel/sched/fair.c +11
-3@@ -7945,9 +7945,13 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool* Scan the asym_capacity domain for idle CPUs; pick the first idle one on which * the task fits. If no CPU is big enough, but there are idle ones, try to * maximize capacity. +* +* When @smt_idle_only is true (asym + SMT), only consider CPUs on cores whose +* SMT siblings are all idle, to avoid stacking and sharing SMT resources. */ static int -select_idle_capacity (struct task_struct *p,struct sched_domain *sd,int target) +select_idle_capacity (struct task_struct *p,struct sched_domain *sd,int target, +bool smt_idle_only) {unsigned long task_util, util_min, util_max, best_cap =0 ;int fits, best_fits =0 ;@@ -7967,6 +7971,9 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)if (!choose_idle_cpu (cpu, p))continue ; +if (smt_idle_only && !is_core_idle (cpu)) +continue ; + fits =util_fits_cpu (task_util, util_min, util_max, cpu);/* This CPU fits with all requirements */ @@ -8102,8 +8109,19 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)* capacity path. */ if (sd) { - i =select_idle_capacity (p, sd, target); -return ((unsigned )i < nr_cpumask_bits) ? i : target; +/* +* When asym + SMT and the hint says idle cores exist, +* try idle cores first to avoid stacking on SMT; else
Quoted 8 lines
kernel/sched/fair.c static int select_idle_sibling(struct task_struct *p, int prev, int target) · line 8120
Quoted 6 lines
kernel/sched/fair.c +6
-0+* scan all idle CPUs. +*/ +if (sched_smt_active () &&test_idle_cores (target)) { + i =select_idle_capacity (p, sd, target, true); +if ((unsigned int )i >= nr_cpumask_bits) + i =select_idle_capacity (p, sd, target, false);Can't you make it one pass in
select_idle_capacity?
Oh yes, absolutely, we can select the best-fit CPU in the same pass and use it as a fallback if we can't find any fully-idle SMT CPU. I'll change that.
Quoted 11 lines
Quoted 11 lines
kernel/sched/fair.c +4
-1+ }else { + i =select_idle_capacity (p, sd, target, false); + } +return ((unsigned int )i < nr_cpumask_bits) ? i : target; } } --2.53.0
Thanks,
-Andrea
Quoted 14 lines · Andrea Righi
Hi Vincent,
Quoted 10 lines · Vincent Guittot
Quoted 5 lines · Andrea Righi
On systems with asymmetric CPU capacity (e.g., ACPI/CPPC reporting different per-core frequencies), the wakeup path uses
select_idle_capacity()and prioritizes idle CPUs with higher capacity for better task placement. However, when those CPUs belong to SMT cores,Interesting, which kind of system has both SMT and
SD_ASYM_CPUCAPACITY? I thought both were never set simultaneously andSD_ASYM_PACKINGwas used for system involving SMT like x86
Quoted 5 lines
It's an NVIDIA platform (not publicly available yet), where the firmware exposes different CPU capacities and has SMT enabled, so both
SD_ASYM_CPUCAPACITYand SMT are present. I'm not sure whether the final firmware release will keep this exact configuration (there's a good chance it will), so I'm targeting it to be prepared.
Andrea,
that makes me think, I've played with a nvidia grace available to me recently, which sets slightly different CPPC highest_perf values (~2%) which automatically will set SD_ASYM_CPUCAPACITY and run the entire capacity-aware scheduling machinery for really almost negligible capacity differences, where it's questionable how sensible that is.
I have an arm64 + CPPC implementation for asym-packing for this machine, maybe we can reuse that for here too?
(Given that really capacity and SMT are contradicting, e.g. a physical core with 1024 capacity but 4 threads may give you a lot lower observed CPU capacity than a 512 nosmt core per (logical) CPU depending on how much the sibling threads are utilized.)
Quoted 1 line
[snip]
Hi Christian,
Quoted 22 lines · Christian Loehle
Quoted 14 lines · Andrea Righi
Hi Vincent,
Quoted 10 lines · Vincent Guittot
Quoted 5 lines · Andrea Righi
On systems with asymmetric CPU capacity (e.g., ACPI/CPPC reporting different per-core frequencies), the wakeup path uses
select_idle_capacity()and prioritizes idle CPUs with higher capacity for better task placement. However, when those CPUs belong to SMT cores,Interesting, which kind of system has both SMT and
SD_ASYM_CPUCAPACITY? I thought both were never set simultaneously andSD_ASYM_PACKINGwas used for system involving SMT like x86Quoted 5 lines
It's an NVIDIA platform (not publicly available yet), where the firmware exposes different CPU capacities and has SMT enabled, so both
SD_ASYM_CPUCAPACITYand SMT are present. I'm not sure whether the final firmware release will keep this exact configuration (there's a good chance it will), so I'm targeting it to be prepared.
Quoted 6 lines
Andrea,
that makes me think, I've played with a nvidia grace available to me recently, which sets slightly different CPPChighest_perfvalues (~2%) which automatically will setSD_ASYM_CPUCAPACITYand run the entire capacity-aware scheduling machinery for really almost negligible capacity differences, where it's questionable how sensible that is.
That looks like the same system that I've been working with. I agree that treating small CPPC differences as full asymmetry can be a bit overkill.
I've been experimenting with flattening the capacities (to force the "regular" idle CPU selection policy), which performs better than the current asym-capacity CPU selection. However, adding the SMT awareness to the asym-capacity, seems to give a consistent +2-3% (same set of CPU-intensive benchmarks) compared to flatening alone, which is not bad.
Quoted 2 lines
I have an arm64 + CPPC implementation for asym-packing for this machine, maybe we can reuse that for here too?
Sure, that sounds interesting, if it's available somewhere I'd be happy to do some testing.
Thanks,
-Andrea
Vincent Guittot
maintainerQuoted 33 lines · Andrea Righi
Hi Christian,
Quoted 22 lines · Christian Loehle
Quoted 14 lines · Andrea Righi
Hi Vincent,
Quoted 10 lines · Vincent Guittot
Quoted 5 lines · Andrea Righi
On systems with asymmetric CPU capacity (e.g., ACPI/CPPC reporting different per-core frequencies), the wakeup path uses
select_idle_capacity()and prioritizes idle CPUs with higher capacity for better task placement. However, when those CPUs belong to SMT cores,Interesting, which kind of system has both SMT and
SD_ASYM_CPUCAPACITY? I thought both were never set simultaneously andSD_ASYM_PACKINGwas used for system involving SMT like x86Quoted 5 lines
It's an NVIDIA platform (not publicly available yet), where the firmware exposes different CPU capacities and has SMT enabled, so both
SD_ASYM_CPUCAPACITYand SMT are present. I'm not sure whether the final firmware release will keep this exact configuration (there's a good chance it will), so I'm targeting it to be prepared.Quoted 6 lines
Andrea,
that makes me think, I've played with a nvidia grace available to me recently, which sets slightly different CPPChighest_perfvalues (~2%) which automatically will setSD_ASYM_CPUCAPACITYand run the entire capacity-aware scheduling machinery for really almost negligible capacity differences, where it's questionable how sensible that is.
Quoted 8 lines
That looks like the same system that I've been working with. I agree that treating small CPPC differences as full asymmetry can be a bit overkill.
I've been experimenting with flattening the capacities (to force the "regular" idle CPU selection policy), which performs better than the current asym-capacity CPU selection. However, adding the SMT awareness to the asym-capacity, seems to give a consistent +2-3% (same set of CPU-intensive benchmarks) compared to flatening alone, which is not bad.
Do you mean that this patch is +2% > vs plain SMP > than current asym cpucapacity implementation ?
Quoted 9 lines
Quoted 3 lines
I have an arm64 + CPPC implementation for asym-packing for this machine, maybe we can reuse that for here too?
Sure, that sounds interesting, if it's available somewhere I'd be happy to do some testing.
Thanks,
-Andrea
Hi Vincent,
Quoted 37 lines · Vincent Guittot
Quoted 36 lines · Andrea Righi
Hi Christian,
Quoted 22 lines · Christian Loehle
Quoted 14 lines · Andrea Righi
Hi Vincent,
Quoted 10 lines · Vincent Guittot
Quoted 5 lines · Andrea Righi
On systems with asymmetric CPU capacity (e.g., ACPI/CPPC reporting different per-core frequencies), the wakeup path uses
select_idle_capacity()and prioritizes idle CPUs with higher capacity for better task placement. However, when those CPUs belong to SMT cores,Interesting, which kind of system has both SMT and
SD_ASYM_CPUCAPACITY? I thought both were never set simultaneously andSD_ASYM_PACKINGwas used for system involving SMT like x86Quoted 5 lines
It's an NVIDIA platform (not publicly available yet), where the firmware exposes different CPU capacities and has SMT enabled, so both
SD_ASYM_CPUCAPACITYand SMT are present. I'm not sure whether the final firmware release will keep this exact configuration (there's a good chance it will), so I'm targeting it to be prepared.Quoted 6 lines
Andrea,
that makes me think, I've played with a nvidia grace available to me recently, which sets slightly different CPPChighest_perfvalues (~2%) which automatically will setSD_ASYM_CPUCAPACITYand run the entire capacity-aware scheduling machinery for really almost negligible capacity differences, where it's questionable how sensible that is.That looks like the same system that I've been working with. I agree that treating small CPPC differences as full asymmetry can be a bit overkill.
Quoted 8 lines
Quoted 5 lines
I've been experimenting with flattening the capacities (to force the "regular" idle CPU selection policy), which performs better than the current asym-capacity CPU selection. However, adding the SMT awareness to the asym-capacity, seems to give a consistent +2-3% (same set of CPU-intensive benchmarks) compared to flatening alone, which is not bad.
Do you mean that this patch is +2% > vs plain SMP > than current asym cpucapacity implementation ?
Yes, that's correct. More exactly:
speedup %
------------------------------+------------
current asym CPU capacity | - equal CPU capacity | +13.6% SMT-aware asym CPU capacity | +15.0%
Thanks,
-Andrea
Quoted 41 lines · Andrea Righi
Hi Christian,
Quoted 22 lines · Christian Loehle
Quoted 14 lines · Andrea Righi
Hi Vincent,
Quoted 10 lines · Vincent Guittot
Quoted 5 lines · Andrea Righi
On systems with asymmetric CPU capacity (e.g., ACPI/CPPC reporting different per-core frequencies), the wakeup path uses
select_idle_capacity()and prioritizes idle CPUs with higher capacity for better task placement. However, when those CPUs belong to SMT cores,Interesting, which kind of system has both SMT and
SD_ASYM_CPUCAPACITY? I thought both were never set simultaneously andSD_ASYM_PACKINGwas used for system involving SMT like x86Quoted 5 lines
It's an NVIDIA platform (not publicly available yet), where the firmware exposes different CPU capacities and has SMT enabled, so both
SD_ASYM_CPUCAPACITYand SMT are present. I'm not sure whether the final firmware release will keep this exact configuration (there's a good chance it will), so I'm targeting it to be prepared.Quoted 6 lines
Andrea,
that makes me think, I've played with a nvidia grace available to me recently, which sets slightly different CPPChighest_perfvalues (~2%) which automatically will setSD_ASYM_CPUCAPACITYand run the entire capacity-aware scheduling machinery for really almost negligible capacity differences, where it's questionable how sensible that is.That looks like the same system that I've been working with. I agree that treating small CPPC differences as full asymmetry can be a bit overkill.
I've been experimenting with flattening the capacities (to force the "regular" idle CPU selection policy), which performs better than the current asym-capacity CPU selection. However, adding the SMT awareness to the asym-capacity, seems to give a consistent +2-3% (same set of CPU-intensive benchmarks) compared to flatening alone, which is not bad.
Quoted 6 lines
Quoted 2 lines
I have an arm64 + CPPC implementation for asym-packing for this machine, maybe we can reuse that for here too?
Sure, that sounds interesting, if it's available somewhere I'd be happy to do some testing.
Hi Andrea,
I will clean up the asympacking code a bit and share it with you for testing.
Interestingly, when we looked at DCPerf MediaWiki, we found the exact opposite.
On NVIDIA Grace, enabling CAS due to the small CPPC highest_perf differences was actually beneficial for the workload. More interestingly, we saw a similar uplift on a different arm64 server without ASYM_CPUCAPACITY when we force-enabled sched_asym_cpucap_active() even though the system was highest_perf-symmetric. That suggests the uplift on Grace may have come from CAS-specific behavior rather than from better selection of the highest_perf CPUs.
I'd be very curious whether something similar (i.e. the inverse) is happening in your case as well, i.e. flattening the capacities but still forcing select_idle_sibling() / sched_asym_cpucap_active() despite equal capacities. Of course, that will also depend on the workloads (what are you testing?)
Just to illustrate, below is one example where CAS improved both score and CPU utilization:
+--------------------------+----------------------+-------------------------+-----------------------------------------+ | Platform | default (v6.8) | force all CPUs = 1024 | force sched_asym_cpucap_active() = TRUE | +--------------------------+----------------------+-------------------------+-----------------------------------------+ | arm64 symmetric (72 CPUs)| 100% (90% CPU util) | ------------- | 104.26% (99%) | | Grace (72 CPUs) | 100% (99%) | 99.49% (90%) | ------------- | +--------------------------+----------------------+-------------------------+-----------------------------------------+
Hi Christian,
Quoted 52 lines · Christian Loehle
Quoted 41 lines · Andrea Righi
Hi Christian,
Quoted 22 lines · Christian Loehle
Quoted 14 lines · Andrea Righi
Hi Vincent,
Quoted 10 lines · Vincent Guittot
Quoted 5 lines · Andrea Righi
On systems with asymmetric CPU capacity (e.g., ACPI/CPPC reporting different per-core frequencies), the wakeup path uses
select_idle_capacity()and prioritizes idle CPUs with higher capacity for better task placement. However, when those CPUs belong to SMT cores,Interesting, which kind of system has both SMT and
SD_ASYM_CPUCAPACITY? I thought both were never set simultaneously andSD_ASYM_PACKINGwas used for system involving SMT like x86Quoted 5 lines
It's an NVIDIA platform (not publicly available yet), where the firmware exposes different CPU capacities and has SMT enabled, so both
SD_ASYM_CPUCAPACITYand SMT are present. I'm not sure whether the final firmware release will keep this exact configuration (there's a good chance it will), so I'm targeting it to be prepared.Quoted 6 lines
Andrea,
that makes me think, I've played with a nvidia grace available to me recently, which sets slightly different CPPChighest_perfvalues (~2%) which automatically will setSD_ASYM_CPUCAPACITYand run the entire capacity-aware scheduling machinery for really almost negligible capacity differences, where it's questionable how sensible that is.That looks like the same system that I've been working with. I agree that treating small CPPC differences as full asymmetry can be a bit overkill.
I've been experimenting with flattening the capacities (to force the "regular" idle CPU selection policy), which performs better than the current asym-capacity CPU selection. However, adding the SMT awareness to the asym-capacity, seems to give a consistent +2-3% (same set of CPU-intensive benchmarks) compared to flatening alone, which is not bad.
Quoted 6 lines
Quoted 2 lines
I have an arm64 + CPPC implementation for asym-packing for this machine, maybe we can reuse that for here too?
Sure, that sounds interesting, if it's available somewhere I'd be happy to do some testing.
Hi Andrea,
I will clean up the asympacking code a bit and share it with you for testing.
Quoted 8 lines
Interestingly, when we looked at DCPerf MediaWiki, we found the exact opposite.
On NVIDIA Grace, enabling CAS due to the small CPPC
highest_perfdifferences was actually beneficial for the workload. More interestingly, we saw a similar uplift on a different arm64 server withoutASYM_CPUCAPACITYwhen we force-enabledsched_asym_cpucap_active()even though the system was highest_perf-symmetric. That suggests the uplift on Grace may have come from CAS-specific behavior rather than from better selection of thehighest_perfCPUs.
What NVIDIA Grace in particular? On GB300 ASYM_CPUCAPACITY seems to be enabled. I can try to disable / equalize the capacities and repeat the test there as well.
Quoted 5 lines
I'd be very curious whether something similar (i.e. the inverse) is happening in your case as well, i.e. flattening the capacities but still forcing
select_idle_sibling()/sched_asym_cpucap_active()despite equal capacities. Of course, that will also depend on the workloads (what are you testing?)
I can definitely try that. I'm using an internal benchmark suite, in particular the benchmark that is showing the bigger improvements is based on the NVBLAS library (but using the CPUs, not the GPUs), not sure if it's publicly available, I'll check.
Quoted 8 lines
Just to illustrate, below is one example where CAS improved both score and CPU utilization:
+--------------------------+----------------------+-------------------------+-----------------------------------------+ | Platform | default (v6.8) | force all CPUs = 1024 | force sched_asym_cpucap_active() = TRUE | +--------------------------+----------------------+-------------------------+-----------------------------------------+ | arm64 symmetric (72 CPUs)| 100% (90% CPU util) | ------------- | 104.26% (99%) | | Grace (72 CPUs) | 100% (99%) | 99.49% (90%) | ------------- | +--------------------------+----------------------+-------------------------+-----------------------------------------+
I see, interesting. Now I'm curious to do the opposite on the GB300 that I have access to, flattening the capacities to 1024 and see what I get.
Thanks,
-Andrea
Vincent Guittot
maintainerQuoted 15 lines · Andrea Righi
Hi Vincent,
Quoted 10 lines · Vincent Guittot
Quoted 5 lines · Andrea Righi
On systems with asymmetric CPU capacity (e.g., ACPI/CPPC reporting different per-core frequencies), the wakeup path uses
select_idle_capacity()and prioritizes idle CPUs with higher capacity for better task placement. However, when those CPUs belong to SMT cores,Interesting, which kind of system has both SMT and
SD_ASYM_CPUCAPACITY? I thought both were never set simultaneously andSD_ASYM_PACKINGwas used for system involving SMT like x86
Quoted 5 lines
It's an NVIDIA platform (not publicly available yet), where the firmware exposes different CPU capacities and has SMT enabled, so both
SD_ASYM_CPUCAPACITYand SMT are present. I'm not sure whether the final firmware release will keep this exact configuration (there's a good chance it will), so I'm targeting it to be prepared.
That's probably not the only place where SD_ASYM_CPUCAPACITY will fail with SMT. The misfit is another place as an example
Quoted 92 lines
Quoted 66 lines
Quoted 66 lines
their effective capacity can be much lower than the nominal capacity when the sibling thread is busy: SMT siblings compete for shared resources, so a "high capacity" CPU that is idle but whose sibling is busy does not deliver its full capacity. This effective capacity reduction cannot be modeled by the static capacity value alone.
Introduce SMT awareness in the asym-capacity idle selection policy: when SMT is active prefer fully-idle SMT cores over partially-idle ones. A two-phase selection first tries only CPUs on fully idle cores, then falls back to any idle CPU if none fit.
Prioritizing fully-idle SMT cores yields better task placement because the effective capacity of partially-idle SMT cores is reduced; always preferring them when available leads to more accurate capacity usage on task wakeup.
On an SMT system with asymmetric CPU capacities, SMT-aware idle selection has been shown to improve throughput by around 15-18% for CPU-bound workloads, running an amount of tasks equal to the amount of SMT cores.
Signed-off-by Andrea Righi <[email protected]>--- kernel/sched/fair.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)kernel/sched/fair.c +11
-3@@ -7945,9 +7945,13 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool* Scan the asym_capacity domain for idle CPUs; pick the first idle one on which * the task fits. If no CPU is big enough, but there are idle ones, try to * maximize capacity. +* +* When @smt_idle_only is true (asym + SMT), only consider CPUs on cores whose +* SMT siblings are all idle, to avoid stacking and sharing SMT resources. */ static int -select_idle_capacity (struct task_struct *p,struct sched_domain *sd,int target) +select_idle_capacity (struct task_struct *p,struct sched_domain *sd,int target, +bool smt_idle_only) {unsigned long task_util, util_min, util_max, best_cap =0 ;int fits, best_fits =0 ;@@ -7967,6 +7971,9 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)if (!choose_idle_cpu (cpu, p))continue ; +if (smt_idle_only && !is_core_idle (cpu)) +continue ; + fits =util_fits_cpu (task_util, util_min, util_max, cpu);/* This CPU fits with all requirements */ @@ -8102,8 +8109,19 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)* capacity path. */ if (sd) { - i =select_idle_capacity (p, sd, target); -return ((unsigned )i < nr_cpumask_bits) ? i : target; +/* +* When asym + SMT and the hint says idle cores exist, +* try idle cores first to avoid stacking on SMT; else Quoted 8 lines
kernel/sched/fair.c static int select_idle_sibling(struct task_struct *p, int prev, int target) · line 8120
Quoted 6 lines
kernel/sched/fair.c +6
-0+* scan all idle CPUs. +*/ +if (sched_smt_active () &&test_idle_cores (target)) { + i =select_idle_capacity (p, sd, target, true); +if ((unsigned int )i >= nr_cpumask_bits) + i =select_idle_capacity (p, sd, target, false);Can't you make it one pass in
select_idle_capacity?Oh yes, absolutely, we can select the best-fit CPU in the same pass and use it as a fallback if we can't find any fully-idle SMT CPU. I'll change that.
Quoted 11 lines
Quoted 11 lines
kernel/sched/fair.c +4
-1+ }else { + i =select_idle_capacity (p, sd, target, false); + } +return ((unsigned int )i < nr_cpumask_bits) ? i : target; } } --2.53.0
Thanks,
-Andrea
Hi Vincent,
Quoted 16 lines · Vincent Guittot
Quoted 15 lines · Andrea Righi
Hi Vincent,
Quoted 10 lines · Vincent Guittot
Quoted 5 lines · Andrea Righi
On systems with asymmetric CPU capacity (e.g., ACPI/CPPC reporting different per-core frequencies), the wakeup path uses
select_idle_capacity()and prioritizes idle CPUs with higher capacity for better task placement. However, when those CPUs belong to SMT cores,Interesting, which kind of system has both SMT and
SD_ASYM_CPUCAPACITY? I thought both were never set simultaneously andSD_ASYM_PACKINGwas used for system involving SMT like x86
Quoted 8 lines
Quoted 5 lines
It's an NVIDIA platform (not publicly available yet), where the firmware exposes different CPU capacities and has SMT enabled, so both
SD_ASYM_CPUCAPACITYand SMT are present. I'm not sure whether the final firmware release will keep this exact configuration (there's a good chance it will), so I'm targeting it to be prepared.That's probably not the only place where
SD_ASYM_CPUCAPACITYwill fail with SMT. The misfit is another place as an example
Yeah, that's right, with SD_ASYM_CPUCAPACITY + SMT when a misfit task is moved from a "small" CPU to a "big" CPU, if the big CPU has a busy sibling, its effective capacity is much lower than its nominal capacity.
Maybe when SMT is active, we could allow pulling a misfit task only when dst_cpu is on a fully idle core. That's a simple change, I'll run some tests with this, but as you said there might be other places to fix as well.
Thanks,
-Andrea