[PATCH 5/5] cpufreq/amd-cppc: move pxfreq_mhz into driver data

Jan Beulich posted 5 patches 3 days, 22 hours ago
[PATCH 5/5] cpufreq/amd-cppc: move pxfreq_mhz into driver data
Posted by Jan Beulich 3 days, 21 hours ago
No reason for it to be a separate per-CPU item; it's connected to a
struct cpufreq_policy instance just like other driver data.

This also eliminates the concern over amd_cppc_cpufreq_cpu_init() being
called for all CPUs, or a CPU going offline that's recorded in policy->cpu
(which would result in accesses of per-CPU data of offline CPUs).

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/x86/acpi/cpufreq/amd-cppc.c
+++ b/xen/arch/x86/acpi/cpufreq/amd-cppc.c
@@ -30,11 +30,6 @@
         printk(XENLOG_DEBUG "AMD-CPPC: CPU%u " fmt, cpu, ## args);  \
 })
 
-/*
- * Core max frequency read from PstateDef as anchor point
- * for freq-to-perf transition
- */
-static DEFINE_PER_CPU_READ_MOSTLY(unsigned int, pxfreq_mhz);
 #ifndef NDEBUG
 static bool __ro_after_init opt_active_mode;
 #else
@@ -117,7 +112,7 @@ static int amd_cppc_khz_to_perf(const st
     {
         /* Read Processor Max Speed(MHz) as anchor point */
         mul = data->caps.highest_perf;
-        div = this_cpu(pxfreq_mhz);
+        div = data->pxfreq_mhz;
         if ( !div )
             return -EOPNOTSUPP;
     }
@@ -160,7 +155,7 @@ static int amd_get_cpc_freq(const struct
     }
 
     /* Read Processor Max Speed(MHz) as anchor point */
-    mul = this_cpu(pxfreq_mhz);
+    mul = data->pxfreq_mhz;
     if ( !mul )
         return -EOPNOTSUPP;
     div = data->caps.highest_perf;
@@ -287,7 +282,7 @@ static void cf_check amd_cppc_init_msrs(
     }
 
     amd_process_freq(&cpu_data[policy->cpu],
-                     NULL, NULL, &this_cpu(pxfreq_mhz));
+                     NULL, NULL, &data->pxfreq_mhz);
 
     data->err = amd_get_cpc_freq(data, data->cppc_data->cpc.lowest_mhz,
                                  data->caps.lowest_perf, &min_freq);
--- a/xen/include/acpi/cpufreq/cpufreq.h
+++ b/xen/include/acpi/cpufreq/cpufreq.h
@@ -145,6 +145,12 @@ struct amd_cppc_drv_data {
 
     uint8_t epp_init;
 
+    /*
+     * Core max frequency read from PstateDef as anchor point
+     * for freq-to-perf transition
+     */
+    unsigned int pxfreq_mhz;
+
     int err;
 };
RE: [PATCH 5/5] cpufreq/amd-cppc: move pxfreq_mhz into driver data
Posted by Penny, Zheng 17 minutes ago
[Public]

> -----Original Message-----
> From: Jan Beulich <jbeulich@suse.com>
> Sent: Thursday, January 22, 2026 5:44 PM
> To: xen-devel@lists.xenproject.org
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>; Roger Pau Monné
> <roger.pau@citrix.com>; Penny, Zheng <penny.zheng@amd.com>
> Subject: [PATCH 5/5] cpufreq/amd-cppc: move pxfreq_mhz into driver data
>
> No reason for it to be a separate per-CPU item; it's connected to a struct
> cpufreq_policy instance just like other driver data.
>
> This also eliminates the concern over amd_cppc_cpufreq_cpu_init() being called for
> all CPUs, or a CPU going offline that's recorded in policy->cpu (which would result
> in accesses of per-CPU data of offline CPUs).
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>

Reviewed-by: Penny Zheng <penny.zheng@amd.com>

Later, I'll rebase your commits and test them all on my board locally, and complement the Tested-by:. Since I guest upstream doesn't have boards with amd-cppc enabled in BIOS

Many thanks,
Penny Zheng