x86/cpuidle: allocate processor_powers[] dynamically
PATCH 1/1 x86/cpuidle: allocate processor_powers[] dynamically
There's no need to have a NR_CPUS-dimensioned static array there.
---
Some of the new conditionals checking processor_powers may arguably want to check (really: might better have been put there long ago) xen_cpuidle instead. Thoughts?
xen/arch/x86/acpi/cpu_idle.c +21 -4
@@ -44,6 +44,7 @@#include <xen/smp.h> #include <xen/softirq.h> #include <xen/trace.h> +#include <xen/xvmalloc.h> #include <asm/apic.h> #include <asm/cpuidle.h>
@@ -149,7 +150,7 @@ custom_param("max_cstate", parse_cstate)static bool __read_mostly local_apic_timer_c2_ok;boolean_param ("lapic_timer_c2_ok" , local_apic_timer_c2_ok); -struct acpi_processor_power *__read_mostly processor_powers[NR_CPUS ]; +struct acpi_processor_power **__read_mostly processor_powers;/* * This field starts out as zero, and can be set to -1 just to signal it has
@@ -447,7 +448,9 @@ static void cf_check dump_cx(unsigned ch static int __init cf_check cpu_idle_key_init(void) { -register_keyhandler ('c' , dump_cx,"dump ACPI Cx structures" ,1 ); +if ( processor_powers ) +register_keyhandler ('c' , dump_cx,"dump ACPI Cx structures" ,1 ); +return 0 ; }__initcall (cpu_idle_key_init);
@@ -1339,6 +1342,9 @@ long set_cx_pminfo(uint32_t acpi_id, strif ( vendor_override >0 )return 0 ; +if ( !processor_powers ) +return -ENOMEM ; +print_cx_pminfo (acpi_id, power); cpu_id =get_cpu_id (acpi_id);
@@ -1512,12 +1518,14 @@ static void amd_cpuidle_init(struct acpi#ifdef CONFIG_PM_STATS uint32_t pmstat_get_cx_nr (unsigned int cpu) { -return processor_powers[cpu] ? processor_powers[cpu]->count :0 ; +return processor_powers && processor_powers[cpu] + ? processor_powers[cpu]->count :0 ; }int pmstat_get_cx_stat (unsigned int cpu,struct pm_cx_stat *stat) { -struct acpi_processor_power *power = processor_powers[cpu]; +struct acpi_processor_power *power = processor_powers + ? processor_powers[cpu] :NULL ;uint64_t idle_usage =0 , idle_res =0 ;uint64_t last_state_update_tick, current_stime, current_tick;uint64_t usage[ACPI_PROCESSOR_MAX_POWER ] = {0 };
@@ -1694,6 +1702,15 @@ static int __init cf_check cpuidle_presmif ( !xen_cpuidle )return 0 ; + processor_powers = xvzalloc_array(struct acpi_processor_power *, + nr_cpu_ids); +if ( !processor_powers ) + { +printk ("CPUIDLE: disabled - not enough memory\n" ); + xen_cpuidle =0 ; +return -ENOMEM ; + } +mwait_idle_init (&cpu_nfb); cpu_nfb.notifier_call (&cpu_nfb,CPU_UP_PREPARE , cpu); cpu_nfb.notifier_call (&cpu_nfb,CPU_ONLINE , cpu);
xen/arch/x86/include/asm/cpuidle.h +1 -1
@@ -5,7 +5,7 @@#include <xen/notifier.h> #include <xen/sched.h> -extern struct acpi_processor_power *processor_powers[]; +extern struct acpi_processor_power **processor_powers;extern void (*pm_idle_save)(void );
Quoted 14 lines · Jan Beulich
There's no need to have a NR_CPUS-dimensioned static array there.
Signed-off-by Jan Beulich <[email protected]>---
Some of the new conditionals checkingprocessor_powersmay arguably want to check (really: might better have been put there long ago)xen_cpuidleinstead. Thoughts?xen/arch/x86/acpi/cpu_idle.c +0
-0@@ -1694,6 +1702,15 @@ static int __init cf_check cpuidle_presmif ( !xen_cpuidle )return 0 ;
xen/arch/x86/acpi/cpu_idle.c static int __init cf_check cpuidle_presm · line 1714
Quoted 10 lines
xen/arch/x86/acpi/cpu_idle.c +9
-0+ processor_powers = xvzalloc_array(struct acpi_processor_power *, + nr_cpu_ids); +if ( !processor_powers ) + { +printk ("CPUIDLE: disabled - not enough memory\n" ); + xen_cpuidle =0 ; +return -ENOMEM ; + } +mwait_idle_init (&cpu_nfb);
mwait-idle.c accesses processor_powers[], too, but that should not be accessible since we don't make it into mwait_idle_init()?
If so:
Thanks,
Jason
Quoted 5 lines · Jason Andryuk
Quoted 4 lines · Jan Beulich
xen/arch/x86/acpi/cpu_idle.c +0
-0@@ -1694,6 +1702,15 @@ static int __init cf_check cpuidle_presmif ( !xen_cpuidle )return 0 ;
Quoted 12 lines
xen/arch/x86/acpi/cpu_idle.c static int __init cf_check cpuidle_presm · line 1714
Quoted 10 lines
xen/arch/x86/acpi/cpu_idle.c +9
-0+ processor_powers = xvzalloc_array(struct acpi_processor_power *, + nr_cpu_ids); +if ( !processor_powers ) + { +printk ("CPUIDLE: disabled - not enough memory\n" ); + xen_cpuidle =0 ; +return -ENOMEM ; + } +mwait_idle_init (&cpu_nfb);
mwait-idle.caccesses processor_powers[], too, but that should not be accessible since we don't make it intomwait_idle_init()?
Indeed.
Quoted 2 lines
If so:
Reviewed-by Jason Andryuk <[email protected]>
Thanks.
Jan