* [PATCH v3 1/5] xen/acpi: upload power and performance related data from a PVH dom0
2025-03-06 11:08 [PATCH v3 0/5] xen/acpi: introduce cppc performance hypercall Penny Zheng
@ 2025-03-06 11:08 ` Penny Zheng
2025-03-25 16:17 ` Jan Beulich
2025-03-25 21:11 ` Elliott Mitchell
2025-03-06 11:08 ` [PATCH v3 2/5] xen: introduces XEN_PM_PSD sub-hypercall for solely delivery of _PSD info Penny Zheng
` (3 subsequent siblings)
4 siblings, 2 replies; 9+ messages in thread
From: Penny Zheng @ 2025-03-06 11:08 UTC (permalink / raw)
To: jbeulich, Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko
Cc: Ray Huang, Jason Andryuk, Penny Zheng, xen-devel, linux-kernel,
Roger Pau Monne
From: Roger Pau Monne <roger.pau@citrix.com>
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.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
---
drivers/xen/pcpu.c | 3 +-
drivers/xen/xen-acpi-processor.c | 232 ++++++++++++++++++++++++++++---
include/xen/xen.h | 2 +-
3 files changed, 216 insertions(+), 21 deletions(-)
diff --git a/drivers/xen/pcpu.c b/drivers/xen/pcpu.c
index 093ad4a08672..36fb5372cd04 100644
--- a/drivers/xen/pcpu.c
+++ b/drivers/xen/pcpu.c
@@ -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)
{
diff --git a/drivers/xen/xen-acpi-processor.c b/drivers/xen/xen-acpi-processor.c
index 296703939846..e9f38f171240 100644
--- a/drivers/xen/xen-acpi-processor.c
+++ b/drivers/xen/xen-acpi-processor.c
@@ -48,6 +48,8 @@ static unsigned long *acpi_id_cst_present;
/* Which ACPI P-State dependencies for a enumerated processor */
static struct acpi_psd_package *acpi_psd;
+static bool pr_initialized;
+
static int push_cxx_to_hypervisor(struct acpi_processor *_pr)
{
struct xen_platform_op op = {
@@ -172,8 +174,13 @@ static int xen_copy_psd_data(struct acpi_processor *_pr,
/* 'acpi_processor_preregister_performance' does not parse if the
* num_processors <= 1, but Xen still requires it. Do it manually here.
+ *
+ * Also init the field if not set, as that's possible if the physical
+ * CPUs on the system doesn't match the data provided in the MADT when
+ * running as a PVH dom0.
*/
- if (pdomain->num_processors <= 1) {
+ if (pdomain->num_processors <= 1 ||
+ dst->shared_type == CPUFREQ_SHARED_TYPE_NONE) {
if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL)
dst->shared_type = CPUFREQ_SHARED_TYPE_ALL;
else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL)
@@ -313,6 +320,155 @@ static unsigned int __init get_max_acpi_id(void)
pr_debug("Max ACPI ID: %u\n", max_acpi_id);
return max_acpi_id;
}
+
+/*
+ * Custom version of the native acpi_processor_evaluate_cst() function, to
+ * avoid some sanity checks done based on the CPUID data. When running as a
+ * Xen domain the CPUID data provided to dom0 is not the native one, so C
+ * states cannot be sanity checked. Leave it to the hypervisor which is also
+ * the entity running the driver.
+ */
+static int xen_acpi_processor_evaluate_cst(acpi_handle handle,
+ struct acpi_processor_power *info)
+{
+ struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+ union acpi_object *cst;
+ acpi_status status;
+ u64 count;
+ int last_index = 0;
+ int i, ret = 0;
+
+ status = acpi_evaluate_object(handle, "_CST", NULL, &buffer);
+ if (ACPI_FAILURE(status)) {
+ acpi_handle_debug(handle, "No _CST\n");
+ return -ENODEV;
+ }
+
+ cst = buffer.pointer;
+
+ /* There must be at least 2 elements. */
+ if (!cst || cst->type != ACPI_TYPE_PACKAGE || cst->package.count < 2) {
+ acpi_handle_warn(handle, "Invalid _CST output\n");
+ ret = -EFAULT;
+ goto end;
+ }
+
+ count = cst->package.elements[0].integer.value;
+
+ /* Validate the number of C-states. */
+ if (count < 1 || count != cst->package.count - 1) {
+ acpi_handle_warn(handle, "Inconsistent _CST data\n");
+ ret = -EFAULT;
+ goto end;
+ }
+
+ for (i = 1; i <= count; i++) {
+ union acpi_object *element;
+ union acpi_object *obj;
+ struct acpi_power_register *reg;
+ struct acpi_processor_cx cx;
+
+ /*
+ * If there is not enough space for all C-states, skip the
+ * excess ones and log a warning.
+ */
+ if (last_index >= ACPI_PROCESSOR_MAX_POWER - 1) {
+ acpi_handle_warn(handle, "No room for more idle states (limit: %d)\n",
+ ACPI_PROCESSOR_MAX_POWER - 1);
+ break;
+ }
+
+ memset(&cx, 0, sizeof(cx));
+
+ element = &cst->package.elements[i];
+ if (element->type != ACPI_TYPE_PACKAGE) {
+ acpi_handle_info(handle, "_CST C%d type(%x) is not package, skip...\n",
+ i, element->type);
+ continue;
+ }
+
+ if (element->package.count != 4) {
+ acpi_handle_info(handle, "_CST C%d package count(%d) is not 4, skip...\n",
+ i, element->package.count);
+ continue;
+ }
+
+ obj = &element->package.elements[0];
+
+ if (obj->type != ACPI_TYPE_BUFFER) {
+ acpi_handle_info(handle, "_CST C%d package element[0] type(%x) is not buffer, skip...\n",
+ i, obj->type);
+ continue;
+ }
+
+ reg = (struct acpi_power_register *)obj->buffer.pointer;
+
+ obj = &element->package.elements[1];
+ if (obj->type != ACPI_TYPE_INTEGER) {
+ acpi_handle_info(handle, "_CST C[%d] package element[1] type(%x) is not integer, skip...\n",
+ i, obj->type);
+ continue;
+ }
+
+ cx.type = obj->integer.value;
+ /*
+ * There are known cases in which the _CST output does not
+ * contain C1, so if the type of the first state found is not
+ * C1, leave an empty slot for C1 to be filled in later.
+ */
+ if (i == 1 && cx.type != ACPI_STATE_C1)
+ last_index = 1;
+
+ cx.address = reg->address;
+ cx.index = last_index + 1;
+
+ switch (reg->space_id) {
+ case ACPI_ADR_SPACE_FIXED_HARDWARE:
+ cx.entry_method = ACPI_CSTATE_FFH;
+ break;
+
+ case ACPI_ADR_SPACE_SYSTEM_IO:
+ cx.entry_method = ACPI_CSTATE_SYSTEMIO;
+ break;
+
+ default:
+ acpi_handle_info(handle, "_CST C%d space_id(%x) neither FIXED_HARDWARE nor SYSTEM_IO, skip...\n",
+ i, reg->space_id);
+ continue;
+ }
+
+ if (cx.type == ACPI_STATE_C1)
+ cx.valid = 1;
+
+ obj = &element->package.elements[2];
+ if (obj->type != ACPI_TYPE_INTEGER) {
+ acpi_handle_info(handle, "_CST C%d package element[2] type(%x) not integer, skip...\n",
+ i, obj->type);
+ continue;
+ }
+
+ cx.latency = obj->integer.value;
+
+ obj = &element->package.elements[3];
+ if (obj->type != ACPI_TYPE_INTEGER) {
+ acpi_handle_info(handle, "_CST C%d package element[3] type(%x) not integer, skip...\n",
+ i, obj->type);
+ continue;
+ }
+
+ memcpy(&info->states[++last_index], &cx, sizeof(cx));
+ }
+
+ acpi_handle_info(handle, "Found %d idle states\n", last_index);
+
+ info->count = last_index;
+
+end:
+ kfree(buffer.pointer);
+
+ return ret;
+}
+
/*
* The read_acpi_id and check_acpi_ids are there to support the Xen
* oddity of virtual CPUs != physical CPUs in the initial domain.
@@ -331,6 +487,7 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv)
unsigned long long tmp;
union acpi_object object = { 0 };
struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
+ struct acpi_buffer cst_buf = { ACPI_ALLOCATE_BUFFER, NULL };
acpi_io_address pblk = 0;
status = acpi_get_type(handle, &acpi_type);
@@ -354,24 +511,45 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv)
default:
return AE_OK;
}
- if (invalid_phys_cpuid(acpi_get_phys_id(handle,
- acpi_type == ACPI_TYPE_DEVICE,
- acpi_id))) {
+
+ if (!xen_processor_present(acpi_id)) {
pr_debug("CPU with ACPI ID %u is unavailable\n", acpi_id);
return AE_OK;
}
- /* There are more ACPI Processor objects than in x2APIC or MADT.
- * This can happen with incorrect ACPI SSDT declerations. */
- if (acpi_id >= nr_acpi_bits) {
- pr_debug("max acpi id %u, trying to set %u\n",
- nr_acpi_bits - 1, acpi_id);
- return AE_OK;
- }
+
/* OK, There is a ACPI Processor object */
__set_bit(acpi_id, acpi_id_present);
pr_debug("ACPI CPU%u w/ PBLK:0x%lx\n", acpi_id, (unsigned long)pblk);
+ if (!pr_initialized) {
+ struct acpi_processor *pr = context;
+ int rc, rc2;
+
+ /*
+ * There's no CPU on the system that has any performance or
+ * power related data, initialize all the required fields by
+ * fetching that info here.
+ *
+ * Note such information is only fetched once, and then reused
+ * for all pCPUs. This won't work on heterogeneous systems
+ * with different Cx anb/or Px states between CPUs.
+ */
+
+ pr->handle = handle;
+
+ rc = acpi_processor_get_performance_info(pr);
+ if (rc)
+ pr_err("ACPI CPU%u failed to get performance data\n",
+ acpi_id);
+ rc2 = xen_acpi_processor_evaluate_cst(handle, &pr->power);
+ if (rc2)
+ pr_err("ACPI CPU%u failed to get _CST data\n", acpi_id);
+
+ if (!rc && !rc2)
+ pr_initialized = true;
+ }
+
/* It has P-state dependencies */
if (!acpi_processor_get_psd(handle, &acpi_psd[acpi_id])) {
pr_debug("ACPI CPU%u w/ PST:coord_type = %llu domain = %llu\n",
@@ -379,11 +557,13 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv)
acpi_psd[acpi_id].domain);
}
- status = acpi_evaluate_object(handle, "_CST", NULL, &buffer);
+ status = acpi_evaluate_object(handle, "_CST", NULL, &cst_buf);
if (ACPI_FAILURE(status)) {
if (!pblk)
return AE_OK;
}
+ kfree(cst_buf.pointer);
+
/* .. and it has a C-state */
__set_bit(acpi_id, acpi_id_cst_present);
@@ -391,10 +571,6 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv)
}
static int check_acpi_ids(struct acpi_processor *pr_backup)
{
-
- if (!pr_backup)
- return -ENODEV;
-
if (acpi_id_present && acpi_id_cst_present)
/* OK, done this once .. skip to uploading */
goto upload;
@@ -422,8 +598,8 @@ static int check_acpi_ids(struct acpi_processor *pr_backup)
acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
ACPI_UINT32_MAX,
- read_acpi_id, NULL, NULL, NULL);
- acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, read_acpi_id, NULL, NULL);
+ read_acpi_id, NULL, pr_backup, NULL);
+ acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, read_acpi_id, pr_backup, NULL);
upload:
if (!bitmap_equal(acpi_id_present, acpi_ids_done, nr_acpi_bits)) {
@@ -464,6 +640,7 @@ static int xen_upload_processor_pm_data(void)
struct acpi_processor *pr_backup = NULL;
int i;
int rc = 0;
+ bool free_perf = false;
pr_info("Uploading Xen processor PM info\n");
@@ -473,12 +650,29 @@ static int xen_upload_processor_pm_data(void)
if (!_pr)
continue;
- if (!pr_backup)
+ if (!pr_backup) {
pr_backup = kmemdup(_pr, sizeof(*_pr), GFP_KERNEL);
+ pr_initialized = true;
+ }
(void)upload_pm_data(_pr);
}
+ if (!pr_backup) {
+ pr_backup = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
+ if (!pr_backup)
+ return -ENOMEM;
+ pr_backup->performance = kzalloc(sizeof(struct acpi_processor_performance),
+ GFP_KERNEL);
+ if (!pr_backup->performance) {
+ kfree(pr_backup);
+ return -ENOMEM;
+ }
+ free_perf = true;
+ }
+
rc = check_acpi_ids(pr_backup);
+ if (free_perf)
+ kfree(pr_backup->performance);
kfree(pr_backup);
return rc;
diff --git a/include/xen/xen.h b/include/xen/xen.h
index a1e5b3f18d69..6ff3e2f40803 100644
--- a/include/xen/xen.h
+++ b/include/xen/xen.h
@@ -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)
--
2.34.1
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH v3 1/5] xen/acpi: upload power and performance related data from a PVH dom0
2025-03-06 11:08 ` [PATCH v3 1/5] xen/acpi: upload power and performance related data from a PVH dom0 Penny Zheng
@ 2025-03-25 16:17 ` Jan Beulich
2025-03-25 16:49 ` Jason Andryuk
2025-03-25 21:11 ` Elliott Mitchell
1 sibling, 1 reply; 9+ messages in thread
From: Jan Beulich @ 2025-03-25 16:17 UTC (permalink / raw)
To: Penny Zheng, Roger Pau Monne
Cc: Ray Huang, Jason Andryuk, xen-devel, linux-kernel, Juergen Gross,
Stefano Stabellini, Oleksandr Tyshchenko
On 06.03.2025 12:08, Penny Zheng wrote:
> From: Roger Pau Monne <roger.pau@citrix.com>
>
> 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.
>
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
> ---
> 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/5] xen/acpi: upload power and performance related data from a PVH dom0
2025-03-25 16:17 ` Jan Beulich
@ 2025-03-25 16:49 ` Jason Andryuk
0 siblings, 0 replies; 9+ messages in thread
From: Jason Andryuk @ 2025-03-25 16:49 UTC (permalink / raw)
To: Jan Beulich, Penny Zheng, Roger Pau Monne
Cc: Ray Huang, xen-devel, linux-kernel, Juergen Gross,
Stefano Stabellini, Oleksandr Tyshchenko
On 2025-03-25 12:17, Jan Beulich wrote:
> On 06.03.2025 12:08, Penny Zheng wrote:
>> From: Roger Pau Monne <roger.pau@citrix.com>
>>
>> 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.
>>
>> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
>> Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
>> ---
>> 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?
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3 1/5] xen/acpi: upload power and performance related data from a PVH dom0
2025-03-06 11:08 ` [PATCH v3 1/5] xen/acpi: upload power and performance related data from a PVH dom0 Penny Zheng
2025-03-25 16:17 ` Jan Beulich
@ 2025-03-25 21:11 ` Elliott Mitchell
1 sibling, 0 replies; 9+ messages in thread
From: Elliott Mitchell @ 2025-03-25 21:11 UTC (permalink / raw)
To: Penny Zheng
Cc: jbeulich, Juergen Gross, Stefano Stabellini,
Oleksandr Tyshchenko, Ray Huang, Jason Andryuk, xen-devel,
linux-kernel, Roger Pau Monne
On Thu, Mar 06, 2025 at 07:08:20PM +0800, Penny Zheng wrote:
> From: Roger Pau Monne <roger.pau@citrix.com>
>
> 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.
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...
--
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | ehem+sigmsg@m5p.com PGP 87145445 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3 2/5] xen: introduces XEN_PM_PSD sub-hypercall for solely delivery of _PSD info
2025-03-06 11:08 [PATCH v3 0/5] xen/acpi: introduce cppc performance hypercall Penny Zheng
2025-03-06 11:08 ` [PATCH v3 1/5] xen/acpi: upload power and performance related data from a PVH dom0 Penny Zheng
@ 2025-03-06 11:08 ` Penny Zheng
2025-03-06 11:08 ` [PATCH v3 3/5] acpi/cppc: extract _cpc entry parsing logic Penny Zheng
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Penny Zheng @ 2025-03-06 11:08 UTC (permalink / raw)
To: jbeulich, Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko
Cc: Ray Huang, Jason Andryuk, Penny Zheng, xen-devel, linux-kernel
_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.
Signed-off-by: Penny Zheng <Penny.Zheng@amd.com>
---
v2 -> v3:
- new commit
---
drivers/xen/xen-acpi-processor.c | 82 ++++++++++++++++++++------------
include/xen/interface/platform.h | 8 ++--
2 files changed, 56 insertions(+), 34 deletions(-)
diff --git a/drivers/xen/xen-acpi-processor.c b/drivers/xen/xen-acpi-processor.c
index e9f38f171240..8db8631a4b9d 100644
--- a/drivers/xen/xen-acpi-processor.c
+++ b/drivers/xen/xen-acpi-processor.c
@@ -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);
diff --git a/include/xen/interface/platform.h b/include/xen/interface/platform.h
index 79a443c65ea9..a35e1eb958f3 100644
--- a/include/xen/interface/platform.h
+++ b/include/xen/interface/platform.h
@@ -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);
--
2.34.1
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v3 3/5] acpi/cppc: extract _cpc entry parsing logic
2025-03-06 11:08 [PATCH v3 0/5] xen/acpi: introduce cppc performance hypercall Penny Zheng
2025-03-06 11:08 ` [PATCH v3 1/5] xen/acpi: upload power and performance related data from a PVH dom0 Penny Zheng
2025-03-06 11:08 ` [PATCH v3 2/5] xen: introduces XEN_PM_PSD sub-hypercall for solely delivery of _PSD info Penny Zheng
@ 2025-03-06 11:08 ` Penny Zheng
2025-03-06 11:08 ` [PATCH v3 4/5] xen/cppc: get xen-required cppc perf caps data Penny Zheng
2025-03-06 11:08 ` [PATCH v3 5/5] xen/cppc: introduce cppc data upload sub-hypercall Penny Zheng
4 siblings, 0 replies; 9+ messages in thread
From: Penny Zheng @ 2025-03-06 11:08 UTC (permalink / raw)
To: jbeulich, Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko
Cc: Ray Huang, Jason Andryuk, Penny Zheng, xen-devel, linux-kernel
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.
Signed-off-by: Penny Zheng <Penny.Zheng@amd.com>
---
v2 -> v3:
- no change
---
drivers/acpi/cppc_acpi.c | 93 +++++++++++++++++++++++-----------------
1 file changed, 53 insertions(+), 40 deletions(-)
diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index f193e713825a..7832bebeb953 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -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);
--
2.34.1
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v3 4/5] xen/cppc: get xen-required cppc perf caps data
2025-03-06 11:08 [PATCH v3 0/5] xen/acpi: introduce cppc performance hypercall Penny Zheng
` (2 preceding siblings ...)
2025-03-06 11:08 ` [PATCH v3 3/5] acpi/cppc: extract _cpc entry parsing logic Penny Zheng
@ 2025-03-06 11:08 ` Penny Zheng
2025-03-06 11:08 ` [PATCH v3 5/5] xen/cppc: introduce cppc data upload sub-hypercall Penny Zheng
4 siblings, 0 replies; 9+ messages in thread
From: Penny Zheng @ 2025-03-06 11:08 UTC (permalink / raw)
To: jbeulich, Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko
Cc: Ray Huang, Jason Andryuk, Penny Zheng, xen-devel, linux-kernel
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@amd.com>
---
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(-)
diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 7832bebeb953..ee8015ce3ddf 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -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 = ®_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.
diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h
index 62d368bcd9ec..dcf129ec540f 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 a17e97e634a6..1decb437c750 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
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH v3 5/5] xen/cppc: introduce cppc data upload sub-hypercall
2025-03-06 11:08 [PATCH v3 0/5] xen/acpi: introduce cppc performance hypercall Penny Zheng
` (3 preceding siblings ...)
2025-03-06 11:08 ` [PATCH v3 4/5] xen/cppc: get xen-required cppc perf caps data Penny Zheng
@ 2025-03-06 11:08 ` Penny Zheng
4 siblings, 0 replies; 9+ messages in thread
From: Penny Zheng @ 2025-03-06 11:08 UTC (permalink / raw)
To: jbeulich, Juergen Gross, Stefano Stabellini, Oleksandr Tyshchenko
Cc: Ray Huang, Jason Andryuk, Penny Zheng, xen-devel, linux-kernel
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.
Signed-off-by: Penny Zheng <Penny.Zheng@amd.com>
---
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(-)
diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index ee8015ce3ddf..6b1c8d167405 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -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;
diff --git a/drivers/xen/xen-acpi-processor.c b/drivers/xen/xen-acpi-processor.c
index 8db8631a4b9d..9c4faad043bc 100644
--- a/drivers/xen/xen-acpi-processor.c
+++ b/drivers/xen/xen-acpi-processor.c
@@ -25,6 +25,7 @@
#include <xen/xen.h>
#include <xen/interface/platform.h>
#include <asm/xen/hypercall.h>
+#include <acpi/cppc_acpi.h>
static int no_hypercall;
MODULE_PARM_DESC(off, "Inhibit the hypercall.");
@@ -45,8 +46,12 @@ static unsigned long *acpi_ids_done;
static unsigned long *acpi_id_present;
/* And if there is an _CST definition (or a PBLK) for the ACPI IDs */
static unsigned long *acpi_id_cst_present;
+/* And if there is an _CPC entry for the ACPI IDs */
+static unsigned long *acpi_id_cpc_present;
/* Which ACPI P-State dependencies for a enumerated processor */
static struct acpi_psd_package *acpi_psd;
+/* ACPI CPPC structures for a enumerated processor */
+static struct cppc_perf_caps *acpi_cppc_data;
static bool pr_initialized;
@@ -228,6 +233,44 @@ static int push_psd_to_hypervisor(struct acpi_processor *_pr)
return 0;
}
+static int push_cppc_to_hypervisor(struct acpi_processor *_pr)
+{
+ int ret = 0;
+ 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_CPPC,
+ };
+ const struct cppc_perf_caps *cppc_perf = acpi_cppc_data + _pr->acpi_id;
+
+ op.u.set_pminfo.cppc_data.highest_perf = cppc_perf->highest_perf;
+ op.u.set_pminfo.cppc_data.lowest_perf = cppc_perf->lowest_perf;
+ op.u.set_pminfo.cppc_data.nominal_perf = cppc_perf->nominal_perf;
+ op.u.set_pminfo.cppc_data.lowest_nonlinear_perf = cppc_perf->lowest_nonlinear_perf;
+ op.u.set_pminfo.cppc_data.lowest_freq = cppc_perf->lowest_freq;
+ op.u.set_pminfo.cppc_data.nominal_freq = cppc_perf->nominal_freq;
+
+ if (!no_hypercall)
+ ret = HYPERVISOR_platform_op(&op);
+
+ if (!ret) {
+ pr_debug("ACPI CPU%u - CPPC uploaded.\n", _pr->acpi_id);
+ pr_debug(" highest_perf: %d\n", cppc_perf->highest_perf);
+ pr_debug(" lowest_perf: %d\n", cppc_perf->lowest_perf);
+ pr_debug(" lowest_nonlinear_perf: %d\n", cppc_perf->lowest_nonlinear_perf);
+ pr_debug(" nominal_perf: %d\n", cppc_perf->nominal_perf);
+ pr_debug(" lowest_freq: %d Mhz\n", cppc_perf->lowest_freq);
+ pr_debug(" nominal_freq: %d Mhz\n", cppc_perf->nominal_freq);
+ } 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("(_CPC): Hypervisor error (%d) for ACPI CPU%u\n",
+ ret, _pr->acpi_id);
+
+ return ret;
+}
static int push_pxx_to_hypervisor(struct acpi_processor *_pr)
{
int ret = 0;
@@ -300,12 +343,16 @@ static int upload_pm_data(struct acpi_processor *_pr)
return -EBUSY;
}
- if (_pr->performance && _pr->performance->states)
+ if ((_pr->performance && _pr->performance->states) ||
+ _pr->flags.has_cpc)
err |= push_psd_to_hypervisor(_pr);
if (_pr->flags.power)
err = push_cxx_to_hypervisor(_pr);
+ if (_pr->flags.has_cpc)
+ err |= push_cppc_to_hypervisor(_pr);
+
if (_pr->performance && _pr->performance->states)
err |= push_pxx_to_hypervisor(_pr);
@@ -510,6 +557,7 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv)
union acpi_object object = { 0 };
struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
struct acpi_buffer cst_buf = { ACPI_ALLOCATE_BUFFER, NULL };
+ struct acpi_buffer cpc_buf = { ACPI_ALLOCATE_BUFFER, NULL };
acpi_io_address pblk = 0;
status = acpi_get_type(handle, &acpi_type);
@@ -589,11 +637,20 @@ read_acpi_id(acpi_handle handle, u32 lvl, void *context, void **rv)
/* .. and it has a C-state */
__set_bit(acpi_id, acpi_id_cst_present);
+ status = acpi_evaluate_object(handle, "_CPC", NULL, &cpc_buf);
+ if (ACPI_FAILURE(status)) {
+ return AE_OK;
+ }
+ kfree(cpc_buf.pointer);
+
+ /* .. and it has a _CPC entry */
+ __set_bit(acpi_id, acpi_id_cpc_present);
+
return AE_OK;
}
static int check_acpi_ids(struct acpi_processor *pr_backup)
{
- if (acpi_id_present && acpi_id_cst_present)
+ if (acpi_id_present && acpi_id_cst_present && acpi_id_cpc_present)
/* OK, done this once .. skip to uploading */
goto upload;
@@ -610,11 +667,19 @@ static int check_acpi_ids(struct acpi_processor *pr_backup)
return -ENOMEM;
}
+ acpi_id_cpc_present = bitmap_zalloc(nr_acpi_bits, GFP_KERNEL);
+ if (!acpi_id_cpc_present) {
+ bitmap_free(acpi_id_present);
+ bitmap_free(acpi_id_cst_present);
+ return -ENOMEM;
+ }
+
acpi_psd = kcalloc(nr_acpi_bits, sizeof(struct acpi_psd_package),
GFP_KERNEL);
if (!acpi_psd) {
bitmap_free(acpi_id_present);
bitmap_free(acpi_id_cst_present);
+ bitmap_free(acpi_id_cpc_present);
return -ENOMEM;
}
@@ -630,6 +695,12 @@ static int check_acpi_ids(struct acpi_processor *pr_backup)
pr_backup->acpi_id = i;
/* Mask out C-states if there are no _CST or PBLK */
pr_backup->flags.power = test_bit(i, acpi_id_cst_present);
+ /* Mask out relevant flag if there are no _CPC */
+ pr_backup->flags.has_cpc = test_bit(i, acpi_id_cpc_present);
+ if (pr_backup->flags.has_cpc) {
+ if (xen_processor_get_perf_caps(pr_backup, acpi_cppc_data + i))
+ return -EINVAL;
+ }
/* num_entries is non-zero if we evaluated _PSD */
if (acpi_psd[i].num_entries) {
memcpy(&pr_backup->performance->domain_info,
@@ -748,6 +819,15 @@ static int __init xen_acpi_processor_init(void)
bitmap_free(acpi_ids_done);
return -ENOMEM;
}
+
+ acpi_cppc_data = kcalloc(nr_acpi_bits, sizeof(struct cppc_perf_caps),
+ GFP_KERNEL);
+ if (!acpi_cppc_data) {
+ pr_debug("Memory allocation error for acpi_cppc_data\n");
+ rc = -ENOMEM;
+ goto err1_out;
+ }
+
for_each_possible_cpu(i) {
if (!zalloc_cpumask_var_node(
&per_cpu_ptr(acpi_perf_data, i)->shared_cpu_map,
@@ -773,6 +853,11 @@ static int __init xen_acpi_processor_init(void)
rc = acpi_processor_get_performance_info(pr);
if (rc)
goto err_out;
+
+ pr->flags.pcc_unsupported = true;
+ rc = xen_processor_get_perf_caps(pr, acpi_cppc_data + i);
+ if (rc)
+ goto err_out;
}
rc = xen_upload_processor_pm_data();
@@ -788,6 +873,8 @@ static int __init xen_acpi_processor_init(void)
err_out:
/* Freeing a NULL pointer is OK: alloc_percpu zeroes. */
+ kfree(acpi_cppc_data);
+err1_out:
free_acpi_perf_data();
bitmap_free(acpi_ids_done);
return rc;
@@ -801,6 +888,7 @@ static void __exit xen_acpi_processor_exit(void)
bitmap_free(acpi_id_present);
bitmap_free(acpi_id_cst_present);
kfree(acpi_psd);
+ kfree(acpi_cppc_data);
for_each_possible_cpu(i)
acpi_processor_unregister_performance(i);
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index 1decb437c750..12c1398abc7e 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 has_cpc:1;
u8 pcc_unsupported:1;
u8 has_lpi:1;
u8 power_setup_done:1;
diff --git a/include/xen/interface/platform.h b/include/xen/interface/platform.h
index a35e1eb958f3..1db915d44dd7 100644
--- a/include/xen/interface/platform.h
+++ b/include/xen/interface/platform.h
@@ -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 */
};
--
2.34.1
^ permalink raw reply [flat|nested] 9+ messages in thread