Skip to content

Commit f55ae08

Browse files
vireshkrafaeljw
authored andcommitted
cpufreq: Avoid unnecessary frequency updates due to mismatch
For some platforms, the frequency returned by hardware may be slightly different from what is provided in the frequency table. For example, hardware may return 499 MHz instead of 500 MHz. In such cases it is better to avoid getting into unnecessary frequency updates, as we may end up switching policy->cur between the two and sending unnecessary pre/post update notifications, etc. This patch has chosen allows the hardware frequency and table frequency to deviate by 1 MHz for now, we may want to increase it a bit later on if someone still complains. Reported-by: Rex-BC Chen <rex-bc.chen@mediatek.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Tested-by: Jia-wei Chang <jia-wei.chang@mediatek.com> Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 02678c0 commit f55ae08

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/suspend.h>
2929
#include <linux/syscore_ops.h>
3030
#include <linux/tick.h>
31+
#include <linux/units.h>
3132
#include <trace/events/power.h>
3233

3334
static LIST_HEAD(cpufreq_policy_list);
@@ -1708,6 +1709,16 @@ static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, b
17081709
return new_freq;
17091710

17101711
if (policy->cur != new_freq) {
1712+
/*
1713+
* For some platforms, the frequency returned by hardware may be
1714+
* slightly different from what is provided in the frequency
1715+
* table, for example hardware may return 499 MHz instead of 500
1716+
* MHz. In such cases it is better to avoid getting into
1717+
* unnecessary frequency updates.
1718+
*/
1719+
if (abs(policy->cur - new_freq) < HZ_PER_MHZ)
1720+
return policy->cur;
1721+
17111722
cpufreq_out_of_sync(policy, new_freq);
17121723
if (update)
17131724
schedule_work(&policy->update);

0 commit comments

Comments
 (0)