Skip to content

Commit 75d6593

Browse files
vingu-linaroIngo Molnar
authored andcommitted
cpufreq: Add a cpufreq pressure feedback for the scheduler
Provide to the scheduler a feedback about the temporary max available capacity. Unlike arch_update_thermal_pressure(), this doesn't need to be filtered as the pressure will happen for dozens of ms or more. Signed-off-by: Vincent Guittot <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Tested-by: Lukasz Luba <[email protected]> Reviewed-by: Qais Yousef <[email protected]> Reviewed-by: Lukasz Luba <[email protected]> Reviewed-by: Dhruva Gole <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Acked-by: Viresh Kumar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent cd18bec commit 75d6593

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,6 +2582,40 @@ int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
25822582
}
25832583
EXPORT_SYMBOL(cpufreq_get_policy);
25842584

2585+
DEFINE_PER_CPU(unsigned long, cpufreq_pressure);
2586+
2587+
/**
2588+
* cpufreq_update_pressure() - Update cpufreq pressure for CPUs
2589+
* @policy: cpufreq policy of the CPUs.
2590+
*
2591+
* Update the value of cpufreq pressure for all @cpus in the policy.
2592+
*/
2593+
static void cpufreq_update_pressure(struct cpufreq_policy *policy)
2594+
{
2595+
unsigned long max_capacity, capped_freq, pressure;
2596+
u32 max_freq;
2597+
int cpu;
2598+
2599+
cpu = cpumask_first(policy->related_cpus);
2600+
max_freq = arch_scale_freq_ref(cpu);
2601+
capped_freq = policy->max;
2602+
2603+
/*
2604+
* Handle properly the boost frequencies, which should simply clean
2605+
* the cpufreq pressure value.
2606+
*/
2607+
if (max_freq <= capped_freq) {
2608+
pressure = 0;
2609+
} else {
2610+
max_capacity = arch_scale_cpu_capacity(cpu);
2611+
pressure = max_capacity -
2612+
mult_frac(max_capacity, capped_freq, max_freq);
2613+
}
2614+
2615+
for_each_cpu(cpu, policy->related_cpus)
2616+
WRITE_ONCE(per_cpu(cpufreq_pressure, cpu), pressure);
2617+
}
2618+
25852619
/**
25862620
* cpufreq_set_policy - Modify cpufreq policy parameters.
25872621
* @policy: Policy object to modify.
@@ -2637,6 +2671,8 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy,
26372671
policy->max = __resolve_freq(policy, policy->max, CPUFREQ_RELATION_H);
26382672
trace_cpu_frequency_limits(policy);
26392673

2674+
cpufreq_update_pressure(policy);
2675+
26402676
policy->cached_target_freq = UINT_MAX;
26412677

26422678
pr_debug("new min and max freqs are %u - %u kHz\n",

include/linux/cpufreq.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy);
241241
void cpufreq_enable_fast_switch(struct cpufreq_policy *policy);
242242
void cpufreq_disable_fast_switch(struct cpufreq_policy *policy);
243243
bool has_target_index(void);
244+
245+
DECLARE_PER_CPU(unsigned long, cpufreq_pressure);
246+
static inline unsigned long cpufreq_get_pressure(int cpu)
247+
{
248+
return READ_ONCE(per_cpu(cpufreq_pressure, cpu));
249+
}
244250
#else
245251
static inline unsigned int cpufreq_get(unsigned int cpu)
246252
{
@@ -264,6 +270,10 @@ static inline bool cpufreq_supports_freq_invariance(void)
264270
}
265271
static inline void disable_cpufreq(void) { }
266272
static inline void cpufreq_update_limits(unsigned int cpu) { }
273+
static inline unsigned long cpufreq_get_pressure(int cpu)
274+
{
275+
return 0;
276+
}
267277
#endif
268278

269279
#ifdef CONFIG_CPU_FREQ_STAT

0 commit comments

Comments
 (0)