From f125db1dd49449cec7d72138579dd5cda514ddaa Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Mon, 9 Apr 2018 15:22:36 +0200 Subject: Change opp at compute capacity equality Signed-off-by: Daniel Lezcano --- drivers/thermal/cpu_cooling.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index b0365415e575..653d5b739408 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -1663,8 +1663,39 @@ static int cpu_cooling_set_cur_state(struct thermal_cooling_device *cdev, */ opp_power = cpufreq_cdev->freq_table[opp_index].power * num_cpus; - idle_state = ((opp_power - power) * 100) / power; + idle_state = ((opp_power - power) * 100) / opp_power; + pr_info("State=%lu, max power=%u, requested power=%u, opp(%d) power=%u, idle ratio=%d\n", + state, cpu_cdev->max_power, power, opp_index, opp_power, idle_state); + + /* + * Compute the capacity of the cluster based on the ratio + * busy/idle and the current OPP's capacity + */ + if (idle_state) { + u32 opp_capacity = cpufreq_cdev->freq_table[opp_index].capacity; + u32 below_opp_capacity = cpufreq_cdev->freq_table[opp_index + 1].capacity; + u32 capacity = ((opp_capacity * (100 - idle_state)) / 100); + + pr_info("Opp capacity=%u, idle inject capacity=%u, below opp capacity=%u\n", + opp_capacity, capacity, below_opp_capacity); + + if (!capacity) + pr_warning("Capacity is zero\n"); + else { + /* + * At this point, it is not worth to stay at + * this level of OPP, as the capacity is less + * or equal of the OPP below, go to the lower + * OPP and reset the idle state_ratio + */ + if (capacity <= below_opp_capacity) { + idle_state = 0; + opp_index++; + } + } + } + /* * Catch unexpected situation where we are out of bound of the * idle state percentage values. -- cgit v1.2.3