From 89feaab758aaeb0c279008d1213a4f743ccac9f1 Mon Sep 17 00:00:00 2001 From: Sai Harshini Nimmala Date: Mon, 23 May 2022 16:31:44 -0700 Subject: [PATCH] sched/walt: Prevent within cluster load balance of misfits A misfit task can be pulled to a CPU within the same cluster in the newly-idle balance path. Since that just increases migration count and does not show any significant benefits, prevent pulling of a task if it is going to be a misfit on the destination CPU. Only pull if there are many such tasks and the source CPU needs help from a newly idle CPU. Change-Id: Ief55e3916d5902e473c0eaa101e8aefa01c04398 Signed-off-by: Sai Harshini Nimmala --- kernel/sched/walt/walt_lb.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/kernel/sched/walt/walt_lb.c b/kernel/sched/walt/walt_lb.c index 500ec59807c4..72b385c3b4e7 100644 --- a/kernel/sched/walt/walt_lb.c +++ b/kernel/sched/walt/walt_lb.c @@ -236,7 +236,7 @@ static void walt_lb_check_for_rotation(struct rq *src_rq) } static inline bool _walt_can_migrate_task(struct task_struct *p, int dst_cpu, - bool to_lower, bool force) + bool to_lower, bool to_higher, bool force) { struct walt_rq *wrq = (struct walt_rq *) task_rq(p)->android_vendor_data1; struct walt_task_struct *wts = (struct walt_task_struct *) p->android_vendor_data1; @@ -245,7 +245,6 @@ static inline bool _walt_can_migrate_task(struct task_struct *p, int dst_cpu, if (wrq->push_task == p) return false; - if (to_lower) { if (wts->iowaited) return false; @@ -258,6 +257,10 @@ static inline bool _walt_can_migrate_task(struct task_struct *p, int dst_cpu, return false; if (!force && !task_fits_max(p, dst_cpu)) return false; + } else if (!to_higher) { + if (!task_fits_max(p, dst_cpu) && + wrq->walt_stats.nr_big_tasks < 2) + return false; } /* Don't detach task if dest cpu is halted */ @@ -292,7 +295,7 @@ static int walt_lb_pull_tasks(int dst_cpu, int src_cpu) struct rq *src_rq = cpu_rq(src_cpu); unsigned long flags; struct task_struct *pulled_task = NULL, *p; - bool active_balance = false, to_lower; + bool active_balance = false, to_lower, to_higher; struct walt_rq *src_wrq = (struct walt_rq *) src_rq->android_vendor_data1; struct walt_rq *dst_wrq = (struct walt_rq *) cpu_rq(dst_cpu)->android_vendor_data1; struct walt_task_struct *wts; @@ -301,6 +304,8 @@ static int walt_lb_pull_tasks(int dst_cpu, int src_cpu) to_lower = dst_wrq->cluster->id < src_wrq->cluster->id; + to_higher = dst_wrq->cluster->id > src_wrq->cluster->id; + raw_spin_lock_irqsave(&src_rq->__lock, flags); list_for_each_entry_reverse(p, &src_rq->cfs_tasks, se.group_node) { @@ -311,7 +316,8 @@ static int walt_lb_pull_tasks(int dst_cpu, int src_cpu) if (task_running(src_rq, p)) continue; - if (!_walt_can_migrate_task(p, dst_cpu, to_lower, false)) + if (!_walt_can_migrate_task(p, dst_cpu, to_lower, to_higher, + false)) continue; walt_detach_task(p, src_rq, dst_rq); @@ -327,7 +333,8 @@ static int walt_lb_pull_tasks(int dst_cpu, int src_cpu) if (task_running(src_rq, p)) continue; - if (!_walt_can_migrate_task(p, dst_cpu, to_lower, true)) + if (!_walt_can_migrate_task(p, dst_cpu, to_lower, to_higher, + true)) continue; walt_detach_task(p, src_rq, dst_rq); @@ -1046,15 +1053,17 @@ static void walt_nohz_balancer_kick(void *unused, struct rq *rq, static void walt_can_migrate_task(void *unused, struct task_struct *p, int dst_cpu, int *can_migrate) { - bool to_lower; + bool to_lower, to_higher; struct walt_rq *dst_wrq = (struct walt_rq *) cpu_rq(dst_cpu)->android_vendor_data1; struct walt_rq *task_wrq = (struct walt_rq *) cpu_rq(task_cpu(p))->android_vendor_data1; if (unlikely(walt_disabled)) return; to_lower = dst_wrq->cluster->id < task_wrq->cluster->id; + to_higher = dst_wrq->cluster->id > task_wrq->cluster->id; - if (_walt_can_migrate_task(p, dst_cpu, to_lower, true)) + if (_walt_can_migrate_task(p, dst_cpu, to_lower, + to_higher, true)) return; *can_migrate = 0;