xen/cpufreq: implement amd-cppc-epp driver for CPPC in active mode
PATCH v8 4/8 xen/cpufreq: implement amd-cppc-epp driver for CPPC in active mode
amd-cppc has 2 operation modes: autonomous (active) mode and non-autonomous (passive) mode.
In active mode, we don't need Xen governor to calculate and tune the cpu frequency, while hardware built-in CPPC power algorithm will calculate the runtime workload and adjust cores frequency automatically according to the power supply, thermal, core voltage and some other hardware conditions. In active mode, CPPC ignores requests done in the desired performance field, and takes into account only the values set to the minimum performance, maximum performance, and energy performance preference registers.
A new field EPP (energy performance preference), in CPPC request register, is introduced. It will be used in the CCLK DPM controller to drive the frequency that a core is going to operate during short periods of activity, called minimum active frequency, It could contatin a range of values from 0 to 0xff. An EPP of zero sets the min active frequency to maximum frequency, while an EPP of 0xff sets the min active frequency to approxiately Idle frequency.
We implement a new AMD CPU frequency driver amd-cppc-epp for active mode. It requires active tag in Xen cmdline for users to explicitly select active mode.
In driver active-cppc-epp, ->setpolicy() is hooked, not the ->target(), as it does not depend on xen governor to do performance tuning.
We also introduce a new field "policy" (CPUFREQ_POLICY_xxx) to represent performance policy. Right now, it supports three values:CPUFREQ_POLICY_PERFORMANCE as maximum performance, CPUFREQ_POLICY_POWERSAVE as the least power consumption, and CPUFREQ_POLICY_ONDEMAND as no preference, just corresponding to "performance", "powersave" and "ondemand" Xen governor, which benefit users from re-using "governor" in Xen cmdline to deliver which performance policy they want to apply.
---
v1 -> v2:
- Remove redundant epp_mode
- Remove pointless initializer
- Define sole caller read_epp_init_once and epp_init value to read pre-defined BIOS epp value only once
- Combine the commit "xen/cpufreq: introduce policy type when cpufreq_driver->setpolicy exists"
---
v2 -> v3:
- Combined with commit "x86/cpufreq: add "cpufreq=amd-cppc,active" para"
- Refactor doc about "active mode"
- Change opt_cpufreq_active to opt_active_mode
- Let caller pass epp_init when unspecified to allow the function parameter to be of uint8_t
- Make epp_init per-cpu value
---
v3 -> v4:
- doc refinement
- use MASK_EXTR() to get epp value
- fix indentation
- replace if-else() with switch()
- combine successive comments and do refinement
- no need to introduce amd_cppc_epp_update_limit() as a wrapper
- rename cpufreq_parse_policy() with cpufreq_policy_from_governor()
- no need to use case-insensitive comparison
---
v4 -> v5:
- refine doc to state what the default is for "active" sub-option and it's of boolean nature
- excess blank after << for AMD_CPPC_EPP_MASK
- set max_perf with lowest_perf to get utmost powersave
- refine commit message to include description about relation between "policy" and "governor"
---
v5 -> v6:
- expand comment for "epp" field
- let min_perf set with lowest_nonliner_perf, not lowest_perf, to constrain performance tuning in P-states range
- refactor doc and comments
- blank lines between non-fall-through case blocks
- introduce and add entry for "CPUFREQ_POLICY_ONDEMAND"
---
v6 -> v7
- make opt_active_mode __initdata when NDEBUG=y
- add assertion check for must-zero des_perf in active mode
- use the local variable max_perf and min_perf
- read_epp_init() doesn't worth a separate function
---
v7 -> v8:
- use "ASSERT(!opt_active_mode || !des_perf);" to remove #ifndef NDEBUG
- add a new helper amd_cppc_prepare_policy()
--- docs/misc/xen-command-line.pandoc | 9 +- xen/arch/x86/acpi/cpufreq/amd-cppc.c | 135 ++++++++++++++++++++++++++- xen/drivers/cpufreq/utility.c | 15 +++ xen/include/acpi/cpufreq/cpufreq.h | 18 ++++ xen/include/public/sysctl.h | 1 + 5 files changed, 173 insertions(+), 5 deletions(-)
docs/misc/xen-command-line.pandoc +8 -1
@@ -515,7 +515,7 @@ If set, force use of the performance counters for oprofile, rather than detectin available support. ### cpufreq -> `= none | {{ <boolean> | xen } { [:[powersave|performance|ondemand|userspace][,[<maxfreq>]][,[<minfreq>]]] } [,verbose]} | dom0-kernel | hwp[:[<hdc>][,verbose]] | amd-cppc[:[verbose]]` +> `= none | {{ <boolean> | xen } { [:[powersave|performance|ondemand|userspace][,[<maxfreq>]][,[<minfreq>]]] } [,verbose]} | dom0-kernel | hwp[:[<hdc>][,verbose]] | amd-cppc[:[active][,verbose]]` > Default: `xen`
@@ -537,6 +537,13 @@ choice of `dom0-kernel` is deprecated and not supported by all Dom0 kernels. * `amd-cppc` selects ACPI Collaborative Performance and Power Control (CPPC) on supported AMD hardware to provide finer grained frequency control mechanism. The default is disabled. +* `active` is a boolean to enable amd-cppc driver in active(autonomous) mode. + In this mode, users don't rely on Xen governor to do performance monitoring + and tuning. Hardware built-in CPPC power algorithm will calculate the runtime + workload and adjust cores frequency automatically according to the power + supply, thermal, core voltage and some other hardware conditions. + The default is disabled, and the option only applies when `amd-cppc` is + enabled. There is also support for `;`-separated fallback options: `cpufreq=hwp;xen,verbose`. This first tries `hwp` and falls back to `xen` if
xen/arch/x86/acpi/cpufreq/amd-cppc.c +131 -4
187 lines not on this page · raw message
xen/drivers/cpufreq/utility.c +15 -0
@@ -250,6 +250,7 @@ int __cpufreq_set_policy(struct cpufreq_policy *data, data->min = policy->min; data->max = policy->max; data->limits = policy->limits; + data->policy = policy->policy;if (cpufreq_driver.setpolicy)return alternative_call (cpufreq_driver.setpolicy, data);
@@ -281,3 +282,17 @@ int __cpufreq_set_policy(struct cpufreq_policy *data,return __cpufreq_governor (data,CPUFREQ_GOV_LIMITS ); } + +unsigned int cpufreq_policy_from_governor (const struct cpufreq_governor *gov) +{ +if ( !strncmp (gov->name,"performance" ,CPUFREQ_NAME_LEN ) ) +return CPUFREQ_POLICY_PERFORMANCE ; + +if ( !strncmp (gov->name,"powersave" ,CPUFREQ_NAME_LEN ) ) +return CPUFREQ_POLICY_POWERSAVE ; + +if ( !strncmp (gov->name,"ondemand" ,CPUFREQ_NAME_LEN ) ) +return CPUFREQ_POLICY_ONDEMAND ; + +return CPUFREQ_POLICY_UNKNOWN ; +}
xen/include/acpi/cpufreq/cpufreq.h +18 -0
@@ -81,6 +81,7 @@ struct cpufreq_policy {int8_t turbo;/* tristate flag: 0 for unsupported * -1 for disable, 1 for enabled * See CPUFREQ_TURBO_* below for defines */ +unsigned int policy;/* CPUFREQ_POLICY_* */ }; DECLARE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_policy);
@@ -131,6 +132,23 @@ extern int cpufreq_register_governor(struct cpufreq_governor *governor);extern struct cpufreq_governor *__find_governor (const char *governor);#define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_dbs +/* +* Performance Policy +* If cpufreq_driver->target() exists, the ->governor decides what frequency +* within the limits is used. If cpufreq_driver->setpolicy() exists, these +* following policies are available: +* CPUFREQ_POLICY_PERFORMANCE represents maximum performance +* CPUFREQ_POLICY_POWERSAVE represents least power consumption +* CPUFREQ_POLICY_ONDEMAND represents no preference over performance or +* powersave +*/ +#define CPUFREQ_POLICY_UNKNOWN 0 +#define CPUFREQ_POLICY_POWERSAVE 1 +#define CPUFREQ_POLICY_PERFORMANCE 2 +#define CPUFREQ_POLICY_ONDEMAND 3 + +unsigned int cpufreq_policy_from_governor (const struct cpufreq_governor *gov); +/* pass a target to the cpufreq driver */ extern int __cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq,
xen/include/public/sysctl.h +1 -0
@@ -454,6 +454,7 @@ struct xen_set_cppc_para { };#define XEN_AMD_CPPC_DRIVER_NAME "amd-cppc" +#define XEN_AMD_CPPC_EPP_DRIVER_NAME "amd-cppc-epp"#define XEN_HWP_DRIVER_NAME "hwp"/*
Signature · 1 line
2.34.1