From 53ef4e9eedc44e7e6888b2688439147d23b4c8c6 Mon Sep 17 00:00:00 2001 From: Stephen Dickey Date: Sat, 19 Feb 2022 14:17:14 -0800 Subject: [PATCH] sched/walt: guarantee result from energy efficient cpu It is possible that walt_find_energy_efficient_cpu will return an error value, or a negative number for the cpu. In walt_lb_tick this was called without checking the return value. Update walt_find_energy_efficient_cpu to guarantee that it never returns a bad value, and that in all cases it returns prev_cpu if it cannot find an energy efficient cpu. Change-Id: Ifc08bdf42b8d54923f8a4ecc3ca8b2c0dba11f4f Signed-off-by: Stephen Dickey --- kernel/sched/walt/walt_cfs.c | 12 +++++++----- kernel/sched/walt/walt_lb.c | 8 ++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/kernel/sched/walt/walt_cfs.c b/kernel/sched/walt/walt_cfs.c index c2bd0d064d18..d708710a3fc2 100644 --- a/kernel/sched/walt/walt_cfs.c +++ b/kernel/sched/walt/walt_cfs.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2020-2022, The Linux Foundation. All rights reserved. + * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -788,7 +789,7 @@ int walt_find_energy_efficient_cpu(struct task_struct *p, int prev_cpu, return prev_cpu; if (unlikely(!cpu_array)) - return -EPERM; + return prev_cpu; walt_get_indicies(p, &order_index, &end_index, task_boost, uclamp_boost, &energy_eval_needed); @@ -926,6 +927,9 @@ int walt_find_energy_efficient_cpu(struct task_struct *p, int prev_cpu, rcu_read_unlock(); done: + if (best_energy_cpu < 0 || best_energy_cpu >= WALT_NR_CPUS) + best_energy_cpu = prev_cpu; + trace_sched_task_util(p, cpumask_bits(candidates)[0], best_energy_cpu, sync, fbt_env.need_idle, fbt_env.fastpath, start_t, uclamp_boost, start_cpu); @@ -934,7 +938,7 @@ int walt_find_energy_efficient_cpu(struct task_struct *p, int prev_cpu, fail: rcu_read_unlock(); - return -EPERM; + return prev_cpu; } static void @@ -952,8 +956,6 @@ walt_select_task_rq_fair(void *unused, struct task_struct *p, int prev_cpu, p->wake_q_count = 0; *target_cpu = walt_find_energy_efficient_cpu(p, prev_cpu, sync, sibling_count_hint); - if (unlikely(*target_cpu < 0)) - *target_cpu = prev_cpu; } static void walt_binder_low_latency_set(void *unused, struct task_struct *task, diff --git a/kernel/sched/walt/walt_lb.c b/kernel/sched/walt/walt_lb.c index 9a0502a59e7b..ed6c2dc9781a 100644 --- a/kernel/sched/walt/walt_lb.c +++ b/kernel/sched/walt/walt_lb.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. - * Copyright (c) 2020-2021, Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2020-2022, Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -633,14 +633,10 @@ void walt_lb_tick(struct rq *rq) new_cpu = walt_find_energy_efficient_cpu(p, prev_cpu, 0, 1); rcu_read_unlock(); - if (new_cpu < 0) - goto out_unlock; - new_wrq = (struct walt_rq *) cpu_rq(new_cpu)->android_vendor_data1; /* prevent active task migration to busy or same/lower capacity CPU */ - if (!available_idle_cpu(new_cpu) || - new_wrq->cluster->id <= prev_wrq->cluster->id) + if (!available_idle_cpu(new_cpu) || new_wrq->cluster->id <= prev_wrq->cluster->id) goto out_unlock; raw_spin_lock(&rq->__lock);