Skip to content

Commit b3edde4

Browse files
vingu-linaroingomolnar
authored andcommitted
cpufreq/schedutil: Use a fixed reference frequency
cpuinfo.max_freq can change at runtime because of boost as an example. This implies that the value could be different than the one that has been used when computing the capacity of a CPU. The new arch_scale_freq_ref() returns a fixed and coherent reference frequency that can be used when computing a frequency based on utilization. Use this arch_scale_freq_ref() when available and fallback to policy otherwise. Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Tested-by: Lukasz Luba <lukasz.luba@arm.com> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com> Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com> Acked-by: Rafael J. Wysocki <rafael@kernel.org> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Link: https://lore.kernel.org/r/20231211104855.558096-4-vincent.guittot@linaro.org
1 parent 599457b commit b3edde4

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

kernel/sched/cpufreq_schedutil.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,28 @@ static void sugov_deferred_update(struct sugov_policy *sg_policy)
114114
}
115115
}
116116

117+
/**
118+
* get_capacity_ref_freq - get the reference frequency that has been used to
119+
* correlate frequency and compute capacity for a given cpufreq policy. We use
120+
* the CPU managing it for the arch_scale_freq_ref() call in the function.
121+
* @policy: the cpufreq policy of the CPU in question.
122+
*
123+
* Return: the reference CPU frequency to compute a capacity.
124+
*/
125+
static __always_inline
126+
unsigned long get_capacity_ref_freq(struct cpufreq_policy *policy)
127+
{
128+
unsigned int freq = arch_scale_freq_ref(policy->cpu);
129+
130+
if (freq)
131+
return freq;
132+
133+
if (arch_scale_freq_invariant())
134+
return policy->cpuinfo.max_freq;
135+
136+
return policy->cur;
137+
}
138+
117139
/**
118140
* get_next_freq - Compute a new frequency for a given cpufreq policy.
119141
* @sg_policy: schedutil policy object to compute the new frequency for.
@@ -140,9 +162,9 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy,
140162
unsigned long util, unsigned long max)
141163
{
142164
struct cpufreq_policy *policy = sg_policy->policy;
143-
unsigned int freq = arch_scale_freq_invariant() ?
144-
policy->cpuinfo.max_freq : policy->cur;
165+
unsigned int freq;
145166

167+
freq = get_capacity_ref_freq(policy);
146168
freq = map_util_freq(util, freq, max);
147169

148170
if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update)

0 commit comments

Comments
 (0)