[PATCH 2/2] sched: load balance core imbalanced load

From: Tim Chen
Date: Wed Aug 28 2019 - 14:22:43 EST


If moving mismatched core scheduling load can reduce load imbalance
more than regular load balancing, move the mismatched load instead.

On regular load balancing, also skip moving a task that could increase
load mismatch.

Move only one mismatched task at a time to reduce load disturbance.

Signed-off-by: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>
---
kernel/sched/fair.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index b3d6a6482553..69939c977797 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7412,6 +7412,11 @@ struct lb_env {
enum fbq_type fbq_type;
enum group_type src_grp_type;
struct list_head tasks;
+#ifdef CONFIG_SCHED_CORE
+ int imbl_cpu;
+ struct task_group *imbl_tg;
+ s64 imbl_load;
+#endif
};

/*
@@ -7560,6 +7565,12 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env)
return 0;
}

+#ifdef CONFIG_SCHED_CORE
+ /* Don't migrate if we increase core imbalance */
+ if (core_sched_imbalance_improvement(env->src_cpu, env->dst_cpu, p) < 0)
+ return 0;
+#endif
+
/* Record that we found atleast one task that could run on dst_cpu */
env->flags &= ~LBF_ALL_PINNED;

@@ -8533,6 +8544,14 @@ static inline void update_sg_lb_stats(struct lb_env *env,

sgs->group_no_capacity = group_is_overloaded(env, sgs);
sgs->group_type = group_classify(group, sgs);
+
+#ifdef CONFIG_SCHED_CORE
+ if (sgs->imbl_load > env->imbl_load) {
+ env->imbl_cpu = sgs->imbl_cpu;
+ env->imbl_tg = sgs->imbl_tg;
+ env->imbl_load = sgs->imbl_load;
+ }
+#endif
}

/**
@@ -9066,6 +9085,15 @@ static struct rq *find_busiest_queue(struct lb_env *env,
unsigned long busiest_load = 0, busiest_capacity = 1;
int i;

+#ifdef CONFIG_SCHED_CORE
+ if (env->imbl_load > env->imbalance) {
+ env->imbalance = cpu_avg_load_per_task(env->imbl_cpu);
+ return cpu_rq(env->imbl_cpu);
+ } else {
+ env->imbl_load = 0;
+ }
+#endif
+
for_each_cpu_and(i, sched_group_span(group), env->cpus) {
unsigned long capacity, wl;
enum fbq_type rt;
--
2.20.1