Skip to contentSkip to conversation

xen/acpi: introduce cppc performance hypercall

PATCH In review Penny Zheng 4 participants 9 messages Mar 6, 2025 – Mar 25, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover xen/acpi: introduce cppc performance hypercall

When running as Xen dom0 PVH guest, MADT table is customized and may have the "wrong" UID processor number, which is inconsistent with the UID in Processor entry in native DSDT.

As a result, during ACPI boot-up for dom0, linux fails to set up proper processor logical id <-> physical id map(acpi_map_cpuid). Furthermore, It leads to that some ACPI processor feature capibility, like per-cpu cpc_desc structure, failed to be correctly stored and processed.

With upstreaming "amd-pstate CPU Performance Scaling Driver"(
https://lore.kernel.org/all/[email protected]/)
to Xen community, amd-pstate driver is supported on Xen platform. And as Xen is uncapable of parsing the ACPI dynamic table, like _CPC entry, this patch serie introduces a new sub-hypercall XEN_PM_CPPC to deliver CPPC performance capability data.

This patch serie is based on commit "xen/acpi: upload power and performance related data from a PVH dom0"(
https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/),
which is still under review.

v2 -> v1 :
- rebase to the latest v3 version of "xen/acpi: upload power and performance related data from a PVH dom0"

v3 -> v2:
- add new commit of "introduces XEN_PM_PSD sub-hypercall for solely delivery of _PSD info" to be compatible with
https://lore.kernel.org/all/[email protected]/

Penny Zheng (4):
xen: introduces XEN_PM_PSD sub-hypercall for solely delivery of _PSD
info
acpi/cppc: extract _cpc entry parsing logic
xen/cppc: get xen-required cppc perf caps data
xen/cppc: introduce cppc data upload sub-hypercall

Roger Pau Monne (1):
xen/acpi: upload power and performance related data from a PVH dom0

 drivers/acpi/cppc_acpi.c         | 204 ++++++++++++----
 drivers/xen/pcpu.c               |   3 +-
 drivers/xen/xen-acpi-processor.c | 398 +++++++++++++++++++++++++++----
 include/acpi/cppc_acpi.h         |   5 +
 include/acpi/processor.h         |   2 +
 include/xen/interface/platform.h |  19 +-
 include/xen/xen.h                |   2 +-
 7 files changed, 529 insertions(+), 104 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/5 xen/acpi: upload power and performance related data from a PVH dom0

From: Roger Pau Monne <[email protected]>

When running as a PVH dom0 the ACPI MADT is crafted by Xen in order to report the correct numbers of vCPUs that dom0 has, so the host MADT is not provided to dom0. This creates issues when parsing the power and performance related data from ACPI dynamic tables, as the ACPI Processor UIDs found on the dynamic code are likely to not match the ones crafted by Xen in the dom0 MADT.

Xen would rely on Linux having filled at least the power and performance related data of the vCPUs on the system, and would clone that information in order to setup the remaining pCPUs on the system if dom0 vCPUs < pCPUs. However when running as PVH dom0 it's likely that none of dom0 CPUs will have the power and performance data filled, and hence the Xen ACPI Processor driver needs to fetch that information by itself.

In order to do so correctly, introduce a new helper to fetch the _CST data without taking into account the system capabilities from the CPUID output, as the capabilities reported to dom0 in CPUID might be different from the ones on the host.

Note that the newly introduced code will only fetch the _CST, _PSS, _PPC and _PCT from a single CPU, and clone that information for all the other Processors. This won't work on an heterogeneous system with Processors having different power and performance related data between them.

---
 drivers/xen/pcpu.c               |   3 +-
 drivers/xen/xen-acpi-processor.c | 232 ++++++++++++++++++++++++++++---
 include/xen/xen.h                |   2 +-
 3 files changed, 216 insertions(+), 21 deletions(-)
drivers/xen/pcpu.c +2 -1
index 093ad4a08672..36fb5372cd04 100644
@@ -388,7 +388,7 @@ static int __init xen_pcpu_init(void)
 arch_initcall(xen_pcpu_init);
 
 #ifdef CONFIG_ACPI
-bool __init xen_processor_present(uint32_t acpi_id)
+bool xen_processor_present(uint32_t acpi_id)
 {
 	const struct pcpu *pcpu;
 	bool online = false;
@@ -403,6 +403,7 @@ bool __init xen_processor_present(uint32_t acpi_id)
 
 	return online;
 }
+EXPORT_SYMBOL_GPL(xen_processor_present);
 
 void xen_sanitize_proc_cap_bits(uint32_t *cap)
 {
drivers/xen/xen-acpi-processor.c +213 -19

310 lines not on this page · raw message

include/xen/xen.h +1 -1
index a1e5b3f18d69..6ff3e2f40803 100644
@@ -81,7 +81,7 @@ static inline void xen_free_unpopulated_pages(unsigned int nr_pages,
 #endif
 
 #if defined(CONFIG_XEN_DOM0) && defined(CONFIG_ACPI) && defined(CONFIG_X86)
-bool __init xen_processor_present(uint32_t acpi_id);
+bool xen_processor_present(uint32_t acpi_id);
 #else
 #include <linux/bug.h>
 static inline bool xen_processor_present(uint32_t acpi_id)
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v3 1/5] xen/acpi: upload power and performance related data from a PVH dom0

Quoted 28 lines · Penny Zheng

From: Roger Pau Monne <[email protected]>

When running as a PVH dom0 the ACPI MADT is crafted by Xen in order to report the correct numbers of vCPUs that dom0 has, so the host MADT is not provided to dom0. This creates issues when parsing the power and performance related data from ACPI dynamic tables, as the ACPI Processor UIDs found on the dynamic code are likely to not match the ones crafted by Xen in the dom0 MADT.

Xen would rely on Linux having filled at least the power and performance related data of the vCPUs on the system, and would clone that information in order to setup the remaining pCPUs on the system if dom0 vCPUs < pCPUs. However when running as PVH dom0 it's likely that none of dom0 CPUs will have the power and performance data filled, and hence the Xen ACPI Processor driver needs to fetch that information by itself.

In order to do so correctly, introduce a new helper to fetch the _CST data without taking into account the system capabilities from the CPUID output, as the capabilities reported to dom0 in CPUID might be different from the ones on the host.

Note that the newly introduced code will only fetch the _CST, _PSS, _PPC and _PCT from a single CPU, and clone that information for all the other Processors. This won't work on an heterogeneous system with Processors having different power and performance related data between them.

Quoted 7 lines
---
 drivers/xen/pcpu.c               |   3 +-
 drivers/xen/xen-acpi-processor.c | 232 ++++++++++++++++++++++++++++---
 include/xen/xen.h                |   2 +-
 3 files changed, 216 insertions(+), 21 deletions(-)

No dependency on another patch is mentioned anywhere (the cover letter only says the series is based on the very patch here), yet the bulk of the changes here (to drivers/xen/xen-acpi-processor.c) are meaningless for a PVH Dom0, because of

config XEN_ACPI_PROCESSOR

	tristate "Xen ACPI processor"
	depends on XEN && XEN_PV_DOM0 && X86 && ACPI_PROCESSOR && CPU_FREQ

(note the XEN_PV_DOM0 in there). Is the patch here perhaps missing an adjustment to the above, to use XEN_DOM0 instead?

Jan

#3 lore raw

Re: [PATCH v3 1/5] xen/acpi: upload power and performance related data from a PVH dom0

Quoted 42 lines · Jan Beulich
Quoted 28 lines · Penny Zheng

From: Roger Pau Monne <[email protected]>

When running as a PVH dom0 the ACPI MADT is crafted by Xen in order to report the correct numbers of vCPUs that dom0 has, so the host MADT is not provided to dom0. This creates issues when parsing the power and performance related data from ACPI dynamic tables, as the ACPI Processor UIDs found on the dynamic code are likely to not match the ones crafted by Xen in the dom0 MADT.

Xen would rely on Linux having filled at least the power and performance related data of the vCPUs on the system, and would clone that information in order to setup the remaining pCPUs on the system if dom0 vCPUs < pCPUs. However when running as PVH dom0 it's likely that none of dom0 CPUs will have the power and performance data filled, and hence the Xen ACPI Processor driver needs to fetch that information by itself.

In order to do so correctly, introduce a new helper to fetch the _CST data without taking into account the system capabilities from the CPUID output, as the capabilities reported to dom0 in CPUID might be different from the ones on the host.

Note that the newly introduced code will only fetch the _CST, _PSS, _PPC and _PCT from a single CPU, and clone that information for all the other Processors. This won't work on an heterogeneous system with Processors having different power and performance related data between them.

Quoted 7 lines
---
  drivers/xen/pcpu.c               |   3 +-
  drivers/xen/xen-acpi-processor.c | 232 ++++++++++++++++++++++++++++---
  include/xen/xen.h                |   2 +-
  3 files changed, 216 insertions(+), 21 deletions(-)

No dependency on another patch is mentioned anywhere (the cover letter only says the series is based on the very patch here), yet the bulk of the changes here (to drivers/xen/xen-acpi-processor.c) are meaningless for a PVH Dom0, because of

Quoted 6 lines

config XEN_ACPI_PROCESSOR

	tristate "Xen ACPI processor"
	depends on XEN && XEN_PV_DOM0 && X86 && ACPI_PROCESSOR && CPU_FREQ

(note the XEN_PV_DOM0 in there). Is the patch here perhaps missing an adjustment to the above, to use XEN_DOM0 instead?

Wow, I'm surprised you found that :) Yes, that is a build-time dependency, but the runtime dependency is only on xen_initial_domain(). Yes, it deserves updating.

Thanks,
Jason

#4 lore raw

Re: [PATCH v3 1/5] xen/acpi: upload power and performance related data from a PVH dom0

In reply to Penny Zheng
Quoted 22 lines · Penny Zheng

From: Roger Pau Monne <[email protected]>

When running as a PVH dom0 the ACPI MADT is crafted by Xen in order to report the correct numbers of vCPUs that dom0 has, so the host MADT is not provided to dom0. This creates issues when parsing the power and performance related data from ACPI dynamic tables, as the ACPI Processor UIDs found on the dynamic code are likely to not match the ones crafted by Xen in the dom0 MADT.

Xen would rely on Linux having filled at least the power and performance related data of the vCPUs on the system, and would clone that information in order to setup the remaining pCPUs on the system if dom0 vCPUs < pCPUs. However when running as PVH dom0 it's likely that none of dom0 CPUs will have the power and performance data filled, and hence the Xen ACPI Processor driver needs to fetch that information by itself.

In order to do so correctly, introduce a new helper to fetch the _CST data without taking into account the system capabilities from the CPUID output, as the capabilities reported to dom0 in CPUID might be different from the ones on the host.

Quoted 5 lines

Note that the newly introduced code will only fetch the _CST, _PSS, _PPC and _PCT from a single CPU, and clone that information for all the other Processors. This won't work on an heterogeneous system with Processors having different power and performance related data between them.

I'm unsure whether the above description is inaccurate versus what I've seen being a distinct issue.

This also effects PV domain 0 and isn't limited to AMD processors. In particular if domain 0 is PV, C-states will only be uploaded for processors which domain 0 has a corresponding vCPU.

xen-acpi-processor uploads C/P-states in two passes. The first pass being for processors which domain 0 has a vCPU. The second pass being for all physical processors. In a PV domain 0, xen-acpi-processor is unable to upload C-states during the second pass.

Snippet from pass 1:

xen_acpi_processor: ACPI CPU0 - C-states uploaded.
xen_acpi_processor:      C1: ACPI HLT 1 uS
xen_acpi_processor:      C2: ACPI IOPORT 0x414 18 uS
xen_acpi_processor:      C3: ACPI IOPORT 0x415 350 uS
xen_acpi_processor: ACPI CPU0 - P-states uploaded.
xen_acpi_processor:      *P0: 4500 MHz, 5625 mW, 0 uS
xen_acpi_processor:       P1: 3000 MHz, 2550 mW, 0 uS
xen_acpi_processor: ACPI CPU2 - C-states uploaded.
xen_acpi_processor:      C1: ACPI HLT 1 uS
xen_acpi_processor:      C2: ACPI IOPORT 0x414 18 uS
xen_acpi_processor:      C3: ACPI IOPORT 0x415 350 uS
xen_acpi_processor: ACPI CPU2 - P-states uploaded.
xen_acpi_processor:      *P0: 4500 MHz, 5625 mW, 0 uS
xen_acpi_processor:       P1: 3000 MHz, 2550 mW, 0 uS

Intermediate:
xen_acpi_processor: ACPI CPU0 w/ PBLK:0x0
xen_acpi_processor: ACPI CPU0 w/ PST:coord_type = 254 domain = 0
xen_acpi_processor: ACPI CPU1 w/ PBLK:0x0
xen_acpi_processor: ACPI CPU1 w/ PST:coord_type = 254 domain = 0
xen_acpi_processor: ACPI CPU2 w/ PBLK:0x0
xen_acpi_processor: ACPI CPU2 w/ PST:coord_type = 254 domain = 1
xen_acpi_processor: ACPI CPU3 w/ PBLK:0x0
xen_acpi_processor: ACPI CPU3 w/ PST:coord_type = 254 domain = 1

Snippet from pass 2:

xen_acpi_processor: ACPI CPU1 - P-states uploaded.
xen_acpi_processor:      *P0: 4500 MHz, 5625 mW, 0 uS
xen_acpi_processor:       P1: 3000 MHz, 2550 mW, 0 uS
xen_acpi_processor: ACPI CPU3 - P-states uploaded.
xen_acpi_processor:      *P0: 4500 MHz, 5625 mW, 0 uS
xen_acpi_processor:       P1: 3000 MHz, 2550 mW, 0 uS

Come to think of it, I've been wondering about the mapping between Xen CPU numbers and ACPI CPU numbers...

Signature · 4 lines
(\___(\___(\______          --=> 8-) EHM <=--          ______/)___/)___/)
 \BS (    |         [email protected]  PGP 87145445         |    )   /
  \_CS\   |  _____  -O #include <stddisclaimer.h> O-   _____  |   /  _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
#5 lore raw

PATCH v3 2/5 xen: introduces XEN_PM_PSD sub-hypercall for solely delivery of _PSD info

In reply to Penny Zheng

_PSD(P-State Dependency) provides performance control, no matter legacy P-state or CPPC, logical processor dependency information.

In order to re-use it for CPPC, this commit extracts the delivery of _PSD info from push_pxx_to_hypervisor() and wrap it with a new sub-hypercall XEN_PM_PSD.

---
v2 -> v3:
- new commit

---
 drivers/xen/xen-acpi-processor.c | 82 ++++++++++++++++++++------------
 include/xen/interface/platform.h |  8 ++--
 2 files changed, 56 insertions(+), 34 deletions(-)
drivers/xen/xen-acpi-processor.c +52 -30
index e9f38f171240..8db8631a4b9d 100644
@@ -157,18 +157,40 @@ xen_copy_pss_data(struct acpi_processor *_pr,
 	}
 	return dst_states;
 }
-static int xen_copy_psd_data(struct acpi_processor *_pr,
-			     struct xen_processor_performance *dst)
+static int xen_copy_pct_data(struct acpi_pct_register *pct,
+			     struct xen_pct_register *dst_pct)
+{
+	/* It would be nice if you could just do 'memcpy(pct, dst_pct') but
+	 * sadly the Xen structure did not have the proper padding so the
+	 * descriptor field takes two (dst_pct) bytes instead of one (pct).
+	 */
+	dst_pct->descriptor = pct->descriptor;
+	dst_pct->length = pct->length;
+	dst_pct->space_id = pct->space_id;
+	dst_pct->bit_width = pct->bit_width;
+	dst_pct->bit_offset = pct->bit_offset;
+	dst_pct->reserved = pct->reserved;
+	dst_pct->address = pct->address;
+	return 0;
+}
+static int push_psd_to_hypervisor(struct acpi_processor *_pr)
 {
+	struct xen_platform_op op = {
+		.cmd                    = XENPF_set_processor_pminfo,
+		.interface_version      = XENPF_INTERFACE_VERSION,
+		.u.set_pminfo.id        = _pr->acpi_id,
+		.u.set_pminfo.type      = XEN_PM_PSD,
+	};
 	struct acpi_psd_package *pdomain;
+	int ret = 0;
 
 	BUILD_BUG_ON(sizeof(struct xen_psd_package) !=
 		     sizeof(struct acpi_psd_package));
 
-	/* This information is enumerated only if acpi_processor_preregister_performance
-	 * has been called.
+	/* This information is enumerated only if
+	 * acpi_processor_preregister_performance has been called.
 	 */
-	dst->shared_type = _pr->performance->shared_type;
+	op.u.set_pminfo.shared_type = _pr->performance->shared_type;
 
 	pdomain = &(_pr->performance->domain_info);
 
@@ -180,32 +202,30 @@ static int xen_copy_psd_data(struct acpi_processor *_pr,
 	 * running as a PVH dom0.
 	 */
 	if (pdomain->num_processors <= 1 ||
-	    dst->shared_type == CPUFREQ_SHARED_TYPE_NONE) {
+	    op.u.set_pminfo.shared_type == CPUFREQ_SHARED_TYPE_NONE) {
 		if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL)
-			dst->shared_type = CPUFREQ_SHARED_TYPE_ALL;
+			op.u.set_pminfo.shared_type = CPUFREQ_SHARED_TYPE_ALL;
 		else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL)
-			dst->shared_type = CPUFREQ_SHARED_TYPE_HW;
+			op.u.set_pminfo.shared_type = CPUFREQ_SHARED_TYPE_HW;
 		else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY)
-			dst->shared_type = CPUFREQ_SHARED_TYPE_ANY;
-
+			op.u.set_pminfo.shared_type = CPUFREQ_SHARED_TYPE_ANY;
 	}
-	memcpy(&(dst->domain_info), pdomain, sizeof(struct acpi_psd_package));
-	return 0;
-}
-static int xen_copy_pct_data(struct acpi_pct_register *pct,
-			     struct xen_pct_register *dst_pct)
-{
-	/* It would be nice if you could just do 'memcpy(pct, dst_pct') but
-	 * sadly the Xen structure did not have the proper padding so the
-	 * descriptor field takes two (dst_pct) bytes instead of one (pct).
-	 */
-	dst_pct->descriptor = pct->descriptor;
-	dst_pct->length = pct->length;
-	dst_pct->space_id = pct->space_id;
-	dst_pct->bit_width = pct->bit_width;
-	dst_pct->bit_offset = pct->bit_offset;
-	dst_pct->reserved = pct->reserved;
-	dst_pct->address = pct->address;
+
+	memcpy(&(op.u.set_pminfo.domain_info), pdomain,
+	       sizeof(struct acpi_psd_package));
+
+	if (!no_hypercall)
+		ret = HYPERVISOR_platform_op(&op);
+
+	if (!ret) {
+		pr_debug("ACPI CPU%u - _PSD uploaded.\n", _pr->acpi_id);
+	} else if ((ret != -EINVAL) && (ret != -ENOSYS))
+		/* EINVAL means the ACPI ID is incorrect - meaning the ACPI
+		 * table is referencing a non-existing CPU - which can happen
+		 * with broken ACPI tables. */
+		pr_warn("(_PSD): Hypervisor error (%d) for ACPI CPU%u\n",
+			ret, _pr->acpi_id);
+
 	return 0;
 }
 static int push_pxx_to_hypervisor(struct acpi_processor *_pr)
@@ -234,10 +254,8 @@ static int push_pxx_to_hypervisor(struct acpi_processor *_pr)
 		set_xen_guest_handle(dst_perf->states, dst_states);
 		dst_perf->flags |= XEN_PX_PSS;
 	}
-	if (!xen_copy_psd_data(_pr, dst_perf))
-		dst_perf->flags |= XEN_PX_PSD;
 
-	if (dst_perf->flags != (XEN_PX_PSD | XEN_PX_PSS | XEN_PX_PCT | XEN_PX_PPC)) {
+	if (dst_perf->flags != (XEN_PX_PSS | XEN_PX_PCT | XEN_PX_PPC)) {
 		pr_warn("ACPI CPU%u missing some P-state data (%x), skipping\n",
 			_pr->acpi_id, dst_perf->flags);
 		ret = -ENODEV;
@@ -281,6 +299,10 @@ static int upload_pm_data(struct acpi_processor *_pr)
 		mutex_unlock(&acpi_ids_mutex);
 		return -EBUSY;
 	}
+
+	if (_pr->performance && _pr->performance->states)
+		err |= push_psd_to_hypervisor(_pr);
+
 	if (_pr->flags.power)
 		err = push_cxx_to_hypervisor(_pr);
 
include/xen/interface/platform.h +4 -4
index 79a443c65ea9..a35e1eb958f3 100644
@@ -319,11 +319,11 @@ DEFINE_GUEST_HANDLE_STRUCT(xenpf_getidletime_t);
 #define XEN_PM_PX   1
 #define XEN_PM_TX   2
 #define XEN_PM_PDC  3
+#define XEN_PM_PSD  4
 /* Px sub info type */
 #define XEN_PX_PCT   1
 #define XEN_PX_PSS   2
 #define XEN_PX_PPC   4
-#define XEN_PX_PSD   8
 
 struct xen_power_register {
 	uint32_t     space_id;
@@ -399,8 +399,6 @@ struct xen_processor_performance {
 	struct xen_pct_register status_register;
 	uint32_t state_count;     /* total available performance states */
 	GUEST_HANDLE(xen_processor_px) states;
-	struct xen_psd_package domain_info;
-	uint32_t shared_type;     /* coordination type of this processor */
 };
 DEFINE_GUEST_HANDLE_STRUCT(xen_processor_performance);
 
@@ -410,9 +408,11 @@ struct xenpf_set_processor_pminfo {
 	uint32_t type;  /* {XEN_PM_CX, XEN_PM_PX} */
 	union {
 		struct xen_processor_power          power;/* Cx: _CST/_CSD */
-		struct xen_processor_performance    perf; /* Px: _PPC/_PCT/_PSS/_PSD */
+		struct xen_psd_package              domain_info; /* _PSD */
+		struct xen_processor_performance    perf; /* Px: _PPC/_PCT/_PSS */
 		GUEST_HANDLE(uint32_t)              pdc;
 	};
+	uint32_t shared_type;     /* coordination type of this processor */
 };
 DEFINE_GUEST_HANDLE_STRUCT(xenpf_set_processor_pminfo);
 
Signature · 1 line
2.34.1
#6 lore raw

PATCH v3 3/5 acpi/cppc: extract _cpc entry parsing logic

In reply to Penny Zheng

When running as Xen dom0 PVH guest, MADT table is customized and may have the "wrong" UID processor number, which is inconsistent with the UID in Processor entry in native DSDT.

As a result, during ACPI boot-up for dom0, linux fails to set up proper processor logical id <-> physical id map(acpi_map_cpuid). Furthermore, It leads to that some ACPI processor feature data, like per-cpu cpc_desc structure, failed to be correctly stored.

In order to re-parse _CPC entry later for delivering correct data in performance hypercall, firstly, we extract parsing logic from acpi_cppc_processor_probe() and export it as a new function acpi_cppc_processor_parse().

Also, replace logical processor id with ACPI ID, to show correct print info in Xen dom0 PVH guest.

---
v2 -> v3:
- no change

---
 drivers/acpi/cppc_acpi.c | 93 +++++++++++++++++++++++-----------------
 1 file changed, 53 insertions(+), 40 deletions(-)
drivers/acpi/cppc_acpi.c +53 -40
index f193e713825a..7832bebeb953 100644
@@ -671,19 +671,11 @@ static int pcc_data_alloc(int pcc_ss_id)
  *  )
  */
 
-/**
- * acpi_cppc_processor_probe - Search for per CPU _CPC objects.
- * @pr: Ptr to acpi_processor containing this CPU's logical ID.
- *
- *	Return: 0 for success or negative value for err.
- */
-int acpi_cppc_processor_probe(struct acpi_processor *pr)
+static int acpi_cppc_processor_parse(struct acpi_processor *pr, struct cpc_desc *cpc_ptr)
 {
 	struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
 	union acpi_object *out_obj, *cpc_obj;
-	struct cpc_desc *cpc_ptr;
 	struct cpc_reg *gas_t;
-	struct device *cpu_dev;
 	acpi_handle handle = pr->handle;
 	unsigned int num_ent, i, cpc_rev;
 	int pcc_subspace_id = -1;
@@ -702,31 +694,24 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
 	status = acpi_evaluate_object_typed(handle, "_CPC", NULL, &output,
 			ACPI_TYPE_PACKAGE);
 	if (ACPI_FAILURE(status)) {
-		ret = -ENODEV;
-		goto out_buf_free;
+		return -ENODEV;
 	}
 
 	out_obj = (union acpi_object *) output.pointer;
 
-	cpc_ptr = kzalloc(sizeof(struct cpc_desc), GFP_KERNEL);
-	if (!cpc_ptr) {
-		ret = -ENOMEM;
-		goto out_buf_free;
-	}
-
 	/* First entry is NumEntries. */
 	cpc_obj = &out_obj->package.elements[0];
 	if (cpc_obj->type == ACPI_TYPE_INTEGER)	{
 		num_ent = cpc_obj->integer.value;
 		if (num_ent <= 1) {
 			pr_debug("Unexpected _CPC NumEntries value (%d) for CPU:%d\n",
-				 num_ent, pr->id);
-			goto out_free;
+				 num_ent, pr->acpi_id);
+			goto out_pointer;
 		}
 	} else {
 		pr_debug("Unexpected _CPC NumEntries entry type (%d) for CPU:%d\n",
-			 cpc_obj->type, pr->id);
-		goto out_free;
+			 cpc_obj->type, pr->acpi_id);
+		goto out_pointer;
 	}
 
 	/* Second entry should be revision. */
@@ -735,14 +720,14 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
 		cpc_rev = cpc_obj->integer.value;
 	} else {
 		pr_debug("Unexpected _CPC Revision entry type (%d) for CPU:%d\n",
-			 cpc_obj->type, pr->id);
-		goto out_free;
+			 cpc_obj->type, pr->acpi_id);
+		goto out_pointer;
 	}
 
 	if (cpc_rev < CPPC_V2_REV) {
 		pr_debug("Unsupported _CPC Revision (%d) for CPU:%d\n", cpc_rev,
-			 pr->id);
-		goto out_free;
+			 pr->acpi_id);
+		goto out_pointer;
 	}
 
 	/*
@@ -754,8 +739,8 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
 	    (cpc_rev == CPPC_V3_REV && num_ent != CPPC_V3_NUM_ENT) ||
 	    (cpc_rev > CPPC_V3_REV && num_ent <= CPPC_V3_NUM_ENT)) {
 		pr_debug("Unexpected number of _CPC return package entries (%d) for CPU:%d\n",
-			 num_ent, pr->id);
-		goto out_free;
+			 num_ent, pr->acpi_id);
+		goto out_pointer;
 	}
 	if (cpc_rev > CPPC_V3_REV) {
 		num_ent = CPPC_V3_NUM_ENT;
@@ -789,7 +774,7 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
 						goto out_free;
 				} else if (pcc_subspace_id != gas_t->access_width) {
 					pr_debug("Mismatched PCC ids in _CPC for CPU:%d\n",
-						 pr->id);
+						 pr->acpi_id);
 					goto out_free;
 				}
 			} else if (gas_t->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
@@ -844,7 +829,7 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
 			memcpy(&cpc_ptr->cpc_regs[i-2].cpc_entry.reg, gas_t, sizeof(*gas_t));
 		} else {
 			pr_debug("Invalid entry type (%d) in _CPC for CPU:%d\n",
-				 i, pr->id);
+				 i, pr->acpi_id);
 			goto out_free;
 		}
 	}
@@ -860,6 +845,45 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
 		cpc_ptr->cpc_regs[i].cpc_entry.int_value = 0;
 	}
 
+	pr_debug("Parsed _CPC entry for CPU: %d\n", pr->acpi_id);
+	kfree(output.pointer);
+	return 0;
+
+ out_free:
+	/* Free all the mapped sys mem areas for this CPU */
+	for (i = 2; i < cpc_ptr->num_entries; i++) {
+		void __iomem *addr = cpc_ptr->cpc_regs[i-2].sys_mem_vaddr;
+
+		if (addr)
+			iounmap(addr);
+	}
+ out_pointer:
+	kfree(output.pointer);
+	return ret;
+}
+
+/**
+ * acpi_cppc_processor_probe - Search for per CPU _CPC objects.
+ * @pr: Ptr to acpi_processor containing this CPU's logical ID.
+ *
+ *	Return: 0 for success or negative value for err.
+ */
+int acpi_cppc_processor_probe(struct acpi_processor *pr)
+{
+	acpi_handle handle = pr->handle;
+	struct cpc_desc *cpc_ptr;
+	struct device *cpu_dev;
+	int pcc_subspace_id = -1;
+	int ret = -ENODATA;
+
+	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 out_free;
+	pcc_subspace_id = per_cpu(cpu_pcc_subspace_idx, pr->id);
 
 	/* Store CPU Logical ID */
 	cpc_ptr->cpu_id = pr->id;
@@ -901,21 +925,10 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
 		goto out_free;
 	}
 
-	kfree(output.pointer);
 	return 0;
 
 out_free:
-	/* Free all the mapped sys mem areas for this CPU */
-	for (i = 2; i < cpc_ptr->num_entries; i++) {
-		void __iomem *addr = cpc_ptr->cpc_regs[i-2].sys_mem_vaddr;
-
-		if (addr)
-			iounmap(addr);
-	}
 	kfree(cpc_ptr);
-
-out_buf_free:
-	kfree(output.pointer);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(acpi_cppc_processor_probe);
Signature · 1 line
2.34.1
#7 lore raw

PATCH v3 4/5 xen/cppc: get xen-required cppc perf caps data

In reply to Penny Zheng

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.

---
v2 -> v3:
- no change

---
 drivers/acpi/cppc_acpi.c | 110 +++++++++++++++++++++++++++++++++++----
 include/acpi/cppc_acpi.h |   5 ++
 include/acpi/processor.h |   1 +
 3 files changed, 105 insertions(+), 11 deletions(-)
drivers/acpi/cppc_acpi.c +99 -11
index 7832bebeb953..ee8015ce3ddf 100644
@@ -768,6 +768,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))
@@ -833,7 +842,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.
@@ -1012,8 +1023,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) {
@@ -1039,14 +1049,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;
@@ -1278,6 +1291,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.
include/acpi/cppc_acpi.h +5 -0
index 62d368bcd9ec..dcf129ec540f 100644
@@ -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*/
include/acpi/processor.h +1 -0
index a17e97e634a6..1decb437c750 100644
@@ -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;
Signature · 1 line
2.34.1
#8 lore raw

PATCH v3 5/5 xen/cppc: introduce cppc data upload sub-hypercall

In reply to Penny Zheng

As Xen is uncapable of parsing the ACPI dynamic table, this commit introduces a new sub-hypercall XEN_PM_CPPC to deliver CPPC perf caps data.

---
v2 -> v3:
- Adapt to the changes from new commit "xen: introduces XEN_PM_PSD sub-hypercall for solely delivery of _PSD info"

---
 drivers/acpi/cppc_acpi.c         |  1 +
 drivers/xen/xen-acpi-processor.c | 92 +++++++++++++++++++++++++++++++-
 include/acpi/processor.h         |  1 +
 include/xen/interface/platform.h | 11 ++++
 4 files changed, 103 insertions(+), 2 deletions(-)
drivers/acpi/cppc_acpi.c +1 -0
index ee8015ce3ddf..6b1c8d167405 100644
@@ -856,6 +856,7 @@ static int acpi_cppc_processor_parse(struct acpi_processor *pr, struct cpc_desc
 		cpc_ptr->cpc_regs[i].cpc_entry.int_value = 0;
 	}
 
+	pr->flags.has_cpc = 1;
 	pr_debug("Parsed _CPC entry for CPU: %d\n", pr->acpi_id);
 	kfree(output.pointer);
 	return 0;
drivers/xen/xen-acpi-processor.c +90 -2

180 lines not on this page · raw message

include/acpi/processor.h +1 -0
index 1decb437c750..12c1398abc7e 100644
@@ -214,6 +214,7 @@ struct acpi_processor_flags {
 	u8 bm_control:1;
 	u8 bm_check:1;
 	u8 has_cst:1;
+	u8 has_cpc:1;
 	u8 pcc_unsupported:1;
 	u8 has_lpi:1;
 	u8 power_setup_done:1;
include/xen/interface/platform.h +11 -0
index a35e1eb958f3..1db915d44dd7 100644
@@ -320,6 +320,7 @@ DEFINE_GUEST_HANDLE_STRUCT(xenpf_getidletime_t);
 #define XEN_PM_TX   2
 #define XEN_PM_PDC  3
 #define XEN_PM_PSD  4
+#define XEN_PM_CPPC 5
 /* Px sub info type */
 #define XEN_PX_PCT   1
 #define XEN_PX_PSS   2
@@ -384,6 +385,15 @@ struct xen_processor_px {
 };
 DEFINE_GUEST_HANDLE_STRUCT(xen_processor_px);
 
+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;
@@ -411,6 +421,7 @@ struct xenpf_set_processor_pminfo {
 		struct xen_psd_package              domain_info; /* _PSD */
 		struct xen_processor_performance    perf; /* Px: _PPC/_PCT/_PSS */
 		GUEST_HANDLE(uint32_t)              pdc;
+		struct xen_processor_cppc           cppc_data; /* _CPC */
 	};
 	uint32_t shared_type;     /* coordination type of this processor */
 };
Signature · 1 line
2.34.1