hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/cpufreq/cpufreq.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/drivers/cpufreq/cpufreq.c
34 *
....@@ -9,10 +10,6 @@
910 * Added handling for CPU hotplug
1011 * Feb 2006 - Jacob Shin <jacob.shin@amd.com>
1112 * 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.
1613 */
1714
1815 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -27,22 +24,15 @@
2724 #include <linux/kernel_stat.h>
2825 #include <linux/module.h>
2926 #include <linux/mutex.h>
27
+#include <linux/pm_qos.h>
3028 #include <linux/slab.h>
3129 #include <linux/suspend.h>
3230 #include <linux/syscore_ops.h>
3331 #include <linux/tick.h>
3432 #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>
3934
4035 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
-}
4636
4737 /* Macros to iterate over CPU policies */
4838 #define for_each_suitable_policy(__policy, __active) \
....@@ -62,7 +52,9 @@
6252 #define for_each_governor(__governor) \
6353 list_for_each_entry(__governor, &cpufreq_governor_list, governor_list)
6454
65
-/**
55
+static char default_governor[CPUFREQ_NAME_LEN];
56
+
57
+/*
6658 * The "cpufreq driver" - the arch- or hardware-dependent low
6759 * level driver of CPUFreq support, and its spinlock. This lock
6860 * also protects the cpufreq_cpu_data array.
....@@ -70,6 +62,12 @@
7062 static struct cpufreq_driver *cpufreq_driver;
7163 static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
7264 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
+}
7371
7472 /* Flag to suspend/resume CPUFreq governors */
7573 static bool cpufreq_suspended;
....@@ -83,11 +81,12 @@
8381 static unsigned int __cpufreq_get(struct cpufreq_policy *policy);
8482 static int cpufreq_init_governor(struct cpufreq_policy *policy);
8583 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);
8884 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);
8988
90
-/**
89
+/*
9190 * Two notifier lists: the "policy" list is involved in the
9291 * validation process for a new CPU frequency policy; the
9392 * "transition" list for kernel code that needs to handle
....@@ -114,6 +113,8 @@
114113 }
115114 EXPORT_SYMBOL_GPL(have_governor_per_policy);
116115
116
+static struct kobject *cpufreq_global_kobject;
117
+
117118 struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy)
118119 {
119120 if (have_governor_per_policy())
....@@ -125,18 +126,21 @@
125126
126127 static inline u64 get_cpu_idle_time_jiffy(unsigned int cpu, u64 *wall)
127128 {
128
- u64 idle_time;
129
+ struct kernel_cpustat kcpustat;
129130 u64 cur_wall_time;
131
+ u64 idle_time;
130132 u64 busy_time;
131133
132134 cur_wall_time = jiffies64_to_nsecs(get_jiffies_64());
133135
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];
140144
141145 idle_time = cur_wall_time - busy_time;
142146 if (wall)
....@@ -158,18 +162,6 @@
158162 }
159163 EXPORT_SYMBOL_GPL(get_cpu_idle_time);
160164
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
-
173165 /*
174166 * This is a generic cpufreq init() routine which can be used by cpufreq
175167 * drivers of SMP systems. It will do following:
....@@ -177,7 +169,7 @@
177169 * - set policies transition latency
178170 * - policy->cpus with all possible CPUs
179171 */
180
-int cpufreq_generic_init(struct cpufreq_policy *policy,
172
+void cpufreq_generic_init(struct cpufreq_policy *policy,
181173 struct cpufreq_frequency_table *table,
182174 unsigned int transition_latency)
183175 {
....@@ -189,8 +181,6 @@
189181 * share the clock and voltage and clock.
190182 */
191183 cpumask_setall(policy->cpus);
192
-
193
- return 0;
194184 }
195185 EXPORT_SYMBOL_GPL(cpufreq_generic_init);
196186
....@@ -217,17 +207,15 @@
217207 EXPORT_SYMBOL_GPL(cpufreq_generic_get);
218208
219209 /**
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.
221212 *
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.
223216 *
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.
231219 */
232220 struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
233221 {
....@@ -254,12 +242,8 @@
254242 EXPORT_SYMBOL_GPL(cpufreq_cpu_get);
255243
256244 /**
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().
263247 */
264248 void cpufreq_cpu_put(struct cpufreq_policy *policy)
265249 {
....@@ -267,11 +251,56 @@
267251 }
268252 EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
269253
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
+
270299 /*********************************************************************
271300 * EXTERNALLY AFFECTING FREQUENCY CHANGES *
272301 *********************************************************************/
273302
274
-/**
303
+/*
275304 * adjust_jiffies - adjust the system "loops_per_jiffy"
276305 *
277306 * This function alters the system "loops_per_jiffy" for the clock
....@@ -317,11 +346,14 @@
317346 struct cpufreq_freqs *freqs,
318347 unsigned int state)
319348 {
349
+ int cpu;
350
+
320351 BUG_ON(irqs_disabled());
321352
322353 if (cpufreq_disabled())
323354 return;
324355
356
+ freqs->policy = policy;
325357 freqs->flags = cpufreq_driver->flags;
326358 pr_debug("notification %u of frequency transition to %u kHz\n",
327359 state, freqs->new);
....@@ -333,18 +365,14 @@
333365 * which is not equal to what the cpufreq core thinks is
334366 * "old frequency".
335367 */
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;
342372 }
343373
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);
348376
349377 adjust_jiffies(CPUFREQ_PRECHANGE, freqs);
350378 break;
....@@ -354,15 +382,16 @@
354382 pr_debug("FREQ: %u - CPUs: %*pbl\n", freqs->new,
355383 cpumask_pr_args(policy->cpus));
356384
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);
362390
363391 cpufreq_stats_record_transition(policy, freqs->new);
364392 cpufreq_times_record_transition(policy, freqs->new);
365393 policy->cur = freqs->new;
394
+ trace_android_rvh_cpufreq_transition(policy);
366395 }
367396 }
368397
....@@ -416,13 +445,19 @@
416445 void cpufreq_freq_transition_end(struct cpufreq_policy *policy,
417446 struct cpufreq_freqs *freqs, int transition_failed)
418447 {
419
- if (unlikely(WARN_ON(!policy->transition_ongoing)))
448
+ if (WARN_ON(!policy->transition_ongoing))
420449 return;
421450
422451 cpufreq_notify_post_transition(policy, freqs, transition_failed);
423452
453
+ arch_set_freq_scale(policy->related_cpus,
454
+ policy->cur,
455
+ policy->cpuinfo.max_freq);
456
+
457
+ spin_lock(&policy->transition_lock);
424458 policy->transition_ongoing = false;
425459 policy->transition_task = NULL;
460
+ spin_unlock(&policy->transition_lock);
426461
427462 wake_up(&policy->transition_wait);
428463 }
....@@ -444,7 +479,7 @@
444479 mutex_lock(&cpufreq_transition_notifier_list.mutex);
445480
446481 for (nb = cpufreq_transition_notifier_list.head; nb; nb = nb->next)
447
- pr_info("%pF\n", nb->notifier_call);
482
+ pr_info("%pS\n", nb->notifier_call);
448483
449484 mutex_unlock(&cpufreq_transition_notifier_list.mutex);
450485 }
....@@ -499,6 +534,7 @@
499534 /**
500535 * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
501536 * one.
537
+ * @policy: associated policy to interrogate
502538 * @target_freq: target frequency to resolve.
503539 *
504540 * The target to driver frequency mapping is cached in the policy.
....@@ -509,11 +545,14 @@
509545 unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
510546 unsigned int target_freq)
511547 {
548
+ unsigned int old_target_freq = target_freq;
549
+
512550 target_freq = clamp_val(target_freq, policy->min, policy->max);
551
+ trace_android_vh_cpufreq_resolve_freq(policy, target_freq, old_target_freq);
513552 policy->cached_target_freq = target_freq;
514553
515554 if (cpufreq_driver->target_index) {
516
- int idx;
555
+ unsigned int idx;
517556
518557 idx = cpufreq_frequency_table_target(policy, target_freq,
519558 CPUFREQ_RELATION_L);
....@@ -596,56 +635,54 @@
596635 return NULL;
597636 }
598637
599
-/**
600
- * cpufreq_parse_governor - parse a governor string
601
- */
602
-static int cpufreq_parse_governor(char *str_governor,
603
- struct cpufreq_policy *policy)
638
+static struct cpufreq_governor *get_governor(const char *str_governor)
604639 {
605
- if (cpufreq_driver->setpolicy) {
606
- if (!strncasecmp(str_governor, "performance", CPUFREQ_NAME_LEN)) {
607
- policy->policy = CPUFREQ_POLICY_PERFORMANCE;
608
- return 0;
609
- }
640
+ struct cpufreq_governor *t;
610641
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;
642
+ mutex_lock(&cpufreq_governor_mutex);
643
+ t = find_governor(str_governor);
644
+ if (!t)
645
+ goto unlock;
617646
618
- mutex_lock(&cpufreq_governor_mutex);
647
+ if (!try_module_get(t->owner))
648
+ t = NULL;
619649
620
- t = find_governor(str_governor);
621
- if (!t) {
622
- int ret;
650
+unlock:
651
+ mutex_unlock(&cpufreq_governor_mutex);
623652
624
- mutex_unlock(&cpufreq_governor_mutex);
653
+ return t;
654
+}
625655
626
- ret = request_module("cpufreq_%s", str_governor);
627
- if (ret)
628
- return -EINVAL;
656
+static unsigned int cpufreq_parse_policy(char *str_governor)
657
+{
658
+ if (!strncasecmp(str_governor, "performance", CPUFREQ_NAME_LEN))
659
+ return CPUFREQ_POLICY_PERFORMANCE;
629660
630
- mutex_lock(&cpufreq_governor_mutex);
661
+ if (!strncasecmp(str_governor, "powersave", CPUFREQ_NAME_LEN))
662
+ return CPUFREQ_POLICY_POWERSAVE;
631663
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;
664
+ return CPUFREQ_POLICY_UNKNOWN;
646665 }
647666
648667 /**
668
+ * cpufreq_parse_governor - parse a governor string only for has_target()
669
+ * @str_governor: Governor name.
670
+ */
671
+static struct cpufreq_governor *cpufreq_parse_governor(char *str_governor)
672
+{
673
+ struct cpufreq_governor *t;
674
+
675
+ t = get_governor(str_governor);
676
+ if (t)
677
+ return t;
678
+
679
+ if (request_module("cpufreq_%s", str_governor))
680
+ return NULL;
681
+
682
+ return get_governor(str_governor);
683
+}
684
+
685
+/*
649686 * cpufreq_per_cpu_attr_read() / show_##file_name() -
650687 * print out cpufreq information
651688 *
....@@ -660,8 +697,16 @@
660697 return sprintf(buf, "%u\n", policy->object); \
661698 }
662699
700
+static ssize_t show_cpuinfo_max_freq(struct cpufreq_policy *policy, char *buf)
701
+{
702
+ unsigned int max_freq = policy->cpuinfo.max_freq;
703
+
704
+ trace_android_vh_show_max_freq(policy, &max_freq);
705
+ trace_android_rvh_show_max_freq(policy, &max_freq);
706
+ return sprintf(buf, "%u\n", max_freq);
707
+}
708
+
663709 show_one(cpuinfo_min_freq, cpuinfo.min_freq);
664
-show_one(cpuinfo_max_freq, cpuinfo.max_freq);
665710 show_one(cpuinfo_transition_latency, cpuinfo.transition_latency);
666711 show_one(scaling_min_freq, min);
667712 show_one(scaling_max_freq, max);
....@@ -679,47 +724,35 @@
679724 freq = arch_freq_get_on_cpu(policy->cpu);
680725 if (freq)
681726 ret = sprintf(buf, "%u\n", freq);
682
- else if (cpufreq_driver && cpufreq_driver->setpolicy &&
683
- cpufreq_driver->get)
727
+ else if (cpufreq_driver->setpolicy && cpufreq_driver->get)
684728 ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu));
685729 else
686730 ret = sprintf(buf, "%u\n", policy->cur);
687731 return ret;
688732 }
689733
690
-static int cpufreq_set_policy(struct cpufreq_policy *policy,
691
- struct cpufreq_policy *new_policy);
692
-
693
-/**
734
+/*
694735 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
695736 */
696737 #define store_one(file_name, object) \
697738 static ssize_t store_##file_name \
698739 (struct cpufreq_policy *policy, const char *buf, size_t count) \
699740 { \
700
- int ret, temp; \
701
- struct cpufreq_policy new_policy; \
741
+ unsigned long val; \
742
+ int ret; \
702743 \
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); \
744
+ ret = sscanf(buf, "%lu", &val); \
708745 if (ret != 1) \
709746 return -EINVAL; \
710747 \
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; \
748
+ ret = freq_qos_update_request(policy->object##_freq_req, val);\
749
+ return ret >= 0 ? count : ret; \
717750 }
718751
719752 store_one(scaling_min_freq, min);
720753 store_one(scaling_max_freq, max);
721754
722
-/**
755
+/*
723756 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
724757 */
725758 static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy,
....@@ -733,7 +766,7 @@
733766 return sprintf(buf, "<unknown>\n");
734767 }
735768
736
-/**
769
+/*
737770 * show_scaling_governor - show the current policy for the specified CPU
738771 */
739772 static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
....@@ -748,34 +781,44 @@
748781 return -EINVAL;
749782 }
750783
751
-/**
784
+/*
752785 * store_scaling_governor - store policy for the specified CPU
753786 */
754787 static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
755788 const char *buf, size_t count)
756789 {
790
+ char str_governor[16];
757791 int ret;
758
- char str_governor[16];
759
- struct cpufreq_policy new_policy;
760
-
761
- memcpy(&new_policy, policy, sizeof(*policy));
762792
763793 ret = sscanf(buf, "%15s", str_governor);
764794 if (ret != 1)
765795 return -EINVAL;
766796
767
- if (cpufreq_parse_governor(str_governor, &new_policy))
768
- return -EINVAL;
797
+ if (cpufreq_driver->setpolicy) {
798
+ unsigned int new_pol;
769799
770
- ret = cpufreq_set_policy(policy, &new_policy);
800
+ new_pol = cpufreq_parse_policy(str_governor);
801
+ if (!new_pol)
802
+ return -EINVAL;
771803
772
- if (new_policy.governor)
773
- module_put(new_policy.governor->owner);
804
+ ret = cpufreq_set_policy(policy, NULL, new_pol);
805
+ } else {
806
+ struct cpufreq_governor *new_gov;
807
+
808
+ new_gov = cpufreq_parse_governor(str_governor);
809
+ if (!new_gov)
810
+ return -EINVAL;
811
+
812
+ ret = cpufreq_set_policy(policy, new_gov,
813
+ CPUFREQ_POLICY_UNKNOWN);
814
+
815
+ module_put(new_gov->owner);
816
+ }
774817
775818 return ret ? ret : count;
776819 }
777820
778
-/**
821
+/*
779822 * show_scaling_driver - show the cpufreq driver currently loaded
780823 */
781824 static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf)
....@@ -783,7 +826,7 @@
783826 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name);
784827 }
785828
786
-/**
829
+/*
787830 * show_scaling_available_governors - show the available CPUfreq governors
788831 */
789832 static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
....@@ -797,12 +840,14 @@
797840 goto out;
798841 }
799842
843
+ mutex_lock(&cpufreq_governor_mutex);
800844 for_each_governor(t) {
801845 if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char))
802846 - (CPUFREQ_NAME_LEN + 2)))
803
- goto out;
847
+ break;
804848 i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name);
805849 }
850
+ mutex_unlock(&cpufreq_governor_mutex);
806851 out:
807852 i += sprintf(&buf[i], "\n");
808853 return i;
....@@ -825,7 +870,7 @@
825870 }
826871 EXPORT_SYMBOL_GPL(cpufreq_show_cpus);
827872
828
-/**
873
+/*
829874 * show_related_cpus - show the CPUs affected by each transition even if
830875 * hw coordination is in use
831876 */
....@@ -834,7 +879,7 @@
834879 return cpufreq_show_cpus(policy->related_cpus, buf);
835880 }
836881
837
-/**
882
+/*
838883 * show_affected_cpus - show the CPUs affected by each transition
839884 */
840885 static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
....@@ -868,18 +913,16 @@
868913 return policy->governor->show_setspeed(policy, buf);
869914 }
870915
871
-/**
916
+/*
872917 * show_bios_limit - show the current cpufreq HW/BIOS limitation
873918 */
874919 static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
875920 {
876921 unsigned int limit;
877922 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
- }
923
+ ret = cpufreq_driver->bios_limit(policy->cpu, &limit);
924
+ if (!ret)
925
+ return sprintf(buf, "%u\n", limit);
883926 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
884927 }
885928
....@@ -978,11 +1021,10 @@
9781021 .release = cpufreq_sysfs_release,
9791022 };
9801023
981
-static void add_cpu_dev_symlink(struct cpufreq_policy *policy, unsigned int cpu)
1024
+static void add_cpu_dev_symlink(struct cpufreq_policy *policy, unsigned int cpu,
1025
+ struct device *dev)
9821026 {
983
- struct device *dev = get_cpu_device(cpu);
984
-
985
- if (!dev)
1027
+ if (unlikely(!dev))
9861028 return;
9871029
9881030 if (cpumask_test_and_set_cpu(cpu, policy->real_cpus))
....@@ -1032,40 +1074,52 @@
10321074 return 0;
10331075 }
10341076
1035
-__weak struct cpufreq_governor *cpufreq_default_governor(void)
1036
-{
1037
- return NULL;
1038
-}
1039
-
10401077 static int cpufreq_init_policy(struct cpufreq_policy *policy)
10411078 {
10421079 struct cpufreq_governor *gov = NULL;
1043
- struct cpufreq_policy new_policy;
1080
+ unsigned int pol = CPUFREQ_POLICY_UNKNOWN;
1081
+ int ret;
10441082
1045
- memcpy(&new_policy, policy, sizeof(*policy));
1083
+ if (has_target()) {
1084
+ /* Update policy governor to the one used before hotplug. */
1085
+ gov = get_governor(policy->last_governor);
1086
+ if (gov) {
1087
+ pr_debug("Restoring governor %s for cpu %d\n",
1088
+ gov->name, policy->cpu);
1089
+ } else {
1090
+ gov = get_governor(default_governor);
1091
+ }
10461092
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);
1093
+ if (!gov) {
1094
+ gov = cpufreq_default_governor();
1095
+ __module_get(gov->owner);
1096
+ }
1097
+
10521098 } else {
1053
- gov = cpufreq_default_governor();
1054
- if (!gov)
1099
+
1100
+ /* Use the default policy if there is no last_policy. */
1101
+ if (policy->last_policy) {
1102
+ pol = policy->last_policy;
1103
+ } else {
1104
+ pol = cpufreq_parse_policy(default_governor);
1105
+ /*
1106
+ * In case the default governor is neither "performance"
1107
+ * nor "powersave", fall back to the initial policy
1108
+ * value set by the driver.
1109
+ */
1110
+ if (pol == CPUFREQ_POLICY_UNKNOWN)
1111
+ pol = policy->policy;
1112
+ }
1113
+ if (pol != CPUFREQ_POLICY_PERFORMANCE &&
1114
+ pol != CPUFREQ_POLICY_POWERSAVE)
10551115 return -ENODATA;
10561116 }
10571117
1058
- new_policy.governor = gov;
1118
+ ret = cpufreq_set_policy(policy, gov, pol);
1119
+ if (gov)
1120
+ module_put(gov->owner);
10591121
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);
1122
+ return ret;
10691123 }
10701124
10711125 static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
....@@ -1091,61 +1145,43 @@
10911145 return ret;
10921146 }
10931147
1148
+void refresh_frequency_limits(struct cpufreq_policy *policy)
1149
+{
1150
+ if (!policy_is_inactive(policy)) {
1151
+ pr_debug("updating policy for CPU %u\n", policy->cpu);
1152
+
1153
+ cpufreq_set_policy(policy, policy->governor, policy->policy);
1154
+ }
1155
+}
1156
+EXPORT_SYMBOL(refresh_frequency_limits);
1157
+
10941158 static void handle_update(struct work_struct *work)
10951159 {
10961160 struct cpufreq_policy *policy =
10971161 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);
1162
+
1163
+ pr_debug("handle_update for cpu %u called\n", policy->cpu);
1164
+ down_write(&policy->rwsem);
1165
+ refresh_frequency_limits(policy);
1166
+ up_write(&policy->rwsem);
11011167 }
11021168
1103
-static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
1169
+static int cpufreq_notifier_min(struct notifier_block *nb, unsigned long freq,
1170
+ void *data)
11041171 {
1105
- struct cpufreq_policy *policy;
1106
- int ret;
1172
+ struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_min);
11071173
1108
- policy = kzalloc(sizeof(*policy), GFP_KERNEL);
1109
- if (!policy)
1110
- return NULL;
1174
+ schedule_work(&policy->update);
1175
+ return 0;
1176
+}
11111177
1112
- if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
1113
- goto err_free_policy;
1178
+static int cpufreq_notifier_max(struct notifier_block *nb, unsigned long freq,
1179
+ void *data)
1180
+{
1181
+ struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_max);
11141182
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;
1183
+ schedule_work(&policy->update);
1184
+ return 0;
11491185 }
11501186
11511187 static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy)
....@@ -1170,6 +1206,89 @@
11701206 pr_debug("wait complete\n");
11711207 }
11721208
1209
+static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
1210
+{
1211
+ struct cpufreq_policy *policy;
1212
+ struct device *dev = get_cpu_device(cpu);
1213
+ int ret;
1214
+
1215
+ if (!dev)
1216
+ return NULL;
1217
+
1218
+ policy = kzalloc(sizeof(*policy), GFP_KERNEL);
1219
+ if (!policy)
1220
+ return NULL;
1221
+
1222
+ if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
1223
+ goto err_free_policy;
1224
+
1225
+ if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
1226
+ goto err_free_cpumask;
1227
+
1228
+ if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL))
1229
+ goto err_free_rcpumask;
1230
+
1231
+ init_completion(&policy->kobj_unregister);
1232
+ ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq,
1233
+ cpufreq_global_kobject, "policy%u", cpu);
1234
+ if (ret) {
1235
+ dev_err(dev, "%s: failed to init policy->kobj: %d\n", __func__, ret);
1236
+ /*
1237
+ * The entire policy object will be freed below, but the extra
1238
+ * memory allocated for the kobject name needs to be freed by
1239
+ * releasing the kobject.
1240
+ */
1241
+ kobject_put(&policy->kobj);
1242
+ goto err_free_real_cpus;
1243
+ }
1244
+
1245
+ freq_constraints_init(&policy->constraints);
1246
+
1247
+ policy->nb_min.notifier_call = cpufreq_notifier_min;
1248
+ policy->nb_max.notifier_call = cpufreq_notifier_max;
1249
+
1250
+ ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MIN,
1251
+ &policy->nb_min);
1252
+ if (ret) {
1253
+ dev_err(dev, "Failed to register MIN QoS notifier: %d (%*pbl)\n",
1254
+ ret, cpumask_pr_args(policy->cpus));
1255
+ goto err_kobj_remove;
1256
+ }
1257
+
1258
+ ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MAX,
1259
+ &policy->nb_max);
1260
+ if (ret) {
1261
+ dev_err(dev, "Failed to register MAX QoS notifier: %d (%*pbl)\n",
1262
+ ret, cpumask_pr_args(policy->cpus));
1263
+ goto err_min_qos_notifier;
1264
+ }
1265
+
1266
+ INIT_LIST_HEAD(&policy->policy_list);
1267
+ init_rwsem(&policy->rwsem);
1268
+ spin_lock_init(&policy->transition_lock);
1269
+ init_waitqueue_head(&policy->transition_wait);
1270
+ INIT_WORK(&policy->update, handle_update);
1271
+
1272
+ policy->cpu = cpu;
1273
+ return policy;
1274
+
1275
+err_min_qos_notifier:
1276
+ freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
1277
+ &policy->nb_min);
1278
+err_kobj_remove:
1279
+ cpufreq_policy_put_kobj(policy);
1280
+err_free_real_cpus:
1281
+ free_cpumask_var(policy->real_cpus);
1282
+err_free_rcpumask:
1283
+ free_cpumask_var(policy->related_cpus);
1284
+err_free_cpumask:
1285
+ free_cpumask_var(policy->cpus);
1286
+err_free_policy:
1287
+ kfree(policy);
1288
+
1289
+ return NULL;
1290
+}
1291
+
11731292 static void cpufreq_policy_free(struct cpufreq_policy *policy)
11741293 {
11751294 unsigned long flags;
....@@ -1182,6 +1301,27 @@
11821301 for_each_cpu(cpu, policy->related_cpus)
11831302 per_cpu(cpufreq_cpu_data, cpu) = NULL;
11841303 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
1304
+
1305
+ freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MAX,
1306
+ &policy->nb_max);
1307
+ freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
1308
+ &policy->nb_min);
1309
+
1310
+ /* Cancel any pending policy->update work before freeing the policy. */
1311
+ cancel_work_sync(&policy->update);
1312
+
1313
+ if (policy->max_freq_req) {
1314
+ /*
1315
+ * CPUFREQ_CREATE_POLICY notification is sent only after
1316
+ * successfully adding max_freq_req request.
1317
+ */
1318
+ blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1319
+ CPUFREQ_REMOVE_POLICY, policy);
1320
+ freq_qos_remove_request(policy->max_freq_req);
1321
+ }
1322
+
1323
+ freq_qos_remove_request(policy->min_freq_req);
1324
+ kfree(policy->min_freq_req);
11851325
11861326 cpufreq_policy_put_kobj(policy);
11871327 free_cpumask_var(policy->real_cpus);
....@@ -1220,28 +1360,44 @@
12201360 return -ENOMEM;
12211361 }
12221362
1223
- cpumask_copy(policy->cpus, cpumask_of(cpu));
1363
+ if (!new_policy && cpufreq_driver->online) {
1364
+ ret = cpufreq_driver->online(policy);
1365
+ if (ret) {
1366
+ pr_debug("%s: %d: initialization failed\n", __func__,
1367
+ __LINE__);
1368
+ goto out_exit_policy;
1369
+ }
12241370
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
- }
1371
+ /* Recover policy->cpus using related_cpus */
1372
+ cpumask_copy(policy->cpus, policy->related_cpus);
1373
+ } else {
1374
+ cpumask_copy(policy->cpus, cpumask_of(cpu));
12331375
1234
- ret = cpufreq_table_validate_and_sort(policy);
1235
- if (ret)
1236
- goto out_exit_policy;
1376
+ /*
1377
+ * Call driver. From then on the cpufreq must be able
1378
+ * to accept all calls to ->verify and ->setpolicy for this CPU.
1379
+ */
1380
+ ret = cpufreq_driver->init(policy);
1381
+ if (ret) {
1382
+ pr_debug("%s: %d: initialization failed\n", __func__,
1383
+ __LINE__);
1384
+ goto out_free_policy;
1385
+ }
12371386
1238
- down_write(&policy->rwsem);
1387
+ /*
1388
+ * The initialization has succeeded and the policy is online.
1389
+ * If there is a problem with its frequency table, take it
1390
+ * offline and drop it.
1391
+ */
1392
+ ret = cpufreq_table_validate_and_sort(policy);
1393
+ if (ret)
1394
+ goto out_offline_policy;
12391395
1240
- if (new_policy) {
12411396 /* related_cpus should at least include policy->cpus. */
12421397 cpumask_copy(policy->related_cpus, policy->cpus);
12431398 }
12441399
1400
+ down_write(&policy->rwsem);
12451401 /*
12461402 * affected cpus must always be the one, which are online. We aren't
12471403 * managing offline cpus here.
....@@ -1249,19 +1405,49 @@
12491405 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
12501406
12511407 if (new_policy) {
1252
- policy->user_policy.min = policy->min;
1253
- policy->user_policy.max = policy->max;
1254
-
12551408 for_each_cpu(j, policy->related_cpus) {
12561409 per_cpu(cpufreq_cpu_data, j) = policy;
1257
- add_cpu_dev_symlink(policy, j);
1410
+ add_cpu_dev_symlink(policy, j, get_cpu_device(j));
12581411 }
1259
- } else {
1260
- policy->min = policy->user_policy.min;
1261
- policy->max = policy->user_policy.max;
1412
+
1413
+ policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req),
1414
+ GFP_KERNEL);
1415
+ if (!policy->min_freq_req)
1416
+ goto out_destroy_policy;
1417
+
1418
+ ret = freq_qos_add_request(&policy->constraints,
1419
+ policy->min_freq_req, FREQ_QOS_MIN,
1420
+ FREQ_QOS_MIN_DEFAULT_VALUE);
1421
+ if (ret < 0) {
1422
+ /*
1423
+ * So we don't call freq_qos_remove_request() for an
1424
+ * uninitialized request.
1425
+ */
1426
+ kfree(policy->min_freq_req);
1427
+ policy->min_freq_req = NULL;
1428
+ goto out_destroy_policy;
1429
+ }
1430
+
1431
+ /*
1432
+ * This must be initialized right here to avoid calling
1433
+ * freq_qos_remove_request() on uninitialized request in case
1434
+ * of errors.
1435
+ */
1436
+ policy->max_freq_req = policy->min_freq_req + 1;
1437
+
1438
+ ret = freq_qos_add_request(&policy->constraints,
1439
+ policy->max_freq_req, FREQ_QOS_MAX,
1440
+ FREQ_QOS_MAX_DEFAULT_VALUE);
1441
+ if (ret < 0) {
1442
+ policy->max_freq_req = NULL;
1443
+ goto out_destroy_policy;
1444
+ }
1445
+
1446
+ blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
1447
+ CPUFREQ_CREATE_POLICY, policy);
12621448 }
12631449
1264
- if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
1450
+ if (cpufreq_driver->get && has_target()) {
12651451 policy->cur = cpufreq_driver->get(policy->cpu);
12661452 if (!policy->cur) {
12671453 pr_err("%s: ->get() failed\n", __func__);
....@@ -1289,14 +1475,13 @@
12891475 */
12901476 if ((cpufreq_driver->flags & CPUFREQ_NEED_INITIAL_FREQ_CHECK)
12911477 && has_target()) {
1478
+ unsigned int old_freq = policy->cur;
1479
+
12921480 /* Are we running at unknown frequency ? */
1293
- ret = cpufreq_frequency_table_get_index(policy, policy->cur);
1481
+ ret = cpufreq_frequency_table_get_index(policy, old_freq);
12941482 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);
1483
+ ret = __cpufreq_driver_target(policy, old_freq - 1,
1484
+ CPUFREQ_RELATION_L);
13001485
13011486 /*
13021487 * Reaching here after boot in a few seconds may not
....@@ -1304,8 +1489,8 @@
13041489 * frequency for longer duration. Hence, a BUG_ON().
13051490 */
13061491 BUG_ON(ret);
1307
- pr_warn("%s: CPU%d: Unlisted initial frequency changed to: %u KHz\n",
1308
- __func__, policy->cpu, policy->cur);
1492
+ pr_info("%s: CPU%d: Running at unlisted initial frequency: %u KHz, changing to: %u KHz\n",
1493
+ __func__, policy->cpu, old_freq, policy->cur);
13091494 }
13101495 }
13111496
....@@ -1326,8 +1511,6 @@
13261511 if (ret) {
13271512 pr_err("%s: Failed to initialize policy for cpu: %d (%d)\n",
13281513 __func__, cpu, ret);
1329
- /* cpufreq_policy_free() will notify based on this */
1330
- new_policy = false;
13311514 goto out_destroy_policy;
13321515 }
13331516
....@@ -1339,8 +1522,7 @@
13391522 if (cpufreq_driver->ready)
13401523 cpufreq_driver->ready(policy);
13411524
1342
- if (IS_ENABLED(CONFIG_CPU_THERMAL) &&
1343
- cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
1525
+ if (cpufreq_thermal_control_enabled(cpufreq_driver))
13441526 policy->cdev = of_cpufreq_cooling_register(policy);
13451527
13461528 pr_debug("initialization complete\n");
....@@ -1352,6 +1534,10 @@
13521534 remove_cpu_dev_symlink(policy, get_cpu_device(j));
13531535
13541536 up_write(&policy->rwsem);
1537
+
1538
+out_offline_policy:
1539
+ if (cpufreq_driver->offline)
1540
+ cpufreq_driver->offline(policy);
13551541
13561542 out_exit_policy:
13571543 if (cpufreq_driver->exit)
....@@ -1384,7 +1570,7 @@
13841570 /* Create sysfs link on CPU registration */
13851571 policy = per_cpu(cpufreq_cpu_data, cpu);
13861572 if (policy)
1387
- add_cpu_dev_symlink(policy, cpu);
1573
+ add_cpu_dev_symlink(policy, cpu, dev);
13881574
13891575 return 0;
13901576 }
....@@ -1430,8 +1616,7 @@
14301616 goto unlock;
14311617 }
14321618
1433
- if (IS_ENABLED(CONFIG_CPU_THERMAL) &&
1434
- cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) {
1619
+ if (cpufreq_thermal_control_enabled(cpufreq_driver)) {
14351620 cpufreq_cooling_unregister(policy->cdev);
14361621 policy->cdev = NULL;
14371622 }
....@@ -1443,11 +1628,12 @@
14431628 cpufreq_exit_governor(policy);
14441629
14451630 /*
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.
1631
+ * Perform the ->offline() during light-weight tear-down, as
1632
+ * that allows fast recovery when the CPU comes back.
14491633 */
1450
- if (cpufreq_driver->exit) {
1634
+ if (cpufreq_driver->offline) {
1635
+ cpufreq_driver->offline(policy);
1636
+ } else if (cpufreq_driver->exit) {
14511637 cpufreq_driver->exit(policy);
14521638 policy->freq_table = NULL;
14531639 }
....@@ -1457,7 +1643,7 @@
14571643 return 0;
14581644 }
14591645
1460
-/**
1646
+/*
14611647 * cpufreq_remove_dev - remove a CPU device
14621648 *
14631649 * Removes the cpufreq interface for a CPU device.
....@@ -1476,8 +1662,13 @@
14761662 cpumask_clear_cpu(cpu, policy->real_cpus);
14771663 remove_cpu_dev_symlink(policy, dev);
14781664
1479
- if (cpumask_empty(policy->real_cpus))
1665
+ if (cpumask_empty(policy->real_cpus)) {
1666
+ /* We did light-weight exit earlier, do full tear down now */
1667
+ if (cpufreq_driver->offline)
1668
+ cpufreq_driver->exit(policy);
1669
+
14801670 cpufreq_policy_free(policy);
1671
+ }
14811672 }
14821673
14831674 /**
....@@ -1502,6 +1693,30 @@
15021693
15031694 cpufreq_freq_transition_begin(policy, &freqs);
15041695 cpufreq_freq_transition_end(policy, &freqs, 0);
1696
+}
1697
+
1698
+static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, bool update)
1699
+{
1700
+ unsigned int new_freq;
1701
+
1702
+ new_freq = cpufreq_driver->get(policy->cpu);
1703
+ if (!new_freq)
1704
+ return 0;
1705
+
1706
+ /*
1707
+ * If fast frequency switching is used with the given policy, the check
1708
+ * against policy->cur is pointless, so skip it in that case.
1709
+ */
1710
+ if (policy->fast_switch_enabled || !has_target())
1711
+ return new_freq;
1712
+
1713
+ if (policy->cur != new_freq) {
1714
+ cpufreq_out_of_sync(policy, new_freq);
1715
+ if (update)
1716
+ schedule_work(&policy->update);
1717
+ }
1718
+
1719
+ return new_freq;
15051720 }
15061721
15071722 /**
....@@ -1557,33 +1772,32 @@
15571772 }
15581773 EXPORT_SYMBOL(cpufreq_quick_get_max);
15591774
1560
-static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
1775
+/**
1776
+ * cpufreq_get_hw_max_freq - get the max hardware frequency of the CPU
1777
+ * @cpu: CPU number
1778
+ *
1779
+ * The default return value is the max_freq field of cpuinfo.
1780
+ */
1781
+__weak unsigned int cpufreq_get_hw_max_freq(unsigned int cpu)
15611782 {
1783
+ struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
15621784 unsigned int ret_freq = 0;
15631785
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
- }
1786
+ if (policy) {
1787
+ ret_freq = policy->cpuinfo.max_freq;
1788
+ cpufreq_cpu_put(policy);
15841789 }
15851790
15861791 return ret_freq;
1792
+}
1793
+EXPORT_SYMBOL(cpufreq_get_hw_max_freq);
1794
+
1795
+static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
1796
+{
1797
+ if (unlikely(policy_is_inactive(policy)))
1798
+ return 0;
1799
+
1800
+ return cpufreq_verify_current_freq(policy, true);
15871801 }
15881802
15891803 /**
....@@ -1599,7 +1813,8 @@
15991813
16001814 if (policy) {
16011815 down_read(&policy->rwsem);
1602
- ret_freq = __cpufreq_get(policy);
1816
+ if (cpufreq_driver->get)
1817
+ ret_freq = __cpufreq_get(policy);
16031818 up_read(&policy->rwsem);
16041819
16051820 cpufreq_cpu_put(policy);
....@@ -1608,24 +1823,6 @@
16081823 return ret_freq;
16091824 }
16101825 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
-}
16291826
16301827 static struct subsys_interface cpufreq_interface = {
16311828 .name = "cpufreq",
....@@ -1688,8 +1885,8 @@
16881885 }
16891886
16901887 if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy))
1691
- pr_err("%s: Failed to suspend driver: %p\n", __func__,
1692
- policy);
1888
+ pr_err("%s: Failed to suspend driver: %s\n", __func__,
1889
+ cpufreq_driver->name);
16931890 }
16941891
16951892 suspend:
....@@ -1734,6 +1931,18 @@
17341931 __func__, policy);
17351932 }
17361933 }
1934
+}
1935
+
1936
+/**
1937
+ * cpufreq_driver_test_flags - Test cpufreq driver's flags against given ones.
1938
+ * @flags: Flags to test against the current cpufreq driver's flags.
1939
+ *
1940
+ * Assumes that the driver is there, so callers must ensure that this is the
1941
+ * case.
1942
+ */
1943
+bool cpufreq_driver_test_flags(u16 flags)
1944
+{
1945
+ return !!(cpufreq_driver->flags & flags);
17371946 }
17381947
17391948 /**
....@@ -1888,15 +2097,30 @@
18882097 unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,
18892098 unsigned int target_freq)
18902099 {
1891
- int ret;
2100
+ unsigned int freq;
2101
+ unsigned int old_target_freq = target_freq;
2102
+ int cpu;
18922103
18932104 target_freq = clamp_val(target_freq, policy->min, policy->max);
2105
+ trace_android_vh_cpufreq_fast_switch(policy, target_freq, old_target_freq);
2106
+ freq = cpufreq_driver->fast_switch(policy, target_freq);
18942107
1895
- ret = cpufreq_driver->fast_switch(policy, target_freq);
1896
- if (ret)
1897
- cpufreq_times_record_transition(policy, ret);
2108
+ if (!freq)
2109
+ return 0;
18982110
1899
- return ret;
2111
+ policy->cur = freq;
2112
+ arch_set_freq_scale(policy->related_cpus, freq,
2113
+ policy->cpuinfo.max_freq);
2114
+ cpufreq_stats_record_transition(policy, freq);
2115
+ cpufreq_times_record_transition(policy, freq);
2116
+ trace_android_rvh_cpufreq_transition(policy);
2117
+
2118
+ if (trace_cpu_frequency_enabled()) {
2119
+ for_each_cpu(cpu, policy->cpus)
2120
+ trace_cpu_frequency(freq, cpu);
2121
+ }
2122
+
2123
+ return freq;
19002124 }
19012125 EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch);
19022126
....@@ -1993,11 +2217,9 @@
19932217 if (cpufreq_disabled())
19942218 return -ENODEV;
19952219
1996
-#ifdef CONFIG_ARM_ROCKCHIP_CPUFREQ
1997
- target_freq = rockchip_cpufreq_adjust_target(policy->cpu, target_freq);
1998
-#endif
19992220 /* Make sure that target_freq is within supported range */
20002221 target_freq = clamp_val(target_freq, policy->min, policy->max);
2222
+ trace_android_vh_cpufreq_target(policy, target_freq, old_target_freq);
20012223
20022224 pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
20032225 policy->cpu, target_freq, relation, old_target_freq);
....@@ -2008,7 +2230,8 @@
20082230 * exactly same freq is called again and so we can save on few function
20092231 * calls.
20102232 */
2011
- if (target_freq == policy->cur)
2233
+ if (target_freq == policy->cur &&
2234
+ !(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS))
20122235 return 0;
20132236
20142237 /* Save last value to restore later on errors */
....@@ -2030,7 +2253,7 @@
20302253 unsigned int target_freq,
20312254 unsigned int relation)
20322255 {
2033
- int ret = -EINVAL;
2256
+ int ret;
20342257
20352258 down_write(&policy->rwsem);
20362259
....@@ -2062,7 +2285,7 @@
20622285 return -EINVAL;
20632286
20642287 /* Platform doesn't want dynamic frequency switching ? */
2065
- if (policy->governor->dynamic_switching &&
2288
+ if (policy->governor->flags & CPUFREQ_GOV_DYNAMIC_SWITCHING &&
20662289 cpufreq_driver->flags & CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING) {
20672290 struct cpufreq_governor *gov = cpufreq_fallback_governor();
20682291
....@@ -2088,6 +2311,8 @@
20882311 }
20892312 }
20902313
2314
+ policy->strict_target = !!(policy->governor->flags & CPUFREQ_GOV_STRICT_TARGET);
2315
+
20912316 return 0;
20922317 }
20932318
....@@ -2104,7 +2329,7 @@
21042329 module_put(policy->governor->owner);
21052330 }
21062331
2107
-static int cpufreq_start_governor(struct cpufreq_policy *policy)
2332
+int cpufreq_start_governor(struct cpufreq_policy *policy)
21082333 {
21092334 int ret;
21102335
....@@ -2116,8 +2341,8 @@
21162341
21172342 pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
21182343
2119
- if (cpufreq_driver->get && !cpufreq_driver->setpolicy)
2120
- cpufreq_update_current_freq(policy);
2344
+ if (cpufreq_driver->get)
2345
+ cpufreq_verify_current_freq(policy, false);
21212346
21222347 if (policy->governor->start) {
21232348 ret = policy->governor->start(policy);
....@@ -2131,7 +2356,7 @@
21312356 return 0;
21322357 }
21332358
2134
-static void cpufreq_stop_governor(struct cpufreq_policy *policy)
2359
+void cpufreq_stop_governor(struct cpufreq_policy *policy)
21352360 {
21362361 if (cpufreq_suspended || !policy->governor)
21372362 return;
....@@ -2212,6 +2437,7 @@
22122437 * cpufreq_get_policy - get the current cpufreq_policy
22132438 * @policy: struct cpufreq_policy into which the current cpufreq_policy
22142439 * is written
2440
+ * @cpu: CPU to find the policy for
22152441 *
22162442 * Reads the current cpufreq policy.
22172443 */
....@@ -2232,54 +2458,53 @@
22322458 }
22332459 EXPORT_SYMBOL(cpufreq_get_policy);
22342460
2235
-/*
2236
- * policy : current policy.
2237
- * new_policy: policy to be set.
2461
+/**
2462
+ * cpufreq_set_policy - Modify cpufreq policy parameters.
2463
+ * @policy: Policy object to modify.
2464
+ * @new_gov: Policy governor pointer.
2465
+ * @new_pol: Policy value (for drivers with built-in governors).
2466
+ *
2467
+ * Invoke the cpufreq driver's ->verify() callback to sanity-check the frequency
2468
+ * limits to be set for the policy, update @policy with the verified limits
2469
+ * values and either invoke the driver's ->setpolicy() callback (if present) or
2470
+ * carry out a governor update for @policy. That is, run the current governor's
2471
+ * ->limits() callback (if @new_gov points to the same object as the one in
2472
+ * @policy) or replace the governor for @policy with @new_gov.
2473
+ *
2474
+ * The cpuinfo part of @policy is not updated by this function.
22382475 */
22392476 static int cpufreq_set_policy(struct cpufreq_policy *policy,
2240
- struct cpufreq_policy *new_policy)
2477
+ struct cpufreq_governor *new_gov,
2478
+ unsigned int new_pol)
22412479 {
2480
+ struct cpufreq_policy_data new_data;
22422481 struct cpufreq_governor *old_gov;
22432482 int ret;
22442483
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
-
2484
+ memcpy(&new_data.cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
2485
+ new_data.freq_table = policy->freq_table;
2486
+ new_data.cpu = policy->cpu;
22502487 /*
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
2488
+ * PM QoS framework collects all the requests from users and provide us
2489
+ * the final aggregated value here.
22692490 */
2270
- ret = cpufreq_driver->verify(new_policy);
2491
+ new_data.min = freq_qos_read_value(&policy->constraints, FREQ_QOS_MIN);
2492
+ new_data.max = freq_qos_read_value(&policy->constraints, FREQ_QOS_MAX);
2493
+
2494
+ pr_debug("setting new policy for CPU %u: %u - %u kHz\n",
2495
+ new_data.cpu, new_data.min, new_data.max);
2496
+
2497
+ /*
2498
+ * Verify that the CPU speed can be set within these limits and make sure
2499
+ * that min <= max.
2500
+ */
2501
+ ret = cpufreq_driver->verify(&new_data);
22712502 if (ret)
22722503 return ret;
22732504
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;
2505
+ policy->min = new_data.min;
2506
+ policy->max = new_data.max;
22802507 trace_cpu_frequency_limits(policy);
2281
-
2282
- arch_set_max_freq_scale(policy->cpus, policy->max);
22832508
22842509 policy->cached_target_freq = UINT_MAX;
22852510
....@@ -2287,13 +2512,13 @@
22872512 policy->min, policy->max);
22882513
22892514 if (cpufreq_driver->setpolicy) {
2290
- policy->policy = new_policy->policy;
2515
+ policy->policy = new_pol;
22912516 pr_debug("setting range\n");
2292
- return cpufreq_driver->setpolicy(new_policy);
2517
+ return cpufreq_driver->setpolicy(policy);
22932518 }
22942519
2295
- if (new_policy->governor == policy->governor) {
2296
- pr_debug("cpufreq: governor limits update\n");
2520
+ if (new_gov == policy->governor) {
2521
+ pr_debug("governor limits update\n");
22972522 cpufreq_governor_limits(policy);
22982523 return 0;
22992524 }
....@@ -2309,12 +2534,12 @@
23092534 }
23102535
23112536 /* start new governor */
2312
- policy->governor = new_policy->governor;
2537
+ policy->governor = new_gov;
23132538 ret = cpufreq_init_governor(policy);
23142539 if (!ret) {
23152540 ret = cpufreq_start_governor(policy);
23162541 if (!ret) {
2317
- pr_debug("cpufreq: governor change\n");
2542
+ pr_debug("governor change\n");
23182543 return 0;
23192544 }
23202545 cpufreq_exit_governor(policy);
....@@ -2332,85 +2557,81 @@
23322557
23332558 return ret;
23342559 }
2560
+EXPORT_TRACEPOINT_SYMBOL_GPL(cpu_frequency_limits);
23352561
23362562 /**
2337
- * cpufreq_update_policy - re-evaluate an existing cpufreq policy
2338
- * @cpu: CPU which shall be re-evaluated
2563
+ * cpufreq_update_policy - Re-evaluate an existing cpufreq policy.
2564
+ * @cpu: CPU to re-evaluate the policy for.
23392565 *
2340
- * Useful for policy notifiers which have different necessities
2341
- * at different times.
2566
+ * Update the current frequency for the cpufreq policy of @cpu and use
2567
+ * cpufreq_set_policy() to re-apply the min and max limits, which triggers the
2568
+ * evaluation of policy notifiers and the cpufreq driver's ->verify() callback
2569
+ * for the policy in question, among other things.
23422570 */
23432571 void cpufreq_update_policy(unsigned int cpu)
23442572 {
2345
- struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
2346
- struct cpufreq_policy new_policy;
2573
+ struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu);
23472574
23482575 if (!policy)
23492576 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;
23602577
23612578 /*
23622579 * BIOS might change freq behind our back
23632580 * -> ask driver for current freq and notify governors about a change
23642581 */
2365
- if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
2366
- if (cpufreq_suspended)
2367
- goto unlock;
2582
+ if (cpufreq_driver->get && has_target() &&
2583
+ (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))
2584
+ goto unlock;
23682585
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);
2586
+ refresh_frequency_limits(policy);
23752587
23762588 unlock:
2377
- up_write(&policy->rwsem);
2378
-
2379
- cpufreq_cpu_put(policy);
2589
+ cpufreq_cpu_release(policy);
23802590 }
23812591 EXPORT_SYMBOL(cpufreq_update_policy);
2592
+
2593
+/**
2594
+ * cpufreq_update_limits - Update policy limits for a given CPU.
2595
+ * @cpu: CPU to update the policy limits for.
2596
+ *
2597
+ * Invoke the driver's ->update_limits callback if present or call
2598
+ * cpufreq_update_policy() for @cpu.
2599
+ */
2600
+void cpufreq_update_limits(unsigned int cpu)
2601
+{
2602
+ if (cpufreq_driver->update_limits)
2603
+ cpufreq_driver->update_limits(cpu);
2604
+ else
2605
+ cpufreq_update_policy(cpu);
2606
+}
2607
+EXPORT_SYMBOL_GPL(cpufreq_update_limits);
23822608
23832609 /*********************************************************************
23842610 * BOOST *
23852611 *********************************************************************/
2386
-static int cpufreq_boost_set_sw(int state)
2612
+static int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state)
23872613 {
2388
- struct cpufreq_policy *policy;
2389
- int ret = -EINVAL;
2614
+ int ret;
23902615
2391
- for_each_active_policy(policy) {
2392
- if (!policy->freq_table)
2393
- continue;
2616
+ if (!policy->freq_table)
2617
+ return -ENXIO;
23942618
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);
2619
+ ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table);
2620
+ if (ret) {
2621
+ pr_err("%s: Policy frequency update failed\n", __func__);
2622
+ return ret;
24072623 }
24082624
2409
- return ret;
2625
+ ret = freq_qos_update_request(policy->max_freq_req, policy->max);
2626
+ if (ret < 0)
2627
+ return ret;
2628
+
2629
+ return 0;
24102630 }
24112631
24122632 int cpufreq_boost_trigger_state(int state)
24132633 {
2634
+ struct cpufreq_policy *policy;
24142635 unsigned long flags;
24152636 int ret = 0;
24162637
....@@ -2421,22 +2642,32 @@
24212642 cpufreq_driver->boost_enabled = state;
24222643 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
24232644
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");
2645
+ get_online_cpus();
2646
+ for_each_active_policy(policy) {
2647
+ ret = cpufreq_driver->set_boost(policy, state);
2648
+ if (ret)
2649
+ goto err_reset_state;
24322650 }
2651
+ put_online_cpus();
2652
+
2653
+ return 0;
2654
+
2655
+err_reset_state:
2656
+ put_online_cpus();
2657
+
2658
+ write_lock_irqsave(&cpufreq_driver_lock, flags);
2659
+ cpufreq_driver->boost_enabled = !state;
2660
+ write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2661
+
2662
+ pr_err("%s: Cannot %s BOOST\n",
2663
+ __func__, state ? "enable" : "disable");
24332664
24342665 return ret;
24352666 }
24362667
24372668 static bool cpufreq_boost_supported(void)
24382669 {
2439
- return likely(cpufreq_driver) && cpufreq_driver->set_boost;
2670
+ return cpufreq_driver->set_boost;
24402671 }
24412672
24422673 static int create_boost_sysfs_file(void)
....@@ -2527,7 +2758,8 @@
25272758 driver_data->target) ||
25282759 (driver_data->setpolicy && (driver_data->target_index ||
25292760 driver_data->target)) ||
2530
- (!!driver_data->get_intermediate != !!driver_data->target_intermediate))
2761
+ (!driver_data->get_intermediate != !driver_data->target_intermediate) ||
2762
+ (!driver_data->online != !driver_data->offline))
25312763 return -EINVAL;
25322764
25332765 pr_debug("trying to register driver %s\n", driver_data->name);
....@@ -2543,6 +2775,15 @@
25432775 }
25442776 cpufreq_driver = driver_data;
25452777 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
2778
+
2779
+ /*
2780
+ * Mark support for the scheduler's frequency invariance engine for
2781
+ * drivers that implement target(), target_index() or fast_switch().
2782
+ */
2783
+ if (!cpufreq_driver->setpolicy) {
2784
+ static_branch_enable_cpuslocked(&cpufreq_freq_invariance);
2785
+ pr_debug("supports frequency invariance");
2786
+ }
25462787
25472788 if (driver_data->setpolicy)
25482789 driver_data->flags |= CPUFREQ_CONST_LOOPS;
....@@ -2592,7 +2833,7 @@
25922833 }
25932834 EXPORT_SYMBOL_GPL(cpufreq_register_driver);
25942835
2595
-/**
2836
+/*
25962837 * cpufreq_unregister_driver - unregister the current CPUFreq driver
25972838 *
25982839 * Unregister the current CPUFreq driver. Only call this if you have
....@@ -2613,6 +2854,7 @@
26132854 cpus_read_lock();
26142855 subsys_interface_unregister(&cpufreq_interface);
26152856 remove_boost_sysfs_file();
2857
+ static_branch_disable_cpuslocked(&cpufreq_freq_invariance);
26162858 cpuhp_remove_state_nocalls_cpuslocked(hp_online);
26172859
26182860 write_lock_irqsave(&cpufreq_driver_lock, flags);
....@@ -2626,18 +2868,21 @@
26262868 }
26272869 EXPORT_SYMBOL_GPL(cpufreq_unregister_driver);
26282870
2629
-struct kobject *cpufreq_global_kobject;
2630
-EXPORT_SYMBOL(cpufreq_global_kobject);
2631
-
26322871 static int __init cpufreq_core_init(void)
26332872 {
2873
+ struct cpufreq_governor *gov = cpufreq_default_governor();
2874
+
26342875 if (cpufreq_disabled())
26352876 return -ENODEV;
26362877
26372878 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj);
26382879 BUG_ON(!cpufreq_global_kobject);
26392880
2881
+ if (!strlen(default_governor))
2882
+ strncpy(default_governor, gov->name, CPUFREQ_NAME_LEN);
2883
+
26402884 return 0;
26412885 }
26422886 module_param(off, int, 0444);
2887
+module_param_string(default_governor, default_governor, CPUFREQ_NAME_LEN, 0444);
26432888 core_initcall(cpufreq_core_init);