From a0f963c16233e8f45394097422ce5268ec80a23c Mon Sep 17 00:00:00 2001 From: Pavankumar Kondeti Date: Mon, 7 Dec 2020 18:44:52 +0530 Subject: [PATCH] sched/walt: Improve the scheduler This change is for general scheduler improvement. Change-Id: I288fc9a8858cb29ae9c6993b398a349b4a8c7475 Signed-off-by: Pavankumar Kondeti --- kernel/sched/rt.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index eae47c6a54d9..2c83330f9ea0 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1652,6 +1652,55 @@ static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p) resched_curr(rq); } +#ifdef CONFIG_SCHED_WALT +#define WALT_RT_PULL_THRESHOLD_NS 250000 +static struct task_struct *pick_highest_pushable_task(struct rq *rq, int cpu); +static void try_pull_rt_task(struct rq *this_rq) +{ + int i, this_cpu = this_rq->cpu, src_cpu = this_cpu; + struct rq *src_rq; + struct task_struct *p; + + if (sched_rt_runnable(this_rq)) + return; + + for_each_possible_cpu(i) { + struct rq *rq = cpu_rq(i); + + if (!has_pushable_tasks(rq)) + continue; + + src_cpu = i; + break; + } + + if (src_cpu == this_cpu) + return; + + src_rq = cpu_rq(src_cpu); + double_lock_balance(this_rq, src_rq); + + /* lock is dropped, so check again */ + if (sched_rt_runnable(this_rq)) + goto unlock; + + p = pick_highest_pushable_task(src_rq, this_cpu); + + if (!p) + goto unlock; + + if (sched_ktime_clock() - p->wts.last_wake_ts < + WALT_RT_PULL_THRESHOLD_NS) + goto unlock; + + deactivate_task(src_rq, p, 0); + set_task_cpu(p, this_cpu); + activate_task(this_rq, p, 0); +unlock: + double_unlock_balance(this_rq, src_rq); +} +#endif + static int balance_rt(struct rq *rq, struct task_struct *p, struct rq_flags *rf) { if (!on_rt_rq(&p->rt) && need_pull_rt_task(rq, p)) { @@ -1662,7 +1711,14 @@ static int balance_rt(struct rq *rq, struct task_struct *p, struct rq_flags *rf) * not yet started the picking loop. */ rq_unpin_lock(rq, rf); +#ifndef CONFIG_SCHED_WALT pull_rt_task(rq); +#else + if (rt_overloaded(rq)) + pull_rt_task(rq); + else + try_pull_rt_task(rq); +#endif rq_repin_lock(rq, rf); }