cpufreq.c (38fd2c202a3d82bc12430bce5789fa2c2a406f71) | cpufreq.c (d3916691c90dfc9f08328d5cef8181e9ea508c55) |
---|---|
1/* 2 * linux/drivers/cpufreq/cpufreq.c 3 * 4 * Copyright (C) 2001 Russell King 5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> 6 * (C) 2013 Viresh Kumar <viresh.kumar@linaro.org> 7 * 8 * Oct 2005 - Ashok Raj <ashok.raj@intel.com> --- 25 unchanged lines hidden (view full) --- 34 * The "cpufreq driver" - the arch- or hardware-dependent low 35 * level driver of CPUFreq support, and its spinlock. This lock 36 * also protects the cpufreq_cpu_data array. 37 */ 38static struct cpufreq_driver *cpufreq_driver; 39static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data); 40static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data_fallback); 41static DEFINE_RWLOCK(cpufreq_driver_lock); | 1/* 2 * linux/drivers/cpufreq/cpufreq.c 3 * 4 * Copyright (C) 2001 Russell King 5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> 6 * (C) 2013 Viresh Kumar <viresh.kumar@linaro.org> 7 * 8 * Oct 2005 - Ashok Raj <ashok.raj@intel.com> --- 25 unchanged lines hidden (view full) --- 34 * The "cpufreq driver" - the arch- or hardware-dependent low 35 * level driver of CPUFreq support, and its spinlock. This lock 36 * also protects the cpufreq_cpu_data array. 37 */ 38static struct cpufreq_driver *cpufreq_driver; 39static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data); 40static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data_fallback); 41static DEFINE_RWLOCK(cpufreq_driver_lock); |
42static DEFINE_MUTEX(cpufreq_governor_lock); | 42DEFINE_MUTEX(cpufreq_governor_lock); |
43static LIST_HEAD(cpufreq_policy_list); 44 45#ifdef CONFIG_HOTPLUG_CPU 46/* This one keeps track of the previously set governor of a removed CPU */ 47static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor); 48#endif 49 50static inline bool has_target(void) --- 264 unchanged lines hidden (view full) --- 315void cpufreq_notify_transition(struct cpufreq_policy *policy, 316 struct cpufreq_freqs *freqs, unsigned int state) 317{ 318 for_each_cpu(freqs->cpu, policy->cpus) 319 __cpufreq_notify_transition(policy, freqs, state); 320} 321EXPORT_SYMBOL_GPL(cpufreq_notify_transition); 322 | 43static LIST_HEAD(cpufreq_policy_list); 44 45#ifdef CONFIG_HOTPLUG_CPU 46/* This one keeps track of the previously set governor of a removed CPU */ 47static DEFINE_PER_CPU(char[CPUFREQ_NAME_LEN], cpufreq_cpu_governor); 48#endif 49 50static inline bool has_target(void) --- 264 unchanged lines hidden (view full) --- 315void cpufreq_notify_transition(struct cpufreq_policy *policy, 316 struct cpufreq_freqs *freqs, unsigned int state) 317{ 318 for_each_cpu(freqs->cpu, policy->cpus) 319 __cpufreq_notify_transition(policy, freqs, state); 320} 321EXPORT_SYMBOL_GPL(cpufreq_notify_transition); 322 |
323/* Do post notifications when there are chances that transition has failed */ 324void cpufreq_notify_post_transition(struct cpufreq_policy *policy, 325 struct cpufreq_freqs *freqs, int transition_failed) 326{ 327 cpufreq_notify_transition(policy, freqs, CPUFREQ_POSTCHANGE); 328 if (!transition_failed) 329 return; |
|
323 | 330 |
331 swap(freqs->old, freqs->new); 332 cpufreq_notify_transition(policy, freqs, CPUFREQ_PRECHANGE); 333 cpufreq_notify_transition(policy, freqs, CPUFREQ_POSTCHANGE); 334} 335EXPORT_SYMBOL_GPL(cpufreq_notify_post_transition); 336 337 |
|
324/********************************************************************* 325 * SYSFS INTERFACE * 326 *********************************************************************/ 327 328static struct cpufreq_governor *__find_governor(const char *str_governor) 329{ 330 struct cpufreq_governor *t; 331 --- 722 unchanged lines hidden (view full) --- 1054 if (cpufreq_driver->get) { 1055 policy->cur = cpufreq_driver->get(policy->cpu); 1056 if (!policy->cur) { 1057 pr_err("%s: ->get() failed\n", __func__); 1058 goto err_get_freq; 1059 } 1060 } 1061 | 338/********************************************************************* 339 * SYSFS INTERFACE * 340 *********************************************************************/ 341 342static struct cpufreq_governor *__find_governor(const char *str_governor) 343{ 344 struct cpufreq_governor *t; 345 --- 722 unchanged lines hidden (view full) --- 1068 if (cpufreq_driver->get) { 1069 policy->cur = cpufreq_driver->get(policy->cpu); 1070 if (!policy->cur) { 1071 pr_err("%s: ->get() failed\n", __func__); 1072 goto err_get_freq; 1073 } 1074 } 1075 |
1076 /* 1077 * Sometimes boot loaders set CPU frequency to a value outside of 1078 * frequency table present with cpufreq core. In such cases CPU might be 1079 * unstable if it has to run on that frequency for long duration of time 1080 * and so its better to set it to a frequency which is specified in 1081 * freq-table. This also makes cpufreq stats inconsistent as 1082 * cpufreq-stats would fail to register because current frequency of CPU 1083 * isn't found in freq-table. 1084 * 1085 * Because we don't want this change to effect boot process badly, we go 1086 * for the next freq which is >= policy->cur ('cur' must be set by now, 1087 * otherwise we will end up setting freq to lowest of the table as 'cur' 1088 * is initialized to zero). 1089 * 1090 * We are passing target-freq as "policy->cur - 1" otherwise 1091 * __cpufreq_driver_target() would simply fail, as policy->cur will be 1092 * equal to target-freq. 1093 */ 1094 if ((cpufreq_driver->flags & CPUFREQ_NEED_INITIAL_FREQ_CHECK) 1095 && has_target()) { 1096 /* Are we running at unknown frequency ? */ 1097 ret = cpufreq_frequency_table_get_index(policy, policy->cur); 1098 if (ret == -EINVAL) { 1099 /* Warn user and fix it */ 1100 pr_warn("%s: CPU%d: Running at unlisted freq: %u KHz\n", 1101 __func__, policy->cpu, policy->cur); 1102 ret = __cpufreq_driver_target(policy, policy->cur - 1, 1103 CPUFREQ_RELATION_L); 1104 1105 /* 1106 * Reaching here after boot in a few seconds may not 1107 * mean that system will remain stable at "unknown" 1108 * frequency for longer duration. Hence, a BUG_ON(). 1109 */ 1110 BUG_ON(ret); 1111 pr_warn("%s: CPU%d: Unlisted initial frequency changed to: %u KHz\n", 1112 __func__, policy->cpu, policy->cur); 1113 } 1114 } 1115 |
|
1062 /* related cpus should atleast have policy->cpus */ 1063 cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus); 1064 1065 /* 1066 * affected cpus must always be the one, which are online. We aren't 1067 * managing offline cpus here. 1068 */ 1069 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); --- 650 unchanged lines hidden (view full) --- 1720 CPUFREQ_PRECHANGE); 1721 } 1722 1723 retval = cpufreq_driver->target_index(policy, index); 1724 if (retval) 1725 pr_err("%s: Failed to change cpu frequency: %d\n", 1726 __func__, retval); 1727 | 1116 /* related cpus should atleast have policy->cpus */ 1117 cpumask_or(policy->related_cpus, policy->related_cpus, policy->cpus); 1118 1119 /* 1120 * affected cpus must always be the one, which are online. We aren't 1121 * managing offline cpus here. 1122 */ 1123 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); --- 650 unchanged lines hidden (view full) --- 1774 CPUFREQ_PRECHANGE); 1775 } 1776 1777 retval = cpufreq_driver->target_index(policy, index); 1778 if (retval) 1779 pr_err("%s: Failed to change cpu frequency: %d\n", 1780 __func__, retval); 1781 |
1728 if (notify) { 1729 /* 1730 * Notify with old freq in case we failed to change 1731 * frequency 1732 */ 1733 if (retval) 1734 freqs.new = freqs.old; 1735 1736 cpufreq_notify_transition(policy, &freqs, 1737 CPUFREQ_POSTCHANGE); 1738 } | 1782 if (notify) 1783 cpufreq_notify_post_transition(policy, &freqs, retval); |
1739 } 1740 1741out: 1742 return retval; 1743} 1744EXPORT_SYMBOL_GPL(__cpufreq_driver_target); 1745 1746int cpufreq_driver_target(struct cpufreq_policy *policy, --- 496 unchanged lines hidden --- | 1784 } 1785 1786out: 1787 return retval; 1788} 1789EXPORT_SYMBOL_GPL(__cpufreq_driver_target); 1790 1791int cpufreq_driver_target(struct cpufreq_policy *policy, --- 496 unchanged lines hidden --- |