amd-cppc CPU Performance Scaling Driver
v8 cover amd-cppc CPU Performance Scaling Driver
amd-cppc is the AMD CPU performance scaling driver that introduces a new CPU frequency control mechanism on modern AMD APU and CPU series in Xen. The new mechanism is based on Collaborative Processor Performance Control (CPPC) which provides finer grain frequency management than legacy ACPI hardware P-States. Current AMD CPU/APU platforms are using the ACPI P-states driver to manage CPU frequency and clocks with switching only in 3 P-states. CPPC replaces the ACPI P-states controls and allows a flexible, low-latency interface for Xen to directly communicate the performance hints to hardware.
amd_cppc driver has 2 operation modes: autonomous (active) mode, and non-autonomous (passive) mode. We register different CPUFreq driver for different modes, "amd-cppc" for passive mode and "amd-cppc-epp" for active mode.
The passive mode leverages common governors such as *ondemand*, *performance*, etc, to manage the performance tuning. While the active mode uses epp to provides a hint to the hardware if software wants to bias toward performance (0x0) or energy efficiency (0xff). CPPC power algorithm in hardware will automatically calculate the runtime workload and adjust the realtime cpu cores frequency according to the power supply and thermal, core voltage and some other hardware conditions.
amd-cppc is enabled on passive mode with a top-level cpufreq=amd-cppc option, while users add extra active flag to select active mode.
With cpufreq=amd-cppc,active, we did a 60s sampling test to see the CPU frequency change, through tweaking the energy_perf preference from xenpm set-cpufreq-cppc powersave to xenpm set-cpufreq-cppc performance. The outputs are as follows:
``` Setting CPU in powersave mode Sampling and Outputs: Avg freq 580000 KHz Avg freq 580000 KHz Avg freq 580000 KHz Setting CPU in performance mode Sampling and Outputs: Avg freq 4640000 KHz Avg freq 4220000 KHz Avg freq 4640000 KHz ```
Penny Zheng (8):
xen/cpufreq: introduce new sub-hypercall to propagate CPPC data xen/cpufreq: introduce "cpufreq=amd-cppc" xen cmdline and amd-cppc
driver
xen/cpufreq: implement amd-cppc driver for CPPC in passive mode xen/cpufreq: implement amd-cppc-epp driver for CPPC in active mode xen/cpufreq: get performance policy from governor set via xenpm tools/cpufreq: extract CPPC para from cpufreq para xen/cpufreq: bypass governor-related para for amd-cppc-epp xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc
driver
docs/misc/xen-command-line.pandoc | 14 +- tools/include/xenctrl.h | 3 +- tools/libs/ctrl/xc_pm.c | 25 +- tools/misc/xenpm.c | 94 ++- xen/arch/x86/acpi/cpufreq/Makefile | 1 + xen/arch/x86/acpi/cpufreq/amd-cppc.c | 766 ++++++++++++++++++++++ xen/arch/x86/acpi/cpufreq/cpufreq.c | 69 +- xen/arch/x86/cpu/amd.c | 8 +- xen/arch/x86/include/asm/amd.h | 2 + xen/arch/x86/include/asm/msr-index.h | 6 + xen/arch/x86/platform_hypercall.c | 19 + xen/arch/x86/x86_64/cpufreq.c | 19 + xen/arch/x86/x86_64/platform_hypercall.c | 3 + xen/drivers/acpi/pm-op.c | 68 +- xen/drivers/acpi/pmstat.c | 4 + xen/drivers/cpufreq/cpufreq.c | 137 +++- xen/drivers/cpufreq/utility.c | 15 + xen/include/acpi/cpufreq/cpufreq.h | 40 +- xen/include/acpi/cpufreq/processor_perf.h | 14 +- xen/include/public/platform.h | 26 + xen/include/public/sysctl.h | 5 +- xen/include/xen/pmstat.h | 5 + xen/include/xlat.lst | 1 + 23 files changed, 1283 insertions(+), 61 deletions(-) create mode 100644 xen/arch/x86/acpi/cpufreq/amd-cppc.c
Signature · 1 line
2.34.1
PATCH v8 1/8 xen/cpufreq: introduce new sub-hypercall to propagate CPPC data
In order to provide backward compatibility with existing governors that represent performance as frequency, like ondemand, the _CPC table can optionally provide processor frequency range values, Lowest frequency and Nominal frequency, to let OS use Lowest Frequency/ Performance and Nominal Frequency/Performance as anchor points to create linear mapping of CPPC performance to CPU frequency.
As Xen is uncapable of parsing the ACPI dynamic table, we'd like to introduce a new sub-hypercall "XEN_PM_CPPC" to propagate required CPPC data from dom0 kernel to Xen.
In the according handler set_cppc_pminfo(), we do _CPC and _PSD sanitization check, as both _PSD and _CPC info are necessary for correctly initializing cpufreq cores in CPPC mode.
Users shall be warned that if we failed at this point,
no fallback scheme, like legacy P-state could be switched to.
A new flag "XEN_CPPC_INIT" is also introduced for cpufreq core initialised in CPPC mode. Then all .init flag checking shall be updated to consider "XEN_CPPC_INIT" too.
We want to bypass construction of px statistic info in cpufreq_statistic_init() for CPPC mode, while not bypassing cpufreq_statistic_lock initialization for a good reason. The same check is unnecessary for cpufreq_statistic_exit(), since it has already been covered by px statistic variable "cpufreq_statistic_data" check
---
v1 -> v2:
- Give the variable des_perf an initializer of 0
- Use the strncmp()s directly in the if()
---
v3 -> v4
- refactor comments
- remove double blank lines
- replace amd_cppc_in_use flag with XEN_PROCESSOR_PM_CPPC
---
v4 -> v5:
- add new field "policy" in "struct xen_cppc_para"
- add new performamce policy XEN_CPUFREQ_POLICY_BALANCE
- drop string comparisons with "processor_pminfo[cpuid]->init & XEN_CPPC_INIT" and "cpufreq.setpolicy == NULL"
- Blank line ahead of the main "return" of a function
- refactor comments, commit message and title
---
v5 -> v6:
- remove duplicated manifest constants, and just move it to public header
- use "else if" to avoid confusion that it looks as if both paths could be taken
- add check for legitimate perf values
- use "unknown" instead of "none"
- introduce "CPUFREQ_POLICY_END" for array overrun check in user space tools
---
v6 -> v7:
- use ARRAY_SIZE() instead
- ->policy print is avoided in passive mode and print "unknown" in invalid cases
- let cpufreq_is_governorless() being the variable's initializer
- refactor with the conditional operator to increase readability
- move duplicated defination ahead and use local variable
- avoid using "else-condition" to bring "dead code" in Misra's nomeclature
- move the comment out of public header and into the respective internal struct field
- wrap set{,get}_amd_cppc_para() with CONFIG_PM_OP
- add symmetry scenario for maximum check
---
v7 -> v8:
- replace -EFAULT with -ENOMEM
- indent fix
- add comment for state_count check for CPPC mode
--- xen/arch/x86/platform_hypercall.c | 5 + xen/arch/x86/x86_64/cpufreq.c | 19 ++++ xen/arch/x86/x86_64/platform_hypercall.c | 3 + xen/drivers/acpi/pm-op.c | 7 +- xen/drivers/acpi/pmstat.c | 4 + xen/drivers/cpufreq/cpufreq.c | 124 +++++++++++++++++++++- xen/include/acpi/cpufreq/processor_perf.h | 4 +- xen/include/public/platform.h | 26 +++++ xen/include/xen/pmstat.h | 5 + xen/include/xlat.lst | 1 + 10 files changed, 193 insertions(+), 5 deletions(-)
xen/arch/x86/platform_hypercall.c +5 -0
@@ -577,6 +577,11 @@ ret_t do_platform_op(break ; } +case XEN_PM_CPPC : + ret =set_cppc_pminfo (op->u.set_pminfo.id, + &op->u.set_pminfo.u.cppc_data); +break ; +default : ret = -EINVAL ;break ;
xen/arch/x86/x86_64/cpufreq.c +19 -0
@@ -54,3 +54,22 @@ int compat_set_px_pminfo(uint32_t acpi_id,return set_px_pminfo (acpi_id, xen_perf); } + +int compat_set_cppc_pminfo (unsigned int acpi_id, +const struct compat_processor_cppc *cppc_data) + +{ +struct xen_processor_cppc *xen_cppc; +unsigned long xlat_page_current; + +xlat_malloc_init (xlat_page_current); + + xen_cppc =xlat_malloc_array (xlat_page_current, + struct xen_processor_cppc, 1); +if (unlikely (xen_cppc ==NULL ) ) +return -ENOMEM ; + +XLAT_processor_cppc (xen_cppc, cppc_data); + +return set_cppc_pminfo (acpi_id, xen_cppc); +}
xen/arch/x86/x86_64/platform_hypercall.c +3 -0
@@ -14,6 +14,9 @@ EMIT_FILE;#define efi_get_info efi_compat_get_info#define efi_runtime_call (x) efi_compat_runtime_call(x) +#define xen_processor_cppc compat_processor_cppc +#define set_cppc_pminfo compat_set_cppc_pminfo +#define xen_processor_performance compat_processor_performance#define set_px_pminfo compat_set_px_pminfo
xen/drivers/acpi/pm-op.c +5 -2
@@ -91,7 +91,10 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op) pmpt = processor_pminfo[op->cpuid]; policy =per_cpu (cpufreq_cpu_policy, op->cpuid); -if ( !pmpt || !pmpt->perf.states || +if ( !pmpt || + ((pmpt->init &XEN_PX_INIT ) && !pmpt->perf.states) || +/* Avoid NULL deref of pmpt->perf.states[] */ + ((pmpt->init &XEN_CPPC_INIT ) && pmpt->perf.state_count) || !policy || !policy->governor )return -EINVAL ;
@@ -351,7 +354,7 @@ int do_pm_op(struct xen_sysctl_pm_op *op)case CPUFREQ_PARA :if ( !(xen_processor_pmbits &XEN_PROCESSOR_PM_PX ) )return -ENODEV ; -if ( !pmpt || !(pmpt->init &XEN_PX_INIT ) ) +if ( !pmpt || !(pmpt->init & (XEN_PX_INIT |XEN_CPPC_INIT )) )return -EINVAL ;break ; }
xen/drivers/acpi/pmstat.c +4 -0
@@ -108,6 +108,10 @@ int cpufreq_statistic_init(unsigned int cpu)if ( !pmpt )return -EINVAL ; +/* Only need to initialize in Px mode */ +if ( !(pmpt->init &XEN_PX_INIT ) ) +return 0 ; +spin_lock (cpufreq_statistic_lock); pxpt =per_cpu (cpufreq_statistic_data, cpu);
xen/drivers/cpufreq/cpufreq.c +122 -2
154 lines not on this page · raw message
xen/include/acpi/cpufreq/processor_perf.h +3 -1
@@ -5,7 +5,8 @@#include <public/sysctl.h> #include <xen/acpi.h> -#define XEN_PX_INIT 0x80000000U +#define XEN_CPPC_INIT 0x40000000U +#define XEN_PX_INIT 0x80000000Uunsigned int powernow_register_driver (void );unsigned int get_measured_perf (unsigned int cpu,unsigned int flag);
@@ -43,6 +44,7 @@ struct processor_pminfo {uint32_t acpi_id;uint32_t id;struct processor_performance perf; +struct xen_processor_cppc cppc_data;uint32_t init; };
xen/include/public/platform.h +26 -0
@@ -363,6 +363,7 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);#define XEN_PM_PX 1#define XEN_PM_TX 2#define XEN_PM_PDC 3 +#define XEN_PM_CPPC 4/* Px sub info type */ #define XEN_PX_PCT 1
@@ -370,6 +371,10 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_getidletime_t);#define XEN_PX_PPC 4#define XEN_PX_PSD 8 +/* CPPC sub info type */ +#define XEN_CPPC_PSD (1U << 0) +#define XEN_CPPC_CPC (1U << 1) +struct xen_power_register {uint32_t space_id;uint32_t bit_width;
@@ -457,6 +462,26 @@ struct xen_processor_performance {typedef struct xen_processor_performance xen_processor_performance_t ;DEFINE_XEN_GUEST_HANDLE (xen_processor_performance_t); +struct xen_processor_cppc { +uint8_t flags;/* IN: XEN_CPPC_xxx */ +uint8_t pad[3 ]; +/* +* IN: Subset _CPC fields useful for CPPC-compatible cpufreq +* driver's initialization +*/ +struct { +uint32_t highest_perf; +uint32_t nominal_perf; +uint32_t lowest_nonlinear_perf; +uint32_t lowest_perf; +uint32_t lowest_mhz; +uint32_t nominal_mhz; + } cpc; +uint32_t shared_type;/* IN: XEN_CPUPERF_SHARED_TYPE_xxx */ +struct xen_psd_package domain_info;/* IN: _PSD */ +}; +typedef struct xen_processor_cppc xen_processor_cppc_t ; +struct xenpf_set_processor_pminfo {/* IN variables */ uint32_t id;/* ACPI CPU ID */
@@ -465,6 +490,7 @@ struct xenpf_set_processor_pminfo {struct xen_processor_power power;/* Cx: _CST/_CSD */ struct xen_processor_performance perf;/* Px: _PPC/_PCT/_PSS/_PSD */ XEN_GUEST_HANDLE (uint32) pdc;/* _PDC */ +xen_processor_cppc_t cppc_data;/* CPPC: _CPC and _PSD */ } u; };typedef struct xenpf_set_processor_pminfo xenpf_set_processor_pminfo_t ;
xen/include/xen/pmstat.h +5 -0
@@ -7,12 +7,17 @@int set_px_pminfo (uint32_t acpi_id,struct xen_processor_performance *perf);long set_cx_pminfo (uint32_t acpi_id,struct xen_processor_power *power); +int set_cppc_pminfo (unsigned int acpi_id, +const struct xen_processor_cppc *cppc_data);#ifdef CONFIG_COMPAT struct compat_processor_performance ;int compat_set_px_pminfo (uint32_t acpi_id,struct compat_processor_performance *perf);struct compat_processor_power ;long compat_set_cx_pminfo (uint32_t acpi_id,struct compat_processor_power *power); +struct compat_processor_cppc ; +int compat_set_cppc_pminfo (unsigned int acpi_id, +const struct compat_processor_cppc *cppc_data);#endif uint32_t pmstat_get_cx_nr (unsigned int cpu);
xen/include/xlat.lst +1 -0
@@ -160,6 +160,7 @@ ! pct_register platform.h ! power_register platform.h +! processor_cppc platform.h ? processor_csd platform.h ! processor_cx platform.h ! processor_flags platform.h
Signature · 1 line
2.34.1