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

[PATCH v1 02/11] xen/x86: introduce new sub-hypercall to get CPPC data


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Tue, 3 Dec 2024 16:11:02 +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=4pMiDIbPnk4KOwi5Wnpl0tX4XgGePDycYMINNFX4f3E=; b=GbG+f9B45tkdX/A3tckiTDzs9iZoNlABvZS8TqPriJPZQh21EtKMS+RRU5nI0XYeo7TiF3IuglNnjHSEHU57CWIzLveCXcaQ+PA1PsYIWc5nNIEetzivR5kNl0XlQy3ASt1T0QKu0Xusrpv10GK+w7+KrBrKEN7SXojZHAP2KyTspnbE3w4qSzLTswX8Bxe5s7B17JGBDEMDxOU/dgSt02fxNkCZAXVUnugFfw4UNDo1b7on+6pNjhJ+K7FpsNU+vsw42JhbSM+/tbjb6ocjwMu2LF9tOM0MPaHAachSArDmr364qiGc6eZ+veztdXX0eqHKQfTBaaAmFcs+TfpC5g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HBALj0iwWTZhtTNB4m/9IaArFm/7IEBRoyPCvWid9Jpm+/9v887vk86iyIwQHnGfc4surbZpPW7RQwhi4zXSvWR2pSH3bO8Izujlv9+LPOLMNJzK8mcHBHU6IFYo6GEn4ubTpZYc5k29zt2NGbWEP7QBsHwxr80l+XMRpiaitZquw7Tb9ZZe2AdMQUF0IOJ6kG6Q/3fEkpA8r8MmwigGEoWVXeqnYw78k1EC0aVr+N1Lk8AP801iwRsvzwDZLoIgwZg9398yo7BgWmIWTwNlgWvbC+iM86CweKbOSDxpxuVIWLNIAxqaD06t0P4/rNgQ8J4CAbwZv7fkI1PuB5xp7Q==
  • Cc: <stefano.stabellini@xxxxxxx>, <Ray.Huang@xxxxxxx>, <Xenia.Ragiadakou@xxxxxxx>, <Jason.Andryuk@xxxxxxx>, <penny.zheng@xxxxxxx>, Penny Zheng <Penny.Zheng@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, "Andrew Cooper" <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Tue, 03 Dec 2024 08:22:09 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

In order to provide backward compatibility with existing governors
that represent performance as frequencies, like ondemand, the _CPC
table can optionally provide processor frequency range values, Lowest
frequency and Norminal frequency, to let OS use Lowest Frequency/
Performance and Nominal Frequency/Performance as anchor points to
create linear mapping of CPPC abstract performance to CPU frequency.

As Xen is uncapable of parsing the ACPI dynamic table, this commit
introduces a new sub-hypercall to get required CPPC data from
dom0 kernel.

Signed-off-by: Penny Zheng <Penny.Zheng@xxxxxxx>
---
 xen/arch/x86/platform_hypercall.c         |  6 +++
 xen/arch/x86/x86_64/cpufreq.c             | 18 ++++++++
 xen/arch/x86/x86_64/platform_hypercall.c  |  3 ++
 xen/drivers/cpufreq/cpufreq.c             | 50 +++++++++++++++++++++++
 xen/include/acpi/cpufreq/processor_perf.h |  1 +
 xen/include/public/platform.h             | 11 +++++
 xen/include/xen/pmstat.h                  |  3 ++
 xen/include/xlat.lst                      |  1 +
 8 files changed, 93 insertions(+)

diff --git a/xen/arch/x86/platform_hypercall.c 
b/xen/arch/x86/platform_hypercall.c
index 67f851237d..917c395f58 100644
--- a/xen/arch/x86/platform_hypercall.c
+++ b/xen/arch/x86/platform_hypercall.c
@@ -572,6 +572,12 @@ ret_t do_platform_op(
             break;
         }
 
+        case XEN_PM_CPPC:
+        {
+            ret = set_cppc_pminfo(op->u.set_pminfo.id, 
&op->u.set_pminfo.u.cppc_data);
+        }
+        break;
+
         default:
             ret = -EINVAL;
             break;
diff --git a/xen/arch/x86/x86_64/cpufreq.c b/xen/arch/x86/x86_64/cpufreq.c
index e4f3d5b436..1aa10a5dbd 100644
--- a/xen/arch/x86/x86_64/cpufreq.c
+++ b/xen/arch/x86/x86_64/cpufreq.c
@@ -54,3 +54,21 @@ int compat_set_px_pminfo(uint32_t acpi_id,
 
     return set_px_pminfo(acpi_id, xen_perf);
 }
+
+int compat_set_cppc_pminfo(uint32_t acpi_id,
+                           struct compat_processor_cppc *cppc_data)
+{
+    struct xen_processor_cppc *xen_cppc;
+    unsigned long xlat_page_current;
+
+    xlat_malloc_init(xlat_page_current);
+
+    xen_cppc = xlat_malloc_array(xlat_page_current,
+                                    struct xen_processor_cppc, 1);
+    if ( unlikely(xen_cppc == NULL) )
+        return -EFAULT;
+
+    XLAT_processor_cppc(xen_cppc, cppc_data);
+
+    return set_cppc_pminfo(acpi_id, xen_cppc);
+}
diff --git a/xen/arch/x86/x86_64/platform_hypercall.c 
b/xen/arch/x86/x86_64/platform_hypercall.c
index 9ab631c17f..8c28465b8e 100644
--- a/xen/arch/x86/x86_64/platform_hypercall.c
+++ b/xen/arch/x86/x86_64/platform_hypercall.c
@@ -20,6 +20,9 @@ EMIT_FILE;
 #define xen_processor_power compat_processor_power
 #define set_cx_pminfo       compat_set_cx_pminfo
 
+#define xen_processor_cppc compat_processor_cppc
+#define set_cppc_pminfo    compat_set_cppc_pminfo
+
 #define xen_pf_pcpuinfo xenpf_pcpuinfo
 CHECK_pf_pcpuinfo;
 #undef xen_pf_pcpuinfo
diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c
index 4a103c6de9..3e3392da1b 100644
--- a/xen/drivers/cpufreq/cpufreq.c
+++ b/xen/drivers/cpufreq/cpufreq.c
@@ -458,6 +458,56 @@ static void print_PPC(unsigned int platform_limit)
     printk("\t_PPC: %d\n", platform_limit);
 }
 
+static void print_CPPC(struct xen_processor_cppc *cppc_data)
+{
+    printk("\t_CPC: highest_perf=%u, lowest_perf=%u, "
+           "nominal_perf=%u, lowest_nonlinear_perf=%u, "
+           "nominal_freq=%uMhz, lowest_freq=%uMhz\n",
+           cppc_data->highest_perf, cppc_data->lowest_perf,
+           cppc_data->nominal_perf, cppc_data->lowest_nonlinear_perf,
+           cppc_data->nominal_freq, cppc_data->lowest_freq);
+}
+
+int set_cppc_pminfo(uint32_t acpi_id, struct xen_processor_cppc *cppc_data)
+{
+    int ret = 0, cpuid;
+    struct processor_pminfo *pm_info;
+
+    cpuid = get_cpu_id(acpi_id);
+    if ( cpuid < 0 || !cppc_data )
+    {
+        ret = -EINVAL;
+        goto out;
+    }
+    if ( cpufreq_verbose )
+        printk("Set CPU acpi_id(%d) cpuid(%d) CPPC State info:\n",
+               acpi_id, cpuid);
+
+    pm_info = processor_pminfo[cpuid];
+    if ( !pm_info )
+    {
+        pm_info = xzalloc(struct processor_pminfo);
+        if ( !pm_info )
+        {
+            ret = -ENOMEM;
+            goto out;
+        }
+        processor_pminfo[cpuid] = pm_info;
+    }
+    pm_info->acpi_id = acpi_id;
+    pm_info->id = cpuid;
+
+    memcpy ((void *)&pm_info->cppc_data,
+            (void *)cppc_data,
+            sizeof(struct xen_processor_cppc));
+
+    if ( cpufreq_verbose )
+        print_CPPC(&pm_info->cppc_data);
+
+ out:
+    return ret;
+}
+
 int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf)
 {
     int ret = 0, cpu;
diff --git a/xen/include/acpi/cpufreq/processor_perf.h 
b/xen/include/acpi/cpufreq/processor_perf.h
index 301104e16f..cfa0fed647 100644
--- a/xen/include/acpi/cpufreq/processor_perf.h
+++ b/xen/include/acpi/cpufreq/processor_perf.h
@@ -37,6 +37,7 @@ struct processor_pminfo {
     uint32_t acpi_id;
     uint32_t id;
     struct processor_performance    perf;
+    struct xen_processor_cppc cppc_data;
 };
 
 extern struct processor_pminfo *processor_pminfo[NR_CPUS];
diff --git a/xen/include/public/platform.h b/xen/include/public/platform.h
index 2725b8d104..be1cf9a12f 100644
--- a/xen/include/public/platform.h
+++ b/xen/include/public/platform.h
@@ -363,6 +363,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);
 #define XEN_PM_PX   1
 #define XEN_PM_TX   2
 #define XEN_PM_PDC  3
+#define XEN_PM_CPPC 4
 
 /* Px sub info type */
 #define XEN_PX_PCT   1
@@ -432,6 +433,15 @@ struct xen_processor_px {
 typedef struct xen_processor_px xen_processor_px_t;
 DEFINE_XEN_GUEST_HANDLE(xen_processor_px_t);
 
+struct xen_processor_cppc {
+    uint32_t highest_perf;
+    uint32_t nominal_perf;
+    uint32_t lowest_perf;
+    uint32_t lowest_nonlinear_perf;
+    uint32_t lowest_freq;
+    uint32_t nominal_freq;
+};
+
 struct xen_psd_package {
     uint64_t num_entries;
     uint64_t revision;
@@ -465,6 +475,7 @@ struct xenpf_set_processor_pminfo {
         struct xen_processor_power          power;/* Cx: _CST/_CSD */
         struct xen_processor_performance    perf; /* Px: _PPC/_PCT/_PSS/_PSD */
         XEN_GUEST_HANDLE(uint32)            pdc;  /* _PDC */
+        struct xen_processor_cppc           cppc_data; /*_CPC */
     } u;
 };
 typedef struct xenpf_set_processor_pminfo xenpf_set_processor_pminfo_t;
diff --git a/xen/include/xen/pmstat.h b/xen/include/xen/pmstat.h
index 8350403e95..7b73b123aa 100644
--- a/xen/include/xen/pmstat.h
+++ b/xen/include/xen/pmstat.h
@@ -5,6 +5,7 @@
 #include <public/platform.h> /* for struct xen_processor_power */
 #include <public/sysctl.h>   /* for struct pm_cx_stat */
 
+int set_cppc_pminfo(uint32_t cpu, struct xen_processor_cppc *cppc_data);
 int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf);
 long set_cx_pminfo(uint32_t acpi_id, struct xen_processor_power *power);
 
@@ -13,6 +14,8 @@ struct compat_processor_performance;
 int compat_set_px_pminfo(uint32_t acpi_id, struct compat_processor_performance 
*perf);
 struct compat_processor_power;
 long compat_set_cx_pminfo(uint32_t acpi_id, struct compat_processor_power 
*power);
+struct compat_processor_cppc;
+int compat_set_cppc_pminfo(uint32_t acpi_id, struct compat_processor_cppc 
*cppc);
 #endif
 
 uint32_t pmstat_get_cx_nr(unsigned int cpu);
diff --git a/xen/include/xlat.lst b/xen/include/xlat.lst
index 2046b36c04..cdd0340c5e 100644
--- a/xen/include/xlat.lst
+++ b/xen/include/xlat.lst
@@ -166,6 +166,7 @@
 !      processor_cx                    platform.h
 !      processor_flags                 platform.h
 !      processor_performance           platform.h
+!      processor_cppc                  platform.h
 !      processor_power                 platform.h
 ?      processor_px                    platform.h
 !      psd_package                     platform.h
-- 
2.34.1




 


Rackspace

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