[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] x86/cpuidle: allocate processor_powers[] dynamically



commit 3a5de37037f3b88aa66032cffd5108604297230a
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Mon Nov 9 11:33:38 2026 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Mon Nov 9 11:33:38 2026 +0100

    x86/cpuidle: allocate processor_powers[] dynamically
    
    There's no need to have a NR_CPUS-dimensioned static array there.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Jason Andryuk <jason.andryuk@xxxxxxx>
---
 xen/arch/x86/acpi/cpu_idle.c       | 25 +++++++++++++++++++++----
 xen/arch/x86/include/asm/cpuidle.h |  2 +-
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/xen/arch/x86/acpi/cpu_idle.c b/xen/arch/x86/acpi/cpu_idle.c
index b2bca4dcf8..874346199e 100644
--- a/xen/arch/x86/acpi/cpu_idle.c
+++ b/xen/arch/x86/acpi/cpu_idle.c
@@ -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 char key)
 
 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, struct 
xen_processor_power *power)
     if ( 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_processor_power *power)
 #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_presmp_init(void)
     if ( !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);
diff --git a/xen/arch/x86/include/asm/cpuidle.h 
b/xen/arch/x86/include/asm/cpuidle.h
index 3a6b73142b..00cef39402 100644
--- a/xen/arch/x86/include/asm/cpuidle.h
+++ b/xen/arch/x86/include/asm/cpuidle.h
@@ -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);
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.