aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/cpufreq/cpufreq.c45
-rw-r--r--drivers/cpufreq/cpufreq_stats.c24
-rw-r--r--drivers/cpufreq/freq_table.c12
3 files changed, 42 insertions, 39 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 1d41496ed2f8..ee1df0d45e81 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -38,10 +38,10 @@
38 * also protects the cpufreq_cpu_data array. 38 * also protects the cpufreq_cpu_data array.
39 */ 39 */
40static struct cpufreq_driver *cpufreq_driver; 40static struct cpufreq_driver *cpufreq_driver;
41static struct cpufreq_policy *cpufreq_cpu_data[NR_CPUS]; 41static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
42#ifdef CONFIG_HOTPLUG_CPU 42#ifdef CONFIG_HOTPLUG_CPU
43/* This one keeps track of the previously set governor of a removed CPU */ 43/* This one keeps track of the previously set governor of a removed CPU */
44static struct cpufreq_governor *cpufreq_cpu_governor[NR_CPUS]; 44static DEFINE_PER_CPU(struct cpufreq_governor *, cpufreq_cpu_governor);
45#endif 45#endif
46static DEFINE_SPINLOCK(cpufreq_driver_lock); 46static DEFINE_SPINLOCK(cpufreq_driver_lock);
47 47
@@ -135,7 +135,7 @@ struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
135 struct cpufreq_policy *data; 135 struct cpufreq_policy *data;
136 unsigned long flags; 136 unsigned long flags;
137 137
138 if (cpu >= NR_CPUS) 138 if (cpu >= nr_cpu_ids)
139 goto err_out; 139 goto err_out;
140 140
141 /* get the cpufreq driver */ 141 /* get the cpufreq driver */
@@ -149,7 +149,7 @@ struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
149 149
150 150
151 /* get the CPU */ 151 /* get the CPU */
152 data = cpufreq_cpu_data[cpu]; 152 data = per_cpu(cpufreq_cpu_data, cpu);
153 153
154 if (!data) 154 if (!data)
155 goto err_out_put_module; 155 goto err_out_put_module;
@@ -327,7 +327,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state)
327 dprintk("notification %u of frequency transition to %u kHz\n", 327 dprintk("notification %u of frequency transition to %u kHz\n",
328 state, freqs->new); 328 state, freqs->new);
329 329
330 policy = cpufreq_cpu_data[freqs->cpu]; 330 policy = per_cpu(cpufreq_cpu_data, freqs->cpu);
331 switch (state) { 331 switch (state) {
332 332
333 case CPUFREQ_PRECHANGE: 333 case CPUFREQ_PRECHANGE:
@@ -828,8 +828,8 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
828#ifdef CONFIG_SMP 828#ifdef CONFIG_SMP
829 829
830#ifdef CONFIG_HOTPLUG_CPU 830#ifdef CONFIG_HOTPLUG_CPU
831 if (cpufreq_cpu_governor[cpu]){ 831 if (per_cpu(cpufreq_cpu_governor, cpu)) {
832 policy->governor = cpufreq_cpu_governor[cpu]; 832 policy->governor = per_cpu(cpufreq_cpu_governor, cpu);
833 dprintk("Restoring governor %s for cpu %d\n", 833 dprintk("Restoring governor %s for cpu %d\n",
834 policy->governor->name, cpu); 834 policy->governor->name, cpu);
835 } 835 }
@@ -854,7 +854,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
854 854
855 spin_lock_irqsave(&cpufreq_driver_lock, flags); 855 spin_lock_irqsave(&cpufreq_driver_lock, flags);
856 managed_policy->cpus = policy->cpus; 856 managed_policy->cpus = policy->cpus;
857 cpufreq_cpu_data[cpu] = managed_policy; 857 per_cpu(cpufreq_cpu_data, cpu) = managed_policy;
858 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 858 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
859 859
860 dprintk("CPU already managed, adding link\n"); 860 dprintk("CPU already managed, adding link\n");
@@ -899,7 +899,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
899 899
900 spin_lock_irqsave(&cpufreq_driver_lock, flags); 900 spin_lock_irqsave(&cpufreq_driver_lock, flags);
901 for_each_cpu_mask(j, policy->cpus) { 901 for_each_cpu_mask(j, policy->cpus) {
902 cpufreq_cpu_data[j] = policy; 902 per_cpu(cpufreq_cpu_data, j) = policy;
903 per_cpu(policy_cpu, j) = policy->cpu; 903 per_cpu(policy_cpu, j) = policy->cpu;
904 } 904 }
905 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 905 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
@@ -946,7 +946,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
946err_out_unregister: 946err_out_unregister:
947 spin_lock_irqsave(&cpufreq_driver_lock, flags); 947 spin_lock_irqsave(&cpufreq_driver_lock, flags);
948 for_each_cpu_mask(j, policy->cpus) 948 for_each_cpu_mask(j, policy->cpus)
949 cpufreq_cpu_data[j] = NULL; 949 per_cpu(cpufreq_cpu_data, j) = NULL;
950 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 950 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
951 951
952 kobject_put(&policy->kobj); 952 kobject_put(&policy->kobj);
@@ -989,7 +989,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
989 dprintk("unregistering CPU %u\n", cpu); 989 dprintk("unregistering CPU %u\n", cpu);
990 990
991 spin_lock_irqsave(&cpufreq_driver_lock, flags); 991 spin_lock_irqsave(&cpufreq_driver_lock, flags);
992 data = cpufreq_cpu_data[cpu]; 992 data = per_cpu(cpufreq_cpu_data, cpu);
993 993
994 if (!data) { 994 if (!data) {
995 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 995 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
@@ -997,7 +997,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
997 unlock_policy_rwsem_write(cpu); 997 unlock_policy_rwsem_write(cpu);
998 return -EINVAL; 998 return -EINVAL;
999 } 999 }
1000 cpufreq_cpu_data[cpu] = NULL; 1000 per_cpu(cpufreq_cpu_data, cpu) = NULL;
1001 1001
1002 1002
1003#ifdef CONFIG_SMP 1003#ifdef CONFIG_SMP
@@ -1019,19 +1019,19 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
1019#ifdef CONFIG_SMP 1019#ifdef CONFIG_SMP
1020 1020
1021#ifdef CONFIG_HOTPLUG_CPU 1021#ifdef CONFIG_HOTPLUG_CPU
1022 cpufreq_cpu_governor[cpu] = data->governor; 1022 per_cpu(cpufreq_cpu_governor, cpu) = data->governor;
1023#endif 1023#endif
1024 1024
1025 /* if we have other CPUs still registered, we need to unlink them, 1025 /* if we have other CPUs still registered, we need to unlink them,
1026 * or else wait_for_completion below will lock up. Clean the 1026 * or else wait_for_completion below will lock up. Clean the
1027 * cpufreq_cpu_data[] while holding the lock, and remove the sysfs 1027 * per_cpu(cpufreq_cpu_data) while holding the lock, and remove
1028 * links afterwards. 1028 * the sysfs links afterwards.
1029 */ 1029 */
1030 if (unlikely(cpus_weight(data->cpus) > 1)) { 1030 if (unlikely(cpus_weight(data->cpus) > 1)) {
1031 for_each_cpu_mask(j, data->cpus) { 1031 for_each_cpu_mask(j, data->cpus) {
1032 if (j == cpu) 1032 if (j == cpu)
1033 continue; 1033 continue;
1034 cpufreq_cpu_data[j] = NULL; 1034 per_cpu(cpufreq_cpu_data, j) = NULL;
1035 } 1035 }
1036 } 1036 }
1037 1037
@@ -1043,7 +1043,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
1043 continue; 1043 continue;
1044 dprintk("removing link for cpu %u\n", j); 1044 dprintk("removing link for cpu %u\n", j);
1045#ifdef CONFIG_HOTPLUG_CPU 1045#ifdef CONFIG_HOTPLUG_CPU
1046 cpufreq_cpu_governor[j] = data->governor; 1046 per_cpu(cpufreq_cpu_governor, j) = data->governor;
1047#endif 1047#endif
1048 cpu_sys_dev = get_cpu_sysdev(j); 1048 cpu_sys_dev = get_cpu_sysdev(j);
1049 sysfs_remove_link(&cpu_sys_dev->kobj, "cpufreq"); 1049 sysfs_remove_link(&cpu_sys_dev->kobj, "cpufreq");
@@ -1153,7 +1153,7 @@ EXPORT_SYMBOL(cpufreq_quick_get);
1153 1153
1154static unsigned int __cpufreq_get(unsigned int cpu) 1154static unsigned int __cpufreq_get(unsigned int cpu)
1155{ 1155{
1156 struct cpufreq_policy *policy = cpufreq_cpu_data[cpu]; 1156 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
1157 unsigned int ret_freq = 0; 1157 unsigned int ret_freq = 0;
1158 1158
1159 if (!cpufreq_driver->get) 1159 if (!cpufreq_driver->get)
@@ -1822,16 +1822,19 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
1822 cpufreq_driver = driver_data; 1822 cpufreq_driver = driver_data;
1823 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 1823 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1824 1824
1825 ret = sysdev_driver_register(&cpu_sysdev_class,&cpufreq_sysdev_driver); 1825 ret = sysdev_driver_register(&cpu_sysdev_class,
1826 &cpufreq_sysdev_driver);
1826 1827
1827 if ((!ret) && !(cpufreq_driver->flags & CPUFREQ_STICKY)) { 1828 if ((!ret) && !(cpufreq_driver->flags & CPUFREQ_STICKY)) {
1828 int i; 1829 int i;
1829 ret = -ENODEV; 1830 ret = -ENODEV;
1830 1831
1831 /* check for at least one working CPU */ 1832 /* check for at least one working CPU */
1832 for (i=0; i<NR_CPUS; i++) 1833 for (i = 0; i < nr_cpu_ids; i++)
1833 if (cpufreq_cpu_data[i]) 1834 if (cpu_possible(i) && per_cpu(cpufreq_cpu_data, i)) {
1834 ret = 0; 1835 ret = 0;
1836 break;
1837 }
1835 1838
1836 /* if all ->init() calls failed, unregister */ 1839 /* if all ->init() calls failed, unregister */
1837 if (ret) { 1840 if (ret) {
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index ae70d63a8b26..c0ff97d375d7 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -43,7 +43,7 @@ struct cpufreq_stats {
43#endif 43#endif
44}; 44};
45 45
46static struct cpufreq_stats *cpufreq_stats_table[NR_CPUS]; 46static DEFINE_PER_CPU(struct cpufreq_stats *, cpufreq_stats_table);
47 47
48struct cpufreq_stats_attribute { 48struct cpufreq_stats_attribute {
49 struct attribute attr; 49 struct attribute attr;
@@ -58,7 +58,7 @@ cpufreq_stats_update (unsigned int cpu)
58 58
59 cur_time = get_jiffies_64(); 59 cur_time = get_jiffies_64();
60 spin_lock(&cpufreq_stats_lock); 60 spin_lock(&cpufreq_stats_lock);
61 stat = cpufreq_stats_table[cpu]; 61 stat = per_cpu(cpufreq_stats_table, cpu);
62 if (stat->time_in_state) 62 if (stat->time_in_state)
63 stat->time_in_state[stat->last_index] = 63 stat->time_in_state[stat->last_index] =
64 cputime64_add(stat->time_in_state[stat->last_index], 64 cputime64_add(stat->time_in_state[stat->last_index],
@@ -71,11 +71,11 @@ cpufreq_stats_update (unsigned int cpu)
71static ssize_t 71static ssize_t
72show_total_trans(struct cpufreq_policy *policy, char *buf) 72show_total_trans(struct cpufreq_policy *policy, char *buf)
73{ 73{
74 struct cpufreq_stats *stat = cpufreq_stats_table[policy->cpu]; 74 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
75 if (!stat) 75 if (!stat)
76 return 0; 76 return 0;
77 return sprintf(buf, "%d\n", 77 return sprintf(buf, "%d\n",
78 cpufreq_stats_table[stat->cpu]->total_trans); 78 per_cpu(cpufreq_stats_table, stat->cpu)->total_trans);
79} 79}
80 80
81static ssize_t 81static ssize_t
@@ -83,7 +83,7 @@ show_time_in_state(struct cpufreq_policy *policy, char *buf)
83{ 83{
84 ssize_t len = 0; 84 ssize_t len = 0;
85 int i; 85 int i;
86 struct cpufreq_stats *stat = cpufreq_stats_table[policy->cpu]; 86 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
87 if (!stat) 87 if (!stat)
88 return 0; 88 return 0;
89 cpufreq_stats_update(stat->cpu); 89 cpufreq_stats_update(stat->cpu);
@@ -101,7 +101,7 @@ show_trans_table(struct cpufreq_policy *policy, char *buf)
101 ssize_t len = 0; 101 ssize_t len = 0;
102 int i, j; 102 int i, j;
103 103
104 struct cpufreq_stats *stat = cpufreq_stats_table[policy->cpu]; 104 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
105 if (!stat) 105 if (!stat)
106 return 0; 106 return 0;
107 cpufreq_stats_update(stat->cpu); 107 cpufreq_stats_update(stat->cpu);
@@ -170,7 +170,7 @@ freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq)
170 170
171static void cpufreq_stats_free_table(unsigned int cpu) 171static void cpufreq_stats_free_table(unsigned int cpu)
172{ 172{
173 struct cpufreq_stats *stat = cpufreq_stats_table[cpu]; 173 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, cpu);
174 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); 174 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
175 if (policy && policy->cpu == cpu) 175 if (policy && policy->cpu == cpu)
176 sysfs_remove_group(&policy->kobj, &stats_attr_group); 176 sysfs_remove_group(&policy->kobj, &stats_attr_group);
@@ -178,7 +178,7 @@ static void cpufreq_stats_free_table(unsigned int cpu)
178 kfree(stat->time_in_state); 178 kfree(stat->time_in_state);
179 kfree(stat); 179 kfree(stat);
180 } 180 }
181 cpufreq_stats_table[cpu] = NULL; 181 per_cpu(cpufreq_stats_table, cpu) = NULL;
182 if (policy) 182 if (policy)
183 cpufreq_cpu_put(policy); 183 cpufreq_cpu_put(policy);
184} 184}
@@ -192,7 +192,7 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy,
192 struct cpufreq_policy *data; 192 struct cpufreq_policy *data;
193 unsigned int alloc_size; 193 unsigned int alloc_size;
194 unsigned int cpu = policy->cpu; 194 unsigned int cpu = policy->cpu;
195 if (cpufreq_stats_table[cpu]) 195 if (per_cpu(cpufreq_stats_table, cpu))
196 return -EBUSY; 196 return -EBUSY;
197 if ((stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL)) == NULL) 197 if ((stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL)) == NULL)
198 return -ENOMEM; 198 return -ENOMEM;
@@ -207,7 +207,7 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy,
207 goto error_out; 207 goto error_out;
208 208
209 stat->cpu = cpu; 209 stat->cpu = cpu;
210 cpufreq_stats_table[cpu] = stat; 210 per_cpu(cpufreq_stats_table, cpu) = stat;
211 211
212 for (i=0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 212 for (i=0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
213 unsigned int freq = table[i].frequency; 213 unsigned int freq = table[i].frequency;
@@ -251,7 +251,7 @@ error_out:
251 cpufreq_cpu_put(data); 251 cpufreq_cpu_put(data);
252error_get_fail: 252error_get_fail:
253 kfree(stat); 253 kfree(stat);
254 cpufreq_stats_table[cpu] = NULL; 254 per_cpu(cpufreq_stats_table, cpu) = NULL;
255 return ret; 255 return ret;
256} 256}
257 257
@@ -284,7 +284,7 @@ cpufreq_stat_notifier_trans (struct notifier_block *nb, unsigned long val,
284 if (val != CPUFREQ_POSTCHANGE) 284 if (val != CPUFREQ_POSTCHANGE)
285 return 0; 285 return 0;
286 286
287 stat = cpufreq_stats_table[freq->cpu]; 287 stat = per_cpu(cpufreq_stats_table, freq->cpu);
288 if (!stat) 288 if (!stat)
289 return 0; 289 return 0;
290 290
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index b64c6bc445e3..9071d80fbba2 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -174,7 +174,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
174} 174}
175EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target); 175EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target);
176 176
177static struct cpufreq_frequency_table *show_table[NR_CPUS]; 177static DEFINE_PER_CPU(struct cpufreq_frequency_table *, show_table);
178/** 178/**
179 * show_available_freqs - show available frequencies for the specified CPU 179 * show_available_freqs - show available frequencies for the specified CPU
180 */ 180 */
@@ -185,10 +185,10 @@ static ssize_t show_available_freqs (struct cpufreq_policy *policy, char *buf)
185 ssize_t count = 0; 185 ssize_t count = 0;
186 struct cpufreq_frequency_table *table; 186 struct cpufreq_frequency_table *table;
187 187
188 if (!show_table[cpu]) 188 if (!per_cpu(show_table, cpu))
189 return -ENODEV; 189 return -ENODEV;
190 190
191 table = show_table[cpu]; 191 table = per_cpu(show_table, cpu);
192 192
193 for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 193 for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
194 if (table[i].frequency == CPUFREQ_ENTRY_INVALID) 194 if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
@@ -217,20 +217,20 @@ void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
217 unsigned int cpu) 217 unsigned int cpu)
218{ 218{
219 dprintk("setting show_table for cpu %u to %p\n", cpu, table); 219 dprintk("setting show_table for cpu %u to %p\n", cpu, table);
220 show_table[cpu] = table; 220 per_cpu(show_table, cpu) = table;
221} 221}
222EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_attr); 222EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_attr);
223 223
224void cpufreq_frequency_table_put_attr(unsigned int cpu) 224void cpufreq_frequency_table_put_attr(unsigned int cpu)
225{ 225{
226 dprintk("clearing show_table for cpu %u\n", cpu); 226 dprintk("clearing show_table for cpu %u\n", cpu);
227 show_table[cpu] = NULL; 227 per_cpu(show_table, cpu) = NULL;
228} 228}
229EXPORT_SYMBOL_GPL(cpufreq_frequency_table_put_attr); 229EXPORT_SYMBOL_GPL(cpufreq_frequency_table_put_attr);
230 230
231struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu) 231struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu)
232{ 232{
233 return show_table[cpu]; 233 return per_cpu(show_table, cpu);
234} 234}
235EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table); 235EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table);
236 236