From 452807ae7e53fa9141f3bf6e2cb186347eb65547 Mon Sep 17 00:00:00 2001 From: Abhijeet Dharmapurikar Date: Sun, 1 Aug 2021 23:48:36 -0700 Subject: [PATCH] sched/walt: choose best cpu based on spare cap When the placement code has to skip energy evaluation and quickly return the best cpu amongst the candidates, the current code chooses the max capacity cpu within them. This leads to overcrowding on the max cpu, as we could be operating in the skip energy eval mode for a long time. So instead of choosing max capacity cpu, choose a cpu with most spare capacity. Change-Id: I13e435cbfc802c5a1002703f928b5f56ef5d8e1f Signed-off-by: Abhijeet Dharmapurikar --- kernel/sched/walt/walt_cfs.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kernel/sched/walt/walt_cfs.c b/kernel/sched/walt/walt_cfs.c index 16815a5ebf4e..e021524a4a12 100644 --- a/kernel/sched/walt/walt_cfs.c +++ b/kernel/sched/walt/walt_cfs.c @@ -670,6 +670,11 @@ static inline bool select_cpu_same_energy(int cpu, int best_cpu, int prev_cpu) return available_idle_cpu(best_cpu); } +static inline unsigned int capacity_spare_of(int cpu) +{ + return capacity_orig_of(cpu) - cpu_util(cpu); +} + static DEFINE_PER_CPU(cpumask_t, energy_cpus); int walt_find_energy_efficient_cpu(struct task_struct *p, int prev_cpu, int sync, int sibling_count_hint) @@ -761,13 +766,13 @@ int walt_find_energy_efficient_cpu(struct task_struct *p, int prev_cpu, } if (!energy_eval_needed) { - int max_cap_cpu = first_cpu; + int max_spare_cpu = first_cpu; for_each_cpu(cpu, candidates) { - if (capacity_orig_of(max_cap_cpu) < capacity_orig_of(cpu)) - max_cap_cpu = cpu; + if (capacity_spare_of(max_spare_cpu) < capacity_spare_of(cpu)) + max_spare_cpu = cpu; } - best_energy_cpu = max_cap_cpu; + best_energy_cpu = max_spare_cpu; goto unlock; }