diff options
author | viresh kumar <viresh.kumar@linaro.org> | 2014-03-03 22:43:59 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-03-06 08:38:44 -0500 |
commit | 6e2c89d16d987e6e11c531b039a42d3f5f1d7c32 (patch) | |
tree | 99eebd82caf833fba1b904db638946cb3cf44cf6 /drivers/cpufreq | |
parent | 3b4aff047275574bff8f50a654d51166d9574079 (diff) |
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>
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r-- | drivers/cpufreq/cpufreq.c | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index df95c039a21c..2de2f1ddd95f 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c | |||
@@ -42,10 +42,8 @@ static DEFINE_RWLOCK(cpufreq_driver_lock); | |||
42 | DEFINE_MUTEX(cpufreq_governor_lock); | 42 | DEFINE_MUTEX(cpufreq_governor_lock); |
43 | static LIST_HEAD(cpufreq_policy_list); | 43 | static LIST_HEAD(cpufreq_policy_list); |
44 | 44 | ||
45 | #ifdef CONFIG_HOTPLUG_CPU | ||
46 | /* This one keeps track of the previously set governor of a removed CPU */ | 45 | /* This one keeps track of the previously set governor of a removed CPU */ |
47 | static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor); | 46 | static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor); |
48 | #endif | ||
49 | 47 | ||
50 | static inline bool has_target(void) | 48 | static inline bool has_target(void) |
51 | { | 49 | { |
@@ -879,18 +877,25 @@ err_out_kobj_put: | |||
879 | 877 | ||
880 | static void cpufreq_init_policy(struct cpufreq_policy *policy) | 878 | static void cpufreq_init_policy(struct cpufreq_policy *policy) |
881 | { | 879 | { |
880 | struct cpufreq_governor *gov = NULL; | ||
882 | struct cpufreq_policy new_policy; | 881 | struct cpufreq_policy new_policy; |
883 | int ret = 0; | 882 | int ret = 0; |
884 | 883 | ||
885 | memcpy(&new_policy, policy, sizeof(*policy)); | 884 | memcpy(&new_policy, policy, sizeof(*policy)); |
886 | 885 | ||
886 | /* Update governor of new_policy to the governor used before hotplug */ | ||
887 | gov = __find_governor(per_cpu(cpufreq_cpu_governor, policy->cpu)); | ||
888 | if (gov) | ||
889 | pr_debug("Restoring governor %s for cpu %d\n", | ||
890 | policy->governor->name, policy->cpu); | ||
891 | else | ||
892 | gov = CPUFREQ_DEFAULT_GOVERNOR; | ||
893 | |||
894 | new_policy.governor = gov; | ||
895 | |||
887 | /* Use the default policy if its valid. */ | 896 | /* Use the default policy if its valid. */ |
888 | if (cpufreq_driver->setpolicy) | 897 | if (cpufreq_driver->setpolicy) |
889 | cpufreq_parse_governor(policy->governor->name, | 898 | cpufreq_parse_governor(gov->name, &new_policy.policy, NULL); |
890 | &new_policy.policy, NULL); | ||
891 | |||
892 | /* assure that the starting sequence is run in cpufreq_set_policy */ | ||
893 | policy->governor = NULL; | ||
894 | 899 | ||
895 | /* set default policy */ | 900 | /* set default policy */ |
896 | ret = cpufreq_set_policy(policy, &new_policy); | 901 | ret = cpufreq_set_policy(policy, &new_policy); |
@@ -949,6 +954,8 @@ static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu) | |||
949 | 954 | ||
950 | read_unlock_irqrestore(&cpufreq_driver_lock, flags); | 955 | read_unlock_irqrestore(&cpufreq_driver_lock, flags); |
951 | 956 | ||
957 | policy->governor = NULL; | ||
958 | |||
952 | return policy; | 959 | return policy; |
953 | } | 960 | } |
954 | 961 | ||
@@ -1036,7 +1043,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, | |||
1036 | unsigned long flags; | 1043 | unsigned long flags; |
1037 | #ifdef CONFIG_HOTPLUG_CPU | 1044 | #ifdef CONFIG_HOTPLUG_CPU |
1038 | struct cpufreq_policy *tpolicy; | 1045 | struct cpufreq_policy *tpolicy; |
1039 | struct cpufreq_governor *gov; | ||
1040 | #endif | 1046 | #endif |
1041 | 1047 | ||
1042 | if (cpu_is_offline(cpu)) | 1048 | if (cpu_is_offline(cpu)) |
@@ -1094,7 +1100,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, | |||
1094 | else | 1100 | else |
1095 | policy->cpu = cpu; | 1101 | policy->cpu = cpu; |
1096 | 1102 | ||
1097 | policy->governor = CPUFREQ_DEFAULT_GOVERNOR; | ||
1098 | cpumask_copy(policy->cpus, cpumask_of(cpu)); | 1103 | cpumask_copy(policy->cpus, cpumask_of(cpu)); |
1099 | 1104 | ||
1100 | init_completion(&policy->kobj_unregister); | 1105 | init_completion(&policy->kobj_unregister); |
@@ -1180,15 +1185,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif, | |||
1180 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, | 1185 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
1181 | CPUFREQ_START, policy); | 1186 | CPUFREQ_START, policy); |
1182 | 1187 | ||
1183 | #ifdef CONFIG_HOTPLUG_CPU | ||
1184 | gov = __find_governor(per_cpu(cpufreq_cpu_governor, cpu)); | ||
1185 | if (gov) { | ||
1186 | policy->governor = gov; | ||
1187 | pr_debug("Restoring governor %s for cpu %d\n", | ||
1188 | policy->governor->name, cpu); | ||
1189 | } | ||
1190 | #endif | ||
1191 | |||
1192 | if (!frozen) { | 1188 | if (!frozen) { |
1193 | ret = cpufreq_add_dev_interface(policy, dev); | 1189 | ret = cpufreq_add_dev_interface(policy, dev); |
1194 | if (ret) | 1190 | if (ret) |
@@ -1314,11 +1310,9 @@ static int __cpufreq_remove_dev_prepare(struct device *dev, | |||
1314 | } | 1310 | } |
1315 | } | 1311 | } |
1316 | 1312 | ||
1317 | #ifdef CONFIG_HOTPLUG_CPU | ||
1318 | if (!cpufreq_driver->setpolicy) | 1313 | if (!cpufreq_driver->setpolicy) |
1319 | strncpy(per_cpu(cpufreq_cpu_governor, cpu), | 1314 | strncpy(per_cpu(cpufreq_cpu_governor, cpu), |
1320 | policy->governor->name, CPUFREQ_NAME_LEN); | 1315 | policy->governor->name, CPUFREQ_NAME_LEN); |
1321 | #endif | ||
1322 | 1316 | ||
1323 | down_read(&policy->rwsem); | 1317 | down_read(&policy->rwsem); |
1324 | cpus = cpumask_weight(policy->cpus); | 1318 | cpus = cpumask_weight(policy->cpus); |
@@ -1950,9 +1944,7 @@ EXPORT_SYMBOL_GPL(cpufreq_register_governor); | |||
1950 | 1944 | ||
1951 | void cpufreq_unregister_governor(struct cpufreq_governor *governor) | 1945 | void cpufreq_unregister_governor(struct cpufreq_governor *governor) |
1952 | { | 1946 | { |
1953 | #ifdef CONFIG_HOTPLUG_CPU | ||
1954 | int cpu; | 1947 | int cpu; |
1955 | #endif | ||
1956 | 1948 | ||
1957 | if (!governor) | 1949 | if (!governor) |
1958 | return; | 1950 | return; |
@@ -1960,14 +1952,12 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor) | |||
1960 | if (cpufreq_disabled()) | 1952 | if (cpufreq_disabled()) |
1961 | return; | 1953 | return; |
1962 | 1954 | ||
1963 | #ifdef CONFIG_HOTPLUG_CPU | ||
1964 | for_each_present_cpu(cpu) { | 1955 | for_each_present_cpu(cpu) { |
1965 | if (cpu_online(cpu)) | 1956 | if (cpu_online(cpu)) |
1966 | continue; | 1957 | continue; |
1967 | if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name)) | 1958 | if (!strcmp(per_cpu(cpufreq_cpu_governor, cpu), governor->name)) |
1968 | strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0"); | 1959 | strcpy(per_cpu(cpufreq_cpu_governor, cpu), "\0"); |
1969 | } | 1960 | } |
1970 | #endif | ||
1971 | 1961 | ||
1972 | mutex_lock(&cpufreq_governor_mutex); | 1962 | mutex_lock(&cpufreq_governor_mutex); |
1973 | list_del(&governor->governor_list); | 1963 | list_del(&governor->governor_list); |