Commit 50109292 authored by Fenghua Yu's avatar Fenghua Yu Committed by Len Brown

acpi-cpufreq: Fix some x86/x86-64 acpi-cpufreq driver issues

This patch addresses some issues in x86/x86-64 acpi-cpufreq driver:

1.  Current memory allocation for acpi_perf_data is actually open-coded
   alloc_percpu().  The patch defines and handles acpi_perf_data as percpu
   data.  The code will be cleaner and easier to be maintained with this
   change.

2. Won't load driver in acpi_cpufreq_early_init() failure case.

3. Add __init for acpi_cpufreq_early_init().
Signed-off-by: default avatarFenghua Yu <fenghua.yu@intel.com>
Acked-by: default avatarVenkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Cc: Dave Jones <davej@codemonkey.org.uk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent ed3110ef
...@@ -68,7 +68,8 @@ struct acpi_cpufreq_data { ...@@ -68,7 +68,8 @@ struct acpi_cpufreq_data {
}; };
static struct acpi_cpufreq_data *drv_data[NR_CPUS]; static struct acpi_cpufreq_data *drv_data[NR_CPUS];
static struct acpi_processor_performance *acpi_perf_data[NR_CPUS]; /* acpi_perf_data is a pointer to percpu data. */
static struct acpi_processor_performance *acpi_perf_data;
static struct cpufreq_driver acpi_cpufreq_driver; static struct cpufreq_driver acpi_cpufreq_driver;
...@@ -508,24 +509,14 @@ acpi_cpufreq_guess_freq(struct acpi_cpufreq_data *data, unsigned int cpu) ...@@ -508,24 +509,14 @@ acpi_cpufreq_guess_freq(struct acpi_cpufreq_data *data, unsigned int cpu)
* do _PDC and _PSD and find out the processor dependency for the * do _PDC and _PSD and find out the processor dependency for the
* actual init that will happen later... * actual init that will happen later...
*/ */
static int acpi_cpufreq_early_init(void) static int __init acpi_cpufreq_early_init(void)
{ {
struct acpi_processor_performance *data;
unsigned int i, j;
dprintk("acpi_cpufreq_early_init\n"); dprintk("acpi_cpufreq_early_init\n");
for_each_possible_cpu(i) { acpi_perf_data = alloc_percpu(struct acpi_processor_performance);
data = kzalloc(sizeof(struct acpi_processor_performance), if (!acpi_perf_data) {
GFP_KERNEL); dprintk("Memory allocation error for acpi_perf_data.\n");
if (!data) { return -ENOMEM;
for_each_possible_cpu(j) {
kfree(acpi_perf_data[j]);
acpi_perf_data[j] = NULL;
}
return -ENOMEM;
}
acpi_perf_data[i] = data;
} }
/* Do initialization in ACPI core */ /* Do initialization in ACPI core */
...@@ -574,14 +565,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) ...@@ -574,14 +565,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
dprintk("acpi_cpufreq_cpu_init\n"); dprintk("acpi_cpufreq_cpu_init\n");
if (!acpi_perf_data[cpu])
return -ENODEV;
data = kzalloc(sizeof(struct acpi_cpufreq_data), GFP_KERNEL); data = kzalloc(sizeof(struct acpi_cpufreq_data), GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
data->acpi_data = acpi_perf_data[cpu]; data->acpi_data = percpu_ptr(acpi_perf_data, cpu);
drv_data[cpu] = data; drv_data[cpu] = data;
if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
...@@ -778,24 +766,25 @@ static struct cpufreq_driver acpi_cpufreq_driver = { ...@@ -778,24 +766,25 @@ static struct cpufreq_driver acpi_cpufreq_driver = {
static int __init acpi_cpufreq_init(void) static int __init acpi_cpufreq_init(void)
{ {
int ret;
dprintk("acpi_cpufreq_init\n"); dprintk("acpi_cpufreq_init\n");
acpi_cpufreq_early_init(); ret = acpi_cpufreq_early_init();
if (ret)
return ret;
return cpufreq_register_driver(&acpi_cpufreq_driver); return cpufreq_register_driver(&acpi_cpufreq_driver);
} }
static void __exit acpi_cpufreq_exit(void) static void __exit acpi_cpufreq_exit(void)
{ {
unsigned int i;
dprintk("acpi_cpufreq_exit\n"); dprintk("acpi_cpufreq_exit\n");
cpufreq_unregister_driver(&acpi_cpufreq_driver); cpufreq_unregister_driver(&acpi_cpufreq_driver);
for_each_possible_cpu(i) { free_percpu(acpi_perf_data);
kfree(acpi_perf_data[i]);
acpi_perf_data[i] = NULL;
}
return; return;
} }
......
...@@ -539,7 +539,7 @@ static int acpi_processor_get_psd(struct acpi_processor *pr) ...@@ -539,7 +539,7 @@ static int acpi_processor_get_psd(struct acpi_processor *pr)
} }
int acpi_processor_preregister_performance( int acpi_processor_preregister_performance(
struct acpi_processor_performance **performance) struct acpi_processor_performance *performance)
{ {
int count, count_target; int count, count_target;
int retval = 0; int retval = 0;
...@@ -567,12 +567,12 @@ int acpi_processor_preregister_performance( ...@@ -567,12 +567,12 @@ int acpi_processor_preregister_performance(
continue; continue;
} }
if (!performance || !performance[i]) { if (!performance || !percpu_ptr(performance, i)) {
retval = -EINVAL; retval = -EINVAL;
continue; continue;
} }
pr->performance = performance[i]; pr->performance = percpu_ptr(performance, i);
cpu_set(i, pr->performance->shared_cpu_map); cpu_set(i, pr->performance->shared_cpu_map);
if (acpi_processor_get_psd(pr)) { if (acpi_processor_get_psd(pr)) {
retval = -EINVAL; retval = -EINVAL;
......
...@@ -232,7 +232,7 @@ struct acpi_processor_errata { ...@@ -232,7 +232,7 @@ struct acpi_processor_errata {
extern int acpi_processor_preregister_performance(struct extern int acpi_processor_preregister_performance(struct
acpi_processor_performance acpi_processor_performance
**performance); *performance);
extern int acpi_processor_register_performance(struct acpi_processor_performance extern int acpi_processor_register_performance(struct acpi_processor_performance
*performance, unsigned int cpu); *performance, unsigned int cpu);
......
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