Skip to content

Commit 69030dd

Browse files
spandruvadarafaeljw
authored andcommitted
cpufreq: use last policy after online for drivers with ->setpolicy
For cpufreq drivers which use setpolicy interface, after offline->online the policy is set to default. This can be reproduced by setting the default policy of intel_pstate or longrun to ondemand and then change to "performance". After offline and online, the setpolicy will be called with the policy=ondemand. For drivers using governors this condition is handled by storing last_governor, during offline and restoring during online. The same should be done for drivers using setpolicy interface. Storing last_policy during offline and restoring during online. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 584ee3d commit 69030dd

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -976,10 +976,14 @@ static int cpufreq_init_policy(struct cpufreq_policy *policy)
976976

977977
new_policy.governor = gov;
978978

979-
/* Use the default policy if its valid. */
980-
if (cpufreq_driver->setpolicy)
981-
cpufreq_parse_governor(gov->name, &new_policy.policy, NULL);
982-
979+
/* Use the default policy if there is no last_policy. */
980+
if (cpufreq_driver->setpolicy) {
981+
if (policy->last_policy)
982+
new_policy.policy = policy->last_policy;
983+
else
984+
cpufreq_parse_governor(gov->name, &new_policy.policy,
985+
NULL);
986+
}
983987
/* set default policy */
984988
return cpufreq_set_policy(policy, &new_policy);
985989
}
@@ -1330,6 +1334,8 @@ static void cpufreq_offline_prepare(unsigned int cpu)
13301334
if (has_target())
13311335
strncpy(policy->last_governor, policy->governor->name,
13321336
CPUFREQ_NAME_LEN);
1337+
else
1338+
policy->last_policy = policy->policy;
13331339
} else if (cpu == policy->cpu) {
13341340
/* Nominate new CPU */
13351341
policy->cpu = cpumask_any(policy->cpus);

include/linux/cpufreq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct cpufreq_policy {
7777
unsigned int suspend_freq; /* freq to set during suspend */
7878

7979
unsigned int policy; /* see above */
80+
unsigned int last_policy; /* policy before unplug */
8081
struct cpufreq_governor *governor; /* see below */
8182
void *governor_data;
8283
bool governor_enabled; /* governor start/stop flag */

0 commit comments

Comments
 (0)