diff mbox series

[v6,6/7] thermal/cpu-cooling: Update thermal pressure in case of a maximum frequency capping

Message ID 1576123908-12105-7-git-send-email-thara.gopinath@linaro.org
State New
Headers show
Series Introduce Thermal Pressure | expand

Commit Message

Thara Gopinath Dec. 12, 2019, 4:11 a.m. UTC
Thermal governors can request for a cpu's maximum supported frequency to
be capped in case of an overheat event. This in turn means that the
maximum capacity available for tasks to run on the particular cpu is
reduced. Delta between the original maximum capacity and capped maximum
capacity is known as thermal pressure. Enable cpufreq cooling device to
update the thermal pressure in event of a capped maximum frequency.

Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>

---

v4->v5:
	- fixed issues in update_sched_max_capacity comment header.
	- Updated update_sched_max_capacity to calculate maximum available
	  capacity.
v5->v6:
	- Removed update_sched_max_capacity. Instead call directly into
	  arch_set_thermal_pressure to update thermal pressure.

 drivers/thermal/cpu_cooling.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

-- 
2.1.4

Comments

Ionela Voinescu Dec. 23, 2019, 5:54 p.m. UTC | #1
On Wednesday 11 Dec 2019 at 23:11:47 (-0500), Thara Gopinath wrote:
[...]
> @@ -430,6 +430,10 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,

>  				 unsigned long state)

>  {

>  	struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;

> +	struct cpumask *cpus;

> +	unsigned int frequency;

> +	unsigned long capacity;

> +	int ret;

>  

>  	/* Request state should be less than max_level */

>  	if (WARN_ON(state > cpufreq_cdev->max_level))

> @@ -441,8 +445,19 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,

>  

>  	cpufreq_cdev->cpufreq_state = state;

>  

> -	return freq_qos_update_request(&cpufreq_cdev->qos_req,

> -				get_state_freq(cpufreq_cdev, state));

> +	frequency = get_state_freq(cpufreq_cdev, state);

> +

> +	ret = freq_qos_update_request(&cpufreq_cdev->qos_req, frequency);

> +

> +	if (ret > 0) {

> +		cpus = cpufreq_cdev->policy->cpus;

> +		capacity = frequency *

> +				arch_scale_cpu_capacity(cpumask_first(cpus));

> +		capacity /= cpufreq_cdev->policy->cpuinfo.max_freq;

> +		arch_set_thermal_pressure(cpus, capacity);


Given that you already get a CPU's capacity (orig) here, why don't
you pass thermal pressure directly to arch_set_thermal_pressure,
rather than passing the capped capacity and subtracting it later from
the same CPU capacity (arch_scale_cpu_capacity)?

If my math is correct this would work nicely:
                pressure = cpufreq_cdev->policy->cpuinfo.max_freq;
		pressure -= frequency;
		pressure *= arch_scale_cpu_capacity(cpumask_first(cpus);
		pressure /= cpufreq_cdev->policy->cpuinfo.max_freq;

Thanks,
Ionela.

> +	}

> +

> +	return ret;

>  }

>  

>  /* Bind cpufreq callbacks to thermal cooling device ops */

> -- 

> 2.1.4

>
diff mbox series

Patch

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 52569b2..c97c13e 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -430,6 +430,10 @@  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 				 unsigned long state)
 {
 	struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
+	struct cpumask *cpus;
+	unsigned int frequency;
+	unsigned long capacity;
+	int ret;
 
 	/* Request state should be less than max_level */
 	if (WARN_ON(state > cpufreq_cdev->max_level))
@@ -441,8 +445,19 @@  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 
 	cpufreq_cdev->cpufreq_state = state;
 
-	return freq_qos_update_request(&cpufreq_cdev->qos_req,
-				get_state_freq(cpufreq_cdev, state));
+	frequency = get_state_freq(cpufreq_cdev, state);
+
+	ret = freq_qos_update_request(&cpufreq_cdev->qos_req, frequency);
+
+	if (ret > 0) {
+		cpus = cpufreq_cdev->policy->cpus;
+		capacity = frequency *
+				arch_scale_cpu_capacity(cpumask_first(cpus));
+		capacity /= cpufreq_cdev->policy->cpuinfo.max_freq;
+		arch_set_thermal_pressure(cpus, capacity);
+	}
+
+	return ret;
 }
 
 /* Bind cpufreq callbacks to thermal cooling device ops */