Skip to content

Commit 4aed8aa

Browse files
Valentin SchneiderPeter Zijlstra
authored andcommitted
sched/fair: Introduce a CPU capacity comparison helper
During load-balance, groups classified as group_misfit_task are filtered out if they do not pass group_smaller_max_cpu_capacity(<candidate group>, <local group>); which itself employs fits_capacity() to compare the sgc->max_capacity of both groups. Due to the underlying margin, fits_capacity(X, 1024) will return false for any X > 819. Tough luck, the capacity_orig's on e.g. the Pixel 4 are {261, 871, 1024}. If a CPU-bound task ends up on one of those "medium" CPUs, misfit migration will never intentionally upmigrate it to a CPU of higher capacity due to the aforementioned margin. One may argue the 20% margin of fits_capacity() is excessive in the advent of counter-enhanced load tracking (APERF/MPERF, AMUs), but one point here is that fits_capacity() is meant to compare a utilization value to a capacity value, whereas here it is being used to compare two capacity values. As CPU capacity and task utilization have different dynamics, a sensible approach here would be to add a new helper dedicated to comparing CPU capacities. Also note that comparing capacity extrema of local and source sched_group's doesn't make much sense when at the day of the day the imbalance will be pulled by a known env->dst_cpu, whose capacity can be anywhere within the local group's capacity extrema. While at it, replace group_smaller_{min, max}_cpu_capacity() with comparisons of the source group's min/max capacity and the destination CPU's capacity. Signed-off-by: Valentin Schneider <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Dietmar Eggemann <[email protected]> Reviewed-by: Qais Yousef <[email protected]> Reviewed-by: Vincent Guittot <[email protected]> Tested-by: Lingutla Chandrasekhar <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 23fb06d commit 4aed8aa

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

kernel/sched/fair.c

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ int __weak arch_asym_cpu_priority(int cpu)
113113
*/
114114
#define fits_capacity(cap, max) ((cap) * 1280 < (max) * 1024)
115115

116+
/*
117+
* The margin used when comparing CPU capacities.
118+
* is 'cap1' noticeably greater than 'cap2'
119+
*
120+
* (default: ~5%)
121+
*/
122+
#define capacity_greater(cap1, cap2) ((cap1) * 1024 > (cap2) * 1078)
116123
#endif
117124

118125
#ifdef CONFIG_CFS_BANDWIDTH
@@ -8395,26 +8402,6 @@ group_is_overloaded(unsigned int imbalance_pct, struct sg_lb_stats *sgs)
83958402
return false;
83968403
}
83978404

8398-
/*
8399-
* group_smaller_min_cpu_capacity: Returns true if sched_group sg has smaller
8400-
* per-CPU capacity than sched_group ref.
8401-
*/
8402-
static inline bool
8403-
group_smaller_min_cpu_capacity(struct sched_group *sg, struct sched_group *ref)
8404-
{
8405-
return fits_capacity(sg->sgc->min_capacity, ref->sgc->min_capacity);
8406-
}
8407-
8408-
/*
8409-
* group_smaller_max_cpu_capacity: Returns true if sched_group sg has smaller
8410-
* per-CPU capacity_orig than sched_group ref.
8411-
*/
8412-
static inline bool
8413-
group_smaller_max_cpu_capacity(struct sched_group *sg, struct sched_group *ref)
8414-
{
8415-
return fits_capacity(sg->sgc->max_capacity, ref->sgc->max_capacity);
8416-
}
8417-
84188405
static inline enum
84198406
group_type group_classify(unsigned int imbalance_pct,
84208407
struct sched_group *group,
@@ -8570,7 +8557,7 @@ static bool update_sd_pick_busiest(struct lb_env *env,
85708557
* internally or be covered by avg_load imbalance (eventually).
85718558
*/
85728559
if (sgs->group_type == group_misfit_task &&
8573-
(!group_smaller_max_cpu_capacity(sg, sds->local) ||
8560+
(!capacity_greater(capacity_of(env->dst_cpu), sg->sgc->max_capacity) ||
85748561
sds->local_stat.group_type != group_has_spare))
85758562
return false;
85768563

@@ -8654,7 +8641,7 @@ static bool update_sd_pick_busiest(struct lb_env *env,
86548641
*/
86558642
if ((env->sd->flags & SD_ASYM_CPUCAPACITY) &&
86568643
(sgs->group_type <= group_fully_busy) &&
8657-
(group_smaller_min_cpu_capacity(sds->local, sg)))
8644+
(capacity_greater(sg->sgc->min_capacity, capacity_of(env->dst_cpu))))
86588645
return false;
86598646

86608647
return true;
@@ -9454,7 +9441,7 @@ static struct rq *find_busiest_queue(struct lb_env *env,
94549441
* average load.
94559442
*/
94569443
if (env->sd->flags & SD_ASYM_CPUCAPACITY &&
9457-
capacity_of(env->dst_cpu) < capacity &&
9444+
!capacity_greater(capacity_of(env->dst_cpu), capacity) &&
94589445
nr_running == 1)
94599446
continue;
94609447

0 commit comments

Comments
 (0)