* [PATCH] cpufreq/amd-pstate: Cache the max frequency in cpudata
@ 2026-03-12 18:24 Mario Limonciello
2026-03-14 16:55 ` kernel test robot
0 siblings, 1 reply; 2+ messages in thread
From: Mario Limonciello @ 2026-03-12 18:24 UTC (permalink / raw)
To: Gautham R . Shenoy
Cc: Perry Yuan, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
open list:CPU FREQUENCY SCALING FRAMEWORK, Mario Limonciello
The value of maximum frequency is fixed and never changes. Doing
calculations every time based off of perf is unnecessary.
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
drivers/cpufreq/amd-pstate.c | 21 ++++++++-------------
drivers/cpufreq/amd-pstate.h | 1 +
2 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 5aa9fcd80cf51..787aa3ba87b33 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -757,15 +757,13 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
static int amd_pstate_cpu_boost_update(struct cpufreq_policy *policy, bool on)
{
struct amd_cpudata *cpudata = policy->driver_data;
- union perf_cached perf = READ_ONCE(cpudata->perf);
- u32 nominal_freq, max_freq;
+ u32 nominal_freq;
int ret = 0;
nominal_freq = READ_ONCE(cpudata->nominal_freq);
- max_freq = perf_to_freq(perf, cpudata->nominal_freq, perf.highest_perf);
if (on)
- policy->cpuinfo.max_freq = max_freq;
+ policy->cpuinfo.max_freq = cpudata->max_freq;
else if (policy->cpuinfo.max_freq > nominal_freq)
policy->cpuinfo.max_freq = nominal_freq;
@@ -952,13 +950,15 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
WRITE_ONCE(cpudata->nominal_freq, nominal_freq);
+ /* max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf */
max_freq = perf_to_freq(perf, nominal_freq, perf.highest_perf);
+ WRITE_ONCE(cpudata->max_freq, max_freq);
+
lowest_nonlinear_freq = perf_to_freq(perf, nominal_freq, perf.lowest_nonlinear_perf);
WRITE_ONCE(cpudata->lowest_nonlinear_freq, lowest_nonlinear_freq);
/**
* Below values need to be initialized correctly, otherwise driver will fail to load
- * max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf
* lowest_nonlinear_freq is a value between [min_freq, nominal_freq]
* Check _CPC in ACPI table objects if any values are incorrect
*/
@@ -1021,9 +1021,7 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
policy->cpuinfo.min_freq = policy->min = perf_to_freq(perf,
cpudata->nominal_freq,
perf.lowest_perf);
- policy->cpuinfo.max_freq = policy->max = perf_to_freq(perf,
- cpudata->nominal_freq,
- perf.highest_perf);
+ policy->cpuinfo.max_freq = policy->max = cpudata->max_freq;
ret = amd_pstate_cppc_enable(policy);
if (ret)
@@ -1096,8 +1094,7 @@ static ssize_t show_amd_pstate_max_freq(struct cpufreq_policy *policy,
cpudata = policy->driver_data;
perf = READ_ONCE(cpudata->perf);
- return sysfs_emit(buf, "%u\n",
- perf_to_freq(perf, cpudata->nominal_freq, perf.highest_perf));
+ return sysfs_emit(buf, "%u\n", cpudata->max_freq);
}
static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *policy,
@@ -1503,9 +1500,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
policy->cpuinfo.min_freq = policy->min = perf_to_freq(perf,
cpudata->nominal_freq,
perf.lowest_perf);
- policy->cpuinfo.max_freq = policy->max = perf_to_freq(perf,
- cpudata->nominal_freq,
- perf.highest_perf);
+ policy->cpuinfo.max_freq = policy->max = cpudata->max_freq;
policy->driver_data = cpudata;
ret = amd_pstate_cppc_enable(policy);
diff --git a/drivers/cpufreq/amd-pstate.h b/drivers/cpufreq/amd-pstate.h
index cb45fdca27a6c..485ee023d79c5 100644
--- a/drivers/cpufreq/amd-pstate.h
+++ b/drivers/cpufreq/amd-pstate.h
@@ -94,6 +94,7 @@ struct amd_cpudata {
u32 min_limit_freq;
u32 max_limit_freq;
u32 nominal_freq;
+ u32 max_freq;
u32 lowest_nonlinear_freq;
struct amd_aperf_mperf cur;
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] cpufreq/amd-pstate: Cache the max frequency in cpudata
2026-03-12 18:24 [PATCH] cpufreq/amd-pstate: Cache the max frequency in cpudata Mario Limonciello
@ 2026-03-14 16:55 ` kernel test robot
0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2026-03-14 16:55 UTC (permalink / raw)
To: Mario Limonciello, Gautham R . Shenoy
Cc: llvm, oe-kbuild-all, Perry Yuan,
open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
open list:CPU FREQUENCY SCALING FRAMEWORK, Mario Limonciello
Hi Mario,
kernel test robot noticed the following build warnings:
[auto build test WARNING on rafael-pm/linux-next]
[also build test WARNING on rafael-pm/bleeding-edge linus/master v6.16-rc1 next-20260313]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mario-Limonciello/cpufreq-amd-pstate-Cache-the-max-frequency-in-cpudata/20260314-194005
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link: https://lore.kernel.org/r/20260312182442.3236386-1-mario.limonciello%40amd.com
patch subject: [PATCH] cpufreq/amd-pstate: Cache the max frequency in cpudata
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20260314/202603141750.mDER1GM9-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260314/202603141750.mDER1GM9-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603141750.mDER1GM9-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> drivers/cpufreq/amd-pstate.c:1092:20: warning: variable 'perf' set but not used [-Wunused-but-set-variable]
1092 | union perf_cached perf;
| ^
1 warning generated.
vim +/perf +1092 drivers/cpufreq/amd-pstate.c
ec4e3326a95507 Huang Rui 2021-12-24 1082
ec4e3326a95507 Huang Rui 2021-12-24 1083 /*
ec4e3326a95507 Huang Rui 2021-12-24 1084 * This frequency is to indicate the maximum hardware frequency.
ec4e3326a95507 Huang Rui 2021-12-24 1085 * If boost is not active but supported, the frequency will be larger than the
ec4e3326a95507 Huang Rui 2021-12-24 1086 * one in cpuinfo.
ec4e3326a95507 Huang Rui 2021-12-24 1087 */
ec4e3326a95507 Huang Rui 2021-12-24 1088 static ssize_t show_amd_pstate_max_freq(struct cpufreq_policy *policy,
ec4e3326a95507 Huang Rui 2021-12-24 1089 char *buf)
ec4e3326a95507 Huang Rui 2021-12-24 1090 {
009d1c29a45194 Mario Limonciello 2025-01-17 1091 struct amd_cpudata *cpudata;
009d1c29a45194 Mario Limonciello 2025-01-17 @1092 union perf_cached perf;
ec4e3326a95507 Huang Rui 2021-12-24 1093
009d1c29a45194 Mario Limonciello 2025-01-17 1094 cpudata = policy->driver_data;
009d1c29a45194 Mario Limonciello 2025-01-17 1095 perf = READ_ONCE(cpudata->perf);
ec4e3326a95507 Huang Rui 2021-12-24 1096
a6b5fc5470a623 Mario Limonciello 2026-03-12 1097 return sysfs_emit(buf, "%u\n", cpudata->max_freq);
ec4e3326a95507 Huang Rui 2021-12-24 1098 }
ec4e3326a95507 Huang Rui 2021-12-24 1099
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-14 16:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12 18:24 [PATCH] cpufreq/amd-pstate: Cache the max frequency in cpudata Mario Limonciello
2026-03-14 16:55 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox