Intel P states enhancements
Subsystems (4)
Srinivas Pandruvada
maintainerv4 cover Intel P states enhancements
This series enhances Intel P state drivers with the following features:
- Use Turbo Activation Ratio, when calculating max non turbo P state. This will show now correct percentage in turbo range
- To calculate busy percent, the estimate is not correct when the max non turbo is limited by tar, hence using physical max non turbo as before.
- Use ACPI _PSS and _PPC in intel_ptate driver.
- Avoid calculation for P state control value when cpufreq policy requests frequency limits when matched in _PSS. Sometime calculations causes reduced control value in boundary conditions.
Although they are independent patches, sending as series to help applying and testing.
I appreciate review and testing on multiple platforms.
v4:
- Dropped patch 1/6 : cpufreq: intel_p_state: Fix limiting turbo sub states Will submit it separately. The other patches are not dependent on this change.
v3:
- Added function : convert_to_native_pstate_format to convert from perf_ctl value to pstate used ratios.
- Fix bug identified by Rafael
v2:
- When CONFIG_ACPI not defined, then acpi/processor.h can't be included. Also some variables will be unused when CONFIG_ACPI is not defined, so there were warnings. Fixed all these compile issues.
v1:
- Change the command line option to "no_acpi"
- changed kernel parameter documentation file and added "no_acpi" parameter
- pr_debug prefixed with "intel_pstate" as suggested by Doug
- Changed the logic to determine turbo freq in _PSS using odd/even convention, although this is the way it is defined in _PSS. But atleast two reviewers has questioned the source of this. This is defined usually in non public documents like BIOS writer guides. Now using the control field value to determine the turbo and non turbo max.
- Fix the Kconfig dependency on ACPI for ACPI_PROCESSOR
- multi line comment styles
v0:
Base version
Srinivas Pandruvada (5):
cpufreq: intel_pstate: get P1 from TAR when available
cpufreq: intel-pstate: Use separate max pstate for scaling
cpufreq: intel_pstate: Use ACPI perf configuration
Documentation: kernel_parameters for Intel P state driver
cpufreq: intel_pstate: Avoid calculation for max/min
Documentation/kernel-parameters.txt | 3 + arch/x86/include/asm/msr-index.h | 7 + drivers/cpufreq/Kconfig.x86 | 1 + drivers/cpufreq/intel_pstate.c | 276 ++++++++++++++++++++++++++++++++++-- 4 files changed, 277 insertions(+), 10 deletions(-)
Signature · 1 line
2.1.4
Srinivas Pandruvada
maintainerPATCH v4 1/5 cpufreq: intel_pstate: get P1 from TAR when available
After Ivybridge, the max non turbo ratio obtained from platform info msr is not always guaranteed P1 on client platforms. The max non turbo activation ratio (TAR), determines the max for the current level of TDP. The ratio in platform info is physical max. The TAR MSR can be locked, so updating this value is not possible on all platforms. This change gets this ratio from MSR TURBO_ACTIVATION_RATIO if available,
but also do some sanity checking to make sure that this value is correct.
The sanity check involves reading the TDP ratio for the current tdp control value when platform has configurable TDP present and matching TAC
with this.
--- arch/x86/include/asm/msr-index.h | 7 +++++++ drivers/cpufreq/intel_pstate.c | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 4 deletions(-)
arch/x86/include/asm/msr-index.h +7 -0
@@ -206,6 +206,13 @@#define MSR_GFX_PERF_LIMIT_REASONS 0x000006B0#define MSR_RING_PERF_LIMIT_REASONS 0x000006B1 +/* Config TDP MSRs */ +#define MSR_CONFIG_TDP_NOMINAL 0x00000648 +#define MSR_CONFIG_TDP_LEVEL1 0x00000649 +#define MSR_CONFIG_TDP_LEVEL2 0x0000064A +#define MSR_CONFIG_TDP_CONTROL 0x0000064B +#define MSR_TURBO_ACTIVATION_RATIO 0x0000064C +/* Hardware P state interface */ #define MSR_PPERF 0x0000064e#define MSR_PERF_LIMIT_REASONS 0x0000064f
drivers/cpufreq/intel_pstate.c +35 -4
@@ -43,7 +43,6 @@#define int_tofp (X ) ((int64_t)(X) << FRAC_BITS)#define fp_toint (X ) ((X) >> FRAC_BITS) -static inline int32_t mul_fp (int32_t x,int32_t y) {return ((int64_t )x * (int64_t )y) >>FRAC_BITS ;
@@ -593,10 +592,42 @@ static int core_get_min_pstate(void)static int core_get_max_pstate (void ) { -u64 value; +u64 tar; +u64 plat_info; +int max_pstate; +int err; + +rdmsrl (MSR_PLATFORM_INFO , plat_info); + max_pstate = (plat_info >>8 ) &0xFF ; + + err =rdmsrl_safe (MSR_TURBO_ACTIVATION_RATIO , &tar); +if (!err) { +/* Do some sanity checking for safety */ +if (plat_info &0x600000000 ) { +u64 tdp_ctrl; +u64 tdp_ratio; +int tdp_msr; + + err =rdmsrl_safe (MSR_CONFIG_TDP_CONTROL , &tdp_ctrl); +if (err) + goto skip_tar; + + tdp_msr =MSR_CONFIG_TDP_NOMINAL + tdp_ctrl; + err =rdmsrl_safe (tdp_msr, &tdp_ratio); +if (err) + goto skip_tar; + +if (tdp_ratio -1 == tar) { + max_pstate = tar; +pr_debug ("max_pstate=TAC %x\n" , max_pstate); + }else { + goto skip_tar; + } + } + } -rdmsrl (MSR_PLATFORM_INFO , value); -return (value >>8 ) &0xFF ; +skip_tar: +return max_pstate; }static int core_get_turbo_pstate (void )
Signature · 1 line
2.1.4
Srinivas Pandruvada
maintainerPATCH v4 2/5 cpufreq: intel-pstate: Use separate max pstate for scaling
In reply to Srinivas PandruvadaSystems with configurable TDP have multiple max non turbo p state. Intel P state uses max non turbo P state for scaling. But using the real max non turbo p state causes underestimation of next P state. So using the physical max non turbo P state as before for scaling.
--- drivers/cpufreq/intel_pstate.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/cpufreq/intel_pstate.c +18 -2
@@ -77,6 +77,7 @@ struct pstate_data {int current_pstate;int min_pstate;int max_pstate; +int max_pstate_physical;int scaling;int turbo_pstate; };
@@ -126,6 +127,7 @@ struct pstate_adjust_policy {struct pstate_funcs {int (*get_max)(void ); +int (*get_max_physical)(void );int (*get_min)(void );int (*get_turbo)(void );int (*get_scaling)(void );
@@ -590,6 +592,14 @@ static int core_get_min_pstate(void)return (value >>40 ) &0xFF ; } +static int core_get_max_pstate_physical (void ) +{ +u64 value; + +rdmsrl (MSR_PLATFORM_INFO , value); +return (value >>8 ) &0xFF ; +} +static int core_get_max_pstate (void ) {u64 tar;
@@ -683,6 +693,7 @@ static struct cpu_defaults core_params = { }, .funcs = { .get_max = core_get_max_pstate, + .get_max_physical = core_get_max_pstate_physical, .get_min = core_get_min_pstate, .get_turbo = core_get_turbo_pstate, .get_scaling = core_get_scaling,
@@ -701,6 +712,7 @@ static struct cpu_defaults byt_params = { }, .funcs = { .get_max = byt_get_max_pstate, + .get_max_physical = byt_get_max_pstate, .get_min = byt_get_min_pstate, .get_turbo = byt_get_turbo_pstate, .set = byt_set_pstate,
@@ -720,6 +732,7 @@ static struct cpu_defaults knl_params = { }, .funcs = { .get_max = core_get_max_pstate, + .get_max_physical = core_get_max_pstate_physical, .get_min = core_get_min_pstate, .get_turbo = knl_get_turbo_pstate, .get_scaling = core_get_scaling,
@@ -774,6 +787,7 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu) { cpu->pstate.min_pstate = pstate_funcs.get_min (); cpu->pstate.max_pstate = pstate_funcs.get_max (); + cpu->pstate.max_pstate_physical = pstate_funcs.get_max_physical (); cpu->pstate.turbo_pstate = pstate_funcs.get_turbo (); cpu->pstate.scaling = pstate_funcs.get_scaling ();
@@ -792,7 +806,8 @@ static inline void intel_pstate_calc_busy(struct cpudata *cpu) sample->freq =fp_toint (mul_fp (int_tofp ( - cpu->pstate.max_pstate * cpu->pstate.scaling /100 ), + cpu->pstate.max_pstate_physical * + cpu->pstate.scaling /100 ), core_pct)); sample->core_pct_busy = (int32_t )core_pct;
@@ -860,7 +875,7 @@ static inline int32_t intel_pstate_get_scaled_busy(struct cpudata *cpu)* specified pstate. */ core_busy = cpu->sample.core_pct_busy; - max_pstate =int_tofp (cpu->pstate.max_pstate); + max_pstate =int_tofp (cpu->pstate.max_pstate_physical); current_pstate =int_tofp (cpu->pstate.current_pstate); core_busy =mul_fp (core_busy,div_fp (max_pstate, current_pstate));
@@ -1144,6 +1159,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)static void copy_cpu_funcs (struct pstate_funcs *funcs) { pstate_funcs.get_max = funcs->get_max; + pstate_funcs.get_max_physical = funcs->get_max_physical; pstate_funcs.get_min = funcs->get_min; pstate_funcs.get_turbo = funcs->get_turbo; pstate_funcs.get_scaling = funcs->get_scaling;
Signature · 1 line
2.1.4
Srinivas Pandruvada
maintainerPATCH v4 3/5 cpufreq: intel_pstate: Use ACPI perf configuration
In reply to Srinivas PandruvadaUse ACPI _PSS to limit the Intel P State turbo, max and min ratios. This driver uses acpi processor perf lib calls to register performance. The following logic is used to adjust Intel P state driver limits:
- If there is no turbo entry in _PSS, then disable Intel P state turbo and limit to non turbo max
- If the non turbo max ratio is more than _PSS max non turbo value, then set the max non turbo ratio to _PSS non turbo max
- If the min ratio is less than _PSS min then change the min ratio matching _PSS min
- Scale the _PSS turbo frequency to max turbo frequency based on control value.
This feature can be disabled by using kernel parameters:
intel_pstate=no_acpi
--- drivers/cpufreq/Kconfig.x86 | 1 + drivers/cpufreq/intel_pstate.c | 171 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 171 insertions(+), 1 deletion(-)
drivers/cpufreq/Kconfig.x86 +1 -0
@@ -5,6 +5,7 @@ config X86_INTEL_PSTATE bool "Intel P state control" depends on X86 + select ACPI_PROCESSOR if ACPI help This driver provides a P state for Intel core processors. The driver implements an internal governor and will become
drivers/cpufreq/intel_pstate.c +170 -1
225 lines not on this page · raw message
Signature · 1 line
2.1.4
Srinivas Pandruvada
maintainerPATCH v4 4/5 Documentation: kernel_parameters for Intel P state driver
In reply to Srinivas PandruvadaAdded new option "no_acpi" for not using ACPI processor performance control objects in Intel P state driver.
--- Documentation/kernel-parameters.txt | 3 +++ 1 file changed, 3 insertions(+)
Documentation/kernel-parameters.txt +3 -0
@@ -1546,6 +1546,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted. hwp_only Only load intel_pstate on systems which support hardware P state control (HWP) if available. + no_acpi + Don't use ACPI processor performance control objects + _PSS and _PPC specified limits. intremap= [X86-64, Intel-IOMMU] on enable Interrupt Remapping (default)
Signature · 1 line
2.1.4
Srinivas Pandruvada
maintainerPATCH v4 5/5 cpufreq: intel_pstate: Avoid calculation for max/min
In reply to Srinivas PandruvadaWhen requested from cpufreq to set policy, look into _pss and get control values, instead of using max/min perf calculations. These calculation misses next control state in boundary conditions.
--- drivers/cpufreq/intel_pstate.c | 50 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-)
drivers/cpufreq/intel_pstate.c +45 -5
@@ -163,6 +163,8 @@ struct perf_limits {int max_sysfs_pct;int min_policy_pct;int min_sysfs_pct; +int max_perf_ctl; +int min_perf_ctl; };static struct perf_limits limits = {
@@ -176,6 +178,8 @@ static struct perf_limits limits = { .max_sysfs_pct = 100, .min_policy_pct = 0, .min_sysfs_pct = 0, + .max_perf_ctl = 0, + .min_perf_ctl = 0, };#if IS_ENABLED (CONFIG_ACPI )
@@ -909,12 +913,23 @@ static void intel_pstate_get_min_max(struct cpudata *cpu, int *min, int *max)* policy, or by cpu specific default values determined through * experimentation. */ - max_perf_adj =fp_toint (mul_fp (int_tofp (max_perf), limits.max_perf)); - *max =clamp_t (int, max_perf_adj, - cpu->pstate.min_pstate, cpu->pstate.turbo_pstate); +if (limits.max_perf_ctl && limits.max_sysfs_pct >= + limits.max_policy_pct) { + *max = limits.max_perf_ctl; + }else { + max_perf_adj =fp_toint (mul_fp (int_tofp (max_perf), + limits.max_perf)); + *max =clamp_t (int, max_perf_adj, cpu->pstate.min_pstate, + cpu->pstate.turbo_pstate); + } - min_perf =fp_toint (mul_fp (int_tofp (max_perf), limits.min_perf)); - *min =clamp_t (int, min_perf, cpu->pstate.min_pstate, max_perf); +if (limits.min_perf_ctl) { + *min = limits.min_perf_ctl; + }else { + min_perf =fp_toint (mul_fp (int_tofp (max_perf), + limits.min_perf)); + *min =clamp_t (int, min_perf, cpu->pstate.min_pstate, max_perf); + } }static void intel_pstate_set_pstate (struct cpudata *cpu,int pstate,bool force)
@@ -1184,6 +1199,12 @@ static unsigned int intel_pstate_get(unsigned int cpu_num)static int intel_pstate_set_policy (struct cpufreq_policy *policy) { +#if IS_ENABLED (CONFIG_ACPI ) +struct cpudata *cpu; +int i; +#endif +pr_debug ("intel_pstate: %s max %u policy->max %u\n" , __func__, + policy->cpuinfo.max_freq, policy->max);if (!policy->cpuinfo.max_freq)return -ENODEV ;
@@ -1196,6 +1217,8 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy) limits.max_perf_pct =100 ; limits.max_perf =int_tofp (1 ); limits.no_turbo =0 ; + limits.max_perf_ctl =0 ; + limits.min_perf_ctl =0 ;return 0 ; }
@@ -1216,6 +1239,23 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy) limits.min_perf =div_fp (int_tofp (limits.min_perf_pct),int_tofp (100 )); limits.max_perf =div_fp (int_tofp (limits.max_perf_pct),int_tofp (100 )); +#if IS_ENABLED (CONFIG_ACPI ) + cpu = all_cpu_data[policy->cpu]; +for (i =0 ; i < cpu->acpi_perf_data.state_count; i++) { +int control; + + control =convert_to_native_pstate_format (cpu, i); +if (control * cpu->pstate.scaling == policy->max) + limits.max_perf_ctl = control; +if (control * cpu->pstate.scaling == policy->min) + limits.min_perf_ctl = control; + } + +pr_debug ("intel_pstate: max %u policy_max %u perf_ctl [0x%x-0x%x]\n" , + policy->cpuinfo.max_freq, policy->max, limits.min_perf_ctl, + limits.max_perf_ctl); +#endif +if (hwp_active)intel_pstate_hwp_set ();
Signature · 1 line
2.1.4
Quoted 51 lines · Srinivas Pandruvada
This series enhances Intel P state drivers with the following features:
- Use Turbo Activation Ratio, when calculating max non turbo P state. This will show now correct percentage in turbo range
- To calculate busy percent, the estimate is not correct when the max non turbo is limited by tar, hence using physical max non turbo as before.
- Use ACPI_PSSand_PPCinintel_ptatedriver.
- Avoid calculation for P state control value when cpufreq policy requests frequency limits when matched in_PSS. Sometime calculations causes reduced control value in boundary conditions.
Although they are independent patches, sending as series to help applying and testing.
I appreciate review and testing on multiple platforms.v4:
- Dropped patch 1/6 : cpufreq:intel_p_state: Fix limiting turbo sub states Will submit it separately. The other patches are not dependent on this change.v3:
- Added function :convert_to_native_pstate_formatto convert fromperf_ctlvalue to pstate used ratios.
- Fix bug identified by Rafaelv2:
- WhenCONFIG_ACPInot defined, thenacpi/processor.hcan't be included. Also some variables will be unused whenCONFIG_ACPIis not defined, so there were warnings. Fixed all these compile issues.v1:
- Change the command line option to "no_acpi"
- changed kernel parameter documentation file and added "no_acpi" parameter
-pr_debugprefixed with "intel_pstate" as suggested by Doug
- Changed the logic to determine turbo freq in_PSSusing odd/even convention, although this is the way it is defined in_PSS. But atleast two reviewers has questioned the source of this. This is defined usually in non public documents like BIOS writer guides. Now using the control field value to determine the turbo and non turbo max.
- Fix theKconfigdependency on ACPI forACPI_PROCESSOR
- multi line comment stylesv0:
Base versionSrinivas Pandruvada (5):
cpufreq:intel_pstate: get P1 from TAR when available
cpufreq: intel-pstate: Use separate max pstate for scaling
cpufreq:intel_pstate: Use ACPI perf configuration
Documentation:kernel_parametersfor Intel P state driver
cpufreq:intel_pstate: Avoid calculation for max/min
Quoted 5 lines
Documentation/kernel-parameters.txt | 3 + arch/x86/include/asm/msr-index.h | 7 + drivers/cpufreq/Kconfig.x86 | 1 + drivers/cpufreq/intel_pstate.c | 276 ++++++++++++++++++++++++++++++++++-- 4 files changed, 277 insertions(+), 10 deletions(-)
Series queued up for v4.4, thanks!
Rafael