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

[PATCH v5 09/18] xen/amd: introduce amd_process_freq() to get processor frequency


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Tue, 27 May 2025 16:48:24 +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=6BWhhOPQucu2ODRuY7WWAlw1Er6mBiipSyVknf/cvyA=; b=KZRMFERKW1dPcfjzPLA8RYdB7mEZQ3Fa3Jer5FmWIWbeEsEih1Q9/NWbwley/De0QPrBoqWDUPHOdRNd5GzTm6ahLZPiaTxhdi+wJF/x2yHxzcWZhqlNFY/HIHGDYCF6tzGg9gMuX/VEJc2x8lgIL6X/LKK8TeVHRwoOpkIM4A4m3bW7oFXf2BaR1ui7eIei+dkWayvZRojr4Em19rjzGl9FrlfxYzZLCq2j6UNck5fwlrjfUI+d98kT9POixFp9K8Q7ulKDjC7teOJPpRv1nCZMWdSRzHe+yWrwx1ktcFRoTSksy2hYBU2dJBLs0o7T56EZm2EvJr8cgzB3jhl26w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=urRXYl3tw+ppii7D9eVrfmRZztVCoCRuR58fL01kMrhYX8IC2XJwXG6c+sQtPlQd0RgKshAnzgwrceT6orvWs+zt6f0rZEwqZMEkNDDidf31wwL7VlZgjQnOwZjxKawbMEGFPOrL/p0aqUHhZEhIWsfrOqvne6502GCF/lonJzVOoidRF8y078ijc784Ymn/Wb5wnoZLNzUf5xQWDcALcmv/lX2Qx3noqf87b6meo6t5PboBiBgW8fy1saFN+gftiKKny0RZ6Luk7pfgGKNrFP24Hit6qB+kM88W6ULZzWuq9tvVdnFwp3zEq7tGIMYrjyVI7GkDlQ5xzLrKCPy65Q==
  • 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: Tue, 27 May 2025 08:49:37 +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()
---
v4 -> v5:
- make amd_process_freq() static to statisfy Misra demand
- change "low_mhz", "nom_mhz" and "hi_mhz" parameter to unsigned int
- fix order of logged frequencies
---
 xen/arch/x86/cpu/amd.c | 58 +++++++++++++++++++++++++++++-------------
 1 file changed, 40 insertions(+), 18 deletions(-)

diff --git a/xen/arch/x86/cpu/amd.c b/xen/arch/x86/cpu/amd.c
index 3770d75150..8c985466fa 100644
--- a/xen/arch/x86/cpu/amd.c
+++ b/xen/arch/x86/cpu/amd.c
@@ -611,14 +611,15 @@ static unsigned int attr_const amd_parse_freq(unsigned 
int family,
        return freq;
 }
 
-void amd_log_freq(const struct cpuinfo_x86 *c)
+static void amd_process_freq(const struct cpuinfo_x86 *c,
+                            unsigned int *low_mhz,
+                            unsigned int *nom_mhz,
+                            unsigned int *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) {
@@ -699,20 +700,20 @@ 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: %u (%u ... %u) 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: %u ... %u MHz\n",
-                      smp_processor_id(),
-                      amd_parse_freq(c->x86, lo),
-                      amd_parse_freq(c->x86, hi));
-       else
-               printk("CPU%u: %u 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)
@@ -723,6 +724,27 @@ void cf_check early_init_amd(struct cpuinfo_x86 *c)
        ctxt_switch_levelling(NULL);
 }
 
+void amd_log_freq(const struct cpuinfo_x86 *c)
+{
+       unsigned int low_mhz = 0, nom_mhz = 0, hi_mhz = 0;
+
+       if (c != &boot_cpu_data &&
+           (!opt_cpu_info || (c->apicid & (c->x86_num_siblings - 1))))
+               return;
+
+       amd_process_freq(c, &low_mhz, &nom_mhz, &hi_mhz);
+
+       if (!low_mhz && !nom_mhz && !hi_mhz)
+               printk("CPU%u: %u (%u ... %u) MHz\n",
+                      smp_processor_id(),
+                      nom_mhz, low_mhz, hi_mhz);
+       else if (!low_mhz && !hi_mhz)
+               printk("CPU%u: %u ... %u MHz\n",
+                      smp_processor_id(), low_mhz, hi_mhz);
+       else if (!low_mhz)
+               printk("CPU%u: %u MHz\n", smp_processor_id(), low_mhz);
+}
+
 void amd_init_lfence(struct cpuinfo_x86 *c)
 {
        uint64_t value;
-- 
2.34.1




 


Rackspace

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