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

[PATCH v2 3/4] xen/cppc: get xen-required cppc perf caps data


  • To: Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Oleksandr Tyshchenko <oleksandr_tyshchenko@xxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Thu, 5 Dec 2024 13:42:51 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com 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=iFOJrAd0KMsoZrN9Shjj1dooQzMESP1akwRRETW6xhI=; b=GMZhXYwPHmkAtCCLbxYdpUXgylFiQ+L7bGRHtGCAXvNXme6/LLJWwIqpaAMgvElOvUFMwcmGVzgjWTcTz+81stLbwI7XsXhUU+lC5cQ8QqH1r0DdfALOjN1Z45LsO6rB+GE4qtIpxsxbOKcuA94Ou99F7Q9p6Aug5V5mDMeCCjVpw9uRS11/FxHlKlVIC0rdBigqCVgBx/2Rv0a4d+fA6/V8hfqItpUBNVnsj2qLi/MzP9S9GGpR8XbghkPiApgnaOIgH6eV1ZR17sK3RsCXMj4yDcMgqIhsk5zb8g9vI/DA4FxJ57Yfku+8qMIj8ocHczHVtd1O1aYUB8UZ49EfCg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=l2myruzZq6Lyh6/aNpzGbce9kl2lX3JhD2RiEihN+BAOD8lNlb29Hq2tRrUFWG3lEs30RVAntG+gAlS8zB9UdWczNlZmvxwADvcWibl0CmzBHt1sguY8y7xV3xX6WPbclXqjNWZlVVUfRODSRgA+pWpVfBgjumgBIDnceAeVGbU/TQzky2XVh042oLM9QU6l96oU+bkd6UlCa1B+cHgXes3G0IpWx9ndaQghprqZV/E74SvwM6vZOw0nr8waZgsaZKklfzy7YH72x2EJk97H4qUqFAZfHKZW74b6c9ev0TsARU+camC5WXdtCFWnFLoLWf0YFQO/iC+Ljv17/jtegg==
  • Cc: Ray Huang <Ray.Huang@xxxxxxx>, Xenia Ragiadakou <Xenia.Ragiadakou@xxxxxxx>, Jason Andryuk <jason.andryuk@xxxxxxx>, "Penny Zheng" <Penny.Zheng@xxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>, <linux-kernel@xxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 05 Dec 2024 05:43:35 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

When running as Xen dom0 PVH guest, processor logical id <-> physical
id map could not be properly set up. So the original function
cppc_get_perf_caps() fails to get correct cppc data for Xen ACPI
processor.

A new function xen_processor_get_perf_caps() is introduced to
get xen-required cppc perf caps data.

Also, as Xen couldn't read and process PCC-type register, this commit
includes a new flag pcc_unsupported in struct acpi_processor_flags to
tell whether platform supports PCC-type register.

Signed-off-by: Penny Zheng <Penny.Zheng@xxxxxxx>
---
 drivers/acpi/cppc_acpi.c | 110 +++++++++++++++++++++++++++++++++++----
 include/acpi/cppc_acpi.h |   5 ++
 include/acpi/processor.h |   1 +
 3 files changed, 105 insertions(+), 11 deletions(-)

diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 13d6ff84a1e9..3a436591da07 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -772,6 +772,15 @@ static int acpi_cppc_processor_parse(struct acpi_processor 
*pr, struct cpc_desc
                         * so extract it only once.
                         */
                        if (gas_t->space_id == ACPI_ADR_SPACE_PLATFORM_COMM) {
+                               /*
+                                * When ACPI processor represents Xen 
processor, PCC register type
+                                * could not be properly read and processed 
right now, as logical
+                                * processor doesn't always have 1:1 map 
relation to physical processor.
+                                */
+                               if (pr->flags.pcc_unsupported) {
+                                       pr_debug("Unsupported PCC register 
type:%d\n", pr->acpi_id);
+                                       goto out_free;
+                               }
                                if (pcc_subspace_id < 0) {
                                        pcc_subspace_id = gas_t->access_width;
                                        if (pcc_data_alloc(pcc_subspace_id))
@@ -837,7 +846,9 @@ static int acpi_cppc_processor_parse(struct acpi_processor 
*pr, struct cpc_desc
                        goto out_free;
                }
        }
-       per_cpu(cpu_pcc_subspace_idx, pr->id) = pcc_subspace_id;
+
+       if (!pr->flags.pcc_unsupported)
+               per_cpu(cpu_pcc_subspace_idx, pr->id) = pcc_subspace_id;
 
        /*
         * Initialize the remaining cpc_regs as unsupported.
@@ -1018,8 +1029,7 @@ int __weak cpc_write_ffh(int cpunum, struct cpc_reg *reg, 
u64 val)
 static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val)
 {
        void __iomem *vaddr = NULL;
-       int size;
-       int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu);
+       int size, pcc_ss_id;
        struct cpc_reg *reg = &reg_res->cpc_entry.reg;
 
        if (reg_res->type == ACPI_TYPE_INTEGER) {
@@ -1044,14 +1054,17 @@ static int cpc_read(int cpu, struct 
cpc_register_resource *reg_res, u64 *val)
 
                *val = val_u32;
                return 0;
-       } else if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM && pcc_ss_id 
>= 0) {
-               /*
-                * For registers in PCC space, the register size is determined
-                * by the bit width field; the access size is used to indicate
-                * the PCC subspace id.
-                */
-               size = reg->bit_width;
-               vaddr = GET_PCC_VADDR(reg->address, pcc_ss_id);
+       } else if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM) {
+               pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu);
+               if (pcc_ss_id >= 0) {
+                       /*
+                        * For registers in PCC space, the register size is 
determined
+                        * by the bit width field; the access size is used to 
indicate
+                        * the PCC subspace id.
+                        */
+                       size = reg->bit_width;
+                       vaddr = GET_PCC_VADDR(reg->address, pcc_ss_id);
+               }
        }
        else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
                vaddr = reg_res->sys_mem_vaddr;
@@ -1282,6 +1295,81 @@ int cppc_get_epp_perf(int cpunum, u64 *epp_perf)
 }
 EXPORT_SYMBOL_GPL(cppc_get_epp_perf);
 
+
+int xen_processor_get_perf_caps(struct acpi_processor *pr, struct 
cppc_perf_caps *perf_caps)
+{
+       struct cpc_desc *cpc_ptr;
+       struct cpc_register_resource *highest_reg, *lowest_reg,
+               *lowest_non_linear_reg, *nominal_reg,
+               *low_freq_reg = NULL, *nom_freq_reg = NULL;
+       u64 high, low, nom, min_nonlinear, low_f = 0, nom_f = 0;
+       int ret = 0;
+
+       cpc_ptr = kzalloc(sizeof(struct cpc_desc), GFP_KERNEL);
+       if (!cpc_ptr)
+               return -ENOMEM;
+
+       ret = acpi_cppc_processor_parse(pr, cpc_ptr);
+       if (ret)
+               goto err;
+
+       highest_reg = &cpc_ptr->cpc_regs[HIGHEST_PERF];
+       lowest_reg = &cpc_ptr->cpc_regs[LOWEST_PERF];
+       lowest_non_linear_reg = &cpc_ptr->cpc_regs[LOW_NON_LINEAR_PERF];
+       nominal_reg = &cpc_ptr->cpc_regs[NOMINAL_PERF];
+       low_freq_reg = &cpc_ptr->cpc_regs[LOWEST_FREQ];
+       nom_freq_reg = &cpc_ptr->cpc_regs[NOMINAL_FREQ];
+
+       /* Are any of the regs PCC ?*/
+       if (CPC_IN_PCC(highest_reg) || CPC_IN_PCC(lowest_reg) ||
+               CPC_IN_PCC(lowest_non_linear_reg) || CPC_IN_PCC(nominal_reg) ||
+               CPC_IN_PCC(low_freq_reg) || CPC_IN_PCC(nom_freq_reg)) {
+               pr_debug("Unsupported register type read for Xen Processor %d,"
+                        "highest_reg in PCC: %s, lowest_reg in PCC: %s,"
+                        "lowest_non_linear_reg in PCC: %s, nominal_reg in PCC: 
%s,"
+                        "low_freq_reg in PCC: %s, nom_freq_reg in PCC: %s\n",
+                        pr->acpi_id, CPC_IN_PCC(highest_reg) ? "true" : 
"false",
+                        CPC_IN_PCC(lowest_reg) ? "true" : "false",
+                        CPC_IN_PCC(lowest_non_linear_reg) ? "true" : "false",
+                        CPC_IN_PCC(nominal_reg) ? "true" : "false",
+                        CPC_IN_PCC(low_freq_reg) ? "true" : "false",
+                        CPC_IN_PCC(nom_freq_reg) ? "true" : "false");
+               goto err;
+       }
+
+       cpc_read(pr->acpi_id, highest_reg, &high);
+       perf_caps->highest_perf = high;
+
+       cpc_read(pr->acpi_id, lowest_reg, &low);
+       perf_caps->lowest_perf = low;
+
+       cpc_read(pr->acpi_id, nominal_reg, &nom);
+       perf_caps->nominal_perf = nom;
+
+       cpc_read(pr->id, lowest_non_linear_reg, &min_nonlinear);
+       perf_caps->lowest_nonlinear_perf = min_nonlinear;
+
+       if (!high || !low || !nom || !min_nonlinear)
+               pr_warn("CPPC: read zero cpc register value for Xen Processor 
%d"
+                       "highest_reg: %llu, lowest_reg: %llu"
+                       "nominal_reg: %llu, lowest_non_linear_reg: %llu\n",
+                       pr->acpi_id, high, low, nom, min_nonlinear);
+
+       /* Read optional lowest and nominal frequencies if present */
+       if (CPC_SUPPORTED(low_freq_reg))
+               cpc_read(pr->acpi_id, low_freq_reg, &low_f);
+
+       if (CPC_SUPPORTED(nom_freq_reg))
+               cpc_read(pr->acpi_id, nom_freq_reg, &nom_f);
+
+       perf_caps->lowest_freq = low_f;
+       perf_caps->nominal_freq = nom_f;
+
+ err:
+       kfree(cpc_ptr);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(xen_processor_get_perf_caps);
 /**
  * cppc_get_perf_caps - Get a CPU's performance capabilities.
  * @cpunum: CPU from which to get capabilities info.
diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h
index 76e44e102780..2281110c00b7 100644
--- a/include/acpi/cppc_acpi.h
+++ b/include/acpi/cppc_acpi.h
@@ -164,6 +164,7 @@ extern int cppc_set_auto_sel(int cpu, bool enable);
 extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf);
 extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator);
 extern int amd_detect_prefcore(bool *detected);
+extern int xen_processor_get_perf_caps(struct acpi_processor *pr, struct 
cppc_perf_caps *perf_caps);
 #else /* !CONFIG_ACPI_CPPC_LIB */
 static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf)
 {
@@ -249,6 +250,10 @@ static inline int amd_detect_prefcore(bool *detected)
 {
        return -ENODEV;
 }
+static inline int xen_processor_get_perf_caps(struct acpi_processor *pr, 
struct cppc_perf_caps *perf_caps)
+{
+       return -ENOTSUPP;
+}
 #endif /* !CONFIG_ACPI_CPPC_LIB */
 
 #endif /* _CPPC_ACPI_H*/
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index e6f6074eadbf..18499cc11366 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -214,6 +214,7 @@ struct acpi_processor_flags {
        u8 bm_control:1;
        u8 bm_check:1;
        u8 has_cst:1;
+       u8 pcc_unsupported:1;
        u8 has_lpi:1;
        u8 power_setup_done:1;
        u8 bm_rld_set:1;
-- 
2.34.1




 


Rackspace

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