[v3,07/10] sched/fair: Do not even the number of busy CPUs via asym_packing
Commit Message
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.
Simplify asym_smt_can_pull_tasks() accordingly.
Cc: Ben Segall <bsegall@google.com>
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Len Brown <len.brown@intel.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Tim C. Chen <tim.c.chen@intel.com>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: x86@kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
---
Changes since v2:
* Introduced this patch.
Changes since v1:
* N/A
---
kernel/sched/fair.c | 37 +++++--------------------------------
1 file changed, 5 insertions(+), 32 deletions(-)
Comments
On 07/02/2023 05:58, Ricardo Neri wrote:
[...]
> @@ -9269,33 +9264,11 @@ static bool asym_smt_can_pull_tasks(int dst_cpu, struct sd_lb_stats *sds,
> struct sched_group *sg)
> {
> #ifdef CONFIG_SCHED_SMT
> - bool local_is_smt;
> int sg_busy_cpus;
>
> - local_is_smt = sds->local->flags & SD_SHARE_CPUCAPACITY;
> sg_busy_cpus = sgs->group_weight - sgs->idle_cpus;
>
> - if (!local_is_smt) {
> - /*
> - * If we are here, @dst_cpu is idle and does not have SMT
> - * siblings. Pull tasks if candidate group has two or more
> - * busy CPUs.
> - */
> - if (sg_busy_cpus >= 2) /* implies sg_is_smt */
> - return true;
> -
> - /*
> - * @dst_cpu does not have SMT siblings. @sg may have SMT
> - * siblings and only one is busy. In such case, @dst_cpu
> - * can help if it has higher priority and is idle (i.e.,
> - * it has no running tasks).
> - */
> - return sched_asym_prefer(dst_cpu, sg->asym_prefer_cpu);
> - }
> -
> /*
> - * @dst_cpu has SMT siblings and are also idle.
> - *
> * If the difference in the number of busy CPUs is two or more, let
> * find_busiest_group() take care of it. We only care if @sg has
> * exactly one busy CPU. This covers SMT and non-SMT sched groups.
Can't this be made lighter by removing asym_smt_can_pull_tasks() and
putting the logic to exclude the call to sched_asym_prefer() into
sched_asym() directly?
Not sure if we need the CONFIG_SCHED_SMT since it's all guarded by
`flags & SD_SHARE_CPUCAPACITY` already, which is only set under.
CONFIG_SCHED_SMT.
static inline bool
sched_asym(struct lb_env *env, struct sd_lb_stats *sds,
struct sg_lb_stats *sgs, struct sched_group *group)
{
bool local_is_smt = sds->local->flags & SD_SHARE_CPUCAPACITY;
if (local_is_smt && !is_core_idle(env->dst_cpu))
return false;
if ((local_is_smt || group->flags & SD_SHARE_CPUCAPACITY)) {
int sg_busy_cpus = sgs->group_weight - sgs->idle_cpus;
if (sg_busy_cpus != 1)
return false;
}
return sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu);
}
[...]
On Mon, Feb 13, 2023 at 01:44:20PM +0100, Dietmar Eggemann wrote:
> On 07/02/2023 05:58, Ricardo Neri wrote:
>
> [...]
>
> > @@ -9269,33 +9264,11 @@ static bool asym_smt_can_pull_tasks(int dst_cpu, struct sd_lb_stats *sds,
> > struct sched_group *sg)
> > {
> > #ifdef CONFIG_SCHED_SMT
> > - bool local_is_smt;
> > int sg_busy_cpus;
> >
> > - local_is_smt = sds->local->flags & SD_SHARE_CPUCAPACITY;
> > sg_busy_cpus = sgs->group_weight - sgs->idle_cpus;
> >
> > - if (!local_is_smt) {
> > - /*
> > - * If we are here, @dst_cpu is idle and does not have SMT
> > - * siblings. Pull tasks if candidate group has two or more
> > - * busy CPUs.
> > - */
> > - if (sg_busy_cpus >= 2) /* implies sg_is_smt */
> > - return true;
> > -
> > - /*
> > - * @dst_cpu does not have SMT siblings. @sg may have SMT
> > - * siblings and only one is busy. In such case, @dst_cpu
> > - * can help if it has higher priority and is idle (i.e.,
> > - * it has no running tasks).
> > - */
> > - return sched_asym_prefer(dst_cpu, sg->asym_prefer_cpu);
> > - }
> > -
> > /*
> > - * @dst_cpu has SMT siblings and are also idle.
> > - *
> > * If the difference in the number of busy CPUs is two or more, let
> > * find_busiest_group() take care of it. We only care if @sg has
> > * exactly one busy CPU. This covers SMT and non-SMT sched groups.
>
> Can't this be made lighter by removing asym_smt_can_pull_tasks() and
> putting the logic to exclude the call to sched_asym_prefer() into
> sched_asym() directly?
Yes, you are right. asym_smt_can_pull_tasks() was simplified significantly.
I'll take your suggestion.
> Not sure if we need the CONFIG_SCHED_SMT since it's all guarded by
> `flags & SD_SHARE_CPUCAPACITY` already, which is only set under.
> CONFIG_SCHED_SMT.
Yes, asym_smt_can_pull_tasks() now cares for a very specific case, which
only happens with CONFIG_SCHED_SMT. I'll remove the !CONFIG_SCHED_SMT part.
>
> static inline bool
> sched_asym(struct lb_env *env, struct sd_lb_stats *sds,
> struct sg_lb_stats *sgs, struct sched_group *group)
> {
> bool local_is_smt = sds->local->flags & SD_SHARE_CPUCAPACITY;
>
> if (local_is_smt && !is_core_idle(env->dst_cpu))
> return false;
>
> if ((local_is_smt || group->flags & SD_SHARE_CPUCAPACITY)) {
> int sg_busy_cpus = sgs->group_weight - sgs->idle_cpus;
>
> if (sg_busy_cpus != 1)
> return false;
> }
>
> return sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu);
I'll take your suggestion. Thanks!
@@ -9247,20 +9247,15 @@ group_type group_classify(unsigned int imbalance_pct,
* @sgs: Load-balancing statistics of the candidate busiest group
* @sg: The candidate busiest group
*
- * Check the state of the SMT siblings of both @sds::local and @sg and decide
- * if @dst_cpu can pull tasks.
+ * Check the state of the SMT siblings of @sg and decide if @dst_cpu can pull
+ * tasks.
*
* This function must be called only if all the SMT siblings of @dst_cpu are
* idle, if any.
*
- * If @dst_cpu does not have SMT siblings, it can pull tasks if two or more of
- * the SMT siblings of @sg are busy. If only one CPU in @sg is busy, pull tasks
- * only if @dst_cpu has higher priority.
- *
- * If @dst_cpu has SMT siblings, decide based on the priority of @sg. Do it only
- * if @sg has exactly one busy CPU (i.e., one more than @sds::local). Bigger
- * imbalances in the number of busy CPUs will be dealt with in
- * find_busiest_group().
+ * @dst_cpu can pull tasks if @sg has exactly one busy CPU (i.e., one more than
+ * @sds::local) and has lower group priority than @sds::local. Bigger imbalances
+ * in the number of busy CPUs will be dealt with in find_busiest_group().
*
* Return: true if @dst_cpu can pull tasks, false otherwise.
*/
@@ -9269,33 +9264,11 @@ static bool asym_smt_can_pull_tasks(int dst_cpu, struct sd_lb_stats *sds,
struct sched_group *sg)
{
#ifdef CONFIG_SCHED_SMT
- bool local_is_smt;
int sg_busy_cpus;
- local_is_smt = sds->local->flags & SD_SHARE_CPUCAPACITY;
sg_busy_cpus = sgs->group_weight - sgs->idle_cpus;
- if (!local_is_smt) {
- /*
- * If we are here, @dst_cpu is idle and does not have SMT
- * siblings. Pull tasks if candidate group has two or more
- * busy CPUs.
- */
- if (sg_busy_cpus >= 2) /* implies sg_is_smt */
- return true;
-
- /*
- * @dst_cpu does not have SMT siblings. @sg may have SMT
- * siblings and only one is busy. In such case, @dst_cpu
- * can help if it has higher priority and is idle (i.e.,
- * it has no running tasks).
- */
- return sched_asym_prefer(dst_cpu, sg->asym_prefer_cpu);
- }
-
/*
- * @dst_cpu has SMT siblings and are also idle.
- *
* If the difference in the number of busy CPUs is two or more, let
* find_busiest_group() take care of it. We only care if @sg has
* exactly one busy CPU. This covers SMT and non-SMT sched groups.