sched: Fix cluster scheduling in the presence of asymmetric capacity
v5 cover sched: Fix cluster scheduling in the presence of asymmetric capacity
Hi,
This is v5 of the patch series. The only changes are optimizations to check same-capacity cluster and SMT siblings only when needed. Please read the changelog for details.
Cluster scheduling aims to maximize performance by spreading load across clusters of CPUs that share mid-level resources [2]. It works well on uniform systems, but it breaks down on topologies with big and small cores arranged in clusters. As a result, it fails on several generations of Intel processors already shipped and upcoming.
Consider the topology below of big (B) cores and clusters of small (s) cores.
------ ------
| B | | B | ----------------- -----------------
| | | | | s | s | s | s | | s | s | s | s |
------ ------ ----------------- -----------------
| L2 | | L2 | | L2 | | L2 |
-------------------------------------------------------
| L3 |
-------------------------------------------------------On a partially busy system (one with idle CPUs; busy CPUs have one task each), scheduling for asymmetric capacity ensures that misfit tasks land on the big CPUs. The remaining tasks, misfit or not, run on the small CPUs. When CONFIG_SCHED_CLUSTER is enabled, these remaining tasks are supposed to be evenly spread among the small-CPU clusters. Today, this does not happen.
Several issues in the load balancer prevent a small CPU in one cluster from pulling tasks from another:
a) update_sd_pick_busiest() may select a fully_busy group with higher per-CPU capacity as the busiest, preventing a subsequent fully_busy group of equal capacity from being correctly selected.
b) Misfit-load statistics are used to identify tasks that would benefit from migrating to bigger CPUs. Accounting misfit load is pointless if the destination CPU is equally small, and it also blocks balancing between clusters.
c) Due to b), groups that are truly has_spare or fully_busy get misclassified as misfit_task. update_sd_pick_busiest() then skips them, since a small destination CPU cannot help with misfit tasks.
d) Once a busiest group has been identified, sched_balance_find_src_rq() will refuse to migrate tasks to CPUs of equal capacity, even when doing so is precisely what is required to balance small-CPU clusters.
e) The SD_PREFER_SIBLING flag is missing from scheduling domains with asymmetric capacity, preventing the balancer from equalizing load across sibling small-core clusters.
Together, these issues prevent cluster-level balancing on systems with asymmetric CPU capacity.
This series addresses each problem and restores the intended behavior. Details, rationale, and code changes are explained in each patch.
I tested these patches on Alder Lake, which has both SMT Pcores and clusters of Ecores. I tested with SMT both disabled and enabled. I also tested on Lunar Lake and Panther Lake, which have an Ecore cluster not connected to the L3 cache. I repeated the same experiment with CONFIG_SCHED_CLUSTER disabled. The load balancer behaves as expected.
Christian also tested this patchset on a synthetic arm64 qemu topology and the expected behavior [3].
Changes in v5:
- Added Tested-by tags from Christian. Thanks!
- Patch 1 (pre-work): Optimized logic to identify CPUs with busy SMT
siblings only when needed. (Prateek, Chen Yu)
- Patch 5: Optimized logic to check for architectural capacity only when
needed.
- Added Reviewed-by tag from Prateek. Thanks!
- Link to v4: https://lore.kernel.org/r/20260608-rneri-fix-cas-clusters-v4-0-1526711c944c@linux.intel.com
Changes in v4:
- Patch 1 (pre-work): Fixed a bug that would block load balancing on SMT
cores with more than one busy sibling.
- Patch 2 (pre-work): Fixed a bug that would needlessly update
sg_overloaded.
- Patch 5: Reworked logic using a local variable for improved
readability.
- Added Reviewed-by tags from Chen Yu, Tim, and Vincent. Thanks!
- Link to v3: https://lore.kernel.org/r/20260514-rneri-fix-cas-clusters-v3-0-0037869554bd@linux.intel.com
Changes in v3:
- Patch 3: Reverted the inverted runtime capacity check. The inverted
form resulted in migrations to CPUs of slightly lower capacity. Guarded
the check for architectural capacity with the sched_cluster_active
static key.
- Patch 4: Expanded the patch description to explain the behavior of
overloaded groups and low-capacity clusters with spare capacity.
- Added Reviewed-by tags from Christian. Thanks!
- Link to v2: https://lore.kernel.org/r/20260429-rneri-fix-cas-clusters-v2-0-cd787de35cc6@linux.intel.com
Changes in v2:
- Patch 1: Rewrote patch description for clarity. Added a note
clarifying that SD_ASYM_CPUCAPACITY and SMT are mutually
exclusive. (Tim)
- Patch 2: Fixed a bug where the capacity check inadvertently broke
the mutual exclusion of the sched_reduced_capacity() path. Keep
marking the root domain as overloaded when misfit tasks are present
to allow bigger CPUs to help via newly idle balance. (sashiko)
Fixed the description to state that capacity_greater() looks for
differences of ~5% or more, not 20%. (Christian)
- Patch 3: Use arch_scale_cpu_capacity() instead of capacity_of() to
ignore runtime capacity variability. Inverted the capacity check.
(Christian)
- Patch 4: Reworded the patch description for clarity.
- Link to v1: https://lore.kernel.org/r/20260330-rneri-fix-cas-clusters-v1-0-1e465b6fecb2@linux.intel.com/
---
Ricardo Neri (6):
sched/fair: Do not skip CPUs of similar capacity with busy SMT siblings sched/fair: Also gate overloaded status update for SD_ASYM_CPUCAPACITY sched/fair: Check CPU capacity before comparing group types during load balance sched/fair: Skip misfit load accounting when the destination CPU cannot help sched/fair: Allow load balancing between CPUs of identical capacity sched/topology: Do not clear SD_PREFER_SIBLING in domains with clusters
include/linux/sched/sd_flags.h | 3 +- kernel/sched/fair.c | 66 ++++++++++++++++++++++++++++++------------ kernel/sched/topology.c | 14 +++++++-- 3 files changed, 62 insertions(+), 21 deletions(-)
---
base-commit: 50436392fe2359ea108fd27308f86c8283be1622
change-id: 20250620-rneri-fix-cas-clusters-bb4287d1e152
Best regards,
Signature · 1 line
Ricardo Neri <[email protected]>
PATCH v5 1/6 sched/fair: Do not skip CPUs of similar capacity with busy SMT siblings
When picking a busiest CPU with only one running task, the function sched_balance_find_src_rq() skips candidate CPUs if the destination CPU has less than ~5% extra capacity. This condition only holds if all the SMT siblings of a CPU are idle.
SMT siblings share the computing resources of a physical core and this results in reduced capacity if more than one sibling is busy.
Skipping a CPU as described would prevent the load balancer from pulling tasks from a scheduling group previously and correctly identified as group_smt_balance (i.e., one with more than one task running).
Do not skip a candidate CPU of similar capacity if it has busy SMT siblings.
---
Changes in v5:
* Optimized logic to identify CPUs with busy SMT siblings only when needed. (Prateek, Chen Yu)
* Added Reviewed-by tag from Prateek. Thanks!
* Christian also provided his Reviewed-by tag, but the patch changed significantly since then. I did not think it was correct to keep it without him reviewing the updated patch first.
Changes in v4:
* Introduced this patch.
Changes in v3:
* N/A
Changes in v2:
* N/A
--- kernel/sched/fair.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
kernel/sched/fair.c +11 -3
@@ -12976,9 +12976,17 @@ static struct rq *sched_balance_find_src_rq(struct lb_env *env,* average load. */ if (env->sd->flags &SD_ASYM_CPUCAPACITY && - !capacity_greater (capacity_of (env->dst_cpu), capacity) && - nr_running ==1 ) -continue ; + nr_running ==1 ) { +bool smt_degraded_cap =sched_smt_active () && !is_core_idle (i); + +/* +* Busy SMT siblings reduce the capacity of CPU @i. Do +* not skip it in this case. +*/ +if (!smt_degraded_cap && + !capacity_greater (capacity_of (env->dst_cpu), capacity)) +continue ; + }/* * Make sure we only pull tasks from a CPU of lower priority
Signature · 1 line
2.43.0
Re: [PATCH v5 1/6] sched/fair: Do not skip CPUs of similar capacity with busy SMT siblings
Quoted 13 lines · Ricardo Neri
When picking a busiest CPU with only one running task, the function
sched_balance_find_src_rq()skips candidate CPUs if the destination CPU has less than ~5% extra capacity. This condition only holds if all the SMT siblings of a CPU are idle.SMT siblings share the computing resources of a physical core and this results in reduced capacity if more than one sibling is busy.
Skipping a CPU as described would prevent the load balancer from pulling tasks from a scheduling group previously and correctly identified as
group_smt_balance(i.e., one with more than one task running).
Quoted 5 lines
Do not skip a candidate CPU of similar capacity if it has busy SMT siblings.
Reviewed-by K Prateek Nayak <[email protected]>Signed-off-by Ricardo Neri <[email protected]>
Quoted 50 lines
---
Changes in v5:
* Optimized logic to identify CPUs with busy SMT siblings only when needed. (Prateek, Chen Yu)
* Added Reviewed-by tag from Prateek. Thanks!
* Christian also provided his Reviewed-by tag, but the patch changed significantly since then. I did not think it was correct to keep it without him reviewing the updated patch first.Changes in v4:
* Introduced this patch.Changes in v3:
* N/AChanges in v2:
* N/A--- kernel/sched/fair.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)kernel/sched/fair.c +11
-4@@ -12976,9 +12976,17 @@ static struct rq *sched_balance_find_src_rq(struct lb_env *env,* average load. */ if (env->sd->flags &SD_ASYM_CPUCAPACITY && - !capacity_greater (capacity_of (env->dst_cpu), capacity) && - nr_running ==1 ) -continue ; + nr_running ==1 ) { +bool smt_degraded_cap =sched_smt_active () && !is_core_idle (i); + +/* +* Busy SMT siblings reduce the capacity of CPU @i. Do +* not skip it in this case. +*/ +if (!smt_degraded_cap && + !capacity_greater (capacity_of (env->dst_cpu), capacity)) +continue ; + }/* * Make sure we only pull tasks from a CPU of lower priority -- 2.43.0
Re: [PATCH v5 1/6] sched/fair: Do not skip CPUs of similar capacity with busy SMT siblings
Quoted 15 lines · Vincent Guittot
Quoted 13 lines · Ricardo Neri
When picking a busiest CPU with only one running task, the function
sched_balance_find_src_rq()skips candidate CPUs if the destination CPU has less than ~5% extra capacity. This condition only holds if all the SMT siblings of a CPU are idle.SMT siblings share the computing resources of a physical core and this results in reduced capacity if more than one sibling is busy.
Skipping a CPU as described would prevent the load balancer from pulling tasks from a scheduling group previously and correctly identified as
group_smt_balance(i.e., one with more than one task running).
Quoted 7 lines
Quoted 5 lines
Do not skip a candidate CPU of similar capacity if it has busy SMT siblings.
Reviewed-by K Prateek Nayak <[email protected]>Signed-off-by Ricardo Neri <[email protected]>Reviewed-by Vincent Guittot <[email protected]>
Thanks you!
PATCH v5 2/6 sched/fair: Also gate overloaded status update for SD_ASYM_CPUCAPACITY
In reply to Ricardo NeriThe argument sg_overloaded of update_sg_lb_stats() is only consumed when balancing at the root domain. It only makes sense to update it in such a case. Commit 3229adbe7875 ("sched/fair: Do not compute overloaded status unnecessarily during lb") updated the logic accordingly but missed the case in which the root domain has the SD_ASYM_CPUCAPACITY flag. Fix this.
---
Changes in v5:
* Added Tested-by tag from Christian. Thanks!
Changes in v4:
* Introduced this patch.
Changes in v3:
* N/A
Changes in v2:
* N/A
--- kernel/sched/fair.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/sched/fair.c +3 -1
@@ -11863,7 +11863,9 @@ static inline void update_sg_lb_stats(struct lb_env *env,/* Check for a misfit task on the cpu */ if (sgs->group_misfit_task_load < rq->misfit_task_load) { sgs->group_misfit_task_load = rq->misfit_task_load; - *sg_overloaded =1 ; + +if (balancing_at_rd) + *sg_overloaded =1 ; } }else if (env->idle &&sched_reduced_capacity (rq, env->sd)) {/* Check for a task running on a CPU with reduced capacity */
Signature · 1 line
2.43.0
Re: [PATCH v5 2/6] sched/fair: Also gate overloaded status update for SD_ASYM_CPUCAPACITY
Quoted 11 lines · Ricardo Neri
The argument
sg_overloadedofupdate_sg_lb_stats()is only consumed when balancing at the root domain. It only makes sense to update it in such a case. Commit3229adbe7875("sched/fair: Do not compute overloaded status unnecessarily during lb") updated the logic accordingly but missed the case in which the root domain has theSD_ASYM_CPUCAPACITYflag. Fix this.Fixes 3229adbe7875 ("sched/fair: Do not compute overloaded status unnecessarily during lb")Tested-by Christian Loehle <[email protected]>Reported-by Chen Yu <[email protected]>Signed-off-by Ricardo Neri <[email protected]>
Quoted 35 lines
---
Changes in v5:
* Added Tested-by tag from Christian. Thanks!Changes in v4:
* Introduced this patch.Changes in v3:
* N/AChanges in v2:
* N/A--- kernel/sched/fair.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kernel/sched/fair.c +3
-2@@ -11863,7 +11863,9 @@ static inline void update_sg_lb_stats(struct lb_env *env,/* Check for a misfit task on the cpu */ if (sgs->group_misfit_task_load < rq->misfit_task_load) { sgs->group_misfit_task_load = rq->misfit_task_load; - *sg_overloaded =1 ; + +if (balancing_at_rd) + *sg_overloaded =1 ; } }else if (env->idle &&sched_reduced_capacity (rq, env->sd)) {/* Check for a task running on a CPU with reduced capacity */ --2.43.0
PATCH v5 3/6 sched/fair: Check CPU capacity before comparing group types during load balance
In reply to Ricardo Neriupdate_sd_pick_busiest() may incorrectly select a fully_busy group as the busiest group when its per-CPU capacity exceeds that of the destination CPU. This happens because the type of busiest group is initialized to group_has_spare and allows the fully_busy group to win the type comparison.
update_sd_pick_busiest() should not choose a candidate scheduling group with at most one runnable task if its per-CPU capacity is greater than that of the destination CPU. Such a check already exists, but it is done too
late: after the type comparison, preventing a subsequent fully_busy group of equal per-CPU capacity from being correctly selected.
Move this check to occur before comparing group types.
---
Changes in v5:
* Added Tested-by tag from Christian. Thanks!
Changes in v4:
* Dropped note on SMT not being affected since SMT + asym capacity is now supported.
* Added Reviewed-by tags from Vincent, Tim, and Chen Yu. Thanks!
Changes in v3:
* Added a Fixes tag. (Christian)
* Added Reviewed-by tag from Christian. Thanks!
Changes in v2:
* Added a note clarifying that SMT and SD_ASYM_CPUCAPACITY are mutually exclusive. (Tim)
* Kept parentheses around bitwise operators for clarity.
* Rewrote patch description for clarity.
--- kernel/sched/fair.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
kernel/sched/fair.c +11 -11
@@ -11944,6 +11944,17 @@ static bool update_sd_pick_busiest(struct lb_env *env, sds->local_stat.group_type != group_has_spare))return false; +/* +* Candidate sg has no more than one task per CPU and has higher +* per-CPU capacity. Migrating tasks to less capable CPUs may harm +* throughput. Maximize throughput, power/energy consequences are not +* considered. +*/ +if ((env->sd->flags &SD_ASYM_CPUCAPACITY ) && + (sgs->group_type <= group_fully_busy) && + (capacity_greater (sg->sgc->min_capacity,capacity_of (env->dst_cpu)))) +return false; +if (sgs->group_type > busiest->group_type)return true;
@@ -12050,17 +12061,6 @@ static bool update_sd_pick_busiest(struct lb_env *env,break ; } -/* -* Candidate sg has no more than one task per CPU and has higher -* per-CPU capacity. Migrating tasks to less capable CPUs may harm -* throughput. Maximize throughput, power/energy consequences are not -* considered. -*/ -if ((env->sd->flags &SD_ASYM_CPUCAPACITY ) && - (sgs->group_type <= group_fully_busy) && - (capacity_greater (sg->sgc->min_capacity,capacity_of (env->dst_cpu)))) -return false; -return true; }
Signature · 1 line
2.43.0
PATCH v5 4/6 sched/fair: Skip misfit load accounting when the destination CPU cannot help
In reply to Ricardo NeriIn domains with asymmetric capacity, identifying misfit load in a scheduling group is not useful when the destination CPU cannot help (i.e., its capacity exceeds the group's maximum CPU capacity by less than ~5%). In such cases, it also prevents load balance among clusters of equal capacity when CONFIG_SCHED_CLUSTER is enabled. This happens because update_sd_pick_busiest() skips candidate groups of type misfit_task if the destination CPU has similar capacity.
Skipping misfit load accounting in this situation allows the group to be classified as has_spare or fully_busy and lets load balancing proceed. Keep marking scheduling groups as overloaded when misfit tasks are present. The sg_overloaded flag propagates to the root domain and allows bigger CPUs in it to help via newly idle balance.
---
Changes in v5:
* Added Tested-by tag from Christian. Thanks!
Changes in v4:
* Added Reviewed-by tags from Vincent and Chen Yu. Thanks!
Changes in v3:
* Added Reviewed-by tag from Christian. Thanks!
Changes in v2:
* Moved the check of the destination CPU capacity inside the code block used for SD_ASYM_CPUCAPACITY. v1 inadvertently broke the mutual exclusion of the sched_reduced_capacity() path.
* Keep marking the root domain as overloaded to allow bigger CPUs to help. (sashiko)
* Fixed patch description to clarify that the capacity_greater() looks for differences of 5% or more. (Christian)
* Reworded the patch description for clarity.
* I did not include the Reviewed-by tag from Christian since the patch changed functionally.
--- kernel/sched/fair.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
kernel/sched/fair.c +17 -4
@@ -11860,12 +11860,25 @@ static inline void update_sg_lb_stats(struct lb_env *env,continue ;if (sd_flags &SD_ASYM_CPUCAPACITY ) { -/* Check for a misfit task on the cpu */ -if (sgs->group_misfit_task_load < rq->misfit_task_load) { - sgs->group_misfit_task_load = rq->misfit_task_load; - +if (rq->misfit_task_load) { +/* +* Always mark the root domain overloaded so big +* CPUs can pick up misfit tasks via newly idle +* balance. +*/ if (balancing_at_rd) *sg_overloaded =1 ; + +/* +* Only account misfit load if @dst_cpu can +* help; otherwise, the group may be classified +* as misfit_task and update_sd_pick_busiest() +* will skip it. +*/ +if (capacity_greater (capacity_of (env->dst_cpu), + group->sgc->max_capacity) && + (sgs->group_misfit_task_load < rq->misfit_task_load)) + sgs->group_misfit_task_load = rq->misfit_task_load; } }else if (env->idle &&sched_reduced_capacity (rq, env->sd)) {/* Check for a task running on a CPU with reduced capacity */
Signature · 1 line
2.43.0
PATCH v5 5/6 sched/fair: Allow load balancing between CPUs of identical capacity
In reply to Ricardo Nerisched_balance_find_src_rq() avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.
When CONFIG_SCHED_CLUSTER is enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.
Use arch_scale_cpu_capacity() to reflect architectural capacity, excluding runtime reductions due to side activity or thermal pressure. Guard this check with the sched_cluster_active static key so that systems without cluster topology are unaffected.
---
Changes in v5:
* Optimized logic to identify same-arch clusters only when needed.
* Added Tested-by tag from Christian. Thanks!
Changes in v4:
* Implemented the check for cluster with a local variable for improved readability.
Changes in v3:
* Reverted the inverted capacity check; the inverted form incorrectly allows migrations to CPUs of slightly less capacity.
* Guarded the check for architectural capacity with the sched_cluster_active static key.
Changes in v2:
* Used arch_scale_cpu_capacity() instead of capacity_of() to ignore runtime variability.
* Inverted the check for runtime capacity. (Christian)
* Reworded patch description for clarity.
--- kernel/sched/fair.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/sched/fair.c +8 -1
@@ -12992,13 +12992,20 @@ static struct rq *sched_balance_find_src_rq(struct lb_env *env,*/ if (env->sd->flags &SD_ASYM_CPUCAPACITY && nr_running ==1 ) { +bool same_arch_cluster =static_branch_unlikely (&sched_cluster_active) && + (arch_scale_cpu_capacity (env->dst_cpu) == +arch_scale_cpu_capacity (i));bool smt_degraded_cap =sched_smt_active () && !is_core_idle (i);/* * Busy SMT siblings reduce the capacity of CPU @i. Do * not skip it in this case. +* +* CONFIG_SCHED_CLUSTER requires balancing load across clusters +* of identical capacity. Use architectural capacity to ignore +* runtime variability. */ -if (!smt_degraded_cap && +if (!smt_degraded_cap && !same_arch_cluster && !capacity_greater (capacity_of (env->dst_cpu), capacity))continue ; }
Signature · 1 line
2.43.0
Vincent Guittot
maintainerRe: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
Quoted 11 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding
capacity_of() reflects not only RT and irq pressure but also thermal pressure or system frequency capping.
If dst cluster is under thermal mitigation but the source cluster is not, we probably shouldn't spread tasks across both clusters. Have you considered using get_actual_cpu_capacity() instead of arch_scale_cpu_capacity() ?
Quoted 60 lines
runtime reductions due to side activity or thermal pressure. Guard this check with the
sched_cluster_activestatic key so that systems without cluster topology are unaffected.Tested-by Christian Loehle <[email protected]>Signed-off-by Ricardo Neri <[email protected]>---
Changes in v5:
* Optimized logic to identify same-arch clusters only when needed.
* Added Tested-by tag from Christian. Thanks!Changes in v4:
* Implemented the check for cluster with a local variable for improved readability.Changes in v3:
* Reverted the inverted capacity check; the inverted form incorrectly allows migrations to CPUs of slightly less capacity.
* Guarded the check for architectural capacity with thesched_cluster_activestatic key.Changes in v2:
* Usedarch_scale_cpu_capacity()instead ofcapacity_of()to ignore runtime variability.
* Inverted the check for runtime capacity. (Christian)
* Reworded patch description for clarity.--- kernel/sched/fair.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)kernel/sched/fair.c +8
-2@@ -12992,13 +12992,20 @@ static struct rq *sched_balance_find_src_rq(struct lb_env *env,*/ if (env->sd->flags &SD_ASYM_CPUCAPACITY && nr_running ==1 ) { +bool same_arch_cluster =static_branch_unlikely (&sched_cluster_active) && + (arch_scale_cpu_capacity (env->dst_cpu) == +arch_scale_cpu_capacity (i));bool smt_degraded_cap =sched_smt_active () && !is_core_idle (i);/* * Busy SMT siblings reduce the capacity of CPU @i. Do * not skip it in this case. +* +* CONFIG_SCHED_CLUSTER requires balancing load across clusters +* of identical capacity. Use architectural capacity to ignore +* runtime variability. */ -if (!smt_degraded_cap && +if (!smt_degraded_cap && !same_arch_cluster && !capacity_greater (capacity_of (env->dst_cpu), capacity))continue ; } --2.43.0
Re: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
Quoted 12 lines · Vincent Guittot
Quoted 10 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.
Quoted 8 lines
Quoted 1 line
Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding
capacity_of()reflects not only RT and irq pressure but also thermal pressure or system frequency capping.
If dst cluster is under thermal mitigation but the source cluster is not, we probably shouldn't spread tasks across both clusters. Have you considered usingget_actual_cpu_capacity()instead ofarch_scale_cpu_capacity()?
Replacing arch_scale_cpu_capacity() with get_actual_cpu_capacity() would make the == comparison below very unlikely to be true FWIW. I think it's fine like that, I will prepare a follow-up anyway to make it work for our "almost equal capacity" cluster systems and then also consider switching to get_actual_cpu_capacity() since we include a margin anyway.
Quoted 61 lines
Quoted 61 lines
runtime reductions due to side activity or thermal pressure. Guard this check with the
sched_cluster_activestatic key so that systems without cluster topology are unaffected.Tested-by Christian Loehle <[email protected]>Signed-off-by Ricardo Neri <[email protected]>---
Changes in v5:
* Optimized logic to identify same-arch clusters only when needed.
* Added Tested-by tag from Christian. Thanks!Changes in v4:
* Implemented the check for cluster with a local variable for improved readability.Changes in v3:
* Reverted the inverted capacity check; the inverted form incorrectly allows migrations to CPUs of slightly less capacity.
* Guarded the check for architectural capacity with thesched_cluster_activestatic key.Changes in v2:
* Usedarch_scale_cpu_capacity()instead ofcapacity_of()to ignore runtime variability.
* Inverted the check for runtime capacity. (Christian)
* Reworded patch description for clarity.--- kernel/sched/fair.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)kernel/sched/fair.c +8
-2@@ -12992,13 +12992,20 @@ static struct rq *sched_balance_find_src_rq(struct lb_env *env,*/ if (env->sd->flags &SD_ASYM_CPUCAPACITY && nr_running ==1 ) { +bool same_arch_cluster =static_branch_unlikely (&sched_cluster_active) && + (arch_scale_cpu_capacity (env->dst_cpu) == +arch_scale_cpu_capacity (i));bool smt_degraded_cap =sched_smt_active () && !is_core_idle (i);/* * Busy SMT siblings reduce the capacity of CPU @i. Do * not skip it in this case. +* +* CONFIG_SCHED_CLUSTER requires balancing load across clusters +* of identical capacity. Use architectural capacity to ignore +* runtime variability. */ -if (!smt_degraded_cap && +if (!smt_degraded_cap && !same_arch_cluster && !capacity_greater (capacity_of (env->dst_cpu), capacity))continue ; } --2.43.0
Re: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
Quoted 22 lines · Christian Loehle
Quoted 12 lines · Vincent Guittot
Quoted 10 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.Quoted 8 lines
Quoted 1 line
Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding
capacity_of()reflects not only RT and irq pressure but also thermal pressure or system frequency capping.
If dst cluster is under thermal mitigation but the source cluster is not, we probably shouldn't spread tasks across both clusters. Have you considered usingget_actual_cpu_capacity()instead ofarch_scale_cpu_capacity()?
Quoted 2 lines
Replacing
arch_scale_cpu_capacity()withget_actual_cpu_capacity()would make the == comparison below very unlikely to be true FWIW.
Yes, this is what I thought too. I did not try with get_actual_cpu_capacity(), though. Perhaps on Intel processors it would work since rq->avg_hw.load_avg is not used, IIUC. I am not sure about cpufreq_pressure. I need to check.
Still, it may work for Intel processors but not for ARM ones.
Quoted 4 lines
I think it's fine like that, I will prepare a follow-up anyway to make it work for our "almost equal capacity" cluster systems and then also consider switching to
get_actual_cpu_capacity()since we include a margin anyway.
Great!
Re: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
Quoted 30 lines · Ricardo Neri
Quoted 22 lines · Christian Loehle
Quoted 12 lines · Vincent Guittot
Quoted 10 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.Quoted 8 lines
Quoted 1 line
Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding
capacity_of()reflects not only RT and irq pressure but also thermal pressure or system frequency capping.
If dst cluster is under thermal mitigation but the source cluster is not, we probably shouldn't spread tasks across both clusters. Have you considered usingget_actual_cpu_capacity()instead ofarch_scale_cpu_capacity()?Quoted 2 lines
Replacing
arch_scale_cpu_capacity()withget_actual_cpu_capacity()would make the == comparison below very unlikely to be true FWIW.Yes, this is what I thought too. I did not try with
get_actual_cpu_capacity(), though. Perhaps on Intel processors it would work sincerq->avg_hw.load_avgis not used, IIUC. I am not sure aboutcpufreq_pressure. I need to check.
Quoted 8 lines
Still, it may work for Intel processors but not for ARM ones.
Quoted 4 lines
I think it's fine like that, I will prepare a follow-up anyway to make it work for our "almost equal capacity" cluster systems and then also consider switching to
get_actual_cpu_capacity()since we include a margin anyway.Great!
I confirmed that does not use rq->avg_hw.load_avg nor cpufreq_pressure. Hence, get_actual_cpu_capacity() worked for me on Intel hybrid processors, but it would not on other architectures.
So perhaps we can stick with arch_scale_cpu_capacity() for now? The series from Christian will add a margin, making the use of get_actual_cpu_capacity() feasible.
Vincent Guittot
maintainerRe: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
Quoted 34 lines · Ricardo Neri
Quoted 32 lines · Ricardo Neri
Quoted 22 lines · Christian Loehle
Quoted 12 lines · Vincent Guittot
Quoted 10 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.Quoted 8 lines
Quoted 1 line
Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding
capacity_of()reflects not only RT and irq pressure but also thermal pressure or system frequency capping.
If dst cluster is under thermal mitigation but the source cluster is not, we probably shouldn't spread tasks across both clusters. Have you considered usingget_actual_cpu_capacity()instead ofarch_scale_cpu_capacity()?Quoted 2 lines
Replacing
arch_scale_cpu_capacity()withget_actual_cpu_capacity()would make the == comparison below very unlikely to be true FWIW.Yes, this is what I thought too. I did not try with
get_actual_cpu_capacity(), though. Perhaps on Intel processors it would work sincerq->avg_hw.load_avgis not used, IIUC. I am not sure aboutcpufreq_pressure. I need to check.Still, it may work for Intel processors but not for ARM ones.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
I think it's fine like that, I will prepare a follow-up anyway to make it work for our "almost equal capacity" cluster systems and then also consider switching to
get_actual_cpu_capacity()since we include a margin anyway.Great!
I confirmed that does not use
rq->avg_hw.load_avgnorcpufreq_pressure.
I'm not surprised that intel don't use rq->avg_hw.load_avg but I'm pretty sure that you use cpufreq_pressure, because any call to freq_qos_add_request(..., FREQ_QOS_MAX), like scaling_max_freq, will update cpufreq_pressure.
If one cluster has its max freq capped, you will spread tasks between the uncapped and the capped clusters which no longer have the same compute capacity.
Quoted 6 lines
Hence,
get_actual_cpu_capacity()worked for me on Intel hybrid processors, but it would not on other architectures.So perhaps we can stick with
arch_scale_cpu_capacity()for now? The series from Christian will add a margin, making the use ofget_actual_cpu_capacity()feasible.
Re: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
Quoted 41 lines · Vincent Guittot
Quoted 39 lines · Ricardo Neri
Quoted 37 lines · Ricardo Neri
Quoted 22 lines · Christian Loehle
Quoted 12 lines · Vincent Guittot
Quoted 10 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.Quoted 8 lines
Quoted 1 line
Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding
capacity_of()reflects not only RT and irq pressure but also thermal pressure or system frequency capping.
If dst cluster is under thermal mitigation but the source cluster is not, we probably shouldn't spread tasks across both clusters. Have you considered usingget_actual_cpu_capacity()instead ofarch_scale_cpu_capacity()?Quoted 2 lines
Replacing
arch_scale_cpu_capacity()withget_actual_cpu_capacity()would make the == comparison below very unlikely to be true FWIW.Yes, this is what I thought too. I did not try with
get_actual_cpu_capacity(), though. Perhaps on Intel processors it would work sincerq->avg_hw.load_avgis not used, IIUC. I am not sure aboutcpufreq_pressure. I need to check.Still, it may work for Intel processors but not for ARM ones.
Quoted 4 lines
I think it's fine like that, I will prepare a follow-up anyway to make it work for our "almost equal capacity" cluster systems and then also consider switching to
get_actual_cpu_capacity()since we include a margin anyway.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Great!
I confirmed that does not use
rq->avg_hw.load_avgnorcpufreq_pressure.I'm not surprised that intel don't use
rq->avg_hw.load_avgbut I'm pretty sure that you usecpufreq_pressure, because any call tofreq_qos_add_request(..., FREQ_QOS_MAX), likescaling_max_freq, will updatecpufreq_pressure.
But in cpufreq_update_pressure() a non-zero pressure can be only computed if arch_scale_freq_ref() returns non-zero. x86 does not implement this function.
The check max_freq <= capped_freq is always true because the default arch_scale_freq_ref() returns 0. The computed pressure is always 0. Am I missing something?
Quoted 4 lines
If one cluster has its max freq capped, you will spread tasks between the uncapped and the capped clusters which no longer have the same compute capacity.
I this I agree.
Vincent Guittot
maintainerRe: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
Quoted 52 lines · Ricardo Neri
Quoted 41 lines · Vincent Guittot
Quoted 39 lines · Ricardo Neri
Quoted 37 lines · Ricardo Neri
Quoted 22 lines · Christian Loehle
Quoted 12 lines · Vincent Guittot
Quoted 10 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.Quoted 8 lines
Quoted 1 line
Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding
capacity_of()reflects not only RT and irq pressure but also thermal pressure or system frequency capping.
If dst cluster is under thermal mitigation but the source cluster is not, we probably shouldn't spread tasks across both clusters. Have you considered usingget_actual_cpu_capacity()instead ofarch_scale_cpu_capacity()?Quoted 2 lines
Replacing
arch_scale_cpu_capacity()withget_actual_cpu_capacity()would make the == comparison below very unlikely to be true FWIW.Yes, this is what I thought too. I did not try with
get_actual_cpu_capacity(), though. Perhaps on Intel processors it would work sincerq->avg_hw.load_avgis not used, IIUC. I am not sure aboutcpufreq_pressure. I need to check.Still, it may work for Intel processors but not for ARM ones.
Quoted 4 lines
I think it's fine like that, I will prepare a follow-up anyway to make it work for our "almost equal capacity" cluster systems and then also consider switching to
get_actual_cpu_capacity()since we include a margin anyway.Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Great!
I confirmed that does not use
rq->avg_hw.load_avgnorcpufreq_pressure.I'm not surprised that intel don't use
rq->avg_hw.load_avgbut I'm pretty sure that you usecpufreq_pressure, because any call tofreq_qos_add_request(..., FREQ_QOS_MAX), likescaling_max_freq, will updatecpufreq_pressure.
Quoted 7 lines
But in
cpufreq_update_pressure()a non-zero pressure can be only computed ifarch_scale_freq_ref()returns non-zero. x86 does not implement this function.The check
max_freq<=capped_freqis always true because the defaultarch_scale_freq_ref()returns 0. The computed pressure is always 0. Am I missing something?
Yeah, I forgot that Intel has not enabled it. You should consider enable it because of the below
Quoted 7 lines
Quoted 5 lines
If one cluster has its max freq capped, you will spread tasks between the uncapped and the capped clusters which no longer have the same compute capacity.
I this I agree.
Re: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
Quoted 59 lines · Vincent Guittot
Quoted 56 lines · Ricardo Neri
Quoted 41 lines · Vincent Guittot
Quoted 39 lines · Ricardo Neri
Quoted 37 lines · Ricardo Neri
Quoted 22 lines · Christian Loehle
Quoted 12 lines · Vincent Guittot
Quoted 10 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.Quoted 8 lines
Quoted 1 line
Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding
capacity_of()reflects not only RT and irq pressure but also thermal pressure or system frequency capping.
If dst cluster is under thermal mitigation but the source cluster is not, we probably shouldn't spread tasks across both clusters. Have you considered usingget_actual_cpu_capacity()instead ofarch_scale_cpu_capacity()?Quoted 2 lines
Replacing
arch_scale_cpu_capacity()withget_actual_cpu_capacity()would make the == comparison below very unlikely to be true FWIW.Yes, this is what I thought too. I did not try with
get_actual_cpu_capacity(), though. Perhaps on Intel processors it would work sincerq->avg_hw.load_avgis not used, IIUC. I am not sure aboutcpufreq_pressure. I need to check.Still, it may work for Intel processors but not for ARM ones.
Quoted 4 lines
I think it's fine like that, I will prepare a follow-up anyway to make it work for our "almost equal capacity" cluster systems and then also consider switching to
get_actual_cpu_capacity()since we include a margin anyway.Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Great!
I confirmed that does not use
rq->avg_hw.load_avgnorcpufreq_pressure.I'm not surprised that intel don't use
rq->avg_hw.load_avgbut I'm pretty sure that you usecpufreq_pressure, because any call tofreq_qos_add_request(..., FREQ_QOS_MAX), likescaling_max_freq, will updatecpufreq_pressure.But in
cpufreq_update_pressure()a non-zero pressure can be only computed ifarch_scale_freq_ref()returns non-zero. x86 does not implement this function.
Quoted 6 lines
Quoted 3 lines
The check
max_freq<=capped_freqis always true because the defaultarch_scale_freq_ref()returns 0. The computed pressure is always 0. Am I missing something?Yeah, I forgot that Intel has not enabled it. You should consider enable it because of the below
Aren't things supposed to still work if it is not enabled though?
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
If one cluster has its max freq capped, you will spread tasks between the uncapped and the capped clusters which no longer have the same compute capacity.
I this I agree.
Vincent Guittot
maintainerRe: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
Quoted 62 lines · Rafael J. Wysocki (Intel)
Quoted 59 lines · Vincent Guittot
Quoted 56 lines · Ricardo Neri
Quoted 41 lines · Vincent Guittot
Quoted 39 lines · Ricardo Neri
Quoted 37 lines · Ricardo Neri
Quoted 22 lines · Christian Loehle
Quoted 12 lines · Vincent Guittot
Quoted 10 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.Quoted 8 lines
Quoted 1 line
Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding
capacity_of()reflects not only RT and irq pressure but also thermal pressure or system frequency capping.
If dst cluster is under thermal mitigation but the source cluster is not, we probably shouldn't spread tasks across both clusters. Have you considered usingget_actual_cpu_capacity()instead ofarch_scale_cpu_capacity()?Quoted 2 lines
Replacing
arch_scale_cpu_capacity()withget_actual_cpu_capacity()would make the == comparison below very unlikely to be true FWIW.Yes, this is what I thought too. I did not try with
get_actual_cpu_capacity(), though. Perhaps on Intel processors it would work sincerq->avg_hw.load_avgis not used, IIUC. I am not sure aboutcpufreq_pressure. I need to check.Still, it may work for Intel processors but not for ARM ones.
Quoted 4 lines
I think it's fine like that, I will prepare a follow-up anyway to make it work for our "almost equal capacity" cluster systems and then also consider switching to
get_actual_cpu_capacity()since we include a margin anyway.Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Great!
I confirmed that does not use
rq->avg_hw.load_avgnorcpufreq_pressure.I'm not surprised that intel don't use
rq->avg_hw.load_avgbut I'm pretty sure that you usecpufreq_pressure, because any call tofreq_qos_add_request(..., FREQ_QOS_MAX), likescaling_max_freq, will updatecpufreq_pressure.But in
cpufreq_update_pressure()a non-zero pressure can be only computed ifarch_scale_freq_ref()returns non-zero. x86 does not implement this function.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
The check
max_freq<=capped_freqis always true because the defaultarch_scale_freq_ref()returns 0. The computed pressure is always 0. Am I missing something?Yeah, I forgot that Intel has not enabled it. You should consider enable it because of the below
Aren't things supposed to still work if it is not enabled though?
The scheduler is not aware of any cpufreq qos max_freq constraint applied on the CPUs and it consideres CPUs being able to run at their max capacity
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
If one cluster has its max freq capped, you will spread tasks between the uncapped and the capped clusters which no longer have the same compute capacity.
I this I agree.
Re: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
Quoted 64 lines · Vincent Guittot
Quoted 62 lines · Rafael J. Wysocki (Intel)
Quoted 59 lines · Vincent Guittot
Quoted 56 lines · Ricardo Neri
Quoted 41 lines · Vincent Guittot
Quoted 39 lines · Ricardo Neri
Quoted 37 lines · Ricardo Neri
Quoted 22 lines · Christian Loehle
Quoted 12 lines · Vincent Guittot
Quoted 10 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.Quoted 8 lines
Quoted 1 line
Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding
capacity_of()reflects not only RT and irq pressure but also thermal pressure or system frequency capping.
If dst cluster is under thermal mitigation but the source cluster is not, we probably shouldn't spread tasks across both clusters. Have you considered usingget_actual_cpu_capacity()instead ofarch_scale_cpu_capacity()?Quoted 2 lines
Replacing
arch_scale_cpu_capacity()withget_actual_cpu_capacity()would make the == comparison below very unlikely to be true FWIW.Yes, this is what I thought too. I did not try with
get_actual_cpu_capacity(), though. Perhaps on Intel processors it would work sincerq->avg_hw.load_avgis not used, IIUC. I am not sure aboutcpufreq_pressure. I need to check.Still, it may work for Intel processors but not for ARM ones.
Quoted 4 lines
I think it's fine like that, I will prepare a follow-up anyway to make it work for our "almost equal capacity" cluster systems and then also consider switching to
get_actual_cpu_capacity()since we include a margin anyway.Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Great!
I confirmed that does not use
rq->avg_hw.load_avgnorcpufreq_pressure.I'm not surprised that intel don't use
rq->avg_hw.load_avgbut I'm pretty sure that you usecpufreq_pressure, because any call tofreq_qos_add_request(..., FREQ_QOS_MAX), likescaling_max_freq, will updatecpufreq_pressure.But in
cpufreq_update_pressure()a non-zero pressure can be only computed ifarch_scale_freq_ref()returns non-zero. x86 does not implement this function.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
The check
max_freq<=capped_freqis always true because the defaultarch_scale_freq_ref()returns 0. The computed pressure is always 0. Am I missing something?Yeah, I forgot that Intel has not enabled it. You should consider enable it because of the below
Sure, I was thinking about the same.
Quoted 2 lines
Quoted 2 lines
Aren't things supposed to still work if it is not enabled though?
In my experiments, after capping frequency I did not observe changes in the behavior of the load balancer.
Quoted 4 lines
The scheduler is not aware of any cpufreq qos
max_freqconstraint applied on the CPUs and it consideres CPUs being able to run at their max capacity
I prototyped code for arch_scale_freq_ref() (along with using get_actual_cpu_capacity()) in my patchset. I did observe the load balancer moving tasks towards uncapped CPUs.
I can post the patch for arch_scale_freq_ref() separately.
Vincent Guittot
maintainerRe: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
Quoted 85 lines · Ricardo Neri
Quoted 64 lines · Vincent Guittot
Quoted 62 lines · Rafael J. Wysocki (Intel)
Quoted 59 lines · Vincent Guittot
Quoted 56 lines · Ricardo Neri
Quoted 41 lines · Vincent Guittot
Quoted 39 lines · Ricardo Neri
Quoted 37 lines · Ricardo Neri
Quoted 22 lines · Christian Loehle
Quoted 12 lines · Vincent Guittot
Quoted 10 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.Quoted 8 lines
Quoted 1 line
Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding
capacity_of()reflects not only RT and irq pressure but also thermal pressure or system frequency capping.
If dst cluster is under thermal mitigation but the source cluster is not, we probably shouldn't spread tasks across both clusters. Have you considered usingget_actual_cpu_capacity()instead ofarch_scale_cpu_capacity()?Quoted 2 lines
Replacing
arch_scale_cpu_capacity()withget_actual_cpu_capacity()would make the == comparison below very unlikely to be true FWIW.Yes, this is what I thought too. I did not try with
get_actual_cpu_capacity(), though. Perhaps on Intel processors it would work sincerq->avg_hw.load_avgis not used, IIUC. I am not sure aboutcpufreq_pressure. I need to check.Still, it may work for Intel processors but not for ARM ones.
Quoted 4 lines
I think it's fine like that, I will prepare a follow-up anyway to make it work for our "almost equal capacity" cluster systems and then also consider switching to
get_actual_cpu_capacity()since we include a margin anyway.Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Great!
I confirmed that does not use
rq->avg_hw.load_avgnorcpufreq_pressure.I'm not surprised that intel don't use
rq->avg_hw.load_avgbut I'm pretty sure that you usecpufreq_pressure, because any call tofreq_qos_add_request(..., FREQ_QOS_MAX), likescaling_max_freq, will updatecpufreq_pressure.But in
cpufreq_update_pressure()a non-zero pressure can be only computed ifarch_scale_freq_ref()returns non-zero. x86 does not implement this function.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
The check
max_freq<=capped_freqis always true because the defaultarch_scale_freq_ref()returns 0. The computed pressure is always 0. Am I missing something?Yeah, I forgot that Intel has not enabled it. You should consider enable it because of the below
Sure, I was thinking about the same.
Quoted 2 lines
Quoted 2 lines
Aren't things supposed to still work if it is not enabled though?
In my experiments, after capping frequency I did not observe changes in the behavior of the load balancer.
Quoted 4 lines
The scheduler is not aware of any cpufreq qos
max_freqconstraint applied on the CPUs and it consideres CPUs being able to run at their max capacity
Quoted 5 lines
I prototyped code for
arch_scale_freq_ref()(along with usingget_actual_cpu_capacity()) in my patchset. I did observe the load balancer moving tasks towards uncapped CPUs.I can post the patch for
arch_scale_freq_ref()separately.
Thanks
Vincent Guittot
maintainerRe: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
In reply to Christian LoehleQuoted 23 lines · Christian Loehle
Quoted 12 lines · Vincent Guittot
Quoted 10 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.Quoted 8 lines
Quoted 1 line
Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding
capacity_of()reflects not only RT and irq pressure but also thermal pressure or system frequency capping.
If dst cluster is under thermal mitigation but the source cluster is not, we probably shouldn't spread tasks across both clusters. Have you considered usingget_actual_cpu_capacity()instead ofarch_scale_cpu_capacity()?
Quoted 2 lines
Replacing
arch_scale_cpu_capacity()withget_actual_cpu_capacity()would make the == comparison below very unlikely to be true FWIW.
Do you have in mind cpufreq_pressure or hw load_avg ?
Quoted 4 lines
I think it's fine like that, I will prepare a follow-up anyway to make it work for our "almost equal capacity" cluster systems and then also consider switching to
get_actual_cpu_capacity()since we include a margin anyway.
I would prefer the other way: Keep the current behavior correct (keep accounting system pressure) before adding a new feature
Quoted 63 lines
Quoted 62 lines
Quoted 62 lines
runtime reductions due to side activity or thermal pressure. Guard this check with the
sched_cluster_activestatic key so that systems without cluster topology are unaffected.Tested-by Christian Loehle <[email protected]>Signed-off-by Ricardo Neri <[email protected]>---
Changes in v5:
* Optimized logic to identify same-arch clusters only when needed.
* Added Tested-by tag from Christian. Thanks!Changes in v4:
* Implemented the check for cluster with a local variable for improved readability.Changes in v3:
* Reverted the inverted capacity check; the inverted form incorrectly allows migrations to CPUs of slightly less capacity.
* Guarded the check for architectural capacity with thesched_cluster_activestatic key.Changes in v2:
* Usedarch_scale_cpu_capacity()instead ofcapacity_of()to ignore runtime variability.
* Inverted the check for runtime capacity. (Christian)
* Reworded patch description for clarity.--- kernel/sched/fair.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)kernel/sched/fair.c +8
-2@@ -12992,13 +12992,20 @@ static struct rq *sched_balance_find_src_rq(struct lb_env *env,*/ if (env->sd->flags &SD_ASYM_CPUCAPACITY && nr_running ==1 ) { +bool same_arch_cluster =static_branch_unlikely (&sched_cluster_active) && + (arch_scale_cpu_capacity (env->dst_cpu) == +arch_scale_cpu_capacity (i));bool smt_degraded_cap =sched_smt_active () && !is_core_idle (i);/* * Busy SMT siblings reduce the capacity of CPU @i. Do * not skip it in this case. +* +* CONFIG_SCHED_CLUSTER requires balancing load across clusters +* of identical capacity. Use architectural capacity to ignore +* runtime variability. */ -if (!smt_degraded_cap && +if (!smt_degraded_cap && !same_arch_cluster && !capacity_greater (capacity_of (env->dst_cpu), capacity))continue ; } --2.43.0
Re: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
In reply to Ricardo NeriHi Ricardo,
Quoted 45 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding runtime reductions due to side activity or thermal pressure. Guard this check with thesched_cluster_activestatic key so that systems without cluster topology are unaffected.Tested-by Christian Loehle <[email protected]>Signed-off-by Ricardo Neri <[email protected]>---
Changes in v5:
* Optimized logic to identify same-arch clusters only when needed.
* Added Tested-by tag from Christian. Thanks!Changes in v4:
* Implemented the check for cluster with a local variable for improved readability.Changes in v3:
* Reverted the inverted capacity check; the inverted form incorrectly allows migrations to CPUs of slightly less capacity.
* Guarded the check for architectural capacity with thesched_cluster_activestatic key.Changes in v2:
* Usedarch_scale_cpu_capacity()instead ofcapacity_of()to ignore runtime variability.
* Inverted the check for runtime capacity. (Christian)
* Reworded patch description for clarity.--- kernel/sched/fair.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)kernel/sched/fair.c +0
-0
kernel/sched/fair.c static struct rq *sched_balance_find_src_rq(struct lb_env *env, · line 12997
Quoted 6 lines
kernel/sched/fair.c +3
-0@@ -12992,13 +12992,20 @@ static struct rq *sched_balance_find_src_rq(struct lb_env *env,*/ if (env->sd->flags &SD_ASYM_CPUCAPACITY && nr_running ==1 ) { +bool same_arch_cluster =static_branch_unlikely (&sched_cluster_active) && + (arch_scale_cpu_capacity (env->dst_cpu) == +arch_scale_cpu_capacity (i));
I find same_arch_cluster a bit misleading. It sounds like "these two CPUs belong to the same cluster", while what it actually checks is whether a cluster topology exists somewhere in the root domain and the two CPUs have exactly the same architectural capacity. Am I understanding it correctly?
If so, would something like same_arch_capacity or cluster_equal_capacity be a better name? I think either would make the intent of the code a bit clearer.
Thanks,
-Andrea
Quoted 19 lines
kernel/sched/fair.c +5
-1bool smt_degraded_cap =sched_smt_active () && !is_core_idle (i);/* * Busy SMT siblings reduce the capacity of CPU @i. Do * not skip it in this case. +* +* CONFIG_SCHED_CLUSTER requires balancing load across clusters +* of identical capacity. Use architectural capacity to ignore +* runtime variability. */ -if (!smt_degraded_cap && +if (!smt_degraded_cap && !same_arch_cluster && !capacity_greater (capacity_of (env->dst_cpu), capacity))continue ; }Signature · 2 lines
-- 2.43.0
Re: [PATCH v5 5/6] sched/fair: Allow load balancing between CPUs of identical capacity
Quoted 43 lines · Andrea Righi
Hi Ricardo,
Quoted 40 lines · Ricardo Neri
sched_balance_find_src_rq()avoids selecting a runqueue with a single running task as busiest if doing so results in migrating the task to a CPU with less than ~5% of extra capacity. It also unintentionally prevents migrations between CPUs of identical capacity.When
CONFIG_SCHED_CLUSTERis enabled, load should be balanced across clusters of CPUs with the same capacity. Allowing migration between CPUs of identical capacity is necessary to meet this goal.Use
arch_scale_cpu_capacity()to reflect architectural capacity, excluding runtime reductions due to side activity or thermal pressure. Guard this check with thesched_cluster_activestatic key so that systems without cluster topology are unaffected.Tested-by Christian Loehle <[email protected]>Signed-off-by Ricardo Neri <[email protected]>---
Changes in v5:
* Optimized logic to identify same-arch clusters only when needed.
* Added Tested-by tag from Christian. Thanks!Changes in v4:
* Implemented the check for cluster with a local variable for improved readability.Changes in v3:
* Reverted the inverted capacity check; the inverted form incorrectly allows migrations to CPUs of slightly less capacity.
* Guarded the check for architectural capacity with thesched_cluster_activestatic key.Changes in v2:
* Usedarch_scale_cpu_capacity()instead ofcapacity_of()to ignore runtime variability.
* Inverted the check for runtime capacity. (Christian)
* Reworded patch description for clarity.--- kernel/sched/fair.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
Quoted 14 lines
kernel/sched/fair.c static struct rq *sched_balance_find_src_rq(struct lb_env *env, · line 12997
Quoted 11 lines
kernel/sched/fair.c +3
-0@@ -12992,13 +12992,20 @@ static struct rq *sched_balance_find_src_rq(struct lb_env *env,*/ if (env->sd->flags &SD_ASYM_CPUCAPACITY && nr_running ==1 ) { +bool same_arch_cluster =static_branch_unlikely (&sched_cluster_active) && + (arch_scale_cpu_capacity (env->dst_cpu) == +arch_scale_cpu_capacity (i));I find
same_arch_clustera bit misleading. It sounds like "these two CPUs belong to the same cluster",
Indeed.
Quoted 3 lines
while what it actually checks is whether a cluster
topology exists somewhere in the root domain and the two CPUs have exactly the same architectural capacity. Am I understanding it correctly?
Yes, it is supposed to mean this.
Quoted 3 lines
If so, would something like
same_arch_capacityorcluster_equal_capacitybe a better name? I think either would make the intent of the code a bit clearer.
Sure. I can change the name. I think a name reflecting the same capacity as you suggest would be better. The name would have to change anyway because in my next version I will use get_actual_cpu_capacity() as Vincent has suggested.
PATCH v5 6/6 sched/topology: Do not clear SD_PREFER_SIBLING in domains with clusters
In reply to Ricardo NeriSome topologies have scheduling domains that contain CPUs of asymmetric capacity, grouped into two or more clusters of equal-capacity CPUs sharing an L2 cache. When CONFIG_SCHED_CLUSTER is enabled, load must be balanced across these clusters.
Do not clear SD_PREFER_SIBLING in the child domains to indicate to the load balancer that it should spread load among cluster siblings.
Checks for capacity in update_sd_pick_busiest(), sched_balance_find_src_group(), and sched_balance_find_src_rq() prevent migrations from high- to low-capacity CPUs if the busiest group is not overloaded.
CPUs with spare capacity, big or small, have always helped overloaded groups. Once the overloading condition disappears, misfit load will still be used to move high-utilization tasks to bigger CPUs if they have spare capacity.
Adding the SD_PREFER_SIBLING flag shifts load balancing in shared-LLC domains from equalizing the number of idle CPUs to equalizing the number of running tasks. This also enables migrations among clusters from newly- idle load balance, where the outgoing task is already dequeued but the CPU has not yet transitioned to idle.
---
Changes in v5:
* Improved inline comments for accuracy.
* Added Tested-by tag from Christian. Thanks!
Changes in v4:
* Added Reviewed-by tag from Tim. Thanks!
Changes in v3:
* Updated documentation of SD_PREFER_SIBLING.
* Expanded the patch description to explain the behavior when overloaded groups are involved.
Changes in v2:
* Reworded the patch description for clarity.
* Kept parentheses around bitwise operators for clarity.
--- include/linux/sched/sd_flags.h | 3 ++- kernel/sched/topology.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-)
include/linux/sched/sd_flags.h +2 -1
@@ -147,7 +147,8 @@ SD_FLAG(SD_ASYM_PACKING, SDF_NEEDS_GROUPS)* Prefer to place tasks in a sibling domain * * Set up until domains start spanning NUMA nodes. Close to being a SHARED_CHILD -* flag, but cleared below domains with SD_ASYM_CPUCAPACITY. +* flag, but cleared below domains with SD_ASYM_CPUCAPACITY unless those child +* domains have clusters of CPUs sharing cache. * * NEEDS_GROUPS: Load balancing flag. */
kernel/sched/topology.c +12 -2
@@ -1995,8 +1995,18 @@ sd_init(struct sched_domain_topology_level *tl,/* * Convert topological properties into behaviour. */ -/* Don't attempt to spread across CPUs of different capacities. */ -if ((sd->flags &SD_ASYM_CPUCAPACITY ) && sd->child) +/* +* Don't attempt to spread across CPUs of different capacities. +* +* If the child domain has clusters of CPUs sharing L2 cache, keep the +* flag to spread tasks across clusters of identical capacity. Checks in +* the load balancer prevent task migrations from high- to low-capacity +* CPUs unless the source group is overloaded. Migrations to a lower- +* capacity CPU can happen if a higher-capacity group is overloaded and +* a lower-capacity CPU has spare capacity. +*/ +if ((sd->flags &SD_ASYM_CPUCAPACITY ) && sd->child && + !(sd->child->flags &SD_CLUSTER )) sd->child->flags &= ~SD_PREFER_SIBLING ;if (sd->flags &SD_SHARE_CPUCAPACITY ) {
Signature · 1 line
2.43.0
Vincent Guittot
maintainerRe: [PATCH v5 6/6] sched/topology: Do not clear SD_PREFER_SIBLING in domains with clusters
Quoted 76 lines · Ricardo Neri
Some topologies have scheduling domains that contain CPUs of asymmetric capacity, grouped into two or more clusters of equal-capacity CPUs sharing an L2 cache. When
CONFIG_SCHED_CLUSTERis enabled, load must be balanced across these clusters.Do not clear
SD_PREFER_SIBLINGin the child domains to indicate to the load balancer that it should spread load among cluster siblings.Checks for capacity in
update_sd_pick_busiest(),sched_balance_find_src_group(), andsched_balance_find_src_rq()prevent migrations from high- to low-capacity CPUs if the busiest group is not overloaded.CPUs with spare capacity, big or small, have always helped overloaded groups. Once the overloading condition disappears, misfit load will still be used to move high-utilization tasks to bigger CPUs if they have spare capacity.
Adding the
SD_PREFER_SIBLINGflag shifts load balancing in shared-LLC domains from equalizing the number of idle CPUs to equalizing the number of running tasks. This also enables migrations among clusters from newly- idle load balance, where the outgoing task is already dequeued but the CPU has not yet transitioned to idle.Reviewed-by Tim Chen <[email protected]>Tested-by Christian Loehle <[email protected]>Signed-off-by Ricardo Neri <[email protected]>---
Changes in v5:
* Improved inline comments for accuracy.
* Added Tested-by tag from Christian. Thanks!Changes in v4:
* Added Reviewed-by tag from Tim. Thanks!Changes in v3:
* Updated documentation ofSD_PREFER_SIBLING.
* Expanded the patch description to explain the behavior when overloaded groups are involved.Changes in v2:
* Reworded the patch description for clarity.
* Kept parentheses around bitwise operators for clarity.--- include/linux/sched/sd_flags.h | 3 ++- kernel/sched/topology.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-)include/linux/sched/sd_flags.h +2
-1@@ -147,7 +147,8 @@ SD_FLAG(SD_ASYM_PACKING, SDF_NEEDS_GROUPS)* Prefer to place tasks in a sibling domain * * Set up until domains start spanning NUMA nodes. Close to being a SHARED_CHILD -* flag, but cleared below domains with SD_ASYM_CPUCAPACITY. +* flag, but cleared below domains with SD_ASYM_CPUCAPACITY unless those child +* domains have clusters of CPUs sharing cache. * * NEEDS_GROUPS: Load balancing flag. */ kernel/sched/topology.c +3
-2@@ -1995,8 +1995,18 @@ sd_init(struct sched_domain_topology_level *tl,/* * Convert topological properties into behaviour. */ -/* Don't attempt to spread across CPUs of different capacities. */ -if ((sd->flags &SD_ASYM_CPUCAPACITY ) && sd->child) +/* +* Don't attempt to spread across CPUs of different capacities. +*
kernel/sched/topology.c sd_init(struct sched_domain_topology_level *tl, · line 2010
Quoted 10 lines
kernel/sched/topology.c +9
-0+* If the child domain has clusters of CPUs sharing L2 cache, keep the +* flag to spread tasks across clusters of identical capacity. Checks in +* the load balancer prevent task migrations from high- to low-capacity +* CPUs unless the source group is overloaded. Migrations to a lower- +* capacity CPU can happen if a higher-capacity group is overloaded and +* a lower-capacity CPU has spare capacity. +*/ +if ((sd->flags &SD_ASYM_CPUCAPACITY ) && sd->child && + !(sd->child->flags &SD_CLUSTER )) sd->child->flags &= ~SD_PREFER_SIBLING ;
Last time I looked at this patch I was balanced between your proposal above and simply keeping SD_PREFER_SIBLING for all HMP topologies. As added in the comment:
" Checks in
* the load balancer prevent task migrations from high- to low-capacity
* CPUs unless the source group is overloaded.
"
So, why should we bother for (SD_ASYM_CPUCAPACITY && !SD_CLUSTER) topology ?
Quoted 6 lines
kernel/sched/topology.c +0
-1if (sd->flags &SD_SHARE_CPUCAPACITY ) { --2.43.0
Re: [PATCH v5 6/6] sched/topology: Do not clear SD_PREFER_SIBLING in domains with clusters
Quoted 89 lines · Vincent Guittot
Quoted 76 lines · Ricardo Neri
Some topologies have scheduling domains that contain CPUs of asymmetric capacity, grouped into two or more clusters of equal-capacity CPUs sharing an L2 cache. When
CONFIG_SCHED_CLUSTERis enabled, load must be balanced across these clusters.Do not clear
SD_PREFER_SIBLINGin the child domains to indicate to the load balancer that it should spread load among cluster siblings.Checks for capacity in
update_sd_pick_busiest(),sched_balance_find_src_group(), andsched_balance_find_src_rq()prevent migrations from high- to low-capacity CPUs if the busiest group is not overloaded.CPUs with spare capacity, big or small, have always helped overloaded groups. Once the overloading condition disappears, misfit load will still be used to move high-utilization tasks to bigger CPUs if they have spare capacity.
Adding the
SD_PREFER_SIBLINGflag shifts load balancing in shared-LLC domains from equalizing the number of idle CPUs to equalizing the number of running tasks. This also enables migrations among clusters from newly- idle load balance, where the outgoing task is already dequeued but the CPU has not yet transitioned to idle.Reviewed-by Tim Chen <[email protected]>Tested-by Christian Loehle <[email protected]>Signed-off-by Ricardo Neri <[email protected]>---
Changes in v5:
* Improved inline comments for accuracy.
* Added Tested-by tag from Christian. Thanks!Changes in v4:
* Added Reviewed-by tag from Tim. Thanks!Changes in v3:
* Updated documentation ofSD_PREFER_SIBLING.
* Expanded the patch description to explain the behavior when overloaded groups are involved.Changes in v2:
* Reworded the patch description for clarity.
* Kept parentheses around bitwise operators for clarity.--- include/linux/sched/sd_flags.h | 3 ++- kernel/sched/topology.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-)include/linux/sched/sd_flags.h +2
-1@@ -147,7 +147,8 @@ SD_FLAG(SD_ASYM_PACKING, SDF_NEEDS_GROUPS)* Prefer to place tasks in a sibling domain * * Set up until domains start spanning NUMA nodes. Close to being a SHARED_CHILD -* flag, but cleared below domains with SD_ASYM_CPUCAPACITY. +* flag, but cleared below domains with SD_ASYM_CPUCAPACITY unless those child +* domains have clusters of CPUs sharing cache. * * NEEDS_GROUPS: Load balancing flag. */ kernel/sched/topology.c +3
-2@@ -1995,8 +1995,18 @@ sd_init(struct sched_domain_topology_level *tl,/* * Convert topological properties into behaviour. */ -/* Don't attempt to spread across CPUs of different capacities. */ -if ((sd->flags &SD_ASYM_CPUCAPACITY ) && sd->child) +/* +* Don't attempt to spread across CPUs of different capacities. +* kernel/sched/topology.c sd_init(struct sched_domain_topology_level *tl, · line 2010
Quoted 10 lines
kernel/sched/topology.c +9
-0+* If the child domain has clusters of CPUs sharing L2 cache, keep the +* flag to spread tasks across clusters of identical capacity. Checks in +* the load balancer prevent task migrations from high- to low-capacity +* CPUs unless the source group is overloaded. Migrations to a lower- +* capacity CPU can happen if a higher-capacity group is overloaded and +* a lower-capacity CPU has spare capacity. +*/ +if ((sd->flags &SD_ASYM_CPUCAPACITY ) && sd->child && + !(sd->child->flags &SD_CLUSTER )) sd->child->flags &= ~SD_PREFER_SIBLING ;
Quoted 8 lines
Last time I looked at this patch I was balanced between your proposal above and simply keeping
SD_PREFER_SIBLINGfor all HMP topologies. As added in the comment:
" Checks in
* the load balancer prevent task migrations from high- to low-capacity
* CPUs unless the source group is overloaded.
"
So, why should we bother for (SD_ASYM_CPUCAPACITY&& !SD_CLUSTER) topology ?
No reason, AFAICS. I just wanted to restrict the change to the target topology of this patchset.
But you raise a good point: given the checks in place in the load balancer, it should be OK to keep SD_PREFER_SIBLING in all asymmetric topologies. I will run a few experiments to confirm.
Re: [PATCH v5 6/6] sched/topology: Do not clear SD_PREFER_SIBLING in domains with clusters
Quoted 99 lines · Ricardo Neri
Quoted 89 lines · Vincent Guittot
Quoted 76 lines · Ricardo Neri
Some topologies have scheduling domains that contain CPUs of asymmetric capacity, grouped into two or more clusters of equal-capacity CPUs sharing an L2 cache. When
CONFIG_SCHED_CLUSTERis enabled, load must be balanced across these clusters.Do not clear
SD_PREFER_SIBLINGin the child domains to indicate to the load balancer that it should spread load among cluster siblings.Checks for capacity in
update_sd_pick_busiest(),sched_balance_find_src_group(), andsched_balance_find_src_rq()prevent migrations from high- to low-capacity CPUs if the busiest group is not overloaded.CPUs with spare capacity, big or small, have always helped overloaded groups. Once the overloading condition disappears, misfit load will still be used to move high-utilization tasks to bigger CPUs if they have spare capacity.
Adding the
SD_PREFER_SIBLINGflag shifts load balancing in shared-LLC domains from equalizing the number of idle CPUs to equalizing the number of running tasks. This also enables migrations among clusters from newly- idle load balance, where the outgoing task is already dequeued but the CPU has not yet transitioned to idle.Reviewed-by Tim Chen <[email protected]>Tested-by Christian Loehle <[email protected]>Signed-off-by Ricardo Neri <[email protected]>---
Changes in v5:
* Improved inline comments for accuracy.
* Added Tested-by tag from Christian. Thanks!Changes in v4:
* Added Reviewed-by tag from Tim. Thanks!Changes in v3:
* Updated documentation ofSD_PREFER_SIBLING.
* Expanded the patch description to explain the behavior when overloaded groups are involved.Changes in v2:
* Reworded the patch description for clarity.
* Kept parentheses around bitwise operators for clarity.--- include/linux/sched/sd_flags.h | 3 ++- kernel/sched/topology.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-)include/linux/sched/sd_flags.h +2
-1@@ -147,7 +147,8 @@ SD_FLAG(SD_ASYM_PACKING, SDF_NEEDS_GROUPS)* Prefer to place tasks in a sibling domain * * Set up until domains start spanning NUMA nodes. Close to being a SHARED_CHILD -* flag, but cleared below domains with SD_ASYM_CPUCAPACITY. +* flag, but cleared below domains with SD_ASYM_CPUCAPACITY unless those child +* domains have clusters of CPUs sharing cache. * * NEEDS_GROUPS: Load balancing flag. */ kernel/sched/topology.c +3
-2@@ -1995,8 +1995,18 @@ sd_init(struct sched_domain_topology_level *tl,/* * Convert topological properties into behaviour. */ -/* Don't attempt to spread across CPUs of different capacities. */ -if ((sd->flags &SD_ASYM_CPUCAPACITY ) && sd->child) +/* +* Don't attempt to spread across CPUs of different capacities. +* kernel/sched/topology.c sd_init(struct sched_domain_topology_level *tl, · line 2010
Quoted 10 lines
kernel/sched/topology.c +9
-0+* If the child domain has clusters of CPUs sharing L2 cache, keep the +* flag to spread tasks across clusters of identical capacity. Checks in +* the load balancer prevent task migrations from high- to low-capacity +* CPUs unless the source group is overloaded. Migrations to a lower- +* capacity CPU can happen if a higher-capacity group is overloaded and +* a lower-capacity CPU has spare capacity. +*/ +if ((sd->flags &SD_ASYM_CPUCAPACITY ) && sd->child && + !(sd->child->flags &SD_CLUSTER )) sd->child->flags &= ~SD_PREFER_SIBLING ;Quoted 8 lines
Last time I looked at this patch I was balanced between your proposal above and simply keeping
SD_PREFER_SIBLINGfor all HMP topologies. As added in the comment:
" Checks in
* the load balancer prevent task migrations from high- to low-capacity
* CPUs unless the source group is overloaded.
"
So, why should we bother for (SD_ASYM_CPUCAPACITY&& !SD_CLUSTER) topology ?
Quoted 6 lines
No reason, AFAICS. I just wanted to restrict the change to the target topology of this patchset.
But you raise a good point: given the checks in place in the load balancer, it should be OK to keep
SD_PREFER_SIBLINGin all asymmetric topologies. I will run a few experiments to confirm.
I ran a few experiments with and without CONFIG_CLUSTER_SCHED. I ran N threads where N < nproc to ensure that sched groups were classified as has_spare or fully_busy. The threads saturated the CPUs to minimize task placement decisions at wake up.
I observed these threads to remain on the CPUs with highest capacity; no spreading.
I repeated the experiment with EAS enabled and threads ramping up utilization. EAS kept them on small CPUs and later duly moved to CPUs of higher capacity as they became misfits.
I will update my patch to keep SD_PREFER_SIBLING regardless of asymmetric capacity.
Vincent Guittot
maintainerRe: [PATCH v5 6/6] sched/topology: Do not clear SD_PREFER_SIBLING in domains with clusters
Quoted 116 lines · Ricardo Neri
Quoted 99 lines · Ricardo Neri
Quoted 89 lines · Vincent Guittot
Quoted 76 lines · Ricardo Neri
Some topologies have scheduling domains that contain CPUs of asymmetric capacity, grouped into two or more clusters of equal-capacity CPUs sharing an L2 cache. When
CONFIG_SCHED_CLUSTERis enabled, load must be balanced across these clusters.Do not clear
SD_PREFER_SIBLINGin the child domains to indicate to the load balancer that it should spread load among cluster siblings.Checks for capacity in
update_sd_pick_busiest(),sched_balance_find_src_group(), andsched_balance_find_src_rq()prevent migrations from high- to low-capacity CPUs if the busiest group is not overloaded.CPUs with spare capacity, big or small, have always helped overloaded groups. Once the overloading condition disappears, misfit load will still be used to move high-utilization tasks to bigger CPUs if they have spare capacity.
Adding the
SD_PREFER_SIBLINGflag shifts load balancing in shared-LLC domains from equalizing the number of idle CPUs to equalizing the number of running tasks. This also enables migrations among clusters from newly- idle load balance, where the outgoing task is already dequeued but the CPU has not yet transitioned to idle.Reviewed-by Tim Chen <[email protected]>Tested-by Christian Loehle <[email protected]>Signed-off-by Ricardo Neri <[email protected]>---
Changes in v5:
* Improved inline comments for accuracy.
* Added Tested-by tag from Christian. Thanks!Changes in v4:
* Added Reviewed-by tag from Tim. Thanks!Changes in v3:
* Updated documentation ofSD_PREFER_SIBLING.
* Expanded the patch description to explain the behavior when overloaded groups are involved.Changes in v2:
* Reworded the patch description for clarity.
* Kept parentheses around bitwise operators for clarity.--- include/linux/sched/sd_flags.h | 3 ++- kernel/sched/topology.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-)include/linux/sched/sd_flags.h +2
-1@@ -147,7 +147,8 @@ SD_FLAG(SD_ASYM_PACKING, SDF_NEEDS_GROUPS)* Prefer to place tasks in a sibling domain * * Set up until domains start spanning NUMA nodes. Close to being a SHARED_CHILD -* flag, but cleared below domains with SD_ASYM_CPUCAPACITY. +* flag, but cleared below domains with SD_ASYM_CPUCAPACITY unless those child +* domains have clusters of CPUs sharing cache. * * NEEDS_GROUPS: Load balancing flag. */ kernel/sched/topology.c +3
-2@@ -1995,8 +1995,18 @@ sd_init(struct sched_domain_topology_level *tl,/* * Convert topological properties into behaviour. */ -/* Don't attempt to spread across CPUs of different capacities. */ -if ((sd->flags &SD_ASYM_CPUCAPACITY ) && sd->child) +/* +* Don't attempt to spread across CPUs of different capacities. +* kernel/sched/topology.c sd_init(struct sched_domain_topology_level *tl, · line 2010
Quoted 10 lines
kernel/sched/topology.c +9
-0+* If the child domain has clusters of CPUs sharing L2 cache, keep the +* flag to spread tasks across clusters of identical capacity. Checks in +* the load balancer prevent task migrations from high- to low-capacity +* CPUs unless the source group is overloaded. Migrations to a lower- +* capacity CPU can happen if a higher-capacity group is overloaded and +* a lower-capacity CPU has spare capacity. +*/ +if ((sd->flags &SD_ASYM_CPUCAPACITY ) && sd->child && + !(sd->child->flags &SD_CLUSTER )) sd->child->flags &= ~SD_PREFER_SIBLING ;Quoted 8 lines
Last time I looked at this patch I was balanced between your proposal above and simply keeping
SD_PREFER_SIBLINGfor all HMP topologies. As added in the comment:
" Checks in
* the load balancer prevent task migrations from high- to low-capacity
* CPUs unless the source group is overloaded.
"
So, why should we bother for (SD_ASYM_CPUCAPACITY&& !SD_CLUSTER) topology ?Quoted 6 lines
No reason, AFAICS. I just wanted to restrict the change to the target topology of this patchset.
But you raise a good point: given the checks in place in the load balancer, it should be OK to keep
SD_PREFER_SIBLINGin all asymmetric topologies. I will run a few experiments to confirm.I ran a few experiments with and without
CONFIG_CLUSTER_SCHED. I ran N threads where N < nproc to ensure that sched groups were classified ashas_spareorfully_busy. The threads saturated the CPUs to minimize task placement decisions at wake up.I observed these threads to remain on the CPUs with highest capacity; no spreading.
Quoted 6 lines
I repeated the experiment with EAS enabled and threads ramping up utilization. EAS kept them on small CPUs and later duly moved to CPUs of higher capacity as they became misfits.
I will update my patch to keep
SD_PREFER_SIBLINGregardless of asymmetric capacity.
Thanks
Hi Ricardo,
Quoted 62 lines · Ricardo Neri
Hi,
This is v5 of the patch series. The only changes are optimizations to check same-capacity cluster and SMT siblings only when needed. Please read the changelog for details.
Cluster scheduling aims to maximize performance by spreading load across clusters of CPUs that share mid-level resources [2]. It works well on uniform systems, but it breaks down on topologies with big and small cores arranged in clusters. As a result, it fails on several generations of Intel processors already shipped and upcoming.
Consider the topology below of big (B) cores and clusters of small (s) cores.
------ ------ | B | | B | ----------------- ----------------- | | | | | s | s | s | s | | s | s | s | s | ------ ------ ----------------- ----------------- | L2 | | L2 | | L2 | | L2 | ------------------------------------------------------- | L3 | -------------------------------------------------------On a partially busy system (one with idle CPUs; busy CPUs have one task each), scheduling for asymmetric capacity ensures that misfit tasks land on the big CPUs. The remaining tasks, misfit or not, run on the small CPUs. When
CONFIG_SCHED_CLUSTERis enabled, these remaining tasks are supposed to be evenly spread among the small-CPU clusters. Today, this does not happen.Several issues in the load balancer prevent a small CPU in one cluster from pulling tasks from another:
a)
update_sd_pick_busiest()may select afully_busygroup with higher per-CPU capacity as the busiest, preventing a subsequentfully_busygroup of equal capacity from being correctly selected.
b) Misfit-load statistics are used to identify tasks that would benefit from migrating to bigger CPUs. Accounting misfit load is pointless if the destination CPU is equally small, and it also blocks balancing between clusters.
c) Due to b), groups that are trulyhas_spareorfully_busyget misclassified asmisfit_task.update_sd_pick_busiest()then skips them, since a small destination CPU cannot help with misfit tasks.
d) Once a busiest group has been identified,sched_balance_find_src_rq()will refuse to migrate tasks to CPUs of equal capacity, even when doing so is precisely what is required to balance small-CPU clusters.
e) TheSD_PREFER_SIBLINGflag is missing from scheduling domains with asymmetric capacity, preventing the balancer from equalizing load across sibling small-core clusters.Together, these issues prevent cluster-level balancing on systems with asymmetric CPU capacity.
This series addresses each problem and restores the intended behavior. Details, rationale, and code changes are explained in each patch.
I tested these patches on Alder Lake, which has both SMT Pcores and clusters of Ecores. I tested with SMT both disabled and enabled. I also tested on Lunar Lake and Panther Lake, which have an Ecore cluster not connected to the L3 cache. I repeated the same experiment with
CONFIG_SCHED_CLUSTERdisabled. The load balancer behaves as expected.
Quoted 6 lines
Christian also tested this patchset on a synthetic arm64 qemu topology and the expected behavior [3].
I looked at this series and did some tests on Vera Rubin (arm64). The series does not directly target this topology, because the system has no usable SD_CLUSTER domain. Nevertheless, there are changes to the common fair load-balancing and SD_ASYM_CPUCAPACITY paths, so I tested it just to check for any potential regression.
I used DCPerf MediaWiki and a CPU-intensive SGEMM workload based on NVPL. The results showed no measurable performance differences, with all observed variations falling within normal run-to-run variability. Based on these results, the series looks good on this platform as well.
Thanks,
-Andrea
Quoted 67 lines
Changes in v5:
- Added Tested-by tags from Christian. Thanks!
- Patch 1 (pre-work): Optimized logic to identify CPUs with busy SMT
siblings only when needed. (Prateek, Chen Yu)
- Patch 5: Optimized logic to check for architectural capacity only when
needed.
- Added Reviewed-by tag from Prateek. Thanks!
- Link to v4: https://lore.kernel.org/r/20260608-rneri-fix-cas-clusters-v4-0-1526711c944c@linux.intel.comChanges in v4:
- Patch 1 (pre-work): Fixed a bug that would block load balancing on SMT
cores with more than one busy sibling.
- Patch 2 (pre-work): Fixed a bug that would needlessly update
sg_overloaded.
- Patch 5: Reworked logic using a local variable for improved
readability.
- Added Reviewed-by tags from Chen Yu, Tim, and Vincent. Thanks!
- Link to v3: https://lore.kernel.org/r/20260514-rneri-fix-cas-clusters-v3-0-0037869554bd@linux.intel.comChanges in v3:
- Patch 3: Reverted the inverted runtime capacity check. The inverted
form resulted in migrations to CPUs of slightly lower capacity. Guarded
the check for architectural capacity with thesched_cluster_active
static key.
- Patch 4: Expanded the patch description to explain the behavior of
overloaded groups and low-capacity clusters with spare capacity.
- Added Reviewed-by tags from Christian. Thanks!
- Link to v2: https://lore.kernel.org/r/20260429-rneri-fix-cas-clusters-v2-0-cd787de35cc6@linux.intel.comChanges in v2:
- Patch 1: Rewrote patch description for clarity. Added a note
clarifying thatSD_ASYM_CPUCAPACITYand SMT are mutually
exclusive. (Tim)
- Patch 2: Fixed a bug where the capacity check inadvertently broke
the mutual exclusion of thesched_reduced_capacity()path. Keep
marking the root domain as overloaded when misfit tasks are present
to allow bigger CPUs to help via newly idle balance. (sashiko)
Fixed the description to state thatcapacity_greater()looks for
differences of ~5% or more, not 20%. (Christian)
- Patch 3: Usearch_scale_cpu_capacity()instead ofcapacity_of()to
ignore runtime capacity variability. Inverted the capacity check.
(Christian)
- Patch 4: Reworded the patch description for clarity.
- Link to v1: https://lore.kernel.org/r/20260330-rneri-fix-cas-clusters-v1-0-1e465b6fecb2@linux.intel.com/---
Ricardo Neri (6):
sched/fair: Do not skip CPUs of similar capacity with busy SMT siblings sched/fair: Also gate overloaded status update forSD_ASYM_CPUCAPACITYsched/fair: Check CPU capacity before comparing group types during load balance sched/fair: Skip misfit load accounting when the destination CPU cannot help sched/fair: Allow load balancing between CPUs of identical capacity sched/topology: Do not clearSD_PREFER_SIBLINGin domains with clustersinclude/linux/sched/sd_flags.h | 3 +- kernel/sched/fair.c | 66 ++++++++++++++++++++++++++++++------------ kernel/sched/topology.c | 14 +++++++-- 3 files changed, 62 insertions(+), 21 deletions(-)---
base-commit:50436392fe2359ea108fd27308f86c8283be1622
change-id: 20250620-rneri-fix-cas-clusters-bb4287d1e152Best regards,
Signature · 1 line
Ricardo Neri <[email protected]>
Quoted 78 lines · Andrea Righi
Hi Ricardo,
Quoted 62 lines · Ricardo Neri
Hi,
This is v5 of the patch series. The only changes are optimizations to check same-capacity cluster and SMT siblings only when needed. Please read the changelog for details.
Cluster scheduling aims to maximize performance by spreading load across clusters of CPUs that share mid-level resources [2]. It works well on uniform systems, but it breaks down on topologies with big and small cores arranged in clusters. As a result, it fails on several generations of Intel processors already shipped and upcoming.
Consider the topology below of big (B) cores and clusters of small (s) cores.
------ ------ | B | | B | ----------------- ----------------- | | | | | s | s | s | s | | s | s | s | s | ------ ------ ----------------- ----------------- | L2 | | L2 | | L2 | | L2 | ------------------------------------------------------- | L3 | -------------------------------------------------------On a partially busy system (one with idle CPUs; busy CPUs have one task each), scheduling for asymmetric capacity ensures that misfit tasks land on the big CPUs. The remaining tasks, misfit or not, run on the small CPUs. When
CONFIG_SCHED_CLUSTERis enabled, these remaining tasks are supposed to be evenly spread among the small-CPU clusters. Today, this does not happen.Several issues in the load balancer prevent a small CPU in one cluster from pulling tasks from another:
a)
update_sd_pick_busiest()may select afully_busygroup with higher per-CPU capacity as the busiest, preventing a subsequentfully_busygroup of equal capacity from being correctly selected.
b) Misfit-load statistics are used to identify tasks that would benefit from migrating to bigger CPUs. Accounting misfit load is pointless if the destination CPU is equally small, and it also blocks balancing between clusters.
c) Due to b), groups that are trulyhas_spareorfully_busyget misclassified asmisfit_task.update_sd_pick_busiest()then skips them, since a small destination CPU cannot help with misfit tasks.
d) Once a busiest group has been identified,sched_balance_find_src_rq()will refuse to migrate tasks to CPUs of equal capacity, even when doing so is precisely what is required to balance small-CPU clusters.
e) TheSD_PREFER_SIBLINGflag is missing from scheduling domains with asymmetric capacity, preventing the balancer from equalizing load across sibling small-core clusters.Together, these issues prevent cluster-level balancing on systems with asymmetric CPU capacity.
This series addresses each problem and restores the intended behavior. Details, rationale, and code changes are explained in each patch.
I tested these patches on Alder Lake, which has both SMT Pcores and clusters of Ecores. I tested with SMT both disabled and enabled. I also tested on Lunar Lake and Panther Lake, which have an Ecore cluster not connected to the L3 cache. I repeated the same experiment with
CONFIG_SCHED_CLUSTERdisabled. The load balancer behaves as expected.Quoted 6 lines
Christian also tested this patchset on a synthetic arm64 qemu topology and the expected behavior [3].
I looked at this series and did some tests on Vera Rubin (arm64). The series does not directly target this topology, because the system has no usable
SD_CLUSTERdomain. Nevertheless, there are changes to the common fair load-balancing andSD_ASYM_CPUCAPACITYpaths, so I tested it just to check for any potential regression.
Quoted 6 lines
I used DCPerf MediaWiki and a CPU-intensive SGEMM workload based on NVPL. The results showed no measurable performance differences, with all observed variations falling within normal run-to-run variability. Based on these results, the series looks good on this platform as well.
Tested-by Andrea Righi <[email protected]>
Thanks Andrea! I will add this details in the cover letter of the next version.