Commit 7a6aedfa authored by Mike Travis's avatar Mike Travis Committed by Dave Jones

[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.gitSigned-off-by: default avatarMike Travis <travis@sgi.com>
Signed-off-by: default avatarDave Jones <davej@redhat.com>
parent 860da5e5
...@@ -38,10 +38,10 @@ ...@@ -38,10 +38,10 @@
* also protects the cpufreq_cpu_data array. * also protects the cpufreq_cpu_data array.
*/ */
static struct cpufreq_driver *cpufreq_driver; static struct cpufreq_driver *cpufreq_driver;
static struct cpufreq_policy *cpufreq_cpu_data[NR_CPUS]; static DEFINE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_data);
#ifdef CONFIG_HOTPLUG_CPU #ifdef CONFIG_HOTPLUG_CPU
/* This one keeps track of the previously set governor of a removed CPU */ /* This one keeps track of the previously set governor of a removed CPU */
static struct cpufreq_governor *cpufreq_cpu_governor[NR_CPUS]; static DEFINE_PER_CPU(struct cpufreq_governor *, cpufreq_cpu_governor);
#endif #endif
static DEFINE_SPINLOCK(cpufreq_driver_lock); static DEFINE_SPINLOCK(cpufreq_driver_lock);
...@@ -135,7 +135,7 @@ struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) ...@@ -135,7 +135,7 @@ struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
struct cpufreq_policy *data; struct cpufreq_policy *data;
unsigned long flags; unsigned long flags;
if (cpu >= NR_CPUS) if (cpu >= nr_cpu_ids)
goto err_out; goto err_out;
/* get the cpufreq driver */ /* get the cpufreq driver */
...@@ -149,7 +149,7 @@ struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) ...@@ -149,7 +149,7 @@ struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
/* get the CPU */ /* get the CPU */
data = cpufreq_cpu_data[cpu]; data = per_cpu(cpufreq_cpu_data, cpu);
if (!data) if (!data)
goto err_out_put_module; goto err_out_put_module;
...@@ -327,7 +327,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state) ...@@ -327,7 +327,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state)
dprintk("notification %u of frequency transition to %u kHz\n", dprintk("notification %u of frequency transition to %u kHz\n",
state, freqs->new); state, freqs->new);
policy = cpufreq_cpu_data[freqs->cpu]; policy = per_cpu(cpufreq_cpu_data, freqs->cpu);
switch (state) { switch (state) {
case CPUFREQ_PRECHANGE: case CPUFREQ_PRECHANGE:
...@@ -828,8 +828,8 @@ static int cpufreq_add_dev(struct sys_device *sys_dev) ...@@ -828,8 +828,8 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
#ifdef CONFIG_HOTPLUG_CPU #ifdef CONFIG_HOTPLUG_CPU
if (cpufreq_cpu_governor[cpu]){ if (per_cpu(cpufreq_cpu_governor, cpu)) {
policy->governor = cpufreq_cpu_governor[cpu]; policy->governor = per_cpu(cpufreq_cpu_governor, cpu);
dprintk("Restoring governor %s for cpu %d\n", dprintk("Restoring governor %s for cpu %d\n",
policy->governor->name, cpu); policy->governor->name, cpu);
} }
...@@ -854,7 +854,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev) ...@@ -854,7 +854,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
spin_lock_irqsave(&cpufreq_driver_lock, flags); spin_lock_irqsave(&cpufreq_driver_lock, flags);
managed_policy->cpus = policy->cpus; managed_policy->cpus = policy->cpus;
cpufreq_cpu_data[cpu] = managed_policy; per_cpu(cpufreq_cpu_data, cpu) = managed_policy;
spin_unlock_irqrestore(&cpufreq_driver_lock, flags); spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
dprintk("CPU already managed, adding link\n"); dprintk("CPU already managed, adding link\n");
...@@ -899,7 +899,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev) ...@@ -899,7 +899,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
spin_lock_irqsave(&cpufreq_driver_lock, flags); spin_lock_irqsave(&cpufreq_driver_lock, flags);
for_each_cpu_mask(j, policy->cpus) { for_each_cpu_mask(j, policy->cpus) {
cpufreq_cpu_data[j] = policy; per_cpu(cpufreq_cpu_data, j) = policy;
per_cpu(policy_cpu, j) = policy->cpu; per_cpu(policy_cpu, j) = policy->cpu;
} }
spin_unlock_irqrestore(&cpufreq_driver_lock, flags); spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
...@@ -946,7 +946,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev) ...@@ -946,7 +946,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
err_out_unregister: err_out_unregister:
spin_lock_irqsave(&cpufreq_driver_lock, flags); spin_lock_irqsave(&cpufreq_driver_lock, flags);
for_each_cpu_mask(j, policy->cpus) for_each_cpu_mask(j, policy->cpus)
cpufreq_cpu_data[j] = NULL; per_cpu(cpufreq_cpu_data, j) = NULL;
spin_unlock_irqrestore(&cpufreq_driver_lock, flags); spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
kobject_put(&policy->kobj); kobject_put(&policy->kobj);
...@@ -989,7 +989,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) ...@@ -989,7 +989,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
dprintk("unregistering CPU %u\n", cpu); dprintk("unregistering CPU %u\n", cpu);
spin_lock_irqsave(&cpufreq_driver_lock, flags); spin_lock_irqsave(&cpufreq_driver_lock, flags);
data = cpufreq_cpu_data[cpu]; data = per_cpu(cpufreq_cpu_data, cpu);
if (!data) { if (!data) {
spin_unlock_irqrestore(&cpufreq_driver_lock, flags); spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
...@@ -997,7 +997,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) ...@@ -997,7 +997,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
unlock_policy_rwsem_write(cpu); unlock_policy_rwsem_write(cpu);
return -EINVAL; return -EINVAL;
} }
cpufreq_cpu_data[cpu] = NULL; per_cpu(cpufreq_cpu_data, cpu) = NULL;
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
...@@ -1019,19 +1019,19 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) ...@@ -1019,19 +1019,19 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
#ifdef CONFIG_HOTPLUG_CPU #ifdef CONFIG_HOTPLUG_CPU
cpufreq_cpu_governor[cpu] = data->governor; per_cpu(cpufreq_cpu_governor, cpu) = data->governor;
#endif #endif
/* if we have other CPUs still registered, we need to unlink them, /* if we have other CPUs still registered, we need to unlink them,
* or else wait_for_completion below will lock up. Clean the * or else wait_for_completion below will lock up. Clean the
* cpufreq_cpu_data[] while holding the lock, and remove the sysfs * per_cpu(cpufreq_cpu_data) while holding the lock, and remove
* links afterwards. * the sysfs links afterwards.
*/ */
if (unlikely(cpus_weight(data->cpus) > 1)) { if (unlikely(cpus_weight(data->cpus) > 1)) {
for_each_cpu_mask(j, data->cpus) { for_each_cpu_mask(j, data->cpus) {
if (j == cpu) if (j == cpu)
continue; continue;
cpufreq_cpu_data[j] = NULL; per_cpu(cpufreq_cpu_data, j) = NULL;
} }
} }
...@@ -1043,7 +1043,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) ...@@ -1043,7 +1043,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev)
continue; continue;
dprintk("removing link for cpu %u\n", j); dprintk("removing link for cpu %u\n", j);
#ifdef CONFIG_HOTPLUG_CPU #ifdef CONFIG_HOTPLUG_CPU
cpufreq_cpu_governor[j] = data->governor; per_cpu(cpufreq_cpu_governor, j) = data->governor;
#endif #endif
cpu_sys_dev = get_cpu_sysdev(j); cpu_sys_dev = get_cpu_sysdev(j);
sysfs_remove_link(&cpu_sys_dev->kobj, "cpufreq"); sysfs_remove_link(&cpu_sys_dev->kobj, "cpufreq");
...@@ -1153,7 +1153,7 @@ EXPORT_SYMBOL(cpufreq_quick_get); ...@@ -1153,7 +1153,7 @@ EXPORT_SYMBOL(cpufreq_quick_get);
static unsigned int __cpufreq_get(unsigned int cpu) static unsigned int __cpufreq_get(unsigned int cpu)
{ {
struct cpufreq_policy *policy = cpufreq_cpu_data[cpu]; struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
unsigned int ret_freq = 0; unsigned int ret_freq = 0;
if (!cpufreq_driver->get) if (!cpufreq_driver->get)
...@@ -1822,16 +1822,19 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data) ...@@ -1822,16 +1822,19 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
cpufreq_driver = driver_data; cpufreq_driver = driver_data;
spin_unlock_irqrestore(&cpufreq_driver_lock, flags); spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
ret = sysdev_driver_register(&cpu_sysdev_class,&cpufreq_sysdev_driver); ret = sysdev_driver_register(&cpu_sysdev_class,
&cpufreq_sysdev_driver);
if ((!ret) && !(cpufreq_driver->flags & CPUFREQ_STICKY)) { if ((!ret) && !(cpufreq_driver->flags & CPUFREQ_STICKY)) {
int i; int i;
ret = -ENODEV; ret = -ENODEV;
/* check for at least one working CPU */ /* check for at least one working CPU */
for (i=0; i<NR_CPUS; i++) for (i = 0; i < nr_cpu_ids; i++)
if (cpufreq_cpu_data[i]) if (cpu_possible(i) && per_cpu(cpufreq_cpu_data, i)) {
ret = 0; ret = 0;
break;
}
/* if all ->init() calls failed, unregister */ /* if all ->init() calls failed, unregister */
if (ret) { if (ret) {
......
...@@ -43,7 +43,7 @@ struct cpufreq_stats { ...@@ -43,7 +43,7 @@ struct cpufreq_stats {
#endif #endif
}; };
static struct cpufreq_stats *cpufreq_stats_table[NR_CPUS]; static DEFINE_PER_CPU(struct cpufreq_stats *, cpufreq_stats_table);
struct cpufreq_stats_attribute { struct cpufreq_stats_attribute {
struct attribute attr; struct attribute attr;
...@@ -58,7 +58,7 @@ cpufreq_stats_update (unsigned int cpu) ...@@ -58,7 +58,7 @@ cpufreq_stats_update (unsigned int cpu)
cur_time = get_jiffies_64(); cur_time = get_jiffies_64();
spin_lock(&cpufreq_stats_lock); spin_lock(&cpufreq_stats_lock);
stat = cpufreq_stats_table[cpu]; stat = per_cpu(cpufreq_stats_table, cpu);
if (stat->time_in_state) if (stat->time_in_state)
stat->time_in_state[stat->last_index] = stat->time_in_state[stat->last_index] =
cputime64_add(stat->time_in_state[stat->last_index], cputime64_add(stat->time_in_state[stat->last_index],
...@@ -71,11 +71,11 @@ cpufreq_stats_update (unsigned int cpu) ...@@ -71,11 +71,11 @@ cpufreq_stats_update (unsigned int cpu)
static ssize_t static ssize_t
show_total_trans(struct cpufreq_policy *policy, char *buf) show_total_trans(struct cpufreq_policy *policy, char *buf)
{ {
struct cpufreq_stats *stat = cpufreq_stats_table[policy->cpu]; struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
if (!stat) if (!stat)
return 0; return 0;
return sprintf(buf, "%d\n", return sprintf(buf, "%d\n",
cpufreq_stats_table[stat->cpu]->total_trans); per_cpu(cpufreq_stats_table, stat->cpu)->total_trans);
} }
static ssize_t static ssize_t
...@@ -83,7 +83,7 @@ show_time_in_state(struct cpufreq_policy *policy, char *buf) ...@@ -83,7 +83,7 @@ show_time_in_state(struct cpufreq_policy *policy, char *buf)
{ {
ssize_t len = 0; ssize_t len = 0;
int i; int i;
struct cpufreq_stats *stat = cpufreq_stats_table[policy->cpu]; struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
if (!stat) if (!stat)
return 0; return 0;
cpufreq_stats_update(stat->cpu); cpufreq_stats_update(stat->cpu);
...@@ -101,7 +101,7 @@ show_trans_table(struct cpufreq_policy *policy, char *buf) ...@@ -101,7 +101,7 @@ show_trans_table(struct cpufreq_policy *policy, char *buf)
ssize_t len = 0; ssize_t len = 0;
int i, j; int i, j;
struct cpufreq_stats *stat = cpufreq_stats_table[policy->cpu]; struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
if (!stat) if (!stat)
return 0; return 0;
cpufreq_stats_update(stat->cpu); cpufreq_stats_update(stat->cpu);
...@@ -170,7 +170,7 @@ freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq) ...@@ -170,7 +170,7 @@ freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq)
static void cpufreq_stats_free_table(unsigned int cpu) static void cpufreq_stats_free_table(unsigned int cpu)
{ {
struct cpufreq_stats *stat = cpufreq_stats_table[cpu]; struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, cpu);
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
if (policy && policy->cpu == cpu) if (policy && policy->cpu == cpu)
sysfs_remove_group(&policy->kobj, &stats_attr_group); sysfs_remove_group(&policy->kobj, &stats_attr_group);
...@@ -178,7 +178,7 @@ static void cpufreq_stats_free_table(unsigned int cpu) ...@@ -178,7 +178,7 @@ static void cpufreq_stats_free_table(unsigned int cpu)
kfree(stat->time_in_state); kfree(stat->time_in_state);
kfree(stat); kfree(stat);
} }
cpufreq_stats_table[cpu] = NULL; per_cpu(cpufreq_stats_table, cpu) = NULL;
if (policy) if (policy)
cpufreq_cpu_put(policy); cpufreq_cpu_put(policy);
} }
...@@ -192,7 +192,7 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy, ...@@ -192,7 +192,7 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy,
struct cpufreq_policy *data; struct cpufreq_policy *data;
unsigned int alloc_size; unsigned int alloc_size;
unsigned int cpu = policy->cpu; unsigned int cpu = policy->cpu;
if (cpufreq_stats_table[cpu]) if (per_cpu(cpufreq_stats_table, cpu))
return -EBUSY; return -EBUSY;
if ((stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL)) == NULL) if ((stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL)) == NULL)
return -ENOMEM; return -ENOMEM;
...@@ -207,7 +207,7 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy, ...@@ -207,7 +207,7 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy,
goto error_out; goto error_out;
stat->cpu = cpu; stat->cpu = cpu;
cpufreq_stats_table[cpu] = stat; per_cpu(cpufreq_stats_table, cpu) = stat;
for (i=0; table[i].frequency != CPUFREQ_TABLE_END; i++) { for (i=0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
unsigned int freq = table[i].frequency; unsigned int freq = table[i].frequency;
...@@ -251,7 +251,7 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy, ...@@ -251,7 +251,7 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy,
cpufreq_cpu_put(data); cpufreq_cpu_put(data);
error_get_fail: error_get_fail:
kfree(stat); kfree(stat);
cpufreq_stats_table[cpu] = NULL; per_cpu(cpufreq_stats_table, cpu) = NULL;
return ret; return ret;
} }
...@@ -284,7 +284,7 @@ cpufreq_stat_notifier_trans (struct notifier_block *nb, unsigned long val, ...@@ -284,7 +284,7 @@ cpufreq_stat_notifier_trans (struct notifier_block *nb, unsigned long val,
if (val != CPUFREQ_POSTCHANGE) if (val != CPUFREQ_POSTCHANGE)
return 0; return 0;
stat = cpufreq_stats_table[freq->cpu]; stat = per_cpu(cpufreq_stats_table, freq->cpu);
if (!stat) if (!stat)
return 0; return 0;
......
...@@ -169,7 +169,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy, ...@@ -169,7 +169,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
} }
EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target); EXPORT_SYMBOL_GPL(cpufreq_frequency_table_target);
static struct cpufreq_frequency_table *show_table[NR_CPUS]; static DEFINE_PER_CPU(struct cpufreq_frequency_table *, show_table);
/** /**
* show_available_freqs - show available frequencies for the specified CPU * show_available_freqs - show available frequencies for the specified CPU
*/ */
...@@ -180,10 +180,10 @@ static ssize_t show_available_freqs (struct cpufreq_policy *policy, char *buf) ...@@ -180,10 +180,10 @@ static ssize_t show_available_freqs (struct cpufreq_policy *policy, char *buf)
ssize_t count = 0; ssize_t count = 0;
struct cpufreq_frequency_table *table; struct cpufreq_frequency_table *table;
if (!show_table[cpu]) if (!per_cpu(show_table, cpu))
return -ENODEV; return -ENODEV;
table = show_table[cpu]; table = per_cpu(show_table, cpu);
for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
if (table[i].frequency == CPUFREQ_ENTRY_INVALID) if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
...@@ -212,20 +212,20 @@ void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table, ...@@ -212,20 +212,20 @@ void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table,
unsigned int cpu) unsigned int cpu)
{ {
dprintk("setting show_table for cpu %u to %p\n", cpu, table); dprintk("setting show_table for cpu %u to %p\n", cpu, table);
show_table[cpu] = table; per_cpu(show_table, cpu) = table;
} }
EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_attr); EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_attr);
void cpufreq_frequency_table_put_attr(unsigned int cpu) void cpufreq_frequency_table_put_attr(unsigned int cpu)
{ {
dprintk("clearing show_table for cpu %u\n", cpu); dprintk("clearing show_table for cpu %u\n", cpu);
show_table[cpu] = NULL; per_cpu(show_table, cpu) = NULL;
} }
EXPORT_SYMBOL_GPL(cpufreq_frequency_table_put_attr); EXPORT_SYMBOL_GPL(cpufreq_frequency_table_put_attr);
struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu) struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu)
{ {
return show_table[cpu]; return per_cpu(show_table, cpu);
} }
EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table); EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment