[PATCH 16/19] cpupower: enable boost state support for amd-pstate module
From: Huang Rui <ray.huang@amd.com>
Date: 2021-09-08 15:02:18
Also in:
lkml
Subsystem:
cpu power monitoring subsystem, the rest · Maintainers:
Thomas Renninger, Shuah Khan, Shuah Khan, John B. Wyatt IV, John B. Wyatt IV, John Kacur, Linus Torvalds
The AMD P-state boost API is different from ACPI hardware P-states, so implement the support for amd-pstate kernel module. Signed-off-by: Huang Rui <ray.huang@amd.com> --- tools/power/cpupower/lib/cpufreq.c | 20 ++++++++++++++++++++ tools/power/cpupower/lib/cpufreq.h | 3 +++ tools/power/cpupower/utils/helpers/misc.c | 7 +++++++ 3 files changed, 30 insertions(+)
diff --git a/tools/power/cpupower/lib/cpufreq.c b/tools/power/cpupower/lib/cpufreq.c
index 3f92ddadaad2..37da87bdcfb1 100644
--- a/tools/power/cpupower/lib/cpufreq.c
+++ b/tools/power/cpupower/lib/cpufreq.c@@ -790,3 +790,23 @@ unsigned long cpufreq_get_transitions(unsigned int cpu) { return sysfs_cpufreq_get_one_value(cpu, STATS_NUM_TRANSITIONS); } + +int amd_pstate_boost_support(unsigned int cpu) +{ + unsigned int highest_perf, nominal_perf; + + highest_perf = sysfs_cpufreq_get_one_value(cpu, AMD_PSTATE_HIGHEST_PERF); + nominal_perf = sysfs_cpufreq_get_one_value(cpu, AMD_PSTATE_NOMINAL_PERF); + + return highest_perf > nominal_perf ? 1 : 0; +} + +int amd_pstate_boost_enabled(unsigned int cpu) +{ + unsigned int cpuinfo_max, amd_pstate_max; + + cpuinfo_max = sysfs_cpufreq_get_one_value(cpu, CPUINFO_MAX_FREQ); + amd_pstate_max = sysfs_cpufreq_get_one_value(cpu, AMD_PSTATE_MAX_FREQ); + + return cpuinfo_max == amd_pstate_max ? 1 : 0; +}
diff --git a/tools/power/cpupower/lib/cpufreq.h b/tools/power/cpupower/lib/cpufreq.h
index 95f4fd9e2656..d54d02a7a4f4 100644
--- a/tools/power/cpupower/lib/cpufreq.h
+++ b/tools/power/cpupower/lib/cpufreq.h@@ -203,6 +203,9 @@ int cpufreq_modify_policy_governor(unsigned int cpu, char *governor); int cpufreq_set_frequency(unsigned int cpu, unsigned long target_frequency); +int amd_pstate_boost_support(unsigned int cpu); +int amd_pstate_boost_enabled(unsigned int cpu); + #ifdef __cplusplus } #endif
diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c
index 07d80775fb68..aba979320760 100644
--- a/tools/power/cpupower/utils/helpers/misc.c
+++ b/tools/power/cpupower/utils/helpers/misc.c@@ -10,6 +10,7 @@ #if defined(__i386__) || defined(__x86_64__) #include "cpupower_intern.h" +#include "cpufreq.h" #define MSR_AMD_HWCR 0xc0010015
@@ -39,6 +40,12 @@ int cpufreq_has_boost_support(unsigned int cpu, int *support, int *active, if (ret) return ret; } + } if ((cpupower_cpu_info.caps & CPUPOWER_CAP_AMD_PSTATE) && + amd_pstate_boost_support(cpu)) { + *support = 1; + + if (amd_pstate_boost_enabled(cpu)) + *active = 1; } else if (cpupower_cpu_info.caps & CPUPOWER_CAP_INTEL_IDA) *support = *active = 1; return 0;
--
2.25.1