From 3eeb00d31818e4d7464f8e8ba602edb962f9d8e9 Mon Sep 17 00:00:00 2001 From: Shaleen Agrawal Date: Wed, 2 Feb 2022 11:54:47 -0800 Subject: [PATCH] sched: Fix negative capacity issue under thermal conditions Currently, there is a issue in the system where the rt capacity could be greater than the thermal capacity, and as a consequence we could end up with a negative capacity in calculations. Change-Id: If81be87878ae7948b0278e30ac4a8618d434d070 Signed-off-by: Shaleen Agrawal --- kernel/sched/walt/walt.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/kernel/sched/walt/walt.c b/kernel/sched/walt/walt.c index fa2d3d3bf5df..4cc53c862870 100644 --- a/kernel/sched/walt/walt.c +++ b/kernel/sched/walt/walt.c @@ -3821,31 +3821,32 @@ static void walt_cpu_frequency_limits(void *unused, struct cpufreq_policy *polic */ static void android_rvh_update_cpu_capacity(void *unused, int cpu, unsigned long *capacity) { - unsigned long max_capacity = arch_scale_cpu_capacity(cpu); + unsigned long fmax_capacity = arch_scale_cpu_capacity(cpu); unsigned long thermal_pressure = arch_scale_thermal_pressure(cpu); unsigned long thermal_cap; struct walt_sched_cluster *cluster; - unsigned long rt_pressure = max_capacity - *capacity; + unsigned long rt_pressure = fmax_capacity - *capacity; + struct rq *rq = cpu_rq(cpu); if (unlikely(walt_disabled)) return; /* - * thermal_pressure = max_capacity - curr_cap_as_per_thermal. + * thermal_pressure = cpu_scale - curr_cap_as_per_thermal. * so, - * curr_cap_as_per_thermal = max_capacity - thermal_pressure. + * curr_cap_as_per_thermal = cpu_scale - thermal_pressure. */ - thermal_cap = max_capacity - thermal_pressure; + thermal_cap = fmax_capacity - thermal_pressure; cluster = cpu_cluster(cpu); - /* reduce the max_capacity under cpufreq constraints */ + /* reduce the fmax_capacity under cpufreq constraints */ if (cluster->max_freq != cluster->max_possible_freq) - max_capacity = mult_frac(max_capacity, cluster->max_freq, + fmax_capacity = mult_frac(fmax_capacity, cluster->max_freq, cluster->max_possible_freq); - cpu_rq(cpu)->cpu_capacity_orig = min(max_capacity, thermal_cap); - *capacity = cpu_rq(cpu)->cpu_capacity_orig - rt_pressure; + rq->cpu_capacity_orig = min(fmax_capacity, thermal_cap); + *capacity = max(rq->cpu_capacity_orig - rt_pressure, 1UL); } static void android_rvh_sched_cpu_starting(void *unused, int cpu)