cpufreq: move call to __find_governor() to cpufreq_init_policy()
We call __find_governor() during the addition of the first CPU of each policy from __cpufreq_add_dev() to find the last governor used for this CPU before it was hot-removed. After that we call cpufreq_parse_governor() in cpufreq_init_policy(), either with this governor, or with the default governor. Right after that policy->governor is set to NULL. While that code is not functionally problematic, the structure of it is suboptimal, because some of the code required in cpufreq_init_policy() is being executed by its caller, __cpufreq_add_dev(). So, it would make more sense to get all of it together in a single place to make code more readable. Accordingly, move the code needed for policy initialization to cpufreq_init_policy() and initialize policy->governor to NULL at the beginning. In order to clean up the code a bit more, some of the #ifdefs for CONFIG_HOTPLUG_CPU are dropped too. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> [rjw: Changelog] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
committed by
Rafael J. Wysocki
parent
3b4aff0472
commit
6e2c89d16d
@@ -42,10 +42,8 @@ static DEFINE_RWLOCK(cpufreq_driver_lock);
|
|||||||
DEFINE_MUTEX(cpufreq_governor_lock);
|
DEFINE_MUTEX(cpufreq_governor_lock);
|
||||||
static LIST_HEAD(cpufreq_policy_list);
|
static LIST_HEAD(cpufreq_policy_list);
|
||||||
|
|
||||||
#ifdef CONFIG_HOTPLUG_CPU
|
|
||||||
/* This one keeps track of the previously set governor of a removed CPU */
|
/* This one keeps track of the previously set governor of a removed CPU */
|
||||||
static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor);
|
static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor);
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline bool has_target(void)
|
static inline bool has_target(void)
|
||||||
{
|
{
|
||||||
@@ -879,18 +877,25 @@ err_out_kobj_put:
|
|||||||
|
|
||||||
static void cpufreq_init_policy(struct cpufreq_policy *policy)
|
static void cpufreq_init_policy(struct cpufreq_policy *policy)
|
||||||
{
|
{
|
||||||
|
struct cpufreq_governor *gov = NULL;
|
||||||
struct cpufreq_policy new_policy;
|
struct cpufreq_policy new_policy;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
memcpy(&new_policy, policy, sizeof(*policy));
|
memcpy(&new_policy, policy, sizeof(*policy));
|
||||||
|
|
||||||
|
/* Update governor of new_policy to the governor used before hotplug */
|
||||||
|
gov = __find_governor(per_cpu(cpufreq_cpu_governor, policy->cpu));
|
||||||
|
if (gov)
|
||||||
|
pr_debug("Restoring governor %s for cpu %d\n",
|
||||||
|
policy->governor->name, policy->cpu);
|
||||||
|
else
|
||||||
|
gov = CPUFREQ_DEFAULT_GOVERNOR;
|
||||||
|
|
||||||
|
new_policy.governor = gov;
|
||||||
|
|
||||||
/* Use the default policy if its valid. */
|
/* Use the default policy if its valid. */
|
||||||
if (cpufreq_driver->setpolicy)
|
if (cpufreq_driver->setpolicy)
|
||||||
cpufreq_parse_governor(policy->governor->name,
|
cpufreq_parse_governor(gov->name, &new_policy.policy, NULL);
|
||||||
&new_policy.policy, NULL);
|
|
||||||
|
|
||||||
/* assure that the starting sequence is run in cpufreq_set_policy */
|
|
||||||
policy->governor = NULL;
|
|
||||||
|
|
||||||
/* set default policy */
|
/* set default policy */
|
||||||
ret = cpufreq_set_policy(policy, &new_policy);
|
ret = cpufreq_set_policy(policy, &new_policy);
|
||||||
@@ -949,6 +954,8 @@ static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu)
|
|||||||
|
|
||||||
read_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
read_unlock_irqrestore(&cpufreq_driver_lock, flags);
|
||||||
|
|
||||||
|
policy->governor = NULL;
|
||||||
|
|
||||||
return policy;
|
return policy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1036,7 +1043,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
|
|||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
#ifdef CONFIG_HOTPLUG_CPU
|
#ifdef CONFIG_HOTPLUG_CPU
|
||||||
struct cpufreq_policy *tpolicy;
|
struct cpufreq_policy *tpolicy;
|
||||||
struct cpufreq_governor *gov;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (cpu_is_offline(cpu))
|
if (cpu_is_offline(cpu))
|
||||||
@@ -1094,7 +1100,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
|
|||||||
else
|
else
|
||||||
policy->cpu = cpu;
|
policy->cpu = cpu;
|
||||||
|
|
||||||
policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
|
|
||||||
cpumask_copy(policy->cpus, cpumask_of(cpu));
|
cpumask_copy(policy->cpus, cpumask_of(cpu));
|
||||||
|
|
||||||
init_completion(&policy->kobj_unregister);
|
init_completion(&policy->kobj_unregister);
|
||||||
@@ -1180,15 +1185,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
|
|||||||
blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
|
blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
|
||||||
CPUFREQ_START, policy);
|
CPUFREQ_START, policy);
|
||||||
|
|
||||||
#ifdef CONFIG_HOTPLUG_CPU
|
|
||||||
gov = __find_governor(per_cpu(cpufreq_cpu_governor, cpu));
|
|
||||||
if (gov) {
|
|
||||||
policy->governor = gov;
|
|
||||||
pr_debug("Restoring governor %s for cpu %d\n",
|
|
||||||
policy->governor->name, cpu);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!frozen) {
|
if (!frozen) {
|
||||||
ret = cpufreq_add_dev_interface(policy, dev);
|
ret = cpufreq_add_dev_interface(policy, dev);
|
||||||
if (ret)
|
if (ret)
|
||||||
@@ -1314,11 +1310,9 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_HOTPLUG_CPU
|
|
||||||
if (!cpufreq_driver->setpolicy)
|
if (!cpufreq_driver->setpolicy)
|
||||||
strncpy(per_cpu(cpufreq_cpu_governor, cpu),
|
strncpy(per_cpu(cpufreq_cpu_governor, cpu),
|
||||||
policy->governor->name, CPUFREQ_NAME_LEN);
|
policy->governor->name, CPUFREQ_NAME_LEN);
|
||||||
#endif
|
|
||||||
|
|
||||||
down_read(&policy->rwsem);
|
down_read(&policy->rwsem);
|
||||||
cpus = cpumask_weight(policy->cpus);
|
cpus = cpumask_weight(policy->cpus);
|
||||||
@@ -1950,9 +1944,7 @@ EXPORT_SYMBOL_GPL(cpufreq_register_governor);
|
|||||||
|
|
||||||
void cpufreq_unregister_governor(struct cpufreq_governor *governor)
|
void cpufreq_unregister_governor(struct cpufreq_governor *governor)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_HOTPLUG_CPU
|
|
||||||
int cpu;
|
int cpu;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!governor)
|
if (!governor)
|
||||||
return;
|
return;
|
||||||
@@ -1960,14 +1952,12 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
|
|||||||
if (cpufreq_disabled())
|
if (cpufreq_disabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef CONFIG_HOTPLUG_CPU
|
|
||||||
for_each_present_cpu(cpu) {
|
for_each_present_cpu(cpu) {
|
||||||
if (cpu_online(cpu))
|
if (cpu_online(cpu))
|
||||||
continue;
|
continue;
|
||||||
if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name))
|
if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name))
|
||||||
strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0");
|
strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
mutex_lock(&cpufreq_governor_mutex);
|
mutex_lock(&cpufreq_governor_mutex);
|
||||||
list_del(&governor->governor_list);
|
list_del(&governor->governor_list);
|
||||||
|
Reference in New Issue
Block a user