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

[PATCH v4 08/15] xen/amd: introduce amd_process_freq() to get processor frequency


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Mon, 14 Apr 2025 15:40:49 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XN4BZakspViyeH4n1uhsJy+yyhej3a/UQkx9Wrv7CvQ=; b=ukYbZ1T3lALT/40uC8K007T2+xL672EFip2K0wpPvwoO3bmgFcZjRfHvqks1QZWuPw2bUp/UOwuoT+swUGXHqFQzr940ieyKz+zyBkkUdlnixd0VTHWJ6fvG4YzIrko8aORX7tnOwW4n2oGp+hKbrxx216umBcMq2qSrjOkXYHOjZCovKFKDJjQX3QBJ+M3e2gGLXxVdxCPmTQJ6EwnMjSx+1DZabnBKXLFzPUV9vbQE4VdUq3SzAdVDctolhpd/Vag/Nz4bqttyGzyzGh6TinEFjOS1MMZVYWkY+HQbGSSwQGfaYsCzdaJswOFyF5JDqOG/0AiFt2uV4DI6iy0KRg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tW9AjRrItGT5FF6J1DcMWYzZk3r9C6uQiNdCyNR/5z09GE7DdDV5psbtSLZnlOzvvnHTlrlZD4zR321mrmkPATVOuEB15Y6QZGKexKPszfQk8/wllWDVU1tQtFLvtVKgCDKm40JQrl7iMSFkK6Zm5cvuxHj9EgB8x3gp8SZBJk4gAwGGc/R2BiimoK6RV7rhCbv0S/zeAhAwiMdR7In2qbQ6gGmKWqrTUtP9I9+s7/vBwEw7WmfeCrK7G6KfVh7HDeqo7DQPB0gYcBPENngmh6c6M/dCn52PDzGTEcNTVb/u+0EyB1Rpo+MsJazszwJbPBgfhd08FRSVne4YfJkvoA==
  • Cc: <ray.huang@xxxxxxx>, Penny Zheng <Penny.Zheng@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Mon, 14 Apr 2025 07:41:47 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

When _CPC table could not provide processor frequency range
values for Xen governor, we need to read processor max frequency
as anchor point.
So we extract amd cpu core frequency calculation logic from amd_log_freq(),
and wrap it as a new helper amd_process_freq().

Signed-off-by: Penny Zheng <Penny.Zheng@xxxxxxx>
---
v1 -> v2:
- new commit
---
v3 -> v4
- introduce amd_process_freq()
---
 xen/arch/x86/cpu/amd.c         | 60 +++++++++++++++++++++++-----------
 xen/arch/x86/include/asm/amd.h |  4 +++
 2 files changed, 45 insertions(+), 19 deletions(-)

diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
index f93dda927e..e875014de9 100644
--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -57,7 +57,6 @@ bool __initdata amd_virt_spec_ctrl;
 static bool __read_mostly fam17_c6_disabled;
 
 static uint64_t attr_const amd_parse_freq(unsigned char c, uint64_t value);
-#define INVAL_FREQ_MHZ  ~(uint64_t)0
 
 static inline int rdmsr_amd_safe(unsigned int msr, unsigned int *lo,
                                 unsigned int *hi)
@@ -596,14 +595,13 @@ static uint64_t amd_parse_freq(unsigned char c, uint64_t 
value)
        return freq;
 }
 
-void amd_log_freq(const struct cpuinfo_x86 *c)
+void amd_process_freq(const struct cpuinfo_x86 *c,
+                     uint64_t *low_mhz, uint64_t *nom_mhz, uint64_t *hi_mhz)
 {
        unsigned int idx = 0, h;
        uint64_t hi, lo, val;
 
-       if (c->x86 < 0x10 || c->x86 > 0x1A ||
-           (c != &boot_cpu_data &&
-            (!opt_cpu_info || (c->apicid & (c->x86_num_siblings - 1)))))
+       if (c->x86 < 0x10 || c->x86 > 0x1A)
                return;
 
        if (c->x86 < 0x17) {
@@ -684,20 +682,21 @@ void amd_log_freq(const struct cpuinfo_x86 *c)
 
        if (idx && idx < h &&
            !rdmsr_safe(0xC0010064 + idx, val) && (val >> 63) &&
-           !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
-               printk("CPU%u: %lu (%lu ... %lu) MHz\n",
-                      smp_processor_id(),
-                      amd_parse_freq(c->x86, val),
-                      amd_parse_freq(c->x86, lo),
-                      amd_parse_freq(c->x86, hi));
-       else if (h && !rdmsr_safe(0xC0010064, hi) && (hi >> 63))
-               printk("CPU%u: %lu ... %lu MHz\n",
-                      smp_processor_id(),
-                      amd_parse_freq(c->x86, lo),
-                      amd_parse_freq(c->x86, hi));
-       else
-               printk("CPU%u: %lu MHz\n", smp_processor_id(),
-                      amd_parse_freq(c->x86, lo));
+           !rdmsr_safe(0xC0010064, hi) && (hi >> 63)) {
+               if (nom_mhz)
+                       *nom_mhz = amd_parse_freq(c->x86, val);
+               if (low_mhz)
+                       *low_mhz = amd_parse_freq(c->x86, lo);
+               if (hi_mhz)
+                       *hi_mhz = amd_parse_freq(c->x86, hi);
+       } else if (h && !rdmsr_safe(0xC0010064, hi) && (hi >> 63)) {
+               if (low_mhz)
+                       *low_mhz = amd_parse_freq(c->x86, lo);
+               if (hi_mhz)
+                       *hi_mhz = amd_parse_freq(c->x86, hi);
+       } else
+               if (low_mhz)
+                       *low_mhz = amd_parse_freq(c->x86, lo);
 }
 
 void cf_check early_init_amd(struct cpuinfo_x86 *c)
@@ -708,6 +707,29 @@ void cf_check early_init_amd(struct cpuinfo_x86 *c)
        ctxt_switch_levelling(NULL);
 }
 
+void amd_log_freq(const struct cpuinfo_x86 *c)
+{
+       uint64_t low_mhz, nom_mhz, hi_mhz;
+
+       if (c != &boot_cpu_data &&
+           (!opt_cpu_info || (c->apicid & (c->x86_num_siblings - 1))))
+               return;
+
+       low_mhz = nom_mhz = hi_mhz = INVAL_FREQ_MHZ;
+       amd_process_freq(c, &low_mhz, &nom_mhz, &hi_mhz);
+
+       if (low_mhz != INVAL_FREQ_MHZ && nom_mhz != INVAL_FREQ_MHZ &&
+           hi_mhz != INVAL_FREQ_MHZ)
+               printk("CPU%u: %lu (%lu ... %lu) MHz\n",
+                      smp_processor_id(),
+                      low_mhz, nom_mhz, hi_mhz);
+       else if (low_mhz != INVAL_FREQ_MHZ && hi_mhz != INVAL_FREQ_MHZ)
+               printk("CPU%u: %lu ... %lu MHz\n",
+                      smp_processor_id(), low_mhz, hi_mhz);
+       else if (low_mhz != INVAL_FREQ_MHZ)
+               printk("CPU%u: %lu MHz\n", smp_processor_id(), low_mhz);
+}
+
 void amd_init_lfence(struct cpuinfo_x86 *c)
 {
        uint64_t value;
diff --git a/xen/arch/x86/include/asm/amd.h b/xen/arch/x86/include/asm/amd.h
index 9c9599a622..9dd3592bbb 100644
--- a/xen/arch/x86/include/asm/amd.h
+++ b/xen/arch/x86/include/asm/amd.h
@@ -174,4 +174,8 @@ bool amd_setup_legacy_ssbd(void);
 void amd_set_legacy_ssbd(bool enable);
 void amd_set_cpuid_user_dis(bool enable);
 
+#define INVAL_FREQ_MHZ  ~(uint64_t)0
+void amd_process_freq(const struct cpuinfo_x86 *c, uint64_t *low_mhz,
+                     uint64_t *nom_mhz, uint64_t *hi_mhz);
+
 #endif /* __AMD_H__ */
-- 
2.34.1




 


Rackspace

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