From 612b4f86c144527ca297bed5a505d344914dda0b Mon Sep 17 00:00:00 2001 From: Stephen Dickey Date: Fri, 12 Nov 2021 16:27:23 -0800 Subject: [PATCH] sched/walt: avoid halted cpus for rt in find_lowest_rq select_task_rq_rt() and push_rt_task() need to select a cpu, and ultimately attempt to get a good match on a cpu through find_lowest_rq. Walt hooks into this routine to make an adjustment such that the best energy aware cpu is found. It is possible that walt_rt_energy_aware_wake_cpu will be unable to find a non-halted cpu. find_lowest_rq at that point will use the lowest_mask, initialized from the task cpus_ptr, to find a CPU. At this point, find_lowest_rq might return a halted CPU. Instead, in the case where walt cannot find a best cpu to choose, force the lowest_mask to no longer include halted cpus, which will push find_lowest_rq to no longer choose a halted cpu. In the unlikely event that find_lowest_rq still fails to find a cpu it will pick anything from the lowest_mask. In the unlikely event that lowest_mask is empty after removing all of the halted cpus, find_lowest_rq will fail and the cpu chosen will be unconstrained by halt. Change-Id: I398bc804eb474396f6f06e2c3d4308fea71dafe8 Signed-off-by: Stephen Dickey --- kernel/sched/walt/walt_rt.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/kernel/sched/walt/walt_rt.c b/kernel/sched/walt/walt_rt.c index 07afcb39fdc6..ec299ce106ef 100644 --- a/kernel/sched/walt/walt_rt.c +++ b/kernel/sched/walt/walt_rt.c @@ -10,8 +10,8 @@ static DEFINE_PER_CPU(cpumask_var_t, walt_local_cpu_mask); -static void walt_rt_energy_aware_wake_cpu(void *unused, struct task_struct *task, - struct cpumask *lowest_mask, int ret, int *best_cpu) +static void walt_rt_energy_aware_wake_cpu(struct task_struct *task, struct cpumask *lowest_mask, + int ret, int *best_cpu) { int cpu; unsigned long util, best_cpu_util = ULONG_MAX; @@ -205,7 +205,7 @@ static void walt_select_task_rq_rt(void *unused, struct task_struct *task, int c ret = cpupri_find_fitness(&task_rq(task)->rd->cpupri, task, lowest_mask, walt_rt_task_fits_capacity); - walt_rt_energy_aware_wake_cpu(NULL, task, lowest_mask, ret, &target); + walt_rt_energy_aware_wake_cpu(task, lowest_mask, ret, &target); /* * If cpu is non-preemptible, prefer remote cpu @@ -220,6 +220,22 @@ static void walt_select_task_rq_rt(void *unused, struct task_struct *task, int c rcu_read_unlock(); } + +static void walt_rt_find_lowest_rq(void *unused, struct task_struct *task, + struct cpumask *lowest_mask, int ret, int *best_cpu) + +{ + walt_rt_energy_aware_wake_cpu(task, lowest_mask, ret, best_cpu); + + /* + * Walt was not able to find a non-halted best cpu. Ensure that + * find_lowest_rq doesn't use a halted cpu going forward, but + * does a best effort itself to find a good CPU. + */ + if (*best_cpu == -1) + cpumask_andnot(lowest_mask, lowest_mask, cpu_halt_mask); +} + void walt_rt_init(void) { unsigned int i; @@ -233,5 +249,5 @@ void walt_rt_init(void) } register_trace_android_rvh_select_task_rq_rt(walt_select_task_rq_rt, NULL); - register_trace_android_rvh_find_lowest_rq(walt_rt_energy_aware_wake_cpu, NULL); + register_trace_android_rvh_find_lowest_rq(walt_rt_find_lowest_rq, NULL); }