diff options
author | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
---|---|---|
committer | Glenn Elliott <gelliott@cs.unc.edu> | 2012-03-04 19:47:13 -0500 |
commit | c71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch) | |
tree | ecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /drivers/cpufreq/cpufreq.c | |
parent | ea53c912f8a86a8567697115b6a0d8152beee5c8 (diff) | |
parent | 6a00f206debf8a5c8899055726ad127dbeeed098 (diff) |
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts:
litmus/sched_cedf.c
Diffstat (limited to 'drivers/cpufreq/cpufreq.c')
-rw-r--r-- | drivers/cpufreq/cpufreq.c | 313 |
1 files changed, 103 insertions, 210 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 199dcb9f0b83..0a5bea9e3585 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c | |||
@@ -28,12 +28,10 @@ | |||
28 | #include <linux/cpu.h> | 28 | #include <linux/cpu.h> |
29 | #include <linux/completion.h> | 29 | #include <linux/completion.h> |
30 | #include <linux/mutex.h> | 30 | #include <linux/mutex.h> |
31 | #include <linux/syscore_ops.h> | ||
31 | 32 | ||
32 | #include <trace/events/power.h> | 33 | #include <trace/events/power.h> |
33 | 34 | ||
34 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, \ | ||
35 | "cpufreq-core", msg) | ||
36 | |||
37 | /** | 35 | /** |
38 | * The "cpufreq driver" - the arch- or hardware-dependent low | 36 | * The "cpufreq driver" - the arch- or hardware-dependent low |
39 | * level driver of CPUFreq support, and its spinlock. This lock | 37 | * level driver of CPUFreq support, and its spinlock. This lock |
@@ -180,93 +178,6 @@ EXPORT_SYMBOL_GPL(cpufreq_cpu_put); | |||
180 | 178 | ||
181 | 179 | ||
182 | /********************************************************************* | 180 | /********************************************************************* |
183 | * UNIFIED DEBUG HELPERS * | ||
184 | *********************************************************************/ | ||
185 | #ifdef CONFIG_CPU_FREQ_DEBUG | ||
186 | |||
187 | /* what part(s) of the CPUfreq subsystem are debugged? */ | ||
188 | static unsigned int debug; | ||
189 | |||
190 | /* is the debug output ratelimit'ed using printk_ratelimit? User can | ||
191 | * set or modify this value. | ||
192 | */ | ||
193 | static unsigned int debug_ratelimit = 1; | ||
194 | |||
195 | /* is the printk_ratelimit'ing enabled? It's enabled after a successful | ||
196 | * loading of a cpufreq driver, temporarily disabled when a new policy | ||
197 | * is set, and disabled upon cpufreq driver removal | ||
198 | */ | ||
199 | static unsigned int disable_ratelimit = 1; | ||
200 | static DEFINE_SPINLOCK(disable_ratelimit_lock); | ||
201 | |||
202 | static void cpufreq_debug_enable_ratelimit(void) | ||
203 | { | ||
204 | unsigned long flags; | ||
205 | |||
206 | spin_lock_irqsave(&disable_ratelimit_lock, flags); | ||
207 | if (disable_ratelimit) | ||
208 | disable_ratelimit--; | ||
209 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); | ||
210 | } | ||
211 | |||
212 | static void cpufreq_debug_disable_ratelimit(void) | ||
213 | { | ||
214 | unsigned long flags; | ||
215 | |||
216 | spin_lock_irqsave(&disable_ratelimit_lock, flags); | ||
217 | disable_ratelimit++; | ||
218 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); | ||
219 | } | ||
220 | |||
221 | void cpufreq_debug_printk(unsigned int type, const char *prefix, | ||
222 | const char *fmt, ...) | ||
223 | { | ||
224 | char s[256]; | ||
225 | va_list args; | ||
226 | unsigned int len; | ||
227 | unsigned long flags; | ||
228 | |||
229 | WARN_ON(!prefix); | ||
230 | if (type & debug) { | ||
231 | spin_lock_irqsave(&disable_ratelimit_lock, flags); | ||
232 | if (!disable_ratelimit && debug_ratelimit | ||
233 | && !printk_ratelimit()) { | ||
234 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); | ||
235 | return; | ||
236 | } | ||
237 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); | ||
238 | |||
239 | len = snprintf(s, 256, KERN_DEBUG "%s: ", prefix); | ||
240 | |||
241 | va_start(args, fmt); | ||
242 | len += vsnprintf(&s[len], (256 - len), fmt, args); | ||
243 | va_end(args); | ||
244 | |||
245 | printk(s); | ||
246 | |||
247 | WARN_ON(len < 5); | ||
248 | } | ||
249 | } | ||
250 | EXPORT_SYMBOL(cpufreq_debug_printk); | ||
251 | |||
252 | |||
253 | module_param(debug, uint, 0644); | ||
254 | MODULE_PARM_DESC(debug, "CPUfreq debugging: add 1 to debug core," | ||
255 | " 2 to debug drivers, and 4 to debug governors."); | ||
256 | |||
257 | module_param(debug_ratelimit, uint, 0644); | ||
258 | MODULE_PARM_DESC(debug_ratelimit, "CPUfreq debugging:" | ||
259 | " set to 0 to disable ratelimiting."); | ||
260 | |||
261 | #else /* !CONFIG_CPU_FREQ_DEBUG */ | ||
262 | |||
263 | static inline void cpufreq_debug_enable_ratelimit(void) { return; } | ||
264 | static inline void cpufreq_debug_disable_ratelimit(void) { return; } | ||
265 | |||
266 | #endif /* CONFIG_CPU_FREQ_DEBUG */ | ||
267 | |||
268 | |||
269 | /********************************************************************* | ||
270 | * EXTERNALLY AFFECTING FREQUENCY CHANGES * | 181 | * EXTERNALLY AFFECTING FREQUENCY CHANGES * |
271 | *********************************************************************/ | 182 | *********************************************************************/ |
272 | 183 | ||
@@ -290,7 +201,7 @@ static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) | |||
290 | if (!l_p_j_ref_freq) { | 201 | if (!l_p_j_ref_freq) { |
291 | l_p_j_ref = loops_per_jiffy; | 202 | l_p_j_ref = loops_per_jiffy; |
292 | l_p_j_ref_freq = ci->old; | 203 | l_p_j_ref_freq = ci->old; |
293 | dprintk("saving %lu as reference value for loops_per_jiffy; " | 204 | pr_debug("saving %lu as reference value for loops_per_jiffy; " |
294 | "freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq); | 205 | "freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq); |
295 | } | 206 | } |
296 | if ((val == CPUFREQ_PRECHANGE && ci->old < ci->new) || | 207 | if ((val == CPUFREQ_PRECHANGE && ci->old < ci->new) || |
@@ -298,7 +209,7 @@ static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) | |||
298 | (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) { | 209 | (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) { |
299 | loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq, | 210 | loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq, |
300 | ci->new); | 211 | ci->new); |
301 | dprintk("scaling loops_per_jiffy to %lu " | 212 | pr_debug("scaling loops_per_jiffy to %lu " |
302 | "for frequency %u kHz\n", loops_per_jiffy, ci->new); | 213 | "for frequency %u kHz\n", loops_per_jiffy, ci->new); |
303 | } | 214 | } |
304 | } | 215 | } |
@@ -325,7 +236,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state) | |||
325 | BUG_ON(irqs_disabled()); | 236 | BUG_ON(irqs_disabled()); |
326 | 237 | ||
327 | freqs->flags = cpufreq_driver->flags; | 238 | freqs->flags = cpufreq_driver->flags; |
328 | dprintk("notification %u of frequency transition to %u kHz\n", | 239 | pr_debug("notification %u of frequency transition to %u kHz\n", |
329 | state, freqs->new); | 240 | state, freqs->new); |
330 | 241 | ||
331 | policy = per_cpu(cpufreq_cpu_data, freqs->cpu); | 242 | policy = per_cpu(cpufreq_cpu_data, freqs->cpu); |
@@ -339,7 +250,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state) | |||
339 | if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { | 250 | if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { |
340 | if ((policy) && (policy->cpu == freqs->cpu) && | 251 | if ((policy) && (policy->cpu == freqs->cpu) && |
341 | (policy->cur) && (policy->cur != freqs->old)) { | 252 | (policy->cur) && (policy->cur != freqs->old)) { |
342 | dprintk("Warning: CPU frequency is" | 253 | pr_debug("Warning: CPU frequency is" |
343 | " %u, cpufreq assumed %u kHz.\n", | 254 | " %u, cpufreq assumed %u kHz.\n", |
344 | freqs->old, policy->cur); | 255 | freqs->old, policy->cur); |
345 | freqs->old = policy->cur; | 256 | freqs->old = policy->cur; |
@@ -352,9 +263,10 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state) | |||
352 | 263 | ||
353 | case CPUFREQ_POSTCHANGE: | 264 | case CPUFREQ_POSTCHANGE: |
354 | adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); | 265 | adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); |
355 | dprintk("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new, | 266 | pr_debug("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new, |
356 | (unsigned long)freqs->cpu); | 267 | (unsigned long)freqs->cpu); |
357 | trace_power_frequency(POWER_PSTATE, freqs->new, freqs->cpu); | 268 | trace_power_frequency(POWER_PSTATE, freqs->new, freqs->cpu); |
269 | trace_cpu_frequency(freqs->new, freqs->cpu); | ||
358 | srcu_notifier_call_chain(&cpufreq_transition_notifier_list, | 270 | srcu_notifier_call_chain(&cpufreq_transition_notifier_list, |
359 | CPUFREQ_POSTCHANGE, freqs); | 271 | CPUFREQ_POSTCHANGE, freqs); |
360 | if (likely(policy) && likely(policy->cpu == freqs->cpu)) | 272 | if (likely(policy) && likely(policy->cpu == freqs->cpu)) |
@@ -409,21 +321,14 @@ static int cpufreq_parse_governor(char *str_governor, unsigned int *policy, | |||
409 | t = __find_governor(str_governor); | 321 | t = __find_governor(str_governor); |
410 | 322 | ||
411 | if (t == NULL) { | 323 | if (t == NULL) { |
412 | char *name = kasprintf(GFP_KERNEL, "cpufreq_%s", | 324 | int ret; |
413 | str_governor); | ||
414 | |||
415 | if (name) { | ||
416 | int ret; | ||
417 | 325 | ||
418 | mutex_unlock(&cpufreq_governor_mutex); | 326 | mutex_unlock(&cpufreq_governor_mutex); |
419 | ret = request_module("%s", name); | 327 | ret = request_module("cpufreq_%s", str_governor); |
420 | mutex_lock(&cpufreq_governor_mutex); | 328 | mutex_lock(&cpufreq_governor_mutex); |
421 | 329 | ||
422 | if (ret == 0) | 330 | if (ret == 0) |
423 | t = __find_governor(str_governor); | 331 | t = __find_governor(str_governor); |
424 | } | ||
425 | |||
426 | kfree(name); | ||
427 | } | 332 | } |
428 | 333 | ||
429 | if (t != NULL) { | 334 | if (t != NULL) { |
@@ -751,7 +656,7 @@ no_policy: | |||
751 | static void cpufreq_sysfs_release(struct kobject *kobj) | 656 | static void cpufreq_sysfs_release(struct kobject *kobj) |
752 | { | 657 | { |
753 | struct cpufreq_policy *policy = to_policy(kobj); | 658 | struct cpufreq_policy *policy = to_policy(kobj); |
754 | dprintk("last reference is dropped\n"); | 659 | pr_debug("last reference is dropped\n"); |
755 | complete(&policy->kobj_unregister); | 660 | complete(&policy->kobj_unregister); |
756 | } | 661 | } |
757 | 662 | ||
@@ -786,7 +691,7 @@ static int cpufreq_add_dev_policy(unsigned int cpu, | |||
786 | gov = __find_governor(per_cpu(cpufreq_cpu_governor, cpu)); | 691 | gov = __find_governor(per_cpu(cpufreq_cpu_governor, cpu)); |
787 | if (gov) { | 692 | if (gov) { |
788 | policy->governor = gov; | 693 | policy->governor = gov; |
789 | dprintk("Restoring governor %s for cpu %d\n", | 694 | pr_debug("Restoring governor %s for cpu %d\n", |
790 | policy->governor->name, cpu); | 695 | policy->governor->name, cpu); |
791 | } | 696 | } |
792 | #endif | 697 | #endif |
@@ -822,7 +727,7 @@ static int cpufreq_add_dev_policy(unsigned int cpu, | |||
822 | per_cpu(cpufreq_cpu_data, cpu) = managed_policy; | 727 | per_cpu(cpufreq_cpu_data, cpu) = managed_policy; |
823 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 728 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
824 | 729 | ||
825 | dprintk("CPU already managed, adding link\n"); | 730 | pr_debug("CPU already managed, adding link\n"); |
826 | ret = sysfs_create_link(&sys_dev->kobj, | 731 | ret = sysfs_create_link(&sys_dev->kobj, |
827 | &managed_policy->kobj, | 732 | &managed_policy->kobj, |
828 | "cpufreq"); | 733 | "cpufreq"); |
@@ -863,7 +768,7 @@ static int cpufreq_add_dev_symlink(unsigned int cpu, | |||
863 | if (!cpu_online(j)) | 768 | if (!cpu_online(j)) |
864 | continue; | 769 | continue; |
865 | 770 | ||
866 | dprintk("CPU %u already managed, adding link\n", j); | 771 | pr_debug("CPU %u already managed, adding link\n", j); |
867 | managed_policy = cpufreq_cpu_get(cpu); | 772 | managed_policy = cpufreq_cpu_get(cpu); |
868 | cpu_sys_dev = get_cpu_sysdev(j); | 773 | cpu_sys_dev = get_cpu_sysdev(j); |
869 | ret = sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj, | 774 | ret = sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj, |
@@ -918,8 +823,8 @@ static int cpufreq_add_dev_interface(unsigned int cpu, | |||
918 | 823 | ||
919 | spin_lock_irqsave(&cpufreq_driver_lock, flags); | 824 | spin_lock_irqsave(&cpufreq_driver_lock, flags); |
920 | for_each_cpu(j, policy->cpus) { | 825 | for_each_cpu(j, policy->cpus) { |
921 | if (!cpu_online(j)) | 826 | if (!cpu_online(j)) |
922 | continue; | 827 | continue; |
923 | per_cpu(cpufreq_cpu_data, j) = policy; | 828 | per_cpu(cpufreq_cpu_data, j) = policy; |
924 | per_cpu(cpufreq_policy_cpu, j) = policy->cpu; | 829 | per_cpu(cpufreq_policy_cpu, j) = policy->cpu; |
925 | } | 830 | } |
@@ -939,7 +844,7 @@ static int cpufreq_add_dev_interface(unsigned int cpu, | |||
939 | policy->user_policy.governor = policy->governor; | 844 | policy->user_policy.governor = policy->governor; |
940 | 845 | ||
941 | if (ret) { | 846 | if (ret) { |
942 | dprintk("setting policy failed\n"); | 847 | pr_debug("setting policy failed\n"); |
943 | if (cpufreq_driver->exit) | 848 | if (cpufreq_driver->exit) |
944 | cpufreq_driver->exit(policy); | 849 | cpufreq_driver->exit(policy); |
945 | } | 850 | } |
@@ -975,8 +880,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev) | |||
975 | if (cpu_is_offline(cpu)) | 880 | if (cpu_is_offline(cpu)) |
976 | return 0; | 881 | return 0; |
977 | 882 | ||
978 | cpufreq_debug_disable_ratelimit(); | 883 | pr_debug("adding CPU %u\n", cpu); |
979 | dprintk("adding CPU %u\n", cpu); | ||
980 | 884 | ||
981 | #ifdef CONFIG_SMP | 885 | #ifdef CONFIG_SMP |
982 | /* check whether a different CPU already registered this | 886 | /* check whether a different CPU already registered this |
@@ -984,7 +888,6 @@ static int cpufreq_add_dev(struct sys_device *sys_dev) | |||
984 | policy = cpufreq_cpu_get(cpu); | 888 | policy = cpufreq_cpu_get(cpu); |
985 | if (unlikely(policy)) { | 889 | if (unlikely(policy)) { |
986 | cpufreq_cpu_put(policy); | 890 | cpufreq_cpu_put(policy); |
987 | cpufreq_debug_enable_ratelimit(); | ||
988 | return 0; | 891 | return 0; |
989 | } | 892 | } |
990 | #endif | 893 | #endif |
@@ -1035,7 +938,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev) | |||
1035 | */ | 938 | */ |
1036 | ret = cpufreq_driver->init(policy); | 939 | ret = cpufreq_driver->init(policy); |
1037 | if (ret) { | 940 | if (ret) { |
1038 | dprintk("initialization failed\n"); | 941 | pr_debug("initialization failed\n"); |
1039 | goto err_unlock_policy; | 942 | goto err_unlock_policy; |
1040 | } | 943 | } |
1041 | policy->user_policy.min = policy->min; | 944 | policy->user_policy.min = policy->min; |
@@ -1061,8 +964,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev) | |||
1061 | 964 | ||
1062 | kobject_uevent(&policy->kobj, KOBJ_ADD); | 965 | kobject_uevent(&policy->kobj, KOBJ_ADD); |
1063 | module_put(cpufreq_driver->owner); | 966 | module_put(cpufreq_driver->owner); |
1064 | dprintk("initialization complete\n"); | 967 | pr_debug("initialization complete\n"); |
1065 | cpufreq_debug_enable_ratelimit(); | ||
1066 | 968 | ||
1067 | return 0; | 969 | return 0; |
1068 | 970 | ||
@@ -1086,7 +988,6 @@ err_free_policy: | |||
1086 | nomem_out: | 988 | nomem_out: |
1087 | module_put(cpufreq_driver->owner); | 989 | module_put(cpufreq_driver->owner); |
1088 | module_out: | 990 | module_out: |
1089 | cpufreq_debug_enable_ratelimit(); | ||
1090 | return ret; | 991 | return ret; |
1091 | } | 992 | } |
1092 | 993 | ||
@@ -1110,15 +1011,13 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) | |||
1110 | unsigned int j; | 1011 | unsigned int j; |
1111 | #endif | 1012 | #endif |
1112 | 1013 | ||
1113 | cpufreq_debug_disable_ratelimit(); | 1014 | pr_debug("unregistering CPU %u\n", cpu); |
1114 | dprintk("unregistering CPU %u\n", cpu); | ||
1115 | 1015 | ||
1116 | spin_lock_irqsave(&cpufreq_driver_lock, flags); | 1016 | spin_lock_irqsave(&cpufreq_driver_lock, flags); |
1117 | data = per_cpu(cpufreq_cpu_data, cpu); | 1017 | data = per_cpu(cpufreq_cpu_data, cpu); |
1118 | 1018 | ||
1119 | if (!data) { | 1019 | if (!data) { |
1120 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 1020 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
1121 | cpufreq_debug_enable_ratelimit(); | ||
1122 | unlock_policy_rwsem_write(cpu); | 1021 | unlock_policy_rwsem_write(cpu); |
1123 | return -EINVAL; | 1022 | return -EINVAL; |
1124 | } | 1023 | } |
@@ -1130,12 +1029,11 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) | |||
1130 | * only need to unlink, put and exit | 1029 | * only need to unlink, put and exit |
1131 | */ | 1030 | */ |
1132 | if (unlikely(cpu != data->cpu)) { | 1031 | if (unlikely(cpu != data->cpu)) { |
1133 | dprintk("removing link\n"); | 1032 | pr_debug("removing link\n"); |
1134 | cpumask_clear_cpu(cpu, data->cpus); | 1033 | cpumask_clear_cpu(cpu, data->cpus); |
1135 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 1034 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
1136 | kobj = &sys_dev->kobj; | 1035 | kobj = &sys_dev->kobj; |
1137 | cpufreq_cpu_put(data); | 1036 | cpufreq_cpu_put(data); |
1138 | cpufreq_debug_enable_ratelimit(); | ||
1139 | unlock_policy_rwsem_write(cpu); | 1037 | unlock_policy_rwsem_write(cpu); |
1140 | sysfs_remove_link(kobj, "cpufreq"); | 1038 | sysfs_remove_link(kobj, "cpufreq"); |
1141 | return 0; | 1039 | return 0; |
@@ -1168,7 +1066,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) | |||
1168 | for_each_cpu(j, data->cpus) { | 1066 | for_each_cpu(j, data->cpus) { |
1169 | if (j == cpu) | 1067 | if (j == cpu) |
1170 | continue; | 1068 | continue; |
1171 | dprintk("removing link for cpu %u\n", j); | 1069 | pr_debug("removing link for cpu %u\n", j); |
1172 | #ifdef CONFIG_HOTPLUG_CPU | 1070 | #ifdef CONFIG_HOTPLUG_CPU |
1173 | strncpy(per_cpu(cpufreq_cpu_governor, j), | 1071 | strncpy(per_cpu(cpufreq_cpu_governor, j), |
1174 | data->governor->name, CPUFREQ_NAME_LEN); | 1072 | data->governor->name, CPUFREQ_NAME_LEN); |
@@ -1197,21 +1095,35 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) | |||
1197 | * not referenced anymore by anybody before we proceed with | 1095 | * not referenced anymore by anybody before we proceed with |
1198 | * unloading. | 1096 | * unloading. |
1199 | */ | 1097 | */ |
1200 | dprintk("waiting for dropping of refcount\n"); | 1098 | pr_debug("waiting for dropping of refcount\n"); |
1201 | wait_for_completion(cmp); | 1099 | wait_for_completion(cmp); |
1202 | dprintk("wait complete\n"); | 1100 | pr_debug("wait complete\n"); |
1203 | 1101 | ||
1204 | lock_policy_rwsem_write(cpu); | 1102 | lock_policy_rwsem_write(cpu); |
1205 | if (cpufreq_driver->exit) | 1103 | if (cpufreq_driver->exit) |
1206 | cpufreq_driver->exit(data); | 1104 | cpufreq_driver->exit(data); |
1207 | unlock_policy_rwsem_write(cpu); | 1105 | unlock_policy_rwsem_write(cpu); |
1208 | 1106 | ||
1107 | #ifdef CONFIG_HOTPLUG_CPU | ||
1108 | /* when the CPU which is the parent of the kobj is hotplugged | ||
1109 | * offline, check for siblings, and create cpufreq sysfs interface | ||
1110 | * and symlinks | ||
1111 | */ | ||
1112 | if (unlikely(cpumask_weight(data->cpus) > 1)) { | ||
1113 | /* first sibling now owns the new sysfs dir */ | ||
1114 | cpumask_clear_cpu(cpu, data->cpus); | ||
1115 | cpufreq_add_dev(get_cpu_sysdev(cpumask_first(data->cpus))); | ||
1116 | |||
1117 | /* finally remove our own symlink */ | ||
1118 | lock_policy_rwsem_write(cpu); | ||
1119 | __cpufreq_remove_dev(sys_dev); | ||
1120 | } | ||
1121 | #endif | ||
1122 | |||
1209 | free_cpumask_var(data->related_cpus); | 1123 | free_cpumask_var(data->related_cpus); |
1210 | free_cpumask_var(data->cpus); | 1124 | free_cpumask_var(data->cpus); |
1211 | kfree(data); | 1125 | kfree(data); |
1212 | per_cpu(cpufreq_cpu_data, cpu) = NULL; | ||
1213 | 1126 | ||
1214 | cpufreq_debug_enable_ratelimit(); | ||
1215 | return 0; | 1127 | return 0; |
1216 | } | 1128 | } |
1217 | 1129 | ||
@@ -1237,7 +1149,7 @@ static void handle_update(struct work_struct *work) | |||
1237 | struct cpufreq_policy *policy = | 1149 | struct cpufreq_policy *policy = |
1238 | container_of(work, struct cpufreq_policy, update); | 1150 | container_of(work, struct cpufreq_policy, update); |
1239 | unsigned int cpu = policy->cpu; | 1151 | unsigned int cpu = policy->cpu; |
1240 | dprintk("handle_update for cpu %u called\n", cpu); | 1152 | pr_debug("handle_update for cpu %u called\n", cpu); |
1241 | cpufreq_update_policy(cpu); | 1153 | cpufreq_update_policy(cpu); |
1242 | } | 1154 | } |
1243 | 1155 | ||
@@ -1255,7 +1167,7 @@ static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq, | |||
1255 | { | 1167 | { |
1256 | struct cpufreq_freqs freqs; | 1168 | struct cpufreq_freqs freqs; |
1257 | 1169 | ||
1258 | dprintk("Warning: CPU frequency out of sync: cpufreq and timing " | 1170 | pr_debug("Warning: CPU frequency out of sync: cpufreq and timing " |
1259 | "core thinks of %u, is %u kHz.\n", old_freq, new_freq); | 1171 | "core thinks of %u, is %u kHz.\n", old_freq, new_freq); |
1260 | 1172 | ||
1261 | freqs.cpu = cpu; | 1173 | freqs.cpu = cpu; |
@@ -1339,50 +1251,45 @@ out: | |||
1339 | } | 1251 | } |
1340 | EXPORT_SYMBOL(cpufreq_get); | 1252 | EXPORT_SYMBOL(cpufreq_get); |
1341 | 1253 | ||
1254 | static struct sysdev_driver cpufreq_sysdev_driver = { | ||
1255 | .add = cpufreq_add_dev, | ||
1256 | .remove = cpufreq_remove_dev, | ||
1257 | }; | ||
1258 | |||
1342 | 1259 | ||
1343 | /** | 1260 | /** |
1344 | * cpufreq_suspend - let the low level driver prepare for suspend | 1261 | * cpufreq_bp_suspend - Prepare the boot CPU for system suspend. |
1262 | * | ||
1263 | * This function is only executed for the boot processor. The other CPUs | ||
1264 | * have been put offline by means of CPU hotplug. | ||
1345 | */ | 1265 | */ |
1346 | 1266 | static int cpufreq_bp_suspend(void) | |
1347 | static int cpufreq_suspend(struct sys_device *sysdev, pm_message_t pmsg) | ||
1348 | { | 1267 | { |
1349 | int ret = 0; | 1268 | int ret = 0; |
1350 | 1269 | ||
1351 | int cpu = sysdev->id; | 1270 | int cpu = smp_processor_id(); |
1352 | struct cpufreq_policy *cpu_policy; | 1271 | struct cpufreq_policy *cpu_policy; |
1353 | 1272 | ||
1354 | dprintk("suspending cpu %u\n", cpu); | 1273 | pr_debug("suspending cpu %u\n", cpu); |
1355 | |||
1356 | if (!cpu_online(cpu)) | ||
1357 | return 0; | ||
1358 | |||
1359 | /* we may be lax here as interrupts are off. Nonetheless | ||
1360 | * we need to grab the correct cpu policy, as to check | ||
1361 | * whether we really run on this CPU. | ||
1362 | */ | ||
1363 | 1274 | ||
1275 | /* If there's no policy for the boot CPU, we have nothing to do. */ | ||
1364 | cpu_policy = cpufreq_cpu_get(cpu); | 1276 | cpu_policy = cpufreq_cpu_get(cpu); |
1365 | if (!cpu_policy) | 1277 | if (!cpu_policy) |
1366 | return -EINVAL; | 1278 | return 0; |
1367 | |||
1368 | /* only handle each CPU group once */ | ||
1369 | if (unlikely(cpu_policy->cpu != cpu)) | ||
1370 | goto out; | ||
1371 | 1279 | ||
1372 | if (cpufreq_driver->suspend) { | 1280 | if (cpufreq_driver->suspend) { |
1373 | ret = cpufreq_driver->suspend(cpu_policy, pmsg); | 1281 | ret = cpufreq_driver->suspend(cpu_policy); |
1374 | if (ret) | 1282 | if (ret) |
1375 | printk(KERN_ERR "cpufreq: suspend failed in ->suspend " | 1283 | printk(KERN_ERR "cpufreq: suspend failed in ->suspend " |
1376 | "step on CPU %u\n", cpu_policy->cpu); | 1284 | "step on CPU %u\n", cpu_policy->cpu); |
1377 | } | 1285 | } |
1378 | 1286 | ||
1379 | out: | ||
1380 | cpufreq_cpu_put(cpu_policy); | 1287 | cpufreq_cpu_put(cpu_policy); |
1381 | return ret; | 1288 | return ret; |
1382 | } | 1289 | } |
1383 | 1290 | ||
1384 | /** | 1291 | /** |
1385 | * cpufreq_resume - restore proper CPU frequency handling after resume | 1292 | * cpufreq_bp_resume - Restore proper frequency handling of the boot CPU. |
1386 | * | 1293 | * |
1387 | * 1.) resume CPUfreq hardware support (cpufreq_driver->resume()) | 1294 | * 1.) resume CPUfreq hardware support (cpufreq_driver->resume()) |
1388 | * 2.) schedule call cpufreq_update_policy() ASAP as interrupts are | 1295 | * 2.) schedule call cpufreq_update_policy() ASAP as interrupts are |
@@ -1390,31 +1297,23 @@ out: | |||
1390 | * what we believe it to be. This is a bit later than when it | 1297 | * what we believe it to be. This is a bit later than when it |
1391 | * should be, but nonethteless it's better than calling | 1298 | * should be, but nonethteless it's better than calling |
1392 | * cpufreq_driver->get() here which might re-enable interrupts... | 1299 | * cpufreq_driver->get() here which might re-enable interrupts... |
1300 | * | ||
1301 | * This function is only executed for the boot CPU. The other CPUs have not | ||
1302 | * been turned on yet. | ||
1393 | */ | 1303 | */ |
1394 | static int cpufreq_resume(struct sys_device *sysdev) | 1304 | static void cpufreq_bp_resume(void) |
1395 | { | 1305 | { |
1396 | int ret = 0; | 1306 | int ret = 0; |
1397 | 1307 | ||
1398 | int cpu = sysdev->id; | 1308 | int cpu = smp_processor_id(); |
1399 | struct cpufreq_policy *cpu_policy; | 1309 | struct cpufreq_policy *cpu_policy; |
1400 | 1310 | ||
1401 | dprintk("resuming cpu %u\n", cpu); | 1311 | pr_debug("resuming cpu %u\n", cpu); |
1402 | |||
1403 | if (!cpu_online(cpu)) | ||
1404 | return 0; | ||
1405 | |||
1406 | /* we may be lax here as interrupts are off. Nonetheless | ||
1407 | * we need to grab the correct cpu policy, as to check | ||
1408 | * whether we really run on this CPU. | ||
1409 | */ | ||
1410 | 1312 | ||
1313 | /* If there's no policy for the boot CPU, we have nothing to do. */ | ||
1411 | cpu_policy = cpufreq_cpu_get(cpu); | 1314 | cpu_policy = cpufreq_cpu_get(cpu); |
1412 | if (!cpu_policy) | 1315 | if (!cpu_policy) |
1413 | return -EINVAL; | 1316 | return; |
1414 | |||
1415 | /* only handle each CPU group once */ | ||
1416 | if (unlikely(cpu_policy->cpu != cpu)) | ||
1417 | goto fail; | ||
1418 | 1317 | ||
1419 | if (cpufreq_driver->resume) { | 1318 | if (cpufreq_driver->resume) { |
1420 | ret = cpufreq_driver->resume(cpu_policy); | 1319 | ret = cpufreq_driver->resume(cpu_policy); |
@@ -1429,14 +1328,11 @@ static int cpufreq_resume(struct sys_device *sysdev) | |||
1429 | 1328 | ||
1430 | fail: | 1329 | fail: |
1431 | cpufreq_cpu_put(cpu_policy); | 1330 | cpufreq_cpu_put(cpu_policy); |
1432 | return ret; | ||
1433 | } | 1331 | } |
1434 | 1332 | ||
1435 | static struct sysdev_driver cpufreq_sysdev_driver = { | 1333 | static struct syscore_ops cpufreq_syscore_ops = { |
1436 | .add = cpufreq_add_dev, | 1334 | .suspend = cpufreq_bp_suspend, |
1437 | .remove = cpufreq_remove_dev, | 1335 | .resume = cpufreq_bp_resume, |
1438 | .suspend = cpufreq_suspend, | ||
1439 | .resume = cpufreq_resume, | ||
1440 | }; | 1336 | }; |
1441 | 1337 | ||
1442 | 1338 | ||
@@ -1524,7 +1420,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, | |||
1524 | { | 1420 | { |
1525 | int retval = -EINVAL; | 1421 | int retval = -EINVAL; |
1526 | 1422 | ||
1527 | dprintk("target for CPU %u: %u kHz, relation %u\n", policy->cpu, | 1423 | pr_debug("target for CPU %u: %u kHz, relation %u\n", policy->cpu, |
1528 | target_freq, relation); | 1424 | target_freq, relation); |
1529 | if (cpu_online(policy->cpu) && cpufreq_driver->target) | 1425 | if (cpu_online(policy->cpu) && cpufreq_driver->target) |
1530 | retval = cpufreq_driver->target(policy, target_freq, relation); | 1426 | retval = cpufreq_driver->target(policy, target_freq, relation); |
@@ -1610,7 +1506,7 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, | |||
1610 | if (!try_module_get(policy->governor->owner)) | 1506 | if (!try_module_get(policy->governor->owner)) |
1611 | return -EINVAL; | 1507 | return -EINVAL; |
1612 | 1508 | ||
1613 | dprintk("__cpufreq_governor for CPU %u, event %u\n", | 1509 | pr_debug("__cpufreq_governor for CPU %u, event %u\n", |
1614 | policy->cpu, event); | 1510 | policy->cpu, event); |
1615 | ret = policy->governor->governor(policy, event); | 1511 | ret = policy->governor->governor(policy, event); |
1616 | 1512 | ||
@@ -1711,8 +1607,7 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, | |||
1711 | { | 1607 | { |
1712 | int ret = 0; | 1608 | int ret = 0; |
1713 | 1609 | ||
1714 | cpufreq_debug_disable_ratelimit(); | 1610 | pr_debug("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu, |
1715 | dprintk("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu, | ||
1716 | policy->min, policy->max); | 1611 | policy->min, policy->max); |
1717 | 1612 | ||
1718 | memcpy(&policy->cpuinfo, &data->cpuinfo, | 1613 | memcpy(&policy->cpuinfo, &data->cpuinfo, |
@@ -1749,19 +1644,19 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, | |||
1749 | data->min = policy->min; | 1644 | data->min = policy->min; |
1750 | data->max = policy->max; | 1645 | data->max = policy->max; |
1751 | 1646 | ||
1752 | dprintk("new min and max freqs are %u - %u kHz\n", | 1647 | pr_debug("new min and max freqs are %u - %u kHz\n", |
1753 | data->min, data->max); | 1648 | data->min, data->max); |
1754 | 1649 | ||
1755 | if (cpufreq_driver->setpolicy) { | 1650 | if (cpufreq_driver->setpolicy) { |
1756 | data->policy = policy->policy; | 1651 | data->policy = policy->policy; |
1757 | dprintk("setting range\n"); | 1652 | pr_debug("setting range\n"); |
1758 | ret = cpufreq_driver->setpolicy(policy); | 1653 | ret = cpufreq_driver->setpolicy(policy); |
1759 | } else { | 1654 | } else { |
1760 | if (policy->governor != data->governor) { | 1655 | if (policy->governor != data->governor) { |
1761 | /* save old, working values */ | 1656 | /* save old, working values */ |
1762 | struct cpufreq_governor *old_gov = data->governor; | 1657 | struct cpufreq_governor *old_gov = data->governor; |
1763 | 1658 | ||
1764 | dprintk("governor switch\n"); | 1659 | pr_debug("governor switch\n"); |
1765 | 1660 | ||
1766 | /* end old governor */ | 1661 | /* end old governor */ |
1767 | if (data->governor) | 1662 | if (data->governor) |
@@ -1771,7 +1666,7 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, | |||
1771 | data->governor = policy->governor; | 1666 | data->governor = policy->governor; |
1772 | if (__cpufreq_governor(data, CPUFREQ_GOV_START)) { | 1667 | if (__cpufreq_governor(data, CPUFREQ_GOV_START)) { |
1773 | /* new governor failed, so re-start old one */ | 1668 | /* new governor failed, so re-start old one */ |
1774 | dprintk("starting governor %s failed\n", | 1669 | pr_debug("starting governor %s failed\n", |
1775 | data->governor->name); | 1670 | data->governor->name); |
1776 | if (old_gov) { | 1671 | if (old_gov) { |
1777 | data->governor = old_gov; | 1672 | data->governor = old_gov; |
@@ -1783,12 +1678,11 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, | |||
1783 | } | 1678 | } |
1784 | /* might be a policy change, too, so fall through */ | 1679 | /* might be a policy change, too, so fall through */ |
1785 | } | 1680 | } |
1786 | dprintk("governor: change or update limits\n"); | 1681 | pr_debug("governor: change or update limits\n"); |
1787 | __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); | 1682 | __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); |
1788 | } | 1683 | } |
1789 | 1684 | ||
1790 | error_out: | 1685 | error_out: |
1791 | cpufreq_debug_enable_ratelimit(); | ||
1792 | return ret; | 1686 | return ret; |
1793 | } | 1687 | } |
1794 | 1688 | ||
@@ -1796,7 +1690,7 @@ error_out: | |||
1796 | * cpufreq_update_policy - re-evaluate an existing cpufreq policy | 1690 | * cpufreq_update_policy - re-evaluate an existing cpufreq policy |
1797 | * @cpu: CPU which shall be re-evaluated | 1691 | * @cpu: CPU which shall be re-evaluated |
1798 | * | 1692 | * |
1799 | * Usefull for policy notifiers which have different necessities | 1693 | * Useful for policy notifiers which have different necessities |
1800 | * at different times. | 1694 | * at different times. |
1801 | */ | 1695 | */ |
1802 | int cpufreq_update_policy(unsigned int cpu) | 1696 | int cpufreq_update_policy(unsigned int cpu) |
@@ -1815,7 +1709,7 @@ int cpufreq_update_policy(unsigned int cpu) | |||
1815 | goto fail; | 1709 | goto fail; |
1816 | } | 1710 | } |
1817 | 1711 | ||
1818 | dprintk("updating policy for CPU %u\n", cpu); | 1712 | pr_debug("updating policy for CPU %u\n", cpu); |
1819 | memcpy(&policy, data, sizeof(struct cpufreq_policy)); | 1713 | memcpy(&policy, data, sizeof(struct cpufreq_policy)); |
1820 | policy.min = data->user_policy.min; | 1714 | policy.min = data->user_policy.min; |
1821 | policy.max = data->user_policy.max; | 1715 | policy.max = data->user_policy.max; |
@@ -1827,7 +1721,7 @@ int cpufreq_update_policy(unsigned int cpu) | |||
1827 | if (cpufreq_driver->get) { | 1721 | if (cpufreq_driver->get) { |
1828 | policy.cur = cpufreq_driver->get(cpu); | 1722 | policy.cur = cpufreq_driver->get(cpu); |
1829 | if (!data->cur) { | 1723 | if (!data->cur) { |
1830 | dprintk("Driver did not initialize current freq"); | 1724 | pr_debug("Driver did not initialize current freq"); |
1831 | data->cur = policy.cur; | 1725 | data->cur = policy.cur; |
1832 | } else { | 1726 | } else { |
1833 | if (data->cur != policy.cur) | 1727 | if (data->cur != policy.cur) |
@@ -1903,7 +1797,7 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data) | |||
1903 | ((!driver_data->setpolicy) && (!driver_data->target))) | 1797 | ((!driver_data->setpolicy) && (!driver_data->target))) |
1904 | return -EINVAL; | 1798 | return -EINVAL; |
1905 | 1799 | ||
1906 | dprintk("trying to register driver %s\n", driver_data->name); | 1800 | pr_debug("trying to register driver %s\n", driver_data->name); |
1907 | 1801 | ||
1908 | if (driver_data->setpolicy) | 1802 | if (driver_data->setpolicy) |
1909 | driver_data->flags |= CPUFREQ_CONST_LOOPS; | 1803 | driver_data->flags |= CPUFREQ_CONST_LOOPS; |
@@ -1918,8 +1812,10 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data) | |||
1918 | 1812 | ||
1919 | ret = sysdev_driver_register(&cpu_sysdev_class, | 1813 | ret = sysdev_driver_register(&cpu_sysdev_class, |
1920 | &cpufreq_sysdev_driver); | 1814 | &cpufreq_sysdev_driver); |
1815 | if (ret) | ||
1816 | goto err_null_driver; | ||
1921 | 1817 | ||
1922 | if ((!ret) && !(cpufreq_driver->flags & CPUFREQ_STICKY)) { | 1818 | if (!(cpufreq_driver->flags & CPUFREQ_STICKY)) { |
1923 | int i; | 1819 | int i; |
1924 | ret = -ENODEV; | 1820 | ret = -ENODEV; |
1925 | 1821 | ||
@@ -1932,23 +1828,23 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data) | |||
1932 | 1828 | ||
1933 | /* if all ->init() calls failed, unregister */ | 1829 | /* if all ->init() calls failed, unregister */ |
1934 | if (ret) { | 1830 | if (ret) { |
1935 | dprintk("no CPU initialized for driver %s\n", | 1831 | pr_debug("no CPU initialized for driver %s\n", |
1936 | driver_data->name); | 1832 | driver_data->name); |
1937 | sysdev_driver_unregister(&cpu_sysdev_class, | 1833 | goto err_sysdev_unreg; |
1938 | &cpufreq_sysdev_driver); | ||
1939 | |||
1940 | spin_lock_irqsave(&cpufreq_driver_lock, flags); | ||
1941 | cpufreq_driver = NULL; | ||
1942 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | ||
1943 | } | 1834 | } |
1944 | } | 1835 | } |
1945 | 1836 | ||
1946 | if (!ret) { | 1837 | register_hotcpu_notifier(&cpufreq_cpu_notifier); |
1947 | register_hotcpu_notifier(&cpufreq_cpu_notifier); | 1838 | pr_debug("driver %s up and running\n", driver_data->name); |
1948 | dprintk("driver %s up and running\n", driver_data->name); | ||
1949 | cpufreq_debug_enable_ratelimit(); | ||
1950 | } | ||
1951 | 1839 | ||
1840 | return 0; | ||
1841 | err_sysdev_unreg: | ||
1842 | sysdev_driver_unregister(&cpu_sysdev_class, | ||
1843 | &cpufreq_sysdev_driver); | ||
1844 | err_null_driver: | ||
1845 | spin_lock_irqsave(&cpufreq_driver_lock, flags); | ||
1846 | cpufreq_driver = NULL; | ||
1847 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | ||
1952 | return ret; | 1848 | return ret; |
1953 | } | 1849 | } |
1954 | EXPORT_SYMBOL_GPL(cpufreq_register_driver); | 1850 | EXPORT_SYMBOL_GPL(cpufreq_register_driver); |
@@ -1966,14 +1862,10 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver) | |||
1966 | { | 1862 | { |
1967 | unsigned long flags; | 1863 | unsigned long flags; |
1968 | 1864 | ||
1969 | cpufreq_debug_disable_ratelimit(); | 1865 | if (!cpufreq_driver || (driver != cpufreq_driver)) |
1970 | |||
1971 | if (!cpufreq_driver || (driver != cpufreq_driver)) { | ||
1972 | cpufreq_debug_enable_ratelimit(); | ||
1973 | return -EINVAL; | 1866 | return -EINVAL; |
1974 | } | ||
1975 | 1867 | ||
1976 | dprintk("unregistering driver %s\n", driver->name); | 1868 | pr_debug("unregistering driver %s\n", driver->name); |
1977 | 1869 | ||
1978 | sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver); | 1870 | sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver); |
1979 | unregister_hotcpu_notifier(&cpufreq_cpu_notifier); | 1871 | unregister_hotcpu_notifier(&cpufreq_cpu_notifier); |
@@ -1998,6 +1890,7 @@ static int __init cpufreq_core_init(void) | |||
1998 | cpufreq_global_kobject = kobject_create_and_add("cpufreq", | 1890 | cpufreq_global_kobject = kobject_create_and_add("cpufreq", |
1999 | &cpu_sysdev_class.kset.kobj); | 1891 | &cpu_sysdev_class.kset.kobj); |
2000 | BUG_ON(!cpufreq_global_kobject); | 1892 | BUG_ON(!cpufreq_global_kobject); |
1893 | register_syscore_ops(&cpufreq_syscore_ops); | ||
2001 | 1894 | ||
2002 | return 0; | 1895 | return 0; |
2003 | } | 1896 | } |