Skip to content

Commit 2ed99e3

Browse files
committed
cpufreq: Skip current frequency initialization for ->setpolicy drivers
After commit da60ce9 (cpufreq: call cpufreq_driver->get() after calling ->init()) __cpufreq_add_dev() sometimes fails for CPUs handled by intel_pstate, because that driver may return 0 from its ->get() callback if it has not run long enough to collect enough samples on the given CPU. That didn't happen before commit da60ce9 which added policy->cur initialization to __cpufreq_add_dev() to help reduce code duplication in other cpufreq drivers. However, the code added by commit da60ce9 need not be executed for cpufreq drivers having the ->setpolicy callback defined, because the subsequent invocation of cpufreq_set_policy() will use that callback to initialize the policy anyway and it doesn't need policy->cur to be initialized upfront. The analogous code in cpufreq_update_policy() is also unnecessary for cpufreq drivers having ->setpolicy set and may be skipped for them as well. Since intel_pstate provides ->setpolicy, skipping the upfront policy->cur initialization for cpufreq drivers with that callback set will cover intel_pstate and the problem it's been having after commit da60ce9 will be addressed. Fixes: da60ce9 (cpufreq: call cpufreq_driver->get() after calling ->init()) References: https://bugzilla.kernel.org/show_bug.cgi?id=71931 Reported-and-tested-by: Patrik Lundquist <patrik.lundquist@gmail.com> Acked-by: Dirk Brandewie <dirk.j.brandewie@intel.com> Cc: 3.13+ <stable@vger.kernel.org> # 3.13+ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent fa389e2 commit 2ed99e3

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎drivers/cpufreq/cpufreq.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
11291129
per_cpu(cpufreq_cpu_data, j) = policy;
11301130
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
11311131

1132-
if (cpufreq_driver->get) {
1132+
if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
11331133
policy->cur = cpufreq_driver->get(policy->cpu);
11341134
if (!policy->cur) {
11351135
pr_err("%s: ->get() failed\n", __func__);
@@ -2143,7 +2143,7 @@ int cpufreq_update_policy(unsigned int cpu)
21432143
* BIOS might change freq behind our back
21442144
* -> ask driver for current freq and notify governors about a change
21452145
*/
2146-
if (cpufreq_driver->get) {
2146+
if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
21472147
new_policy.cur = cpufreq_driver->get(cpu);
21482148
if (!policy->cur) {
21492149
pr_debug("Driver did not initialize current freq");

0 commit comments

Comments
 (0)