aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMike Travis <travis@sgi.com>2008-03-25 18:06:53 -0400
committerDave Jones <davej@redhat.com>2008-05-19 18:17:49 -0400
commit7a6aedfac98c6d54ecf97ca1ffb1e6a1f3d26aea (patch)
tree404f941cae556ce45b53c90bb4192d9fb53bd233 /drivers
parent860da5e578c25d1ab4528c0d1ad13f9969e3490f (diff)
[CPUFREQ] change cpu freq arrays to per_cpu variables
Change cpufreq_policy and cpufreq_governor pointer tables from arrays to per_cpu variables in the cpufreq subsystem. Also some minor complaints from checkpatch.pl fixed. Based on: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git git://git.kernel.org/pub/scm/linux/kernel/git/x86/linux-2.6-x86.git Signed-off-by: Mike Travis <travis@sgi.com> Signed-off-by: Dave Jones <davej@redhat.com>
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 7fce038fa57e..6b73d163fa83 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 ae6cd60d5c14..fe485c9515d1 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -169,7 +169,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
169} 169}
170EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target); 170EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target);
171 171
172static struct cpufreq_frequency_table *show_table[NR_CPUS]; 172static DEFINE_PER_CPU(struct cpufreq_frequency_table *, show_table);
173/** 173/**
174 * show_available_freqs - show available frequencies for the specified CPU 174 * show_available_freqs - show available frequencies for the specified CPU
175 */ 175 */
@@ -180,10 +180,10 @@ static ssize_t show_available_freqs (struct cpufreq_policy *policy, char *buf)
180 ssize_t count = 0; 180 ssize_t count = 0;
181 struct cpufreq_frequency_table *table; 181 struct cpufreq_frequency_table *table;
182 182
183 if (!show_table[cpu]) 183 if (!per_cpu(show_table, cpu))
184 return -ENODEV; 184 return -ENODEV;
185 185
186 table = show_table[cpu]; 186 table = per_cpu(show_table, cpu);
187 187
188 for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 188 for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
189 if (table[i].frequency == CPUFREQ_ENTRY_INVALID) 189 if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
@@ -212,20 +212,20 @@ void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
212 unsigned int cpu) 212 unsigned int cpu)
213{ 213{
214 dprintk("setting show_table for cpu %u to %p\n", cpu, table); 214 dprintk("setting show_table for cpu %u to %p\n", cpu, table);
215 show_table[cpu] = table; 215 per_cpu(show_table, cpu) = table;
216} 216}
217EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_attr); 217EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_attr);
218 218
219void cpufreq_frequency_table_put_attr(unsigned int cpu) 219void cpufreq_frequency_table_put_attr(unsigned int cpu)
220{ 220{
221 dprintk("clearing show_table for cpu %u\n", cpu); 221 dprintk("clearing show_table for cpu %u\n", cpu);
222 show_table[cpu] = NULL; 222 per_cpu(show_table, cpu) = NULL;
223} 223}
224EXPORT_SYMBOL_GPL(cpufreq_frequency_table_put_attr); 224EXPORT_SYMBOL_GPL(cpufreq_frequency_table_put_attr);
225 225
226struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu) 226struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu)
227{ 227{
228 return show_table[cpu]; 228 return per_cpu(show_table, cpu);
229} 229}
230EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table); 230EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table);
231 231