hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
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,10 +445,14 @@
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);
452
+
453
+ arch_set_freq_scale(policy->related_cpus,
454
+ policy->cur,
455
+ policy->cpuinfo.max_freq);
423456
424457 policy->transition_ongoing = false;
425458 policy->transition_task = NULL;
....@@ -444,7 +477,7 @@
444477 mutex_lock(&cpufreq_transition_notifier_list.mutex);
445478
446479 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);
448481
449482 mutex_unlock(&cpufreq_transition_notifier_list.mutex);
450483 }
....@@ -499,6 +532,7 @@
499532 /**
500533 * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
501534 * one.
535
+ * @policy: associated policy to interrogate
502536 * @target_freq: target frequency to resolve.
503537 *
504538 * The target to driver frequency mapping is cached in the policy.
....@@ -509,11 +543,14 @@
509543 unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
510544 unsigned int target_freq)
511545 {
546
+ unsigned int old_target_freq = target_freq;
547
+
512548 target_freq = clamp_val(target_freq, policy->min, policy->max);
549
+ trace_android_vh_cpufreq_resolve_freq(policy, target_freq, old_target_freq);
513550 policy->cached_target_freq = target_freq;
514551
515552 if (cpufreq_driver->target_index) {
516
- int idx;
553
+ unsigned int idx;
517554
518555 idx = cpufreq_frequency_table_target(policy, target_freq,
519556 CPUFREQ_RELATION_L);
....@@ -596,56 +633,54 @@
596633 return NULL;
597634 }
598635
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)
604637 {
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;
610639
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;
617644
618
- mutex_lock(&cpufreq_governor_mutex);
645
+ if (!try_module_get(t->owner))
646
+ t = NULL;
619647
620
- t = find_governor(str_governor);
621
- if (!t) {
622
- int ret;
648
+unlock:
649
+ mutex_unlock(&cpufreq_governor_mutex);
623650
624
- mutex_unlock(&cpufreq_governor_mutex);
651
+ return t;
652
+}
625653
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;
629658
630
- mutex_lock(&cpufreq_governor_mutex);
659
+ if (!strncasecmp(str_governor, "powersave", CPUFREQ_NAME_LEN))
660
+ return CPUFREQ_POLICY_POWERSAVE;
631661
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;
646663 }
647664
648665 /**
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
+/*
649684 * cpufreq_per_cpu_attr_read() / show_##file_name() -
650685 * print out cpufreq information
651686 *
....@@ -660,8 +695,16 @@
660695 return sprintf(buf, "%u\n", policy->object); \
661696 }
662697
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
+
663707 show_one(cpuinfo_min_freq, cpuinfo.min_freq);
664
-show_one(cpuinfo_max_freq, cpuinfo.max_freq);
665708 show_one(cpuinfo_transition_latency, cpuinfo.transition_latency);
666709 show_one(scaling_min_freq, min);
667710 show_one(scaling_max_freq, max);
....@@ -679,47 +722,35 @@
679722 freq = arch_freq_get_on_cpu(policy->cpu);
680723 if (freq)
681724 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)
684726 ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu));
685727 else
686728 ret = sprintf(buf, "%u\n", policy->cur);
687729 return ret;
688730 }
689731
690
-static int cpufreq_set_policy(struct cpufreq_policy *policy,
691
- struct cpufreq_policy *new_policy);
692
-
693
-/**
732
+/*
694733 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
695734 */
696735 #define store_one(file_name, object) \
697736 static ssize_t store_##file_name \
698737 (struct cpufreq_policy *policy, const char *buf, size_t count) \
699738 { \
700
- int ret, temp; \
701
- struct cpufreq_policy new_policy; \
739
+ unsigned long val; \
740
+ int ret; \
702741 \
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); \
708743 if (ret != 1) \
709744 return -EINVAL; \
710745 \
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; \
717748 }
718749
719750 store_one(scaling_min_freq, min);
720751 store_one(scaling_max_freq, max);
721752
722
-/**
753
+/*
723754 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
724755 */
725756 static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy,
....@@ -733,7 +764,7 @@
733764 return sprintf(buf, "<unknown>\n");
734765 }
735766
736
-/**
767
+/*
737768 * show_scaling_governor - show the current policy for the specified CPU
738769 */
739770 static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
....@@ -748,34 +779,44 @@
748779 return -EINVAL;
749780 }
750781
751
-/**
782
+/*
752783 * store_scaling_governor - store policy for the specified CPU
753784 */
754785 static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
755786 const char *buf, size_t count)
756787 {
788
+ char str_governor[16];
757789 int ret;
758
- char str_governor[16];
759
- struct cpufreq_policy new_policy;
760
-
761
- memcpy(&new_policy, policy, sizeof(*policy));
762790
763791 ret = sscanf(buf, "%15s", str_governor);
764792 if (ret != 1)
765793 return -EINVAL;
766794
767
- if (cpufreq_parse_governor(str_governor, &new_policy))
768
- return -EINVAL;
795
+ if (cpufreq_driver->setpolicy) {
796
+ unsigned int new_pol;
769797
770
- ret = cpufreq_set_policy(policy, &new_policy);
798
+ new_pol = cpufreq_parse_policy(str_governor);
799
+ if (!new_pol)
800
+ return -EINVAL;
771801
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
+ }
774815
775816 return ret ? ret : count;
776817 }
777818
778
-/**
819
+/*
779820 * show_scaling_driver - show the cpufreq driver currently loaded
780821 */
781822 static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf)
....@@ -783,7 +824,7 @@
783824 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name);
784825 }
785826
786
-/**
827
+/*
787828 * show_scaling_available_governors - show the available CPUfreq governors
788829 */
789830 static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
....@@ -797,12 +838,14 @@
797838 goto out;
798839 }
799840
841
+ mutex_lock(&cpufreq_governor_mutex);
800842 for_each_governor(t) {
801843 if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char))
802844 - (CPUFREQ_NAME_LEN + 2)))
803
- goto out;
845
+ break;
804846 i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name);
805847 }
848
+ mutex_unlock(&cpufreq_governor_mutex);
806849 out:
807850 i += sprintf(&buf[i], "\n");
808851 return i;
....@@ -825,7 +868,7 @@
825868 }
826869 EXPORT_SYMBOL_GPL(cpufreq_show_cpus);
827870
828
-/**
871
+/*
829872 * show_related_cpus - show the CPUs affected by each transition even if
830873 * hw coordination is in use
831874 */
....@@ -834,7 +877,7 @@
834877 return cpufreq_show_cpus(policy->related_cpus, buf);
835878 }
836879
837
-/**
880
+/*
838881 * show_affected_cpus - show the CPUs affected by each transition
839882 */
840883 static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
....@@ -868,18 +911,16 @@
868911 return policy->governor->show_setspeed(policy, buf);
869912 }
870913
871
-/**
914
+/*
872915 * show_bios_limit - show the current cpufreq HW/BIOS limitation
873916 */
874917 static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
875918 {
876919 unsigned int limit;
877920 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);
883924 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
884925 }
885926
....@@ -978,11 +1019,10 @@
9781019 .release = cpufreq_sysfs_release,
9791020 };
9801021
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)
9821024 {
983
- struct device *dev = get_cpu_device(cpu);
984
-
985
- if (!dev)
1025
+ if (unlikely(!dev))
9861026 return;
9871027
9881028 if (cpumask_test_and_set_cpu(cpu, policy->real_cpus))
....@@ -1032,40 +1072,52 @@
10321072 return 0;
10331073 }
10341074
1035
-__weak struct cpufreq_governor *cpufreq_default_governor(void)
1036
-{
1037
- return NULL;
1038
-}
1039
-
10401075 static int cpufreq_init_policy(struct cpufreq_policy *policy)
10411076 {
10421077 struct cpufreq_governor *gov = NULL;
1043
- struct cpufreq_policy new_policy;
1078
+ unsigned int pol = CPUFREQ_POLICY_UNKNOWN;
1079
+ int ret;
10441080
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
+ }
10461090
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
+
10521096 } 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)
10551113 return -ENODATA;
10561114 }
10571115
1058
- new_policy.governor = gov;
1116
+ ret = cpufreq_set_policy(policy, gov, pol);
1117
+ if (gov)
1118
+ module_put(gov->owner);
10591119
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;
10691121 }
10701122
10711123 static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
....@@ -1091,61 +1143,43 @@
10911143 return ret;
10921144 }
10931145
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
+
10941156 static void handle_update(struct work_struct *work)
10951157 {
10961158 struct cpufreq_policy *policy =
10971159 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);
11011165 }
11021166
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)
11041169 {
1105
- struct cpufreq_policy *policy;
1106
- int ret;
1170
+ struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_min);
11071171
1108
- policy = kzalloc(sizeof(*policy), GFP_KERNEL);
1109
- if (!policy)
1110
- return NULL;
1172
+ schedule_work(&policy->update);
1173
+ return 0;
1174
+}
11111175
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);
11141180
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;
11491183 }
11501184
11511185 static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy)
....@@ -1170,6 +1204,89 @@
11701204 pr_debug("wait complete\n");
11711205 }
11721206
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
+
11731290 static void cpufreq_policy_free(struct cpufreq_policy *policy)
11741291 {
11751292 unsigned long flags;
....@@ -1182,6 +1299,27 @@
11821299 for_each_cpu(cpu, policy->related_cpus)
11831300 per_cpu(cpufreq_cpu_data, cpu) = NULL;
11841301 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);
11851323
11861324 cpufreq_policy_put_kobj(policy);
11871325 free_cpumask_var(policy->real_cpus);
....@@ -1220,28 +1358,44 @@
12201358 return -ENOMEM;
12211359 }
12221360
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
+ }
12241368
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));
12331373
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
+ }
12371384
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;
12391393
1240
- if (new_policy) {
12411394 /* related_cpus should at least include policy->cpus. */
12421395 cpumask_copy(policy->related_cpus, policy->cpus);
12431396 }
12441397
1398
+ down_write(&policy->rwsem);
12451399 /*
12461400 * affected cpus must always be the one, which are online. We aren't
12471401 * managing offline cpus here.
....@@ -1249,19 +1403,49 @@
12491403 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
12501404
12511405 if (new_policy) {
1252
- policy->user_policy.min = policy->min;
1253
- policy->user_policy.max = policy->max;
1254
-
12551406 for_each_cpu(j, policy->related_cpus) {
12561407 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));
12581409 }
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);
12621446 }
12631447
1264
- if (cpufreq_driver->get && !cpufreq_driver->setpolicy) {
1448
+ if (cpufreq_driver->get && has_target()) {
12651449 policy->cur = cpufreq_driver->get(policy->cpu);
12661450 if (!policy->cur) {
12671451 pr_err("%s: ->get() failed\n", __func__);
....@@ -1289,14 +1473,13 @@
12891473 */
12901474 if ((cpufreq_driver->flags & CPUFREQ_NEED_INITIAL_FREQ_CHECK)
12911475 && has_target()) {
1476
+ unsigned int old_freq = policy->cur;
1477
+
12921478 /* 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);
12941480 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);
13001483
13011484 /*
13021485 * Reaching here after boot in a few seconds may not
....@@ -1304,8 +1487,8 @@
13041487 * frequency for longer duration. Hence, a BUG_ON().
13051488 */
13061489 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);
13091492 }
13101493 }
13111494
....@@ -1326,8 +1509,6 @@
13261509 if (ret) {
13271510 pr_err("%s: Failed to initialize policy for cpu: %d (%d)\n",
13281511 __func__, cpu, ret);
1329
- /* cpufreq_policy_free() will notify based on this */
1330
- new_policy = false;
13311512 goto out_destroy_policy;
13321513 }
13331514
....@@ -1339,8 +1520,7 @@
13391520 if (cpufreq_driver->ready)
13401521 cpufreq_driver->ready(policy);
13411522
1342
- if (IS_ENABLED(CONFIG_CPU_THERMAL) &&
1343
- cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV)
1523
+ if (cpufreq_thermal_control_enabled(cpufreq_driver))
13441524 policy->cdev = of_cpufreq_cooling_register(policy);
13451525
13461526 pr_debug("initialization complete\n");
....@@ -1352,6 +1532,10 @@
13521532 remove_cpu_dev_symlink(policy, get_cpu_device(j));
13531533
13541534 up_write(&policy->rwsem);
1535
+
1536
+out_offline_policy:
1537
+ if (cpufreq_driver->offline)
1538
+ cpufreq_driver->offline(policy);
13551539
13561540 out_exit_policy:
13571541 if (cpufreq_driver->exit)
....@@ -1384,7 +1568,7 @@
13841568 /* Create sysfs link on CPU registration */
13851569 policy = per_cpu(cpufreq_cpu_data, cpu);
13861570 if (policy)
1387
- add_cpu_dev_symlink(policy, cpu);
1571
+ add_cpu_dev_symlink(policy, cpu, dev);
13881572
13891573 return 0;
13901574 }
....@@ -1430,8 +1614,7 @@
14301614 goto unlock;
14311615 }
14321616
1433
- if (IS_ENABLED(CONFIG_CPU_THERMAL) &&
1434
- cpufreq_driver->flags & CPUFREQ_IS_COOLING_DEV) {
1617
+ if (cpufreq_thermal_control_enabled(cpufreq_driver)) {
14351618 cpufreq_cooling_unregister(policy->cdev);
14361619 policy->cdev = NULL;
14371620 }
....@@ -1443,11 +1626,12 @@
14431626 cpufreq_exit_governor(policy);
14441627
14451628 /*
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.
14491631 */
1450
- if (cpufreq_driver->exit) {
1632
+ if (cpufreq_driver->offline) {
1633
+ cpufreq_driver->offline(policy);
1634
+ } else if (cpufreq_driver->exit) {
14511635 cpufreq_driver->exit(policy);
14521636 policy->freq_table = NULL;
14531637 }
....@@ -1457,7 +1641,7 @@
14571641 return 0;
14581642 }
14591643
1460
-/**
1644
+/*
14611645 * cpufreq_remove_dev - remove a CPU device
14621646 *
14631647 * Removes the cpufreq interface for a CPU device.
....@@ -1476,8 +1660,13 @@
14761660 cpumask_clear_cpu(cpu, policy->real_cpus);
14771661 remove_cpu_dev_symlink(policy, dev);
14781662
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
+
14801668 cpufreq_policy_free(policy);
1669
+ }
14811670 }
14821671
14831672 /**
....@@ -1502,6 +1691,30 @@
15021691
15031692 cpufreq_freq_transition_begin(policy, &freqs);
15041693 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;
15051718 }
15061719
15071720 /**
....@@ -1557,33 +1770,32 @@
15571770 }
15581771 EXPORT_SYMBOL(cpufreq_quick_get_max);
15591772
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)
15611780 {
1781
+ struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
15621782 unsigned int ret_freq = 0;
15631783
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);
15841787 }
15851788
15861789 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);
15871799 }
15881800
15891801 /**
....@@ -1599,7 +1811,8 @@
15991811
16001812 if (policy) {
16011813 down_read(&policy->rwsem);
1602
- ret_freq = __cpufreq_get(policy);
1814
+ if (cpufreq_driver->get)
1815
+ ret_freq = __cpufreq_get(policy);
16031816 up_read(&policy->rwsem);
16041817
16051818 cpufreq_cpu_put(policy);
....@@ -1608,24 +1821,6 @@
16081821 return ret_freq;
16091822 }
16101823 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
-}
16291824
16301825 static struct subsys_interface cpufreq_interface = {
16311826 .name = "cpufreq",
....@@ -1688,8 +1883,8 @@
16881883 }
16891884
16901885 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);
16931888 }
16941889
16951890 suspend:
....@@ -1734,6 +1929,18 @@
17341929 __func__, policy);
17351930 }
17361931 }
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);
17371944 }
17381945
17391946 /**
....@@ -1888,15 +2095,30 @@
18882095 unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,
18892096 unsigned int target_freq)
18902097 {
1891
- int ret;
2098
+ unsigned int freq;
2099
+ unsigned int old_target_freq = target_freq;
2100
+ int cpu;
18922101
18932102 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);
18942105
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;
18982108
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;
19002122 }
19012123 EXPORT_SYMBOL_GPL(cpufreq_driver_fast_switch);
19022124
....@@ -1993,11 +2215,9 @@
19932215 if (cpufreq_disabled())
19942216 return -ENODEV;
19952217
1996
-#ifdef CONFIG_ARM_ROCKCHIP_CPUFREQ
1997
- target_freq = rockchip_cpufreq_adjust_target(policy->cpu, target_freq);
1998
-#endif
19992218 /* Make sure that target_freq is within supported range */
20002219 target_freq = clamp_val(target_freq, policy->min, policy->max);
2220
+ trace_android_vh_cpufreq_target(policy, target_freq, old_target_freq);
20012221
20022222 pr_debug("target for CPU %u: %u kHz, relation %u, requested %u kHz\n",
20032223 policy->cpu, target_freq, relation, old_target_freq);
....@@ -2008,7 +2228,8 @@
20082228 * exactly same freq is called again and so we can save on few function
20092229 * calls.
20102230 */
2011
- if (target_freq == policy->cur)
2231
+ if (target_freq == policy->cur &&
2232
+ !(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS))
20122233 return 0;
20132234
20142235 /* Save last value to restore later on errors */
....@@ -2030,7 +2251,7 @@
20302251 unsigned int target_freq,
20312252 unsigned int relation)
20322253 {
2033
- int ret = -EINVAL;
2254
+ int ret;
20342255
20352256 down_write(&policy->rwsem);
20362257
....@@ -2062,7 +2283,7 @@
20622283 return -EINVAL;
20632284
20642285 /* Platform doesn't want dynamic frequency switching ? */
2065
- if (policy->governor->dynamic_switching &&
2286
+ if (policy->governor->flags & CPUFREQ_GOV_DYNAMIC_SWITCHING &&
20662287 cpufreq_driver->flags & CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING) {
20672288 struct cpufreq_governor *gov = cpufreq_fallback_governor();
20682289
....@@ -2088,6 +2309,8 @@
20882309 }
20892310 }
20902311
2312
+ policy->strict_target = !!(policy->governor->flags & CPUFREQ_GOV_STRICT_TARGET);
2313
+
20912314 return 0;
20922315 }
20932316
....@@ -2104,7 +2327,7 @@
21042327 module_put(policy->governor->owner);
21052328 }
21062329
2107
-static int cpufreq_start_governor(struct cpufreq_policy *policy)
2330
+int cpufreq_start_governor(struct cpufreq_policy *policy)
21082331 {
21092332 int ret;
21102333
....@@ -2116,8 +2339,8 @@
21162339
21172340 pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
21182341
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);
21212344
21222345 if (policy->governor->start) {
21232346 ret = policy->governor->start(policy);
....@@ -2131,7 +2354,7 @@
21312354 return 0;
21322355 }
21332356
2134
-static void cpufreq_stop_governor(struct cpufreq_policy *policy)
2357
+void cpufreq_stop_governor(struct cpufreq_policy *policy)
21352358 {
21362359 if (cpufreq_suspended || !policy->governor)
21372360 return;
....@@ -2212,6 +2435,7 @@
22122435 * cpufreq_get_policy - get the current cpufreq_policy
22132436 * @policy: struct cpufreq_policy into which the current cpufreq_policy
22142437 * is written
2438
+ * @cpu: CPU to find the policy for
22152439 *
22162440 * Reads the current cpufreq policy.
22172441 */
....@@ -2232,54 +2456,53 @@
22322456 }
22332457 EXPORT_SYMBOL(cpufreq_get_policy);
22342458
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.
22382473 */
22392474 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)
22412477 {
2478
+ struct cpufreq_policy_data new_data;
22422479 struct cpufreq_governor *old_gov;
22432480 int ret;
22442481
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;
22502485 /*
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.
22692488 */
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);
22712500 if (ret)
22722501 return ret;
22732502
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;
22802505 trace_cpu_frequency_limits(policy);
2281
-
2282
- arch_set_max_freq_scale(policy->cpus, policy->max);
22832506
22842507 policy->cached_target_freq = UINT_MAX;
22852508
....@@ -2287,13 +2510,13 @@
22872510 policy->min, policy->max);
22882511
22892512 if (cpufreq_driver->setpolicy) {
2290
- policy->policy = new_policy->policy;
2513
+ policy->policy = new_pol;
22912514 pr_debug("setting range\n");
2292
- return cpufreq_driver->setpolicy(new_policy);
2515
+ return cpufreq_driver->setpolicy(policy);
22932516 }
22942517
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");
22972520 cpufreq_governor_limits(policy);
22982521 return 0;
22992522 }
....@@ -2309,12 +2532,12 @@
23092532 }
23102533
23112534 /* start new governor */
2312
- policy->governor = new_policy->governor;
2535
+ policy->governor = new_gov;
23132536 ret = cpufreq_init_governor(policy);
23142537 if (!ret) {
23152538 ret = cpufreq_start_governor(policy);
23162539 if (!ret) {
2317
- pr_debug("cpufreq: governor change\n");
2540
+ pr_debug("governor change\n");
23182541 return 0;
23192542 }
23202543 cpufreq_exit_governor(policy);
....@@ -2332,85 +2555,81 @@
23322555
23332556 return ret;
23342557 }
2558
+EXPORT_TRACEPOINT_SYMBOL_GPL(cpu_frequency_limits);
23352559
23362560 /**
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.
23392563 *
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.
23422568 */
23432569 void cpufreq_update_policy(unsigned int cpu)
23442570 {
2345
- struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
2346
- struct cpufreq_policy new_policy;
2571
+ struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu);
23472572
23482573 if (!policy)
23492574 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;
23602575
23612576 /*
23622577 * BIOS might change freq behind our back
23632578 * -> ask driver for current freq and notify governors about a change
23642579 */
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;
23682583
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);
23752585
23762586 unlock:
2377
- up_write(&policy->rwsem);
2378
-
2379
- cpufreq_cpu_put(policy);
2587
+ cpufreq_cpu_release(policy);
23802588 }
23812589 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);
23822606
23832607 /*********************************************************************
23842608 * BOOST *
23852609 *********************************************************************/
2386
-static int cpufreq_boost_set_sw(int state)
2610
+static int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state)
23872611 {
2388
- struct cpufreq_policy *policy;
2389
- int ret = -EINVAL;
2612
+ int ret;
23902613
2391
- for_each_active_policy(policy) {
2392
- if (!policy->freq_table)
2393
- continue;
2614
+ if (!policy->freq_table)
2615
+ return -ENXIO;
23942616
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;
24072621 }
24082622
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;
24102628 }
24112629
24122630 int cpufreq_boost_trigger_state(int state)
24132631 {
2632
+ struct cpufreq_policy *policy;
24142633 unsigned long flags;
24152634 int ret = 0;
24162635
....@@ -2421,22 +2640,32 @@
24212640 cpufreq_driver->boost_enabled = state;
24222641 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
24232642
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;
24322648 }
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");
24332662
24342663 return ret;
24352664 }
24362665
24372666 static bool cpufreq_boost_supported(void)
24382667 {
2439
- return likely(cpufreq_driver) && cpufreq_driver->set_boost;
2668
+ return cpufreq_driver->set_boost;
24402669 }
24412670
24422671 static int create_boost_sysfs_file(void)
....@@ -2527,7 +2756,8 @@
25272756 driver_data->target) ||
25282757 (driver_data->setpolicy && (driver_data->target_index ||
25292758 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))
25312761 return -EINVAL;
25322762
25332763 pr_debug("trying to register driver %s\n", driver_data->name);
....@@ -2543,6 +2773,15 @@
25432773 }
25442774 cpufreq_driver = driver_data;
25452775 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
+ }
25462785
25472786 if (driver_data->setpolicy)
25482787 driver_data->flags |= CPUFREQ_CONST_LOOPS;
....@@ -2592,7 +2831,7 @@
25922831 }
25932832 EXPORT_SYMBOL_GPL(cpufreq_register_driver);
25942833
2595
-/**
2834
+/*
25962835 * cpufreq_unregister_driver - unregister the current CPUFreq driver
25972836 *
25982837 * Unregister the current CPUFreq driver. Only call this if you have
....@@ -2613,6 +2852,7 @@
26132852 cpus_read_lock();
26142853 subsys_interface_unregister(&cpufreq_interface);
26152854 remove_boost_sysfs_file();
2855
+ static_branch_disable_cpuslocked(&cpufreq_freq_invariance);
26162856 cpuhp_remove_state_nocalls_cpuslocked(hp_online);
26172857
26182858 write_lock_irqsave(&cpufreq_driver_lock, flags);
....@@ -2626,18 +2866,21 @@
26262866 }
26272867 EXPORT_SYMBOL_GPL(cpufreq_unregister_driver);
26282868
2629
-struct kobject *cpufreq_global_kobject;
2630
-EXPORT_SYMBOL(cpufreq_global_kobject);
2631
-
26322869 static int __init cpufreq_core_init(void)
26332870 {
2871
+ struct cpufreq_governor *gov = cpufreq_default_governor();
2872
+
26342873 if (cpufreq_disabled())
26352874 return -ENODEV;
26362875
26372876 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj);
26382877 BUG_ON(!cpufreq_global_kobject);
26392878
2879
+ if (!strlen(default_governor))
2880
+ strncpy(default_governor, gov->name, CPUFREQ_NAME_LEN);
2881
+
26402882 return 0;
26412883 }
26422884 module_param(off, int, 0444);
2885
+module_param_string(default_governor, default_governor, CPUFREQ_NAME_LEN, 0444);
26432886 core_initcall(cpufreq_core_init);