# Re: \[PATCH 1/2\] sched/fair: Take thermal pressure into account while estimating energy

- From: Quentin Perret \<hidden\>
- Date: 2021-06-02 15:00:55 
- List: linux-pm
- Page: https://ratatoskr.run/linux-pm/2021/06/1400054
- Thread: https://ratatoskr.run/linux-pm/2021/06/1399917/t.md

```text
Hi Lukasz,

On Wednesday 02 Jun 2021 at 14:56:08 (+0100), Lukasz Luba wrote:
>  compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd)
>  {
>  	struct cpumask *pd_mask = perf_domain_span(pd);
> -	unsigned long cpu_cap = arch_scale_cpu_capacity(cpumask_first(pd_mask));
> +	unsigned long _cpu_cap = arch_scale_cpu_capacity(cpumask_first(pd_mask));
>  	unsigned long max_util = 0, sum_util = 0;
> +	unsigned long cpu_cap = _cpu_cap;
>  	int cpu;
>  
>  	/*
> @@ -6558,6 +6559,14 @@ compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd)
>  				cpu_util_next(cpu, p, -1) + task_util_est(p);
>  		}
>  
> +		/*
> +		 * Take the thermal pressure from non-idle CPUs. They have
> +		 * most up-to-date information. For idle CPUs thermal pressure
> +		 * signal is not updated so often.
> +		 */
> +		if (!idle_cpu(cpu))
> +			cpu_cap = _cpu_cap - thermal_load_avg(cpu_rq(cpu));

This messes up the irq time scaling no? Maybe move the capping in this
function instead of relying on effective_cpu_util() to do it for you?

>  		/*
>  		 * Busy time computation: utilization clamping is not
>  		 * required since the ratio (sum_util / cpu_capacity)
> -- 
> 2.17.1
> 
```
