Skip to content

Commit 45de206

Browse files
Alex ShiIngo Molnar
authored andcommitted
sched/fair: Rework sched_use_asym_prio() and sched_asym_prefer()
sched_use_asym_prio() and sched_asym_prefer() are used together in various places. Consolidate them into a single function sched_asym(). The existing sched_asym() function is only used when collecting statistics of a scheduling group. Rename it as sched_group_asym(), and remove the obsolete function description. This makes the code easier to read. No functional changes. Signed-off-by: Alex Shi <alexs@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Tested-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com> Reviewed-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com> Reviewed-by: Vincent Guittot <vincent.guittot@linaro.org> Link: https://lore.kernel.org/r/20240210113924.1130448-3-alexs@kernel.org
1 parent 5a64983 commit 45de206

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

kernel/sched/fair.c

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9750,43 +9750,40 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
97509750
return sd->flags & SD_SHARE_CPUCAPACITY || is_core_idle(cpu);
97519751
}
97529752

9753+
static inline bool sched_asym(struct sched_domain *sd, int dst_cpu, int src_cpu)
9754+
{
9755+
/*
9756+
* First check if @dst_cpu can do asym_packing load balance. Only do it
9757+
* if it has higher priority than @src_cpu.
9758+
*/
9759+
return sched_use_asym_prio(sd, dst_cpu) &&
9760+
sched_asym_prefer(dst_cpu, src_cpu);
9761+
}
9762+
97539763
/**
9754-
* sched_asym - Check if the destination CPU can do asym_packing load balance
9764+
* sched_group_asym - Check if the destination CPU can do asym_packing balance
97559765
* @env: The load balancing environment
97569766
* @sgs: Load-balancing statistics of the candidate busiest group
97579767
* @group: The candidate busiest group
97589768
*
97599769
* @env::dst_cpu can do asym_packing if it has higher priority than the
97609770
* preferred CPU of @group.
97619771
*
9762-
* SMT is a special case. If we are balancing load between cores, @env::dst_cpu
9763-
* can do asym_packing balance only if all its SMT siblings are idle. Also, it
9764-
* can only do it if @group is an SMT group and has exactly on busy CPU. Larger
9765-
* imbalances in the number of CPUS are dealt with in find_busiest_group().
9766-
*
9767-
* If we are balancing load within an SMT core, or at PKG domain level, always
9768-
* proceed.
9769-
*
97709772
* Return: true if @env::dst_cpu can do with asym_packing load balance. False
97719773
* otherwise.
97729774
*/
97739775
static inline bool
9774-
sched_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group *group)
9776+
sched_group_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group *group)
97759777
{
9776-
/* Ensure that the whole local core is idle, if applicable. */
9777-
if (!sched_use_asym_prio(env->sd, env->dst_cpu))
9778-
return false;
9779-
97809778
/*
9781-
* CPU priorities does not make sense for SMT cores with more than one
9779+
* CPU priorities do not make sense for SMT cores with more than one
97829780
* busy sibling.
97839781
*/
9784-
if (group->flags & SD_SHARE_CPUCAPACITY) {
9785-
if (sgs->group_weight - sgs->idle_cpus != 1)
9786-
return false;
9787-
}
9782+
if ((group->flags & SD_SHARE_CPUCAPACITY) &&
9783+
(sgs->group_weight - sgs->idle_cpus != 1))
9784+
return false;
97889785

9789-
return sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu);
9786+
return sched_asym(env->sd, env->dst_cpu, group->asym_prefer_cpu);
97909787
}
97919788

97929789
/* One group has more than one SMT CPU while the other group does not */
@@ -9942,7 +9939,7 @@ static inline void update_sg_lb_stats(struct lb_env *env,
99429939
/* Check if dst CPU is idle and preferred to this group */
99439940
if (!local_group && env->sd->flags & SD_ASYM_PACKING &&
99449941
env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running &&
9945-
sched_asym(env, sgs, group)) {
9942+
sched_group_asym(env, sgs, group)) {
99469943
sgs->group_asym_packing = 1;
99479944
}
99489945

@@ -11028,8 +11025,7 @@ static struct rq *find_busiest_queue(struct lb_env *env,
1102811025
* SMT cores with more than one busy sibling.
1102911026
*/
1103011027
if ((env->sd->flags & SD_ASYM_PACKING) &&
11031-
sched_use_asym_prio(env->sd, i) &&
11032-
sched_asym_prefer(i, env->dst_cpu) &&
11028+
sched_asym(env->sd, i, env->dst_cpu) &&
1103311029
nr_running == 1)
1103411030
continue;
1103511031

@@ -11899,8 +11895,7 @@ static void nohz_balancer_kick(struct rq *rq)
1189911895
* preferred CPU must be idle.
1190011896
*/
1190111897
for_each_cpu_and(i, sched_domain_span(sd), nohz.idle_cpus_mask) {
11902-
if (sched_use_asym_prio(sd, i) &&
11903-
sched_asym_prefer(i, cpu)) {
11898+
if (sched_asym(sd, i, cpu)) {
1190411899
flags = NOHZ_STATS_KICK | NOHZ_BALANCE_KICK;
1190511900
goto unlock;
1190611901
}

0 commit comments

Comments
 (0)