Skip to content

Commit c9ca078

Browse files
ricardonPeter Zijlstra
authored and
Peter Zijlstra
committed
sched/fair: Do not even the number of busy CPUs via asym_packing
Now that find_busiest_group() triggers load balancing between a fully_ busy SMT2 core and an idle non-SMT core, it is no longer needed to force balancing via asym_packing. Use asym_packing only as intended: when there is high-priority CPU that is idle. After this change, the same logic apply to SMT and non-SMT local groups. It makes less sense having a separate function to deal specifically with SMT. Fold the logic in asym_smt_can_pull_tasks() into sched_asym(). Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Zhang Rui <rui.zhang@intel.com> Link: https://lore.kernel.org/r/20230406203148.19182-8-ricardo.neri-calderon@linux.intel.com
1 parent 43726bd commit c9ca078

File tree

1 file changed

+21
-65
lines changed

1 file changed

+21
-65
lines changed

kernel/sched/fair.c

+21-65
Original file line numberDiff line numberDiff line change
@@ -9350,74 +9350,26 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
93509350
}
93519351

93529352
/**
9353-
* asym_smt_can_pull_tasks - Check whether the load balancing CPU can pull tasks
9354-
* @dst_cpu: Destination CPU of the load balancing
9353+
* sched_asym - Check if the destination CPU can do asym_packing load balance
9354+
* @env: The load balancing environment
93559355
* @sds: Load-balancing data with statistics of the local group
93569356
* @sgs: Load-balancing statistics of the candidate busiest group
9357-
* @sg: The candidate busiest group
9357+
* @group: The candidate busiest group
93589358
*
9359-
* Check the state of the SMT siblings of both @sds::local and @sg and decide
9360-
* if @dst_cpu can pull tasks.
9359+
* @env::dst_cpu can do asym_packing if it has higher priority than the
9360+
* preferred CPU of @group.
93619361
*
9362-
* This function must be called only if all the SMT siblings of @dst_cpu are
9363-
* idle, if any.
9362+
* SMT is a special case. If we are balancing load between cores, @env::dst_cpu
9363+
* can do asym_packing balance only if all its SMT siblings are idle. Also, it
9364+
* can only do it if @group is an SMT group and has exactly on busy CPU. Larger
9365+
* imbalances in the number of CPUS are dealt with in find_busiest_group().
93649366
*
9365-
* If @dst_cpu does not have SMT siblings, it can pull tasks if two or more of
9366-
* the SMT siblings of @sg are busy. If only one CPU in @sg is busy, pull tasks
9367-
* only if @dst_cpu has higher priority.
9367+
* If we are balancing load within an SMT core, or at DIE domain level, always
9368+
* proceed.
93689369
*
9369-
* When dealing with SMT cores, only use priorities if the SMT core has exactly
9370-
* one busy sibling. find_busiest_group() will handle bigger imbalances in the
9371-
* number of busy CPUs.
9372-
*
9373-
* Return: true if @dst_cpu can pull tasks, false otherwise.
9370+
* Return: true if @env::dst_cpu can do with asym_packing load balance. False
9371+
* otherwise.
93749372
*/
9375-
static bool asym_smt_can_pull_tasks(int dst_cpu, struct sd_lb_stats *sds,
9376-
struct sg_lb_stats *sgs,
9377-
struct sched_group *sg)
9378-
{
9379-
#ifdef CONFIG_SCHED_SMT
9380-
bool local_is_smt;
9381-
int sg_busy_cpus;
9382-
9383-
local_is_smt = sds->local->flags & SD_SHARE_CPUCAPACITY;
9384-
sg_busy_cpus = sgs->group_weight - sgs->idle_cpus;
9385-
9386-
if (!local_is_smt) {
9387-
/*
9388-
* If we are here, @dst_cpu is idle and does not have SMT
9389-
* siblings. Pull tasks if candidate group has two or more
9390-
* busy CPUs.
9391-
*/
9392-
if (sg_busy_cpus >= 2) /* implies sg_is_smt */
9393-
return true;
9394-
9395-
/*
9396-
* @dst_cpu does not have SMT siblings. @sg may have SMT
9397-
* siblings and only one is busy. In such case, @dst_cpu
9398-
* can help if it has higher priority and is idle (i.e.,
9399-
* it has no running tasks).
9400-
*/
9401-
return sched_asym_prefer(dst_cpu, sg->asym_prefer_cpu);
9402-
}
9403-
9404-
/*
9405-
* If we are here @dst_cpu has SMT siblings and are also idle.
9406-
*
9407-
* CPU priorities does not make sense for SMT cores with more than one
9408-
* busy sibling.
9409-
*/
9410-
if (group->flags & SD_SHARE_CPUCAPACITY && sg_busy_cpus != 1)
9411-
return false;
9412-
9413-
return sched_asym_prefer(dst_cpu, sg->asym_prefer_cpu);
9414-
9415-
#else
9416-
/* Always return false so that callers deal with non-SMT cases. */
9417-
return false;
9418-
#endif
9419-
}
9420-
94219373
static inline bool
94229374
sched_asym(struct lb_env *env, struct sd_lb_stats *sds, struct sg_lb_stats *sgs,
94239375
struct sched_group *group)
@@ -9426,10 +9378,14 @@ sched_asym(struct lb_env *env, struct sd_lb_stats *sds, struct sg_lb_stats *sgs
94269378
if (!sched_use_asym_prio(env->sd, env->dst_cpu))
94279379
return false;
94289380

9429-
/* Only do SMT checks if either local or candidate have SMT siblings. */
9430-
if ((sds->local->flags & SD_SHARE_CPUCAPACITY) ||
9431-
(group->flags & SD_SHARE_CPUCAPACITY))
9432-
return asym_smt_can_pull_tasks(env->dst_cpu, sds, sgs, group);
9381+
/*
9382+
* CPU priorities does not make sense for SMT cores with more than one
9383+
* busy sibling.
9384+
*/
9385+
if (group->flags & SD_SHARE_CPUCAPACITY) {
9386+
if (sgs->group_weight - sgs->idle_cpus != 1)
9387+
return false;
9388+
}
94339389

94349390
return sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu);
94359391
}

0 commit comments

Comments
 (0)