blob: 013812fe669b23b1cf3bb78e3617270173c7c025 [file] [log] [blame]
From 83d55cfa41a9042753cdf4dc3b5477c1e961390d Mon Sep 17 00:00:00 2001
From: Quentin Perret <quentin.perret@arm.com>
Date: Wed, 27 Feb 2019 11:21:24 +0000
Subject: [PATCH] NOUPSTREAM: ANDROID: sched/fair: Bias EAS placement for
latency
Add to find_energy_efficient_cpu() a latency sensitive case which mimics
what was done for prefer-idle in android-4.19 and before (see [1] for
reference).
This isn't strictly equivalent to the legacy algorithm but comes real
close, and isn't very invasive. Overall, the idea is to select the
biggest idle CPU we can find for latency-sensitive boosted tasks, and
the smallest CPU where the can fit for latency-sensitive non-boosted
tasks.
The main differences with the legacy behaviour are the following:
1. the policy for 'prefer idle' when there isn't a single idle CPU in
the system is simpler now. We just pick the CPU with the highest
spare capacity;
2. the cstate awareness is implemented by minimizing the exit latency
rather than the idle state index. This is how it is done in the slow
path (find_idlest_group_cpu()), it doesn't require us to keep hooks
into CPUIdle, and should actually be better because what we want is
a CPU that can wake up quickly;
3. non-latency-sensitive tasks just use the standard mainline
energy-aware wake-up path, which decides the placement using the
Energy Model;
4. the 'boosted' and 'latency_sensitive' attributes of a task come from
util_clamp (which now replaces schedtune).
[1] https://android.googlesource.com/kernel/common.git/+/c27c56105dcaaae54ecc39ef33fbfac87a1486fc
[CPNOTE: 30/06/21] Lee: Hoping for an upstream alternative (conversation died)
Bug: 120440300
Change-Id: Ia58516906e9cb5abe08385a8cd088097043d8703
Signed-off-by: Quentin Perret <quentin.perret@arm.com>
---
kernel/sched/fair.c | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index d2d10057d35f8651e56c030f15bb83dc09a0d107..7ddcdd981c46030cfc5ef5a1e0e0ca16880ea496 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7044,8 +7044,13 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu, int sy
{
struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_rq_mask);
unsigned long prev_delta = ULONG_MAX, best_delta = ULONG_MAX;
+ int max_spare_cap_cpu_ls = prev_cpu, best_idle_cpu = -1;
+ unsigned long max_spare_cap_ls = 0, target_cap;
struct root_domain *rd = this_rq()->rd;
int cpu, best_energy_cpu, target = -1;
+ bool boosted, latency_sensitive = false;
+ unsigned int min_exit_lat = UINT_MAX;
+ struct cpuidle_state *idle;
struct sched_domain *sd;
struct perf_domain *pd;
struct energy_env eenv;
@@ -7079,6 +7084,9 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu, int sy
goto unlock;
eenv_task_busy_time(&eenv, p, prev_cpu);
+ latency_sensitive = uclamp_latency_sensitive(p);
+ boosted = uclamp_boosted(p);
+ target_cap = boosted ? 0 : ULONG_MAX;
for (; pd; pd = pd->next) {
unsigned long cpu_cap, cpu_thermal_cap, util;
@@ -7125,7 +7133,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu, int sy
lsub_positive(&cpu_cap, util);
- if (cpu == prev_cpu) {
+ if (!latency_sensitive && cpu == prev_cpu) {
/* Always use prev_cpu as a candidate. */
compute_prev_delta = true;
} else if (cpu_cap > max_spare_cap) {
@@ -7136,9 +7144,32 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu, int sy
max_spare_cap = cpu_cap;
max_spare_cap_cpu = cpu;
}
+
+ if (!latency_sensitive)
+ continue;
+
+ if (idle_cpu(cpu)) {
+ cpu_cap = arch_scale_cpu_capacity(cpu);
+ if (boosted && cpu_cap < target_cap)
+ continue;
+ if (!boosted && cpu_cap > target_cap)
+ continue;
+ idle = idle_get_state(cpu_rq(cpu));
+ if (idle && idle->exit_latency > min_exit_lat &&
+ cpu_cap == target_cap)
+ continue;
+
+ if (idle)
+ min_exit_lat = idle->exit_latency;
+ target_cap = cpu_cap;
+ best_idle_cpu = cpu;
+ } else if (cpu_cap > max_spare_cap_ls) {
+ max_spare_cap_ls = cpu_cap;
+ max_spare_cap_cpu_ls = cpu;
+ }
}
- if (max_spare_cap_cpu < 0 && !compute_prev_delta)
+ if (!latency_sensitive && max_spare_cap_cpu < 0 && !compute_prev_delta)
continue;
eenv_pd_busy_time(&eenv, cpus, p);
@@ -7172,6 +7203,9 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu, int sy
}
rcu_read_unlock();
+ if (latency_sensitive)
+ return best_idle_cpu >= 0 ? best_idle_cpu : max_spare_cap_cpu_ls;
+
if (best_delta < prev_delta)
target = best_energy_cpu;
--
2.38.1.584.g0f3c55d4c2-goog