.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * linux/drivers/cpufreq/cpufreq.c |
---|
3 | 4 | * |
---|
.. | .. |
---|
9 | 10 | * Added handling for CPU hotplug |
---|
10 | 11 | * Feb 2006 - Jacob Shin <jacob.shin@amd.com> |
---|
11 | 12 | * Fix handling for CPU hotplug -- affected CPUs |
---|
12 | | - * |
---|
13 | | - * This program is free software; you can redistribute it and/or modify |
---|
14 | | - * it under the terms of the GNU General Public License version 2 as |
---|
15 | | - * published by the Free Software Foundation. |
---|
16 | 13 | */ |
---|
17 | 14 | |
---|
18 | 15 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
---|
.. | .. |
---|
27 | 24 | #include <linux/kernel_stat.h> |
---|
28 | 25 | #include <linux/module.h> |
---|
29 | 26 | #include <linux/mutex.h> |
---|
| 27 | +#include <linux/pm_qos.h> |
---|
30 | 28 | #include <linux/slab.h> |
---|
31 | 29 | #include <linux/suspend.h> |
---|
32 | 30 | #include <linux/syscore_ops.h> |
---|
33 | 31 | #include <linux/tick.h> |
---|
34 | 32 | #include <trace/events/power.h> |
---|
35 | | - |
---|
36 | | -#if IS_ENABLED(CONFIG_ARM_ROCKCHIP_CPUFREQ) |
---|
37 | | -#include "rockchip-cpufreq.h" |
---|
38 | | -#endif |
---|
| 33 | +#include <trace/hooks/cpufreq.h> |
---|
39 | 34 | |
---|
40 | 35 | static LIST_HEAD(cpufreq_policy_list); |
---|
41 | | - |
---|
42 | | -static inline bool policy_is_inactive(struct cpufreq_policy *policy) |
---|
43 | | -{ |
---|
44 | | - return cpumask_empty(policy->cpus); |
---|
45 | | -} |
---|
46 | 36 | |
---|
47 | 37 | /* Macros to iterate over CPU policies */ |
---|
48 | 38 | #define for_each_suitable_policy(__policy, __active) \ |
---|
.. | .. |
---|
62 | 52 | #define for_each_governor(__governor) \ |
---|
63 | 53 | list_for_each_entry(__governor, &cpufreq_governor_list, governor_list) |
---|
64 | 54 | |
---|
65 | | -/** |
---|
| 55 | +static char default_governor[CPUFREQ_NAME_LEN]; |
---|
| 56 | + |
---|
| 57 | +/* |
---|
66 | 58 | * The "cpufreq driver" - the arch- or hardware-dependent low |
---|
67 | 59 | * level driver of CPUFreq support, and its spinlock. This lock |
---|
68 | 60 | * also protects the cpufreq_cpu_data array. |
---|
.. | .. |
---|
70 | 62 | static struct cpufreq_driver *cpufreq_driver; |
---|
71 | 63 | static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data); |
---|
72 | 64 | static DEFINE_RWLOCK(cpufreq_driver_lock); |
---|
| 65 | + |
---|
| 66 | +static DEFINE_STATIC_KEY_FALSE(cpufreq_freq_invariance); |
---|
| 67 | +bool cpufreq_supports_freq_invariance(void) |
---|
| 68 | +{ |
---|
| 69 | + return static_branch_likely(&cpufreq_freq_invariance); |
---|
| 70 | +} |
---|
73 | 71 | |
---|
74 | 72 | /* Flag to suspend/resume CPUFreq governors */ |
---|
75 | 73 | static bool cpufreq_suspended; |
---|
.. | .. |
---|
83 | 81 | static unsigned int __cpufreq_get(struct cpufreq_policy *policy); |
---|
84 | 82 | static int cpufreq_init_governor(struct cpufreq_policy *policy); |
---|
85 | 83 | static void cpufreq_exit_governor(struct cpufreq_policy *policy); |
---|
86 | | -static int cpufreq_start_governor(struct cpufreq_policy *policy); |
---|
87 | | -static void cpufreq_stop_governor(struct cpufreq_policy *policy); |
---|
88 | 84 | static void cpufreq_governor_limits(struct cpufreq_policy *policy); |
---|
| 85 | +static int cpufreq_set_policy(struct cpufreq_policy *policy, |
---|
| 86 | + struct cpufreq_governor *new_gov, |
---|
| 87 | + unsigned int new_pol); |
---|
89 | 88 | |
---|
90 | | -/** |
---|
| 89 | +/* |
---|
91 | 90 | * Two notifier lists: the "policy" list is involved in the |
---|
92 | 91 | * validation process for a new CPU frequency policy; the |
---|
93 | 92 | * "transition" list for kernel code that needs to handle |
---|
.. | .. |
---|
114 | 113 | } |
---|
115 | 114 | EXPORT_SYMBOL_GPL(have_governor_per_policy); |
---|
116 | 115 | |
---|
| 116 | +static struct kobject *cpufreq_global_kobject; |
---|
| 117 | + |
---|
117 | 118 | struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy) |
---|
118 | 119 | { |
---|
119 | 120 | if (have_governor_per_policy()) |
---|
.. | .. |
---|
125 | 126 | |
---|
126 | 127 | static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall) |
---|
127 | 128 | { |
---|
128 | | - u64 idle_time; |
---|
| 129 | + struct kernel_cpustat kcpustat; |
---|
129 | 130 | u64 cur_wall_time; |
---|
| 131 | + u64 idle_time; |
---|
130 | 132 | u64 busy_time; |
---|
131 | 133 | |
---|
132 | 134 | cur_wall_time = jiffies64_to_nsecs(get_jiffies_64()); |
---|
133 | 135 | |
---|
134 | | - busy_time = kcpustat_cpu(cpu).cpustat[CPUTIME_USER]; |
---|
135 | | - busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SYSTEM]; |
---|
136 | | - busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_IRQ]; |
---|
137 | | - busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_SOFTIRQ]; |
---|
138 | | - busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_STEAL]; |
---|
139 | | - busy_time += kcpustat_cpu(cpu).cpustat[CPUTIME_NICE]; |
---|
| 136 | + kcpustat_cpu_fetch(&kcpustat, cpu); |
---|
| 137 | + |
---|
| 138 | + busy_time = kcpustat.cpustat[CPUTIME_USER]; |
---|
| 139 | + busy_time += kcpustat.cpustat[CPUTIME_SYSTEM]; |
---|
| 140 | + busy_time += kcpustat.cpustat[CPUTIME_IRQ]; |
---|
| 141 | + busy_time += kcpustat.cpustat[CPUTIME_SOFTIRQ]; |
---|
| 142 | + busy_time += kcpustat.cpustat[CPUTIME_STEAL]; |
---|
| 143 | + busy_time += kcpustat.cpustat[CPUTIME_NICE]; |
---|
140 | 144 | |
---|
141 | 145 | idle_time = cur_wall_time - busy_time; |
---|
142 | 146 | if (wall) |
---|
.. | .. |
---|
158 | 162 | } |
---|
159 | 163 | EXPORT_SYMBOL_GPL(get_cpu_idle_time); |
---|
160 | 164 | |
---|
161 | | -__weak void arch_set_freq_scale(struct cpumask *cpus, unsigned long cur_freq, |
---|
162 | | - unsigned long max_freq) |
---|
163 | | -{ |
---|
164 | | -} |
---|
165 | | -EXPORT_SYMBOL_GPL(arch_set_freq_scale); |
---|
166 | | - |
---|
167 | | -__weak void arch_set_max_freq_scale(struct cpumask *cpus, |
---|
168 | | - unsigned long policy_max_freq) |
---|
169 | | -{ |
---|
170 | | -} |
---|
171 | | -EXPORT_SYMBOL_GPL(arch_set_max_freq_scale); |
---|
172 | | - |
---|
173 | 165 | /* |
---|
174 | 166 | * This is a generic cpufreq init() routine which can be used by cpufreq |
---|
175 | 167 | * drivers of SMP systems. It will do following: |
---|
.. | .. |
---|
177 | 169 | * - set policies transition latency |
---|
178 | 170 | * - policy->cpus with all possible CPUs |
---|
179 | 171 | */ |
---|
180 | | -int cpufreq_generic_init(struct cpufreq_policy *policy, |
---|
| 172 | +void cpufreq_generic_init(struct cpufreq_policy *policy, |
---|
181 | 173 | struct cpufreq_frequency_table *table, |
---|
182 | 174 | unsigned int transition_latency) |
---|
183 | 175 | { |
---|
.. | .. |
---|
189 | 181 | * share the clock and voltage and clock. |
---|
190 | 182 | */ |
---|
191 | 183 | cpumask_setall(policy->cpus); |
---|
192 | | - |
---|
193 | | - return 0; |
---|
194 | 184 | } |
---|
195 | 185 | EXPORT_SYMBOL_GPL(cpufreq_generic_init); |
---|
196 | 186 | |
---|
.. | .. |
---|
217 | 207 | EXPORT_SYMBOL_GPL(cpufreq_generic_get); |
---|
218 | 208 | |
---|
219 | 209 | /** |
---|
220 | | - * cpufreq_cpu_get: returns policy for a cpu and marks it busy. |
---|
| 210 | + * cpufreq_cpu_get - Return policy for a CPU and mark it as busy. |
---|
| 211 | + * @cpu: CPU to find the policy for. |
---|
221 | 212 | * |
---|
222 | | - * @cpu: cpu to find policy for. |
---|
| 213 | + * Call cpufreq_cpu_get_raw() to obtain a cpufreq policy for @cpu and increment |
---|
| 214 | + * the kobject reference counter of that policy. Return a valid policy on |
---|
| 215 | + * success or NULL on failure. |
---|
223 | 216 | * |
---|
224 | | - * This returns policy for 'cpu', returns NULL if it doesn't exist. |
---|
225 | | - * It also increments the kobject reference count to mark it busy and so would |
---|
226 | | - * require a corresponding call to cpufreq_cpu_put() to decrement it back. |
---|
227 | | - * If corresponding call cpufreq_cpu_put() isn't made, the policy wouldn't be |
---|
228 | | - * freed as that depends on the kobj count. |
---|
229 | | - * |
---|
230 | | - * Return: A valid policy on success, otherwise NULL on failure. |
---|
| 217 | + * The policy returned by this function has to be released with the help of |
---|
| 218 | + * cpufreq_cpu_put() to balance its kobject reference counter properly. |
---|
231 | 219 | */ |
---|
232 | 220 | struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) |
---|
233 | 221 | { |
---|
.. | .. |
---|
254 | 242 | EXPORT_SYMBOL_GPL(cpufreq_cpu_get); |
---|
255 | 243 | |
---|
256 | 244 | /** |
---|
257 | | - * cpufreq_cpu_put: Decrements the usage count of a policy |
---|
258 | | - * |
---|
259 | | - * @policy: policy earlier returned by cpufreq_cpu_get(). |
---|
260 | | - * |
---|
261 | | - * This decrements the kobject reference count incremented earlier by calling |
---|
262 | | - * cpufreq_cpu_get(). |
---|
| 245 | + * cpufreq_cpu_put - Decrement kobject usage counter for cpufreq policy. |
---|
| 246 | + * @policy: cpufreq policy returned by cpufreq_cpu_get(). |
---|
263 | 247 | */ |
---|
264 | 248 | void cpufreq_cpu_put(struct cpufreq_policy *policy) |
---|
265 | 249 | { |
---|
.. | .. |
---|
267 | 251 | } |
---|
268 | 252 | EXPORT_SYMBOL_GPL(cpufreq_cpu_put); |
---|
269 | 253 | |
---|
| 254 | +/** |
---|
| 255 | + * cpufreq_cpu_release - Unlock a policy and decrement its usage counter. |
---|
| 256 | + * @policy: cpufreq policy returned by cpufreq_cpu_acquire(). |
---|
| 257 | + */ |
---|
| 258 | +void cpufreq_cpu_release(struct cpufreq_policy *policy) |
---|
| 259 | +{ |
---|
| 260 | + if (WARN_ON(!policy)) |
---|
| 261 | + return; |
---|
| 262 | + |
---|
| 263 | + lockdep_assert_held(&policy->rwsem); |
---|
| 264 | + |
---|
| 265 | + up_write(&policy->rwsem); |
---|
| 266 | + |
---|
| 267 | + cpufreq_cpu_put(policy); |
---|
| 268 | +} |
---|
| 269 | + |
---|
| 270 | +/** |
---|
| 271 | + * cpufreq_cpu_acquire - Find policy for a CPU, mark it as busy and lock it. |
---|
| 272 | + * @cpu: CPU to find the policy for. |
---|
| 273 | + * |
---|
| 274 | + * Call cpufreq_cpu_get() to get a reference on the cpufreq policy for @cpu and |
---|
| 275 | + * if the policy returned by it is not NULL, acquire its rwsem for writing. |
---|
| 276 | + * Return the policy if it is active or release it and return NULL otherwise. |
---|
| 277 | + * |
---|
| 278 | + * The policy returned by this function has to be released with the help of |
---|
| 279 | + * cpufreq_cpu_release() in order to release its rwsem and balance its usage |
---|
| 280 | + * counter properly. |
---|
| 281 | + */ |
---|
| 282 | +struct cpufreq_policy *cpufreq_cpu_acquire(unsigned int cpu) |
---|
| 283 | +{ |
---|
| 284 | + struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); |
---|
| 285 | + |
---|
| 286 | + if (!policy) |
---|
| 287 | + return NULL; |
---|
| 288 | + |
---|
| 289 | + down_write(&policy->rwsem); |
---|
| 290 | + |
---|
| 291 | + if (policy_is_inactive(policy)) { |
---|
| 292 | + cpufreq_cpu_release(policy); |
---|
| 293 | + return NULL; |
---|
| 294 | + } |
---|
| 295 | + |
---|
| 296 | + return policy; |
---|
| 297 | +} |
---|
| 298 | + |
---|
270 | 299 | /********************************************************************* |
---|
271 | 300 | * EXTERNALLY AFFECTING FREQUENCY CHANGES * |
---|
272 | 301 | *********************************************************************/ |
---|
273 | 302 | |
---|
274 | | -/** |
---|
| 303 | +/* |
---|
275 | 304 | * adjust_jiffies - adjust the system "loops_per_jiffy" |
---|
276 | 305 | * |
---|
277 | 306 | * This function alters the system "loops_per_jiffy" for the clock |
---|
.. | .. |
---|
317 | 346 | struct cpufreq_freqs *freqs, |
---|
318 | 347 | unsigned int state) |
---|
319 | 348 | { |
---|
| 349 | + int cpu; |
---|
| 350 | + |
---|
320 | 351 | BUG_ON(irqs_disabled()); |
---|
321 | 352 | |
---|
322 | 353 | if (cpufreq_disabled()) |
---|
323 | 354 | return; |
---|
324 | 355 | |
---|
| 356 | + freqs->policy = policy; |
---|
325 | 357 | freqs->flags = cpufreq_driver->flags; |
---|
326 | 358 | pr_debug("notification %u of frequency transition to %u kHz\n", |
---|
327 | 359 | state, freqs->new); |
---|
.. | .. |
---|
333 | 365 | * which is not equal to what the cpufreq core thinks is |
---|
334 | 366 | * "old frequency". |
---|
335 | 367 | */ |
---|
336 | | - if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { |
---|
337 | | - if (policy->cur && (policy->cur != freqs->old)) { |
---|
338 | | - pr_debug("Warning: CPU frequency is %u, cpufreq assumed %u kHz\n", |
---|
339 | | - freqs->old, policy->cur); |
---|
340 | | - freqs->old = policy->cur; |
---|
341 | | - } |
---|
| 368 | + if (policy->cur && policy->cur != freqs->old) { |
---|
| 369 | + pr_debug("Warning: CPU frequency is %u, cpufreq assumed %u kHz\n", |
---|
| 370 | + freqs->old, policy->cur); |
---|
| 371 | + freqs->old = policy->cur; |
---|
342 | 372 | } |
---|
343 | 373 | |
---|
344 | | - for_each_cpu(freqs->cpu, policy->cpus) { |
---|
345 | | - srcu_notifier_call_chain(&cpufreq_transition_notifier_list, |
---|
346 | | - CPUFREQ_PRECHANGE, freqs); |
---|
347 | | - } |
---|
| 374 | + srcu_notifier_call_chain(&cpufreq_transition_notifier_list, |
---|
| 375 | + CPUFREQ_PRECHANGE, freqs); |
---|
348 | 376 | |
---|
349 | 377 | adjust_jiffies(CPUFREQ_PRECHANGE, freqs); |
---|
350 | 378 | break; |
---|
.. | .. |
---|
354 | 382 | pr_debug("FREQ: %u - CPUs: %*pbl\n", freqs->new, |
---|
355 | 383 | cpumask_pr_args(policy->cpus)); |
---|
356 | 384 | |
---|
357 | | - for_each_cpu(freqs->cpu, policy->cpus) { |
---|
358 | | - trace_cpu_frequency(freqs->new, freqs->cpu); |
---|
359 | | - srcu_notifier_call_chain(&cpufreq_transition_notifier_list, |
---|
360 | | - CPUFREQ_POSTCHANGE, freqs); |
---|
361 | | - } |
---|
| 385 | + for_each_cpu(cpu, policy->cpus) |
---|
| 386 | + trace_cpu_frequency(freqs->new, cpu); |
---|
| 387 | + |
---|
| 388 | + srcu_notifier_call_chain(&cpufreq_transition_notifier_list, |
---|
| 389 | + CPUFREQ_POSTCHANGE, freqs); |
---|
362 | 390 | |
---|
363 | 391 | cpufreq_stats_record_transition(policy, freqs->new); |
---|
364 | 392 | cpufreq_times_record_transition(policy, freqs->new); |
---|
365 | 393 | policy->cur = freqs->new; |
---|
| 394 | + trace_android_rvh_cpufreq_transition(policy); |
---|
366 | 395 | } |
---|
367 | 396 | } |
---|
368 | 397 | |
---|
.. | .. |
---|
416 | 445 | void cpufreq_freq_transition_end(struct cpufreq_policy *policy, |
---|
417 | 446 | struct cpufreq_freqs *freqs, int transition_failed) |
---|
418 | 447 | { |
---|
419 | | - if (unlikely(WARN_ON(!policy->transition_ongoing))) |
---|
| 448 | + if (WARN_ON(!policy->transition_ongoing)) |
---|
420 | 449 | return; |
---|
421 | 450 | |
---|
422 | 451 | cpufreq_notify_post_transition(policy, freqs, transition_failed); |
---|
| 452 | + |
---|
| 453 | + arch_set_freq_scale(policy->related_cpus, |
---|
| 454 | + policy->cur, |
---|
| 455 | + policy->cpuinfo.max_freq); |
---|
423 | 456 | |
---|
424 | 457 | policy->transition_ongoing = false; |
---|
425 | 458 | policy->transition_task = NULL; |
---|
.. | .. |
---|
444 | 477 | mutex_lock(&cpufreq_transition_notifier_list.mutex); |
---|
445 | 478 | |
---|
446 | 479 | for (nb = cpufreq_transition_notifier_list.head; nb; nb = nb->next) |
---|
447 | | - pr_info("%pF\n", nb->notifier_call); |
---|
| 480 | + pr_info("%pS\n", nb->notifier_call); |
---|
448 | 481 | |
---|
449 | 482 | mutex_unlock(&cpufreq_transition_notifier_list.mutex); |
---|
450 | 483 | } |
---|
.. | .. |
---|
499 | 532 | /** |
---|
500 | 533 | * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported |
---|
501 | 534 | * one. |
---|
| 535 | + * @policy: associated policy to interrogate |
---|
502 | 536 | * @target_freq: target frequency to resolve. |
---|
503 | 537 | * |
---|
504 | 538 | * The target to driver frequency mapping is cached in the policy. |
---|
.. | .. |
---|
509 | 543 | unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, |
---|
510 | 544 | unsigned int target_freq) |
---|
511 | 545 | { |
---|
| 546 | + unsigned int old_target_freq = target_freq; |
---|
| 547 | + |
---|
512 | 548 | target_freq = clamp_val(target_freq, policy->min, policy->max); |
---|
| 549 | + trace_android_vh_cpufreq_resolve_freq(policy, target_freq, old_target_freq); |
---|
513 | 550 | policy->cached_target_freq = target_freq; |
---|
514 | 551 | |
---|
515 | 552 | if (cpufreq_driver->target_index) { |
---|
516 | | - int idx; |
---|
| 553 | + unsigned int idx; |
---|
517 | 554 | |
---|
518 | 555 | idx = cpufreq_frequency_table_target(policy, target_freq, |
---|
519 | 556 | CPUFREQ_RELATION_L); |
---|
.. | .. |
---|
596 | 633 | return NULL; |
---|
597 | 634 | } |
---|
598 | 635 | |
---|
599 | | -/** |
---|
600 | | - * cpufreq_parse_governor - parse a governor string |
---|
601 | | - */ |
---|
602 | | -static int cpufreq_parse_governor(char *str_governor, |
---|
603 | | - struct cpufreq_policy *policy) |
---|
| 636 | +static struct cpufreq_governor *get_governor(const char *str_governor) |
---|
604 | 637 | { |
---|
605 | | - if (cpufreq_driver->setpolicy) { |
---|
606 | | - if (!strncasecmp(str_governor, "performance", CPUFREQ_NAME_LEN)) { |
---|
607 | | - policy->policy = CPUFREQ_POLICY_PERFORMANCE; |
---|
608 | | - return 0; |
---|
609 | | - } |
---|
| 638 | + struct cpufreq_governor *t; |
---|
610 | 639 | |
---|
611 | | - if (!strncasecmp(str_governor, "powersave", CPUFREQ_NAME_LEN)) { |
---|
612 | | - policy->policy = CPUFREQ_POLICY_POWERSAVE; |
---|
613 | | - return 0; |
---|
614 | | - } |
---|
615 | | - } else { |
---|
616 | | - struct cpufreq_governor *t; |
---|
| 640 | + mutex_lock(&cpufreq_governor_mutex); |
---|
| 641 | + t = find_governor(str_governor); |
---|
| 642 | + if (!t) |
---|
| 643 | + goto unlock; |
---|
617 | 644 | |
---|
618 | | - mutex_lock(&cpufreq_governor_mutex); |
---|
| 645 | + if (!try_module_get(t->owner)) |
---|
| 646 | + t = NULL; |
---|
619 | 647 | |
---|
620 | | - t = find_governor(str_governor); |
---|
621 | | - if (!t) { |
---|
622 | | - int ret; |
---|
| 648 | +unlock: |
---|
| 649 | + mutex_unlock(&cpufreq_governor_mutex); |
---|
623 | 650 | |
---|
624 | | - mutex_unlock(&cpufreq_governor_mutex); |
---|
| 651 | + return t; |
---|
| 652 | +} |
---|
625 | 653 | |
---|
626 | | - ret = request_module("cpufreq_%s", str_governor); |
---|
627 | | - if (ret) |
---|
628 | | - return -EINVAL; |
---|
| 654 | +static unsigned int cpufreq_parse_policy(char *str_governor) |
---|
| 655 | +{ |
---|
| 656 | + if (!strncasecmp(str_governor, "performance", CPUFREQ_NAME_LEN)) |
---|
| 657 | + return CPUFREQ_POLICY_PERFORMANCE; |
---|
629 | 658 | |
---|
630 | | - mutex_lock(&cpufreq_governor_mutex); |
---|
| 659 | + if (!strncasecmp(str_governor, "powersave", CPUFREQ_NAME_LEN)) |
---|
| 660 | + return CPUFREQ_POLICY_POWERSAVE; |
---|
631 | 661 | |
---|
632 | | - t = find_governor(str_governor); |
---|
633 | | - } |
---|
634 | | - if (t && !try_module_get(t->owner)) |
---|
635 | | - t = NULL; |
---|
636 | | - |
---|
637 | | - mutex_unlock(&cpufreq_governor_mutex); |
---|
638 | | - |
---|
639 | | - if (t) { |
---|
640 | | - policy->governor = t; |
---|
641 | | - return 0; |
---|
642 | | - } |
---|
643 | | - } |
---|
644 | | - |
---|
645 | | - return -EINVAL; |
---|
| 662 | + return CPUFREQ_POLICY_UNKNOWN; |
---|
646 | 663 | } |
---|
647 | 664 | |
---|
648 | 665 | /** |
---|
| 666 | + * cpufreq_parse_governor - parse a governor string only for has_target() |
---|
| 667 | + * @str_governor: Governor name. |
---|
| 668 | + */ |
---|
| 669 | +static struct cpufreq_governor *cpufreq_parse_governor(char *str_governor) |
---|
| 670 | +{ |
---|
| 671 | + struct cpufreq_governor *t; |
---|
| 672 | + |
---|
| 673 | + t = get_governor(str_governor); |
---|
| 674 | + if (t) |
---|
| 675 | + return t; |
---|
| 676 | + |
---|
| 677 | + if (request_module("cpufreq_%s", str_governor)) |
---|
| 678 | + return NULL; |
---|
| 679 | + |
---|
| 680 | + return get_governor(str_governor); |
---|
| 681 | +} |
---|
| 682 | + |
---|
| 683 | +/* |
---|
649 | 684 | * cpufreq_per_cpu_attr_read() / show_##file_name() - |
---|
650 | 685 | * print out cpufreq information |
---|
651 | 686 | * |
---|
.. | .. |
---|
660 | 695 | return sprintf(buf, "%u\n", policy->object); \ |
---|
661 | 696 | } |
---|
662 | 697 | |
---|
| 698 | +static ssize_t show_cpuinfo_max_freq(struct cpufreq_policy *policy, char *buf) |
---|
| 699 | +{ |
---|
| 700 | + unsigned int max_freq = policy->cpuinfo.max_freq; |
---|
| 701 | + |
---|
| 702 | + trace_android_vh_show_max_freq(policy, &max_freq); |
---|
| 703 | + trace_android_rvh_show_max_freq(policy, &max_freq); |
---|
| 704 | + return sprintf(buf, "%u\n", max_freq); |
---|
| 705 | +} |
---|
| 706 | + |
---|
663 | 707 | show_one(cpuinfo_min_freq, cpuinfo.min_freq); |
---|
664 | | -show_one(cpuinfo_max_freq, cpuinfo.max_freq); |
---|
665 | 708 | show_one(cpuinfo_transition_latency, cpuinfo.transition_latency); |
---|
666 | 709 | show_one(scaling_min_freq, min); |
---|
667 | 710 | show_one(scaling_max_freq, max); |
---|
.. | .. |
---|
679 | 722 | freq = arch_freq_get_on_cpu(policy->cpu); |
---|
680 | 723 | if (freq) |
---|
681 | 724 | ret = sprintf(buf, "%u\n", freq); |
---|
682 | | - else if (cpufreq_driver && cpufreq_driver->setpolicy && |
---|
683 | | - cpufreq_driver->get) |
---|
| 725 | + else if (cpufreq_driver->setpolicy && cpufreq_driver->get) |
---|
684 | 726 | ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu)); |
---|
685 | 727 | else |
---|
686 | 728 | ret = sprintf(buf, "%u\n", policy->cur); |
---|
687 | 729 | return ret; |
---|
688 | 730 | } |
---|
689 | 731 | |
---|
690 | | -static int cpufreq_set_policy(struct cpufreq_policy *policy, |
---|
691 | | - struct cpufreq_policy *new_policy); |
---|
692 | | - |
---|
693 | | -/** |
---|
| 732 | +/* |
---|
694 | 733 | * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access |
---|
695 | 734 | */ |
---|
696 | 735 | #define store_one(file_name, object) \ |
---|
697 | 736 | static ssize_t store_##file_name \ |
---|
698 | 737 | (struct cpufreq_policy *policy, const char *buf, size_t count) \ |
---|
699 | 738 | { \ |
---|
700 | | - int ret, temp; \ |
---|
701 | | - struct cpufreq_policy new_policy; \ |
---|
| 739 | + unsigned long val; \ |
---|
| 740 | + int ret; \ |
---|
702 | 741 | \ |
---|
703 | | - memcpy(&new_policy, policy, sizeof(*policy)); \ |
---|
704 | | - new_policy.min = policy->user_policy.min; \ |
---|
705 | | - new_policy.max = policy->user_policy.max; \ |
---|
706 | | - \ |
---|
707 | | - ret = sscanf(buf, "%u", &new_policy.object); \ |
---|
| 742 | + ret = sscanf(buf, "%lu", &val); \ |
---|
708 | 743 | if (ret != 1) \ |
---|
709 | 744 | return -EINVAL; \ |
---|
710 | 745 | \ |
---|
711 | | - temp = new_policy.object; \ |
---|
712 | | - ret = cpufreq_set_policy(policy, &new_policy); \ |
---|
713 | | - if (!ret) \ |
---|
714 | | - policy->user_policy.object = temp; \ |
---|
715 | | - \ |
---|
716 | | - return ret ? ret : count; \ |
---|
| 746 | + ret = freq_qos_update_request(policy->object##_freq_req, val);\ |
---|
| 747 | + return ret >= 0 ? count : ret; \ |
---|
717 | 748 | } |
---|
718 | 749 | |
---|
719 | 750 | store_one(scaling_min_freq, min); |
---|
720 | 751 | store_one(scaling_max_freq, max); |
---|
721 | 752 | |
---|
722 | | -/** |
---|
| 753 | +/* |
---|
723 | 754 | * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware |
---|
724 | 755 | */ |
---|
725 | 756 | static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy, |
---|
.. | .. |
---|
733 | 764 | return sprintf(buf, "<unknown>\n"); |
---|
734 | 765 | } |
---|
735 | 766 | |
---|
736 | | -/** |
---|
| 767 | +/* |
---|
737 | 768 | * show_scaling_governor - show the current policy for the specified CPU |
---|
738 | 769 | */ |
---|
739 | 770 | static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf) |
---|
.. | .. |
---|
748 | 779 | return -EINVAL; |
---|
749 | 780 | } |
---|
750 | 781 | |
---|
751 | | -/** |
---|
| 782 | +/* |
---|
752 | 783 | * store_scaling_governor - store policy for the specified CPU |
---|
753 | 784 | */ |
---|
754 | 785 | static ssize_t store_scaling_governor(struct cpufreq_policy *policy, |
---|
755 | 786 | const char *buf, size_t count) |
---|
756 | 787 | { |
---|
| 788 | + char str_governor[16]; |
---|
757 | 789 | int ret; |
---|
758 | | - char str_governor[16]; |
---|
759 | | - struct cpufreq_policy new_policy; |
---|
760 | | - |
---|
761 | | - memcpy(&new_policy, policy, sizeof(*policy)); |
---|
762 | 790 | |
---|
763 | 791 | ret = sscanf(buf, "%15s", str_governor); |
---|
764 | 792 | if (ret != 1) |
---|
765 | 793 | return -EINVAL; |
---|
766 | 794 | |
---|
767 | | - if (cpufreq_parse_governor(str_governor, &new_policy)) |
---|
768 | | - return -EINVAL; |
---|
| 795 | + if (cpufreq_driver->setpolicy) { |
---|
| 796 | + unsigned int new_pol; |
---|
769 | 797 | |
---|
770 | | - ret = cpufreq_set_policy(policy, &new_policy); |
---|
| 798 | + new_pol = cpufreq_parse_policy(str_governor); |
---|
| 799 | + if (!new_pol) |
---|
| 800 | + return -EINVAL; |
---|
771 | 801 | |
---|
772 | | - if (new_policy.governor) |
---|
773 | | - module_put(new_policy.governor->owner); |
---|
| 802 | + ret = cpufreq_set_policy(policy, NULL, new_pol); |
---|
| 803 | + } else { |
---|
| 804 | + struct cpufreq_governor *new_gov; |
---|
| 805 | + |
---|
| 806 | + new_gov = cpufreq_parse_governor(str_governor); |
---|
| 807 | + if (!new_gov) |
---|
| 808 | + return -EINVAL; |
---|
| 809 | + |
---|
| 810 | + ret = cpufreq_set_policy(policy, new_gov, |
---|
| 811 | + CPUFREQ_POLICY_UNKNOWN); |
---|
| 812 | + |
---|
| 813 | + module_put(new_gov->owner); |
---|
| 814 | + } |
---|
774 | 815 | |
---|
775 | 816 | return ret ? ret : count; |
---|
776 | 817 | } |
---|
777 | 818 | |
---|
778 | | -/** |
---|
| 819 | +/* |
---|
779 | 820 | * show_scaling_driver - show the cpufreq driver currently loaded |
---|
780 | 821 | */ |
---|
781 | 822 | static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf) |
---|
.. | .. |
---|
783 | 824 | return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name); |
---|
784 | 825 | } |
---|
785 | 826 | |
---|
786 | | -/** |
---|
| 827 | +/* |
---|
787 | 828 | * show_scaling_available_governors - show the available CPUfreq governors |
---|
788 | 829 | */ |
---|
789 | 830 | static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy, |
---|
.. | .. |
---|
797 | 838 | goto out; |
---|
798 | 839 | } |
---|
799 | 840 | |
---|
| 841 | + mutex_lock(&cpufreq_governor_mutex); |
---|
800 | 842 | for_each_governor(t) { |
---|
801 | 843 | if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) |
---|
802 | 844 | - (CPUFREQ_NAME_LEN + 2))) |
---|
803 | | - goto out; |
---|
| 845 | + break; |
---|
804 | 846 | i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name); |
---|
805 | 847 | } |
---|
| 848 | + mutex_unlock(&cpufreq_governor_mutex); |
---|
806 | 849 | out: |
---|
807 | 850 | i += sprintf(&buf[i], "\n"); |
---|
808 | 851 | return i; |
---|
.. | .. |
---|
825 | 868 | } |
---|
826 | 869 | EXPORT_SYMBOL_GPL(cpufreq_show_cpus); |
---|
827 | 870 | |
---|
828 | | -/** |
---|
| 871 | +/* |
---|
829 | 872 | * show_related_cpus - show the CPUs affected by each transition even if |
---|
830 | 873 | * hw coordination is in use |
---|
831 | 874 | */ |
---|
.. | .. |
---|
834 | 877 | return cpufreq_show_cpus(policy->related_cpus, buf); |
---|
835 | 878 | } |
---|
836 | 879 | |
---|
837 | | -/** |
---|
| 880 | +/* |
---|
838 | 881 | * show_affected_cpus - show the CPUs affected by each transition |
---|
839 | 882 | */ |
---|
840 | 883 | static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf) |
---|
.. | .. |
---|
868 | 911 | return policy->governor->show_setspeed(policy, buf); |
---|
869 | 912 | } |
---|
870 | 913 | |
---|
871 | | -/** |
---|
| 914 | +/* |
---|
872 | 915 | * show_bios_limit - show the current cpufreq HW/BIOS limitation |
---|
873 | 916 | */ |
---|
874 | 917 | static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf) |
---|
875 | 918 | { |
---|
876 | 919 | unsigned int limit; |
---|
877 | 920 | int ret; |
---|
878 | | - if (cpufreq_driver->bios_limit) { |
---|
879 | | - ret = cpufreq_driver->bios_limit(policy->cpu, &limit); |
---|
880 | | - if (!ret) |
---|
881 | | - return sprintf(buf, "%u\n", limit); |
---|
882 | | - } |
---|
| 921 | + ret = cpufreq_driver->bios_limit(policy->cpu, &limit); |
---|
| 922 | + if (!ret) |
---|
| 923 | + return sprintf(buf, "%u\n", limit); |
---|
883 | 924 | return sprintf(buf, "%u\n", policy->cpuinfo.max_freq); |
---|
884 | 925 | } |
---|
885 | 926 | |
---|
.. | .. |
---|
978 | 1019 | .release = cpufreq_sysfs_release, |
---|
979 | 1020 | }; |
---|
980 | 1021 | |
---|
981 | | -static void add_cpu_dev_symlink(struct cpufreq_policy *policy, unsigned int cpu) |
---|
| 1022 | +static void add_cpu_dev_symlink(struct cpufreq_policy *policy, unsigned int cpu, |
---|
| 1023 | + struct device *dev) |
---|
982 | 1024 | { |
---|
983 | | - struct device *dev = get_cpu_device(cpu); |
---|
984 | | - |
---|
985 | | - if (!dev) |
---|
| 1025 | + if (unlikely(!dev)) |
---|
986 | 1026 | return; |
---|
987 | 1027 | |
---|
988 | 1028 | if (cpumask_test_and_set_cpu(cpu, policy->real_cpus)) |
---|
.. | .. |
---|
1032 | 1072 | return 0; |
---|
1033 | 1073 | } |
---|
1034 | 1074 | |
---|
1035 | | -__weak struct cpufreq_governor *cpufreq_default_governor(void) |
---|
1036 | | -{ |
---|
1037 | | - return NULL; |
---|
1038 | | -} |
---|
1039 | | - |
---|
1040 | 1075 | static int cpufreq_init_policy(struct cpufreq_policy *policy) |
---|
1041 | 1076 | { |
---|
1042 | 1077 | struct cpufreq_governor *gov = NULL; |
---|
1043 | | - struct cpufreq_policy new_policy; |
---|
| 1078 | + unsigned int pol = CPUFREQ_POLICY_UNKNOWN; |
---|
| 1079 | + int ret; |
---|
1044 | 1080 | |
---|
1045 | | - memcpy(&new_policy, policy, sizeof(*policy)); |
---|
| 1081 | + if (has_target()) { |
---|
| 1082 | + /* Update policy governor to the one used before hotplug. */ |
---|
| 1083 | + gov = get_governor(policy->last_governor); |
---|
| 1084 | + if (gov) { |
---|
| 1085 | + pr_debug("Restoring governor %s for cpu %d\n", |
---|
| 1086 | + gov->name, policy->cpu); |
---|
| 1087 | + } else { |
---|
| 1088 | + gov = get_governor(default_governor); |
---|
| 1089 | + } |
---|
1046 | 1090 | |
---|
1047 | | - /* Update governor of new_policy to the governor used before hotplug */ |
---|
1048 | | - gov = find_governor(policy->last_governor); |
---|
1049 | | - if (gov) { |
---|
1050 | | - pr_debug("Restoring governor %s for cpu %d\n", |
---|
1051 | | - policy->governor->name, policy->cpu); |
---|
| 1091 | + if (!gov) { |
---|
| 1092 | + gov = cpufreq_default_governor(); |
---|
| 1093 | + __module_get(gov->owner); |
---|
| 1094 | + } |
---|
| 1095 | + |
---|
1052 | 1096 | } else { |
---|
1053 | | - gov = cpufreq_default_governor(); |
---|
1054 | | - if (!gov) |
---|
| 1097 | + |
---|
| 1098 | + /* Use the default policy if there is no last_policy. */ |
---|
| 1099 | + if (policy->last_policy) { |
---|
| 1100 | + pol = policy->last_policy; |
---|
| 1101 | + } else { |
---|
| 1102 | + pol = cpufreq_parse_policy(default_governor); |
---|
| 1103 | + /* |
---|
| 1104 | + * In case the default governor is neither "performance" |
---|
| 1105 | + * nor "powersave", fall back to the initial policy |
---|
| 1106 | + * value set by the driver. |
---|
| 1107 | + */ |
---|
| 1108 | + if (pol == CPUFREQ_POLICY_UNKNOWN) |
---|
| 1109 | + pol = policy->policy; |
---|
| 1110 | + } |
---|
| 1111 | + if (pol != CPUFREQ_POLICY_PERFORMANCE && |
---|
| 1112 | + pol != CPUFREQ_POLICY_POWERSAVE) |
---|
1055 | 1113 | return -ENODATA; |
---|
1056 | 1114 | } |
---|
1057 | 1115 | |
---|
1058 | | - new_policy.governor = gov; |
---|
| 1116 | + ret = cpufreq_set_policy(policy, gov, pol); |
---|
| 1117 | + if (gov) |
---|
| 1118 | + module_put(gov->owner); |
---|
1059 | 1119 | |
---|
1060 | | - /* Use the default policy if there is no last_policy. */ |
---|
1061 | | - if (cpufreq_driver->setpolicy) { |
---|
1062 | | - if (policy->last_policy) |
---|
1063 | | - new_policy.policy = policy->last_policy; |
---|
1064 | | - else |
---|
1065 | | - cpufreq_parse_governor(gov->name, &new_policy); |
---|
1066 | | - } |
---|
1067 | | - /* set default policy */ |
---|
1068 | | - return cpufreq_set_policy(policy, &new_policy); |
---|
| 1120 | + return ret; |
---|
1069 | 1121 | } |
---|
1070 | 1122 | |
---|
1071 | 1123 | static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu) |
---|
.. | .. |
---|
1091 | 1143 | return ret; |
---|
1092 | 1144 | } |
---|
1093 | 1145 | |
---|
| 1146 | +void refresh_frequency_limits(struct cpufreq_policy *policy) |
---|
| 1147 | +{ |
---|
| 1148 | + if (!policy_is_inactive(policy)) { |
---|
| 1149 | + pr_debug("updating policy for CPU %u\n", policy->cpu); |
---|
| 1150 | + |
---|
| 1151 | + cpufreq_set_policy(policy, policy->governor, policy->policy); |
---|
| 1152 | + } |
---|
| 1153 | +} |
---|
| 1154 | +EXPORT_SYMBOL(refresh_frequency_limits); |
---|
| 1155 | + |
---|
1094 | 1156 | static void handle_update(struct work_struct *work) |
---|
1095 | 1157 | { |
---|
1096 | 1158 | struct cpufreq_policy *policy = |
---|
1097 | 1159 | container_of(work, struct cpufreq_policy, update); |
---|
1098 | | - unsigned int cpu = policy->cpu; |
---|
1099 | | - pr_debug("handle_update for cpu %u called\n", cpu); |
---|
1100 | | - cpufreq_update_policy(cpu); |
---|
| 1160 | + |
---|
| 1161 | + pr_debug("handle_update for cpu %u called\n", policy->cpu); |
---|
| 1162 | + down_write(&policy->rwsem); |
---|
| 1163 | + refresh_frequency_limits(policy); |
---|
| 1164 | + up_write(&policy->rwsem); |
---|
1101 | 1165 | } |
---|
1102 | 1166 | |
---|
1103 | | -static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) |
---|
| 1167 | +static int cpufreq_notifier_min(struct notifier_block *nb, unsigned long freq, |
---|
| 1168 | + void *data) |
---|
1104 | 1169 | { |
---|
1105 | | - struct cpufreq_policy *policy; |
---|
1106 | | - int ret; |
---|
| 1170 | + struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_min); |
---|
1107 | 1171 | |
---|
1108 | | - policy = kzalloc(sizeof(*policy), GFP_KERNEL); |
---|
1109 | | - if (!policy) |
---|
1110 | | - return NULL; |
---|
| 1172 | + schedule_work(&policy->update); |
---|
| 1173 | + return 0; |
---|
| 1174 | +} |
---|
1111 | 1175 | |
---|
1112 | | - if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL)) |
---|
1113 | | - goto err_free_policy; |
---|
| 1176 | +static int cpufreq_notifier_max(struct notifier_block *nb, unsigned long freq, |
---|
| 1177 | + void *data) |
---|
| 1178 | +{ |
---|
| 1179 | + struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_max); |
---|
1114 | 1180 | |
---|
1115 | | - if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) |
---|
1116 | | - goto err_free_cpumask; |
---|
1117 | | - |
---|
1118 | | - if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL)) |
---|
1119 | | - goto err_free_rcpumask; |
---|
1120 | | - |
---|
1121 | | - ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, |
---|
1122 | | - cpufreq_global_kobject, "policy%u", cpu); |
---|
1123 | | - if (ret) { |
---|
1124 | | - pr_err("%s: failed to init policy->kobj: %d\n", __func__, ret); |
---|
1125 | | - kobject_put(&policy->kobj); |
---|
1126 | | - goto err_free_real_cpus; |
---|
1127 | | - } |
---|
1128 | | - |
---|
1129 | | - INIT_LIST_HEAD(&policy->policy_list); |
---|
1130 | | - init_rwsem(&policy->rwsem); |
---|
1131 | | - spin_lock_init(&policy->transition_lock); |
---|
1132 | | - init_waitqueue_head(&policy->transition_wait); |
---|
1133 | | - init_completion(&policy->kobj_unregister); |
---|
1134 | | - INIT_WORK(&policy->update, handle_update); |
---|
1135 | | - |
---|
1136 | | - policy->cpu = cpu; |
---|
1137 | | - return policy; |
---|
1138 | | - |
---|
1139 | | -err_free_real_cpus: |
---|
1140 | | - free_cpumask_var(policy->real_cpus); |
---|
1141 | | -err_free_rcpumask: |
---|
1142 | | - free_cpumask_var(policy->related_cpus); |
---|
1143 | | -err_free_cpumask: |
---|
1144 | | - free_cpumask_var(policy->cpus); |
---|
1145 | | -err_free_policy: |
---|
1146 | | - kfree(policy); |
---|
1147 | | - |
---|
1148 | | - return NULL; |
---|
| 1181 | + schedule_work(&policy->update); |
---|
| 1182 | + return 0; |
---|
1149 | 1183 | } |
---|
1150 | 1184 | |
---|
1151 | 1185 | static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy) |
---|
.. | .. |
---|
1170 | 1204 | pr_debug("wait complete\n"); |
---|
1171 | 1205 | } |
---|
1172 | 1206 | |
---|
| 1207 | +static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu) |
---|
| 1208 | +{ |
---|
| 1209 | + struct cpufreq_policy *policy; |
---|
| 1210 | + struct device *dev = get_cpu_device(cpu); |
---|
| 1211 | + int ret; |
---|
| 1212 | + |
---|
| 1213 | + if (!dev) |
---|
| 1214 | + return NULL; |
---|
| 1215 | + |
---|
| 1216 | + policy = kzalloc(sizeof(*policy), GFP_KERNEL); |
---|
| 1217 | + if (!policy) |
---|
| 1218 | + return NULL; |
---|
| 1219 | + |
---|
| 1220 | + if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL)) |
---|
| 1221 | + goto err_free_policy; |
---|
| 1222 | + |
---|
| 1223 | + if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) |
---|
| 1224 | + goto err_free_cpumask; |
---|
| 1225 | + |
---|
| 1226 | + if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL)) |
---|
| 1227 | + goto err_free_rcpumask; |
---|
| 1228 | + |
---|
| 1229 | + ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, |
---|
| 1230 | + cpufreq_global_kobject, "policy%u", cpu); |
---|
| 1231 | + if (ret) { |
---|
| 1232 | + dev_err(dev, "%s: failed to init policy->kobj: %d\n", __func__, ret); |
---|
| 1233 | + /* |
---|
| 1234 | + * The entire policy object will be freed below, but the extra |
---|
| 1235 | + * memory allocated for the kobject name needs to be freed by |
---|
| 1236 | + * releasing the kobject. |
---|
| 1237 | + */ |
---|
| 1238 | + kobject_put(&policy->kobj); |
---|
| 1239 | + goto err_free_real_cpus; |
---|
| 1240 | + } |
---|
| 1241 | + |
---|
| 1242 | + freq_constraints_init(&policy->constraints); |
---|
| 1243 | + |
---|
| 1244 | + policy->nb_min.notifier_call = cpufreq_notifier_min; |
---|
| 1245 | + policy->nb_max.notifier_call = cpufreq_notifier_max; |
---|
| 1246 | + |
---|
| 1247 | + ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MIN, |
---|
| 1248 | + &policy->nb_min); |
---|
| 1249 | + if (ret) { |
---|
| 1250 | + dev_err(dev, "Failed to register MIN QoS notifier: %d (%*pbl)\n", |
---|
| 1251 | + ret, cpumask_pr_args(policy->cpus)); |
---|
| 1252 | + goto err_kobj_remove; |
---|
| 1253 | + } |
---|
| 1254 | + |
---|
| 1255 | + ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MAX, |
---|
| 1256 | + &policy->nb_max); |
---|
| 1257 | + if (ret) { |
---|
| 1258 | + dev_err(dev, "Failed to register MAX QoS notifier: %d (%*pbl)\n", |
---|
| 1259 | + ret, cpumask_pr_args(policy->cpus)); |
---|
| 1260 | + goto err_min_qos_notifier; |
---|
| 1261 | + } |
---|
| 1262 | + |
---|
| 1263 | + INIT_LIST_HEAD(&policy->policy_list); |
---|
| 1264 | + init_rwsem(&policy->rwsem); |
---|
| 1265 | + spin_lock_init(&policy->transition_lock); |
---|
| 1266 | + init_waitqueue_head(&policy->transition_wait); |
---|
| 1267 | + init_completion(&policy->kobj_unregister); |
---|
| 1268 | + INIT_WORK(&policy->update, handle_update); |
---|
| 1269 | + |
---|
| 1270 | + policy->cpu = cpu; |
---|
| 1271 | + return policy; |
---|
| 1272 | + |
---|
| 1273 | +err_min_qos_notifier: |
---|
| 1274 | + freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, |
---|
| 1275 | + &policy->nb_min); |
---|
| 1276 | +err_kobj_remove: |
---|
| 1277 | + cpufreq_policy_put_kobj(policy); |
---|
| 1278 | +err_free_real_cpus: |
---|
| 1279 | + free_cpumask_var(policy->real_cpus); |
---|
| 1280 | +err_free_rcpumask: |
---|
| 1281 | + free_cpumask_var(policy->related_cpus); |
---|
| 1282 | +err_free_cpumask: |
---|
| 1283 | + free_cpumask_var(policy->cpus); |
---|
| 1284 | +err_free_policy: |
---|
| 1285 | + kfree(policy); |
---|
| 1286 | + |
---|
| 1287 | + return NULL; |
---|
| 1288 | +} |
---|
| 1289 | + |
---|
1173 | 1290 | static void cpufreq_policy_free(struct cpufreq_policy *policy) |
---|
1174 | 1291 | { |
---|
1175 | 1292 | unsigned long flags; |
---|
.. | .. |
---|
1182 | 1299 | for_each_cpu(cpu, policy->related_cpus) |
---|
1183 | 1300 | per_cpu(cpufreq_cpu_data, cpu) = NULL; |
---|
1184 | 1301 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
---|
| 1302 | + |
---|
| 1303 | + freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MAX, |
---|
| 1304 | + &policy->nb_max); |
---|
| 1305 | + freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, |
---|
| 1306 | + &policy->nb_min); |
---|
| 1307 | + |
---|
| 1308 | + /* Cancel any pending policy->update work before freeing the policy. */ |
---|
| 1309 | + cancel_work_sync(&policy->update); |
---|
| 1310 | + |
---|
| 1311 | + if (policy->max_freq_req) { |
---|
| 1312 | + /* |
---|
| 1313 | + * CPUFREQ_CREATE_POLICY notification is sent only after |
---|
| 1314 | + * successfully adding max_freq_req request. |
---|
| 1315 | + */ |
---|
| 1316 | + blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
---|
| 1317 | + CPUFREQ_REMOVE_POLICY, policy); |
---|
| 1318 | + freq_qos_remove_request(policy->max_freq_req); |
---|
| 1319 | + } |
---|
| 1320 | + |
---|
| 1321 | + freq_qos_remove_request(policy->min_freq_req); |
---|
| 1322 | + kfree(policy->min_freq_req); |
---|
1185 | 1323 | |
---|
1186 | 1324 | cpufreq_policy_put_kobj(policy); |
---|
1187 | 1325 | free_cpumask_var(policy->real_cpus); |
---|
.. | .. |
---|
1220 | 1358 | return -ENOMEM; |
---|
1221 | 1359 | } |
---|
1222 | 1360 | |
---|
1223 | | - cpumask_copy(policy->cpus, cpumask_of(cpu)); |
---|
| 1361 | + if (!new_policy && cpufreq_driver->online) { |
---|
| 1362 | + ret = cpufreq_driver->online(policy); |
---|
| 1363 | + if (ret) { |
---|
| 1364 | + pr_debug("%s: %d: initialization failed\n", __func__, |
---|
| 1365 | + __LINE__); |
---|
| 1366 | + goto out_exit_policy; |
---|
| 1367 | + } |
---|
1224 | 1368 | |
---|
1225 | | - /* call driver. From then on the cpufreq must be able |
---|
1226 | | - * to accept all calls to ->verify and ->setpolicy for this CPU |
---|
1227 | | - */ |
---|
1228 | | - ret = cpufreq_driver->init(policy); |
---|
1229 | | - if (ret) { |
---|
1230 | | - pr_debug("initialization failed\n"); |
---|
1231 | | - goto out_free_policy; |
---|
1232 | | - } |
---|
| 1369 | + /* Recover policy->cpus using related_cpus */ |
---|
| 1370 | + cpumask_copy(policy->cpus, policy->related_cpus); |
---|
| 1371 | + } else { |
---|
| 1372 | + cpumask_copy(policy->cpus, cpumask_of(cpu)); |
---|
1233 | 1373 | |
---|
1234 | | - ret = cpufreq_table_validate_and_sort(policy); |
---|
1235 | | - if (ret) |
---|
1236 | | - goto out_exit_policy; |
---|
| 1374 | + /* |
---|
| 1375 | + * Call driver. From then on the cpufreq must be able |
---|
| 1376 | + * to accept all calls to ->verify and ->setpolicy for this CPU. |
---|
| 1377 | + */ |
---|
| 1378 | + ret = cpufreq_driver->init(policy); |
---|
| 1379 | + if (ret) { |
---|
| 1380 | + pr_debug("%s: %d: initialization failed\n", __func__, |
---|
| 1381 | + __LINE__); |
---|
| 1382 | + goto out_free_policy; |
---|
| 1383 | + } |
---|
1237 | 1384 | |
---|
1238 | | - down_write(&policy->rwsem); |
---|
| 1385 | + /* |
---|
| 1386 | + * The initialization has succeeded and the policy is online. |
---|
| 1387 | + * If there is a problem with its frequency table, take it |
---|
| 1388 | + * offline and drop it. |
---|
| 1389 | + */ |
---|
| 1390 | + ret = cpufreq_table_validate_and_sort(policy); |
---|
| 1391 | + if (ret) |
---|
| 1392 | + goto out_offline_policy; |
---|
1239 | 1393 | |
---|
1240 | | - if (new_policy) { |
---|
1241 | 1394 | /* related_cpus should at least include policy->cpus. */ |
---|
1242 | 1395 | cpumask_copy(policy->related_cpus, policy->cpus); |
---|
1243 | 1396 | } |
---|
1244 | 1397 | |
---|
| 1398 | + down_write(&policy->rwsem); |
---|
1245 | 1399 | /* |
---|
1246 | 1400 | * affected cpus must always be the one, which are online. We aren't |
---|
1247 | 1401 | * managing offline cpus here. |
---|
.. | .. |
---|
1249 | 1403 | cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); |
---|
1250 | 1404 | |
---|
1251 | 1405 | if (new_policy) { |
---|
1252 | | - policy->user_policy.min = policy->min; |
---|
1253 | | - policy->user_policy.max = policy->max; |
---|
1254 | | - |
---|
1255 | 1406 | for_each_cpu(j, policy->related_cpus) { |
---|
1256 | 1407 | per_cpu(cpufreq_cpu_data, j) = policy; |
---|
1257 | | - add_cpu_dev_symlink(policy, j); |
---|
| 1408 | + add_cpu_dev_symlink(policy, j, get_cpu_device(j)); |
---|
1258 | 1409 | } |
---|
1259 | | - } else { |
---|
1260 | | - policy->min = policy->user_policy.min; |
---|
1261 | | - policy->max = policy->user_policy.max; |
---|
| 1410 | + |
---|
| 1411 | + policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req), |
---|
| 1412 | + GFP_KERNEL); |
---|
| 1413 | + if (!policy->min_freq_req) |
---|
| 1414 | + goto out_destroy_policy; |
---|
| 1415 | + |
---|
| 1416 | + ret = freq_qos_add_request(&policy->constraints, |
---|
| 1417 | + policy->min_freq_req, FREQ_QOS_MIN, |
---|
| 1418 | + FREQ_QOS_MIN_DEFAULT_VALUE); |
---|
| 1419 | + if (ret < 0) { |
---|
| 1420 | + /* |
---|
| 1421 | + * So we don't call freq_qos_remove_request() for an |
---|
| 1422 | + * uninitialized request. |
---|
| 1423 | + */ |
---|
| 1424 | + kfree(policy->min_freq_req); |
---|
| 1425 | + policy->min_freq_req = NULL; |
---|
| 1426 | + goto out_destroy_policy; |
---|
| 1427 | + } |
---|
| 1428 | + |
---|
| 1429 | + /* |
---|
| 1430 | + * This must be initialized right here to avoid calling |
---|
| 1431 | + * freq_qos_remove_request() on uninitialized request in case |
---|
| 1432 | + * of errors. |
---|
| 1433 | + */ |
---|
| 1434 | + policy->max_freq_req = policy->min_freq_req + 1; |
---|
| 1435 | + |
---|
| 1436 | + ret = freq_qos_add_request(&policy->constraints, |
---|
| 1437 | + policy->max_freq_req, FREQ_QOS_MAX, |
---|
| 1438 | + FREQ_QOS_MAX_DEFAULT_VALUE); |
---|
| 1439 | + if (ret < 0) { |
---|
| 1440 | + policy->max_freq_req = NULL; |
---|
| 1441 | + goto out_destroy_policy; |
---|
| 1442 | + } |
---|
| 1443 | + |
---|
| 1444 | + blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
---|
| 1445 | + CPUFREQ_CREATE_POLICY, policy); |
---|
1262 | 1446 | } |
---|
1263 | 1447 | |
---|
1264 | | - if (cpufreq_driver->get && !cpufreq_driver->setpolicy) { |
---|
| 1448 | + if (cpufreq_driver->get && has_target()) { |
---|
1265 | 1449 | policy->cur = cpufreq_driver->get(policy->cpu); |
---|
1266 | 1450 | if (!policy->cur) { |
---|
1267 | 1451 | pr_err("%s: ->get() failed\n", __func__); |
---|
.. | .. |
---|
1289 | 1473 | */ |
---|
1290 | 1474 | if ((cpufreq_driver->flags & CPUFREQ_NEED_INITIAL_FREQ_CHECK) |
---|
1291 | 1475 | && has_target()) { |
---|
| 1476 | + unsigned int old_freq = policy->cur; |
---|
| 1477 | + |
---|
1292 | 1478 | /* Are we running at unknown frequency ? */ |
---|
1293 | | - ret = cpufreq_frequency_table_get_index(policy, policy->cur); |
---|
| 1479 | + ret = cpufreq_frequency_table_get_index(policy, old_freq); |
---|
1294 | 1480 | if (ret == -EINVAL) { |
---|
1295 | | - /* Warn user and fix it */ |
---|
1296 | | - pr_warn("%s: CPU%d: Running at unlisted freq: %u KHz\n", |
---|
1297 | | - __func__, policy->cpu, policy->cur); |
---|
1298 | | - ret = __cpufreq_driver_target(policy, policy->cur - 1, |
---|
1299 | | - CPUFREQ_RELATION_L); |
---|
| 1481 | + ret = __cpufreq_driver_target(policy, old_freq - 1, |
---|
| 1482 | + CPUFREQ_RELATION_L); |
---|
1300 | 1483 | |
---|
1301 | 1484 | /* |
---|
1302 | 1485 | * Reaching here after boot in a few seconds may not |
---|
.. | .. |
---|
1304 | 1487 | * frequency for longer duration. Hence, a BUG_ON(). |
---|
1305 | 1488 | */ |
---|
1306 | 1489 | BUG_ON(ret); |
---|
1307 | | - pr_warn("%s: CPU%d: Unlisted initial frequency changed to: %u KHz\n", |
---|
1308 | | - __func__, policy->cpu, policy->cur); |
---|
| 1490 | + pr_info("%s: CPU%d: Running at unlisted initial frequency: %u KHz, changing to: %u KHz\n", |
---|
| 1491 | + __func__, policy->cpu, old_freq, policy->cur); |
---|
1309 | 1492 | } |
---|
1310 | 1493 | } |
---|
1311 | 1494 | |
---|
.. | .. |
---|
1326 | 1509 | if (ret) { |
---|
1327 | 1510 | pr_err("%s: Failed to initialize policy for cpu: %d (%d)\n", |
---|
1328 | 1511 | __func__, cpu, ret); |
---|
1329 | | - /* cpufreq_policy_free() will notify based on this */ |
---|
1330 | | - new_policy = false; |
---|
1331 | 1512 | goto out_destroy_policy; |
---|
1332 | 1513 | } |
---|
1333 | 1514 | |
---|
.. | .. |
---|
1339 | 1520 | if (cpufreq_driver->ready) |
---|
1340 | 1521 | cpufreq_driver->ready(policy); |
---|
1341 | 1522 | |
---|
1342 | | - if (IS_ENABLED(CONFIG_CPU_THERMAL) && |
---|
1343 | | - cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) |
---|
| 1523 | + if (cpufreq_thermal_control_enabled(cpufreq_driver)) |
---|
1344 | 1524 | policy->cdev = of_cpufreq_cooling_register(policy); |
---|
1345 | 1525 | |
---|
1346 | 1526 | pr_debug("initialization complete\n"); |
---|
.. | .. |
---|
1352 | 1532 | remove_cpu_dev_symlink(policy, get_cpu_device(j)); |
---|
1353 | 1533 | |
---|
1354 | 1534 | up_write(&policy->rwsem); |
---|
| 1535 | + |
---|
| 1536 | +out_offline_policy: |
---|
| 1537 | + if (cpufreq_driver->offline) |
---|
| 1538 | + cpufreq_driver->offline(policy); |
---|
1355 | 1539 | |
---|
1356 | 1540 | out_exit_policy: |
---|
1357 | 1541 | if (cpufreq_driver->exit) |
---|
.. | .. |
---|
1384 | 1568 | /* Create sysfs link on CPU registration */ |
---|
1385 | 1569 | policy = per_cpu(cpufreq_cpu_data, cpu); |
---|
1386 | 1570 | if (policy) |
---|
1387 | | - add_cpu_dev_symlink(policy, cpu); |
---|
| 1571 | + add_cpu_dev_symlink(policy, cpu, dev); |
---|
1388 | 1572 | |
---|
1389 | 1573 | return 0; |
---|
1390 | 1574 | } |
---|
.. | .. |
---|
1430 | 1614 | goto unlock; |
---|
1431 | 1615 | } |
---|
1432 | 1616 | |
---|
1433 | | - if (IS_ENABLED(CONFIG_CPU_THERMAL) && |
---|
1434 | | - cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) { |
---|
| 1617 | + if (cpufreq_thermal_control_enabled(cpufreq_driver)) { |
---|
1435 | 1618 | cpufreq_cooling_unregister(policy->cdev); |
---|
1436 | 1619 | policy->cdev = NULL; |
---|
1437 | 1620 | } |
---|
.. | .. |
---|
1443 | 1626 | cpufreq_exit_governor(policy); |
---|
1444 | 1627 | |
---|
1445 | 1628 | /* |
---|
1446 | | - * Perform the ->exit() even during light-weight tear-down, |
---|
1447 | | - * since this is a core component, and is essential for the |
---|
1448 | | - * subsequent light-weight ->init() to succeed. |
---|
| 1629 | + * Perform the ->offline() during light-weight tear-down, as |
---|
| 1630 | + * that allows fast recovery when the CPU comes back. |
---|
1449 | 1631 | */ |
---|
1450 | | - if (cpufreq_driver->exit) { |
---|
| 1632 | + if (cpufreq_driver->offline) { |
---|
| 1633 | + cpufreq_driver->offline(policy); |
---|
| 1634 | + } else if (cpufreq_driver->exit) { |
---|
1451 | 1635 | cpufreq_driver->exit(policy); |
---|
1452 | 1636 | policy->freq_table = NULL; |
---|
1453 | 1637 | } |
---|
.. | .. |
---|
1457 | 1641 | return 0; |
---|
1458 | 1642 | } |
---|
1459 | 1643 | |
---|
1460 | | -/** |
---|
| 1644 | +/* |
---|
1461 | 1645 | * cpufreq_remove_dev - remove a CPU device |
---|
1462 | 1646 | * |
---|
1463 | 1647 | * Removes the cpufreq interface for a CPU device. |
---|
.. | .. |
---|
1476 | 1660 | cpumask_clear_cpu(cpu, policy->real_cpus); |
---|
1477 | 1661 | remove_cpu_dev_symlink(policy, dev); |
---|
1478 | 1662 | |
---|
1479 | | - if (cpumask_empty(policy->real_cpus)) |
---|
| 1663 | + if (cpumask_empty(policy->real_cpus)) { |
---|
| 1664 | + /* We did light-weight exit earlier, do full tear down now */ |
---|
| 1665 | + if (cpufreq_driver->offline) |
---|
| 1666 | + cpufreq_driver->exit(policy); |
---|
| 1667 | + |
---|
1480 | 1668 | cpufreq_policy_free(policy); |
---|
| 1669 | + } |
---|
1481 | 1670 | } |
---|
1482 | 1671 | |
---|
1483 | 1672 | /** |
---|
.. | .. |
---|
1502 | 1691 | |
---|
1503 | 1692 | cpufreq_freq_transition_begin(policy, &freqs); |
---|
1504 | 1693 | cpufreq_freq_transition_end(policy, &freqs, 0); |
---|
| 1694 | +} |
---|
| 1695 | + |
---|
| 1696 | +static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, bool update) |
---|
| 1697 | +{ |
---|
| 1698 | + unsigned int new_freq; |
---|
| 1699 | + |
---|
| 1700 | + new_freq = cpufreq_driver->get(policy->cpu); |
---|
| 1701 | + if (!new_freq) |
---|
| 1702 | + return 0; |
---|
| 1703 | + |
---|
| 1704 | + /* |
---|
| 1705 | + * If fast frequency switching is used with the given policy, the check |
---|
| 1706 | + * against policy->cur is pointless, so skip it in that case. |
---|
| 1707 | + */ |
---|
| 1708 | + if (policy->fast_switch_enabled || !has_target()) |
---|
| 1709 | + return new_freq; |
---|
| 1710 | + |
---|
| 1711 | + if (policy->cur != new_freq) { |
---|
| 1712 | + cpufreq_out_of_sync(policy, new_freq); |
---|
| 1713 | + if (update) |
---|
| 1714 | + schedule_work(&policy->update); |
---|
| 1715 | + } |
---|
| 1716 | + |
---|
| 1717 | + return new_freq; |
---|
1505 | 1718 | } |
---|
1506 | 1719 | |
---|
1507 | 1720 | /** |
---|
.. | .. |
---|
1557 | 1770 | } |
---|
1558 | 1771 | EXPORT_SYMBOL(cpufreq_quick_get_max); |
---|
1559 | 1772 | |
---|
1560 | | -static unsigned int __cpufreq_get(struct cpufreq_policy *policy) |
---|
| 1773 | +/** |
---|
| 1774 | + * cpufreq_get_hw_max_freq - get the max hardware frequency of the CPU |
---|
| 1775 | + * @cpu: CPU number |
---|
| 1776 | + * |
---|
| 1777 | + * The default return value is the max_freq field of cpuinfo. |
---|
| 1778 | + */ |
---|
| 1779 | +__weak unsigned int cpufreq_get_hw_max_freq(unsigned int cpu) |
---|
1561 | 1780 | { |
---|
| 1781 | + struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); |
---|
1562 | 1782 | unsigned int ret_freq = 0; |
---|
1563 | 1783 | |
---|
1564 | | - if (unlikely(policy_is_inactive(policy)) || !cpufreq_driver->get) |
---|
1565 | | - return ret_freq; |
---|
1566 | | - |
---|
1567 | | - ret_freq = cpufreq_driver->get(policy->cpu); |
---|
1568 | | - |
---|
1569 | | - /* |
---|
1570 | | - * If fast frequency switching is used with the given policy, the check |
---|
1571 | | - * against policy->cur is pointless, so skip it in that case too. |
---|
1572 | | - */ |
---|
1573 | | - if (policy->fast_switch_enabled) |
---|
1574 | | - return ret_freq; |
---|
1575 | | - |
---|
1576 | | - if (ret_freq && policy->cur && |
---|
1577 | | - !(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { |
---|
1578 | | - /* verify no discrepancy between actual and |
---|
1579 | | - saved value exists */ |
---|
1580 | | - if (unlikely(ret_freq != policy->cur)) { |
---|
1581 | | - cpufreq_out_of_sync(policy, ret_freq); |
---|
1582 | | - schedule_work(&policy->update); |
---|
1583 | | - } |
---|
| 1784 | + if (policy) { |
---|
| 1785 | + ret_freq = policy->cpuinfo.max_freq; |
---|
| 1786 | + cpufreq_cpu_put(policy); |
---|
1584 | 1787 | } |
---|
1585 | 1788 | |
---|
1586 | 1789 | return ret_freq; |
---|
| 1790 | +} |
---|
| 1791 | +EXPORT_SYMBOL(cpufreq_get_hw_max_freq); |
---|
| 1792 | + |
---|
| 1793 | +static unsigned int __cpufreq_get(struct cpufreq_policy *policy) |
---|
| 1794 | +{ |
---|
| 1795 | + if (unlikely(policy_is_inactive(policy))) |
---|
| 1796 | + return 0; |
---|
| 1797 | + |
---|
| 1798 | + return cpufreq_verify_current_freq(policy, true); |
---|
1587 | 1799 | } |
---|
1588 | 1800 | |
---|
1589 | 1801 | /** |
---|
.. | .. |
---|
1599 | 1811 | |
---|
1600 | 1812 | if (policy) { |
---|
1601 | 1813 | down_read(&policy->rwsem); |
---|
1602 | | - ret_freq = __cpufreq_get(policy); |
---|
| 1814 | + if (cpufreq_driver->get) |
---|
| 1815 | + ret_freq = __cpufreq_get(policy); |
---|
1603 | 1816 | up_read(&policy->rwsem); |
---|
1604 | 1817 | |
---|
1605 | 1818 | cpufreq_cpu_put(policy); |
---|
.. | .. |
---|
1608 | 1821 | return ret_freq; |
---|
1609 | 1822 | } |
---|
1610 | 1823 | EXPORT_SYMBOL(cpufreq_get); |
---|
1611 | | - |
---|
1612 | | -static unsigned int cpufreq_update_current_freq(struct cpufreq_policy *policy) |
---|
1613 | | -{ |
---|
1614 | | - unsigned int new_freq; |
---|
1615 | | - |
---|
1616 | | - new_freq = cpufreq_driver->get(policy->cpu); |
---|
1617 | | - if (!new_freq) |
---|
1618 | | - return 0; |
---|
1619 | | - |
---|
1620 | | - if (!policy->cur) { |
---|
1621 | | - pr_debug("cpufreq: Driver did not initialize current freq\n"); |
---|
1622 | | - policy->cur = new_freq; |
---|
1623 | | - } else if (policy->cur != new_freq && has_target()) { |
---|
1624 | | - cpufreq_out_of_sync(policy, new_freq); |
---|
1625 | | - } |
---|
1626 | | - |
---|
1627 | | - return new_freq; |
---|
1628 | | -} |
---|
1629 | 1824 | |
---|
1630 | 1825 | static struct subsys_interface cpufreq_interface = { |
---|
1631 | 1826 | .name = "cpufreq", |
---|
.. | .. |
---|
1688 | 1883 | } |
---|
1689 | 1884 | |
---|
1690 | 1885 | if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy)) |
---|
1691 | | - pr_err("%s: Failed to suspend driver: %p\n", __func__, |
---|
1692 | | - policy); |
---|
| 1886 | + pr_err("%s: Failed to suspend driver: %s\n", __func__, |
---|
| 1887 | + cpufreq_driver->name); |
---|
1693 | 1888 | } |
---|
1694 | 1889 | |
---|
1695 | 1890 | suspend: |
---|
.. | .. |
---|
1734 | 1929 | __func__, policy); |
---|
1735 | 1930 | } |
---|
1736 | 1931 | } |
---|
| 1932 | +} |
---|
| 1933 | + |
---|
| 1934 | +/** |
---|
| 1935 | + * cpufreq_driver_test_flags - Test cpufreq driver's flags against given ones. |
---|
| 1936 | + * @flags: Flags to test against the current cpufreq driver's flags. |
---|
| 1937 | + * |
---|
| 1938 | + * Assumes that the driver is there, so callers must ensure that this is the |
---|
| 1939 | + * case. |
---|
| 1940 | + */ |
---|
| 1941 | +bool cpufreq_driver_test_flags(u16 flags) |
---|
| 1942 | +{ |
---|
| 1943 | + return !!(cpufreq_driver->flags & flags); |
---|
1737 | 1944 | } |
---|
1738 | 1945 | |
---|
1739 | 1946 | /** |
---|
.. | .. |
---|
1888 | 2095 | unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, |
---|
1889 | 2096 | unsigned int target_freq) |
---|
1890 | 2097 | { |
---|
1891 | | - int ret; |
---|
| 2098 | + unsigned int freq; |
---|
| 2099 | + unsigned int old_target_freq = target_freq; |
---|
| 2100 | + int cpu; |
---|
1892 | 2101 | |
---|
1893 | 2102 | target_freq = clamp_val(target_freq, policy->min, policy->max); |
---|
| 2103 | + trace_android_vh_cpufreq_fast_switch(policy, target_freq, old_target_freq); |
---|
| 2104 | + freq = cpufreq_driver->fast_switch(policy, target_freq); |
---|
1894 | 2105 | |
---|
1895 | | - ret = cpufreq_driver->fast_switch(policy, target_freq); |
---|
1896 | | - if (ret) |
---|
1897 | | - cpufreq_times_record_transition(policy, ret); |
---|
| 2106 | + if (!freq) |
---|
| 2107 | + return 0; |
---|
1898 | 2108 | |
---|
1899 | | - return ret; |
---|
| 2109 | + policy->cur = freq; |
---|
| 2110 | + arch_set_freq_scale(policy->related_cpus, freq, |
---|
| 2111 | + policy->cpuinfo.max_freq); |
---|
| 2112 | + cpufreq_stats_record_transition(policy, freq); |
---|
| 2113 | + cpufreq_times_record_transition(policy, freq); |
---|
| 2114 | + trace_android_rvh_cpufreq_transition(policy); |
---|
| 2115 | + |
---|
| 2116 | + if (trace_cpu_frequency_enabled()) { |
---|
| 2117 | + for_each_cpu(cpu, policy->cpus) |
---|
| 2118 | + trace_cpu_frequency(freq, cpu); |
---|
| 2119 | + } |
---|
| 2120 | + |
---|
| 2121 | + return freq; |
---|
1900 | 2122 | } |
---|
1901 | 2123 | EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch); |
---|
1902 | 2124 | |
---|
.. | .. |
---|
1993 | 2215 | if (cpufreq_disabled()) |
---|
1994 | 2216 | return -ENODEV; |
---|
1995 | 2217 | |
---|
1996 | | -#ifdef CONFIG_ARM_ROCKCHIP_CPUFREQ |
---|
1997 | | - target_freq = rockchip_cpufreq_adjust_target(policy->cpu, target_freq); |
---|
1998 | | -#endif |
---|
1999 | 2218 | /* Make sure that target_freq is within supported range */ |
---|
2000 | 2219 | target_freq = clamp_val(target_freq, policy->min, policy->max); |
---|
| 2220 | + trace_android_vh_cpufreq_target(policy, target_freq, old_target_freq); |
---|
2001 | 2221 | |
---|
2002 | 2222 | pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n", |
---|
2003 | 2223 | policy->cpu, target_freq, relation, old_target_freq); |
---|
.. | .. |
---|
2008 | 2228 | * exactly same freq is called again and so we can save on few function |
---|
2009 | 2229 | * calls. |
---|
2010 | 2230 | */ |
---|
2011 | | - if (target_freq == policy->cur) |
---|
| 2231 | + if (target_freq == policy->cur && |
---|
| 2232 | + !(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS)) |
---|
2012 | 2233 | return 0; |
---|
2013 | 2234 | |
---|
2014 | 2235 | /* Save last value to restore later on errors */ |
---|
.. | .. |
---|
2030 | 2251 | unsigned int target_freq, |
---|
2031 | 2252 | unsigned int relation) |
---|
2032 | 2253 | { |
---|
2033 | | - int ret = -EINVAL; |
---|
| 2254 | + int ret; |
---|
2034 | 2255 | |
---|
2035 | 2256 | down_write(&policy->rwsem); |
---|
2036 | 2257 | |
---|
.. | .. |
---|
2062 | 2283 | return -EINVAL; |
---|
2063 | 2284 | |
---|
2064 | 2285 | /* Platform doesn't want dynamic frequency switching ? */ |
---|
2065 | | - if (policy->governor->dynamic_switching && |
---|
| 2286 | + if (policy->governor->flags & CPUFREQ_GOV_DYNAMIC_SWITCHING && |
---|
2066 | 2287 | cpufreq_driver->flags & CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING) { |
---|
2067 | 2288 | struct cpufreq_governor *gov = cpufreq_fallback_governor(); |
---|
2068 | 2289 | |
---|
.. | .. |
---|
2088 | 2309 | } |
---|
2089 | 2310 | } |
---|
2090 | 2311 | |
---|
| 2312 | + policy->strict_target = !!(policy->governor->flags & CPUFREQ_GOV_STRICT_TARGET); |
---|
| 2313 | + |
---|
2091 | 2314 | return 0; |
---|
2092 | 2315 | } |
---|
2093 | 2316 | |
---|
.. | .. |
---|
2104 | 2327 | module_put(policy->governor->owner); |
---|
2105 | 2328 | } |
---|
2106 | 2329 | |
---|
2107 | | -static int cpufreq_start_governor(struct cpufreq_policy *policy) |
---|
| 2330 | +int cpufreq_start_governor(struct cpufreq_policy *policy) |
---|
2108 | 2331 | { |
---|
2109 | 2332 | int ret; |
---|
2110 | 2333 | |
---|
.. | .. |
---|
2116 | 2339 | |
---|
2117 | 2340 | pr_debug("%s: for CPU %u\n", __func__, policy->cpu); |
---|
2118 | 2341 | |
---|
2119 | | - if (cpufreq_driver->get && !cpufreq_driver->setpolicy) |
---|
2120 | | - cpufreq_update_current_freq(policy); |
---|
| 2342 | + if (cpufreq_driver->get) |
---|
| 2343 | + cpufreq_verify_current_freq(policy, false); |
---|
2121 | 2344 | |
---|
2122 | 2345 | if (policy->governor->start) { |
---|
2123 | 2346 | ret = policy->governor->start(policy); |
---|
.. | .. |
---|
2131 | 2354 | return 0; |
---|
2132 | 2355 | } |
---|
2133 | 2356 | |
---|
2134 | | -static void cpufreq_stop_governor(struct cpufreq_policy *policy) |
---|
| 2357 | +void cpufreq_stop_governor(struct cpufreq_policy *policy) |
---|
2135 | 2358 | { |
---|
2136 | 2359 | if (cpufreq_suspended || !policy->governor) |
---|
2137 | 2360 | return; |
---|
.. | .. |
---|
2212 | 2435 | * cpufreq_get_policy - get the current cpufreq_policy |
---|
2213 | 2436 | * @policy: struct cpufreq_policy into which the current cpufreq_policy |
---|
2214 | 2437 | * is written |
---|
| 2438 | + * @cpu: CPU to find the policy for |
---|
2215 | 2439 | * |
---|
2216 | 2440 | * Reads the current cpufreq policy. |
---|
2217 | 2441 | */ |
---|
.. | .. |
---|
2232 | 2456 | } |
---|
2233 | 2457 | EXPORT_SYMBOL(cpufreq_get_policy); |
---|
2234 | 2458 | |
---|
2235 | | -/* |
---|
2236 | | - * policy : current policy. |
---|
2237 | | - * new_policy: policy to be set. |
---|
| 2459 | +/** |
---|
| 2460 | + * cpufreq_set_policy - Modify cpufreq policy parameters. |
---|
| 2461 | + * @policy: Policy object to modify. |
---|
| 2462 | + * @new_gov: Policy governor pointer. |
---|
| 2463 | + * @new_pol: Policy value (for drivers with built-in governors). |
---|
| 2464 | + * |
---|
| 2465 | + * Invoke the cpufreq driver's ->verify() callback to sanity-check the frequency |
---|
| 2466 | + * limits to be set for the policy, update @policy with the verified limits |
---|
| 2467 | + * values and either invoke the driver's ->setpolicy() callback (if present) or |
---|
| 2468 | + * carry out a governor update for @policy. That is, run the current governor's |
---|
| 2469 | + * ->limits() callback (if @new_gov points to the same object as the one in |
---|
| 2470 | + * @policy) or replace the governor for @policy with @new_gov. |
---|
| 2471 | + * |
---|
| 2472 | + * The cpuinfo part of @policy is not updated by this function. |
---|
2238 | 2473 | */ |
---|
2239 | 2474 | static int cpufreq_set_policy(struct cpufreq_policy *policy, |
---|
2240 | | - struct cpufreq_policy *new_policy) |
---|
| 2475 | + struct cpufreq_governor *new_gov, |
---|
| 2476 | + unsigned int new_pol) |
---|
2241 | 2477 | { |
---|
| 2478 | + struct cpufreq_policy_data new_data; |
---|
2242 | 2479 | struct cpufreq_governor *old_gov; |
---|
2243 | 2480 | int ret; |
---|
2244 | 2481 | |
---|
2245 | | - pr_debug("setting new policy for CPU %u: %u - %u kHz\n", |
---|
2246 | | - new_policy->cpu, new_policy->min, new_policy->max); |
---|
2247 | | - |
---|
2248 | | - memcpy(&new_policy->cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo)); |
---|
2249 | | - |
---|
| 2482 | + memcpy(&new_data.cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo)); |
---|
| 2483 | + new_data.freq_table = policy->freq_table; |
---|
| 2484 | + new_data.cpu = policy->cpu; |
---|
2250 | 2485 | /* |
---|
2251 | | - * This check works well when we store new min/max freq attributes, |
---|
2252 | | - * because new_policy is a copy of policy with one field updated. |
---|
2253 | | - */ |
---|
2254 | | - if (new_policy->min > new_policy->max) |
---|
2255 | | - return -EINVAL; |
---|
2256 | | - |
---|
2257 | | - /* verify the cpu speed can be set within this limit */ |
---|
2258 | | - ret = cpufreq_driver->verify(new_policy); |
---|
2259 | | - if (ret) |
---|
2260 | | - return ret; |
---|
2261 | | - |
---|
2262 | | - /* adjust if necessary - all reasons */ |
---|
2263 | | - blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
---|
2264 | | - CPUFREQ_ADJUST, new_policy); |
---|
2265 | | - |
---|
2266 | | - /* |
---|
2267 | | - * verify the cpu speed can be set within this limit, which might be |
---|
2268 | | - * different to the first one |
---|
| 2486 | + * PM QoS framework collects all the requests from users and provide us |
---|
| 2487 | + * the final aggregated value here. |
---|
2269 | 2488 | */ |
---|
2270 | | - ret = cpufreq_driver->verify(new_policy); |
---|
| 2489 | + new_data.min = freq_qos_read_value(&policy->constraints, FREQ_QOS_MIN); |
---|
| 2490 | + new_data.max = freq_qos_read_value(&policy->constraints, FREQ_QOS_MAX); |
---|
| 2491 | + |
---|
| 2492 | + pr_debug("setting new policy for CPU %u: %u - %u kHz\n", |
---|
| 2493 | + new_data.cpu, new_data.min, new_data.max); |
---|
| 2494 | + |
---|
| 2495 | + /* |
---|
| 2496 | + * Verify that the CPU speed can be set within these limits and make sure |
---|
| 2497 | + * that min <= max. |
---|
| 2498 | + */ |
---|
| 2499 | + ret = cpufreq_driver->verify(&new_data); |
---|
2271 | 2500 | if (ret) |
---|
2272 | 2501 | return ret; |
---|
2273 | 2502 | |
---|
2274 | | - /* notification of the new policy */ |
---|
2275 | | - blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
---|
2276 | | - CPUFREQ_NOTIFY, new_policy); |
---|
2277 | | - |
---|
2278 | | - policy->min = new_policy->min; |
---|
2279 | | - policy->max = new_policy->max; |
---|
| 2503 | + policy->min = new_data.min; |
---|
| 2504 | + policy->max = new_data.max; |
---|
2280 | 2505 | trace_cpu_frequency_limits(policy); |
---|
2281 | | - |
---|
2282 | | - arch_set_max_freq_scale(policy->cpus, policy->max); |
---|
2283 | 2506 | |
---|
2284 | 2507 | policy->cached_target_freq = UINT_MAX; |
---|
2285 | 2508 | |
---|
.. | .. |
---|
2287 | 2510 | policy->min, policy->max); |
---|
2288 | 2511 | |
---|
2289 | 2512 | if (cpufreq_driver->setpolicy) { |
---|
2290 | | - policy->policy = new_policy->policy; |
---|
| 2513 | + policy->policy = new_pol; |
---|
2291 | 2514 | pr_debug("setting range\n"); |
---|
2292 | | - return cpufreq_driver->setpolicy(new_policy); |
---|
| 2515 | + return cpufreq_driver->setpolicy(policy); |
---|
2293 | 2516 | } |
---|
2294 | 2517 | |
---|
2295 | | - if (new_policy->governor == policy->governor) { |
---|
2296 | | - pr_debug("cpufreq: governor limits update\n"); |
---|
| 2518 | + if (new_gov == policy->governor) { |
---|
| 2519 | + pr_debug("governor limits update\n"); |
---|
2297 | 2520 | cpufreq_governor_limits(policy); |
---|
2298 | 2521 | return 0; |
---|
2299 | 2522 | } |
---|
.. | .. |
---|
2309 | 2532 | } |
---|
2310 | 2533 | |
---|
2311 | 2534 | /* start new governor */ |
---|
2312 | | - policy->governor = new_policy->governor; |
---|
| 2535 | + policy->governor = new_gov; |
---|
2313 | 2536 | ret = cpufreq_init_governor(policy); |
---|
2314 | 2537 | if (!ret) { |
---|
2315 | 2538 | ret = cpufreq_start_governor(policy); |
---|
2316 | 2539 | if (!ret) { |
---|
2317 | | - pr_debug("cpufreq: governor change\n"); |
---|
| 2540 | + pr_debug("governor change\n"); |
---|
2318 | 2541 | return 0; |
---|
2319 | 2542 | } |
---|
2320 | 2543 | cpufreq_exit_governor(policy); |
---|
.. | .. |
---|
2332 | 2555 | |
---|
2333 | 2556 | return ret; |
---|
2334 | 2557 | } |
---|
| 2558 | +EXPORT_TRACEPOINT_SYMBOL_GPL(cpu_frequency_limits); |
---|
2335 | 2559 | |
---|
2336 | 2560 | /** |
---|
2337 | | - * cpufreq_update_policy - re-evaluate an existing cpufreq policy |
---|
2338 | | - * @cpu: CPU which shall be re-evaluated |
---|
| 2561 | + * cpufreq_update_policy - Re-evaluate an existing cpufreq policy. |
---|
| 2562 | + * @cpu: CPU to re-evaluate the policy for. |
---|
2339 | 2563 | * |
---|
2340 | | - * Useful for policy notifiers which have different necessities |
---|
2341 | | - * at different times. |
---|
| 2564 | + * Update the current frequency for the cpufreq policy of @cpu and use |
---|
| 2565 | + * cpufreq_set_policy() to re-apply the min and max limits, which triggers the |
---|
| 2566 | + * evaluation of policy notifiers and the cpufreq driver's ->verify() callback |
---|
| 2567 | + * for the policy in question, among other things. |
---|
2342 | 2568 | */ |
---|
2343 | 2569 | void cpufreq_update_policy(unsigned int cpu) |
---|
2344 | 2570 | { |
---|
2345 | | - struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); |
---|
2346 | | - struct cpufreq_policy new_policy; |
---|
| 2571 | + struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu); |
---|
2347 | 2572 | |
---|
2348 | 2573 | if (!policy) |
---|
2349 | 2574 | return; |
---|
2350 | | - |
---|
2351 | | - down_write(&policy->rwsem); |
---|
2352 | | - |
---|
2353 | | - if (policy_is_inactive(policy)) |
---|
2354 | | - goto unlock; |
---|
2355 | | - |
---|
2356 | | - pr_debug("updating policy for CPU %u\n", cpu); |
---|
2357 | | - memcpy(&new_policy, policy, sizeof(*policy)); |
---|
2358 | | - new_policy.min = policy->user_policy.min; |
---|
2359 | | - new_policy.max = policy->user_policy.max; |
---|
2360 | 2575 | |
---|
2361 | 2576 | /* |
---|
2362 | 2577 | * BIOS might change freq behind our back |
---|
2363 | 2578 | * -> ask driver for current freq and notify governors about a change |
---|
2364 | 2579 | */ |
---|
2365 | | - if (cpufreq_driver->get && !cpufreq_driver->setpolicy) { |
---|
2366 | | - if (cpufreq_suspended) |
---|
2367 | | - goto unlock; |
---|
| 2580 | + if (cpufreq_driver->get && has_target() && |
---|
| 2581 | + (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false)))) |
---|
| 2582 | + goto unlock; |
---|
2368 | 2583 | |
---|
2369 | | - new_policy.cur = cpufreq_update_current_freq(policy); |
---|
2370 | | - if (WARN_ON(!new_policy.cur)) |
---|
2371 | | - goto unlock; |
---|
2372 | | - } |
---|
2373 | | - |
---|
2374 | | - cpufreq_set_policy(policy, &new_policy); |
---|
| 2584 | + refresh_frequency_limits(policy); |
---|
2375 | 2585 | |
---|
2376 | 2586 | unlock: |
---|
2377 | | - up_write(&policy->rwsem); |
---|
2378 | | - |
---|
2379 | | - cpufreq_cpu_put(policy); |
---|
| 2587 | + cpufreq_cpu_release(policy); |
---|
2380 | 2588 | } |
---|
2381 | 2589 | EXPORT_SYMBOL(cpufreq_update_policy); |
---|
| 2590 | + |
---|
| 2591 | +/** |
---|
| 2592 | + * cpufreq_update_limits - Update policy limits for a given CPU. |
---|
| 2593 | + * @cpu: CPU to update the policy limits for. |
---|
| 2594 | + * |
---|
| 2595 | + * Invoke the driver's ->update_limits callback if present or call |
---|
| 2596 | + * cpufreq_update_policy() for @cpu. |
---|
| 2597 | + */ |
---|
| 2598 | +void cpufreq_update_limits(unsigned int cpu) |
---|
| 2599 | +{ |
---|
| 2600 | + if (cpufreq_driver->update_limits) |
---|
| 2601 | + cpufreq_driver->update_limits(cpu); |
---|
| 2602 | + else |
---|
| 2603 | + cpufreq_update_policy(cpu); |
---|
| 2604 | +} |
---|
| 2605 | +EXPORT_SYMBOL_GPL(cpufreq_update_limits); |
---|
2382 | 2606 | |
---|
2383 | 2607 | /********************************************************************* |
---|
2384 | 2608 | * BOOST * |
---|
2385 | 2609 | *********************************************************************/ |
---|
2386 | | -static int cpufreq_boost_set_sw(int state) |
---|
| 2610 | +static int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state) |
---|
2387 | 2611 | { |
---|
2388 | | - struct cpufreq_policy *policy; |
---|
2389 | | - int ret = -EINVAL; |
---|
| 2612 | + int ret; |
---|
2390 | 2613 | |
---|
2391 | | - for_each_active_policy(policy) { |
---|
2392 | | - if (!policy->freq_table) |
---|
2393 | | - continue; |
---|
| 2614 | + if (!policy->freq_table) |
---|
| 2615 | + return -ENXIO; |
---|
2394 | 2616 | |
---|
2395 | | - ret = cpufreq_frequency_table_cpuinfo(policy, |
---|
2396 | | - policy->freq_table); |
---|
2397 | | - if (ret) { |
---|
2398 | | - pr_err("%s: Policy frequency update failed\n", |
---|
2399 | | - __func__); |
---|
2400 | | - break; |
---|
2401 | | - } |
---|
2402 | | - |
---|
2403 | | - down_write(&policy->rwsem); |
---|
2404 | | - policy->user_policy.max = policy->max; |
---|
2405 | | - cpufreq_governor_limits(policy); |
---|
2406 | | - up_write(&policy->rwsem); |
---|
| 2617 | + ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table); |
---|
| 2618 | + if (ret) { |
---|
| 2619 | + pr_err("%s: Policy frequency update failed\n", __func__); |
---|
| 2620 | + return ret; |
---|
2407 | 2621 | } |
---|
2408 | 2622 | |
---|
2409 | | - return ret; |
---|
| 2623 | + ret = freq_qos_update_request(policy->max_freq_req, policy->max); |
---|
| 2624 | + if (ret < 0) |
---|
| 2625 | + return ret; |
---|
| 2626 | + |
---|
| 2627 | + return 0; |
---|
2410 | 2628 | } |
---|
2411 | 2629 | |
---|
2412 | 2630 | int cpufreq_boost_trigger_state(int state) |
---|
2413 | 2631 | { |
---|
| 2632 | + struct cpufreq_policy *policy; |
---|
2414 | 2633 | unsigned long flags; |
---|
2415 | 2634 | int ret = 0; |
---|
2416 | 2635 | |
---|
.. | .. |
---|
2421 | 2640 | cpufreq_driver->boost_enabled = state; |
---|
2422 | 2641 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
---|
2423 | 2642 | |
---|
2424 | | - ret = cpufreq_driver->set_boost(state); |
---|
2425 | | - if (ret) { |
---|
2426 | | - write_lock_irqsave(&cpufreq_driver_lock, flags); |
---|
2427 | | - cpufreq_driver->boost_enabled = !state; |
---|
2428 | | - write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
---|
2429 | | - |
---|
2430 | | - pr_err("%s: Cannot %s BOOST\n", |
---|
2431 | | - __func__, state ? "enable" : "disable"); |
---|
| 2643 | + get_online_cpus(); |
---|
| 2644 | + for_each_active_policy(policy) { |
---|
| 2645 | + ret = cpufreq_driver->set_boost(policy, state); |
---|
| 2646 | + if (ret) |
---|
| 2647 | + goto err_reset_state; |
---|
2432 | 2648 | } |
---|
| 2649 | + put_online_cpus(); |
---|
| 2650 | + |
---|
| 2651 | + return 0; |
---|
| 2652 | + |
---|
| 2653 | +err_reset_state: |
---|
| 2654 | + put_online_cpus(); |
---|
| 2655 | + |
---|
| 2656 | + write_lock_irqsave(&cpufreq_driver_lock, flags); |
---|
| 2657 | + cpufreq_driver->boost_enabled = !state; |
---|
| 2658 | + write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
---|
| 2659 | + |
---|
| 2660 | + pr_err("%s: Cannot %s BOOST\n", |
---|
| 2661 | + __func__, state ? "enable" : "disable"); |
---|
2433 | 2662 | |
---|
2434 | 2663 | return ret; |
---|
2435 | 2664 | } |
---|
2436 | 2665 | |
---|
2437 | 2666 | static bool cpufreq_boost_supported(void) |
---|
2438 | 2667 | { |
---|
2439 | | - return likely(cpufreq_driver) && cpufreq_driver->set_boost; |
---|
| 2668 | + return cpufreq_driver->set_boost; |
---|
2440 | 2669 | } |
---|
2441 | 2670 | |
---|
2442 | 2671 | static int create_boost_sysfs_file(void) |
---|
.. | .. |
---|
2527 | 2756 | driver_data->target) || |
---|
2528 | 2757 | (driver_data->setpolicy && (driver_data->target_index || |
---|
2529 | 2758 | driver_data->target)) || |
---|
2530 | | - (!!driver_data->get_intermediate != !!driver_data->target_intermediate)) |
---|
| 2759 | + (!driver_data->get_intermediate != !driver_data->target_intermediate) || |
---|
| 2760 | + (!driver_data->online != !driver_data->offline)) |
---|
2531 | 2761 | return -EINVAL; |
---|
2532 | 2762 | |
---|
2533 | 2763 | pr_debug("trying to register driver %s\n", driver_data->name); |
---|
.. | .. |
---|
2543 | 2773 | } |
---|
2544 | 2774 | cpufreq_driver = driver_data; |
---|
2545 | 2775 | write_unlock_irqrestore(&cpufreq_driver_lock, flags); |
---|
| 2776 | + |
---|
| 2777 | + /* |
---|
| 2778 | + * Mark support for the scheduler's frequency invariance engine for |
---|
| 2779 | + * drivers that implement target(), target_index() or fast_switch(). |
---|
| 2780 | + */ |
---|
| 2781 | + if (!cpufreq_driver->setpolicy) { |
---|
| 2782 | + static_branch_enable_cpuslocked(&cpufreq_freq_invariance); |
---|
| 2783 | + pr_debug("supports frequency invariance"); |
---|
| 2784 | + } |
---|
2546 | 2785 | |
---|
2547 | 2786 | if (driver_data->setpolicy) |
---|
2548 | 2787 | driver_data->flags |= CPUFREQ_CONST_LOOPS; |
---|
.. | .. |
---|
2592 | 2831 | } |
---|
2593 | 2832 | EXPORT_SYMBOL_GPL(cpufreq_register_driver); |
---|
2594 | 2833 | |
---|
2595 | | -/** |
---|
| 2834 | +/* |
---|
2596 | 2835 | * cpufreq_unregister_driver - unregister the current CPUFreq driver |
---|
2597 | 2836 | * |
---|
2598 | 2837 | * Unregister the current CPUFreq driver. Only call this if you have |
---|
.. | .. |
---|
2613 | 2852 | cpus_read_lock(); |
---|
2614 | 2853 | subsys_interface_unregister(&cpufreq_interface); |
---|
2615 | 2854 | remove_boost_sysfs_file(); |
---|
| 2855 | + static_branch_disable_cpuslocked(&cpufreq_freq_invariance); |
---|
2616 | 2856 | cpuhp_remove_state_nocalls_cpuslocked(hp_online); |
---|
2617 | 2857 | |
---|
2618 | 2858 | write_lock_irqsave(&cpufreq_driver_lock, flags); |
---|
.. | .. |
---|
2626 | 2866 | } |
---|
2627 | 2867 | EXPORT_SYMBOL_GPL(cpufreq_unregister_driver); |
---|
2628 | 2868 | |
---|
2629 | | -struct kobject *cpufreq_global_kobject; |
---|
2630 | | -EXPORT_SYMBOL(cpufreq_global_kobject); |
---|
2631 | | - |
---|
2632 | 2869 | static int __init cpufreq_core_init(void) |
---|
2633 | 2870 | { |
---|
| 2871 | + struct cpufreq_governor *gov = cpufreq_default_governor(); |
---|
| 2872 | + |
---|
2634 | 2873 | if (cpufreq_disabled()) |
---|
2635 | 2874 | return -ENODEV; |
---|
2636 | 2875 | |
---|
2637 | 2876 | cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj); |
---|
2638 | 2877 | BUG_ON(!cpufreq_global_kobject); |
---|
2639 | 2878 | |
---|
| 2879 | + if (!strlen(default_governor)) |
---|
| 2880 | + strncpy(default_governor, gov->name, CPUFREQ_NAME_LEN); |
---|
| 2881 | + |
---|
2640 | 2882 | return 0; |
---|
2641 | 2883 | } |
---|
2642 | 2884 | module_param(off, int, 0444); |
---|
| 2885 | +module_param_string(default_governor, default_governor, CPUFREQ_NAME_LEN, 0444); |
---|
2643 | 2886 | core_initcall(cpufreq_core_init); |
---|