Skip to content

Commit 8cdc494

Browse files
committed
cpufreq/amd-pstate: Cache the max frequency in cpudata
The value of maximum frequency is fixed and never changes. Doing calculations every time based off of perf is unnecessary. Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com> Link: https://lore.kernel.org/r/20260326193620.649441-1-mario.limonciello@amd.com Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
1 parent 88d2ca6 commit 8cdc494

2 files changed

Lines changed: 11 additions & 18 deletions

File tree

drivers/cpufreq/amd-pstate.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -826,15 +826,13 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
826826
static int amd_pstate_cpu_boost_update(struct cpufreq_policy *policy, bool on)
827827
{
828828
struct amd_cpudata *cpudata = policy->driver_data;
829-
union perf_cached perf = READ_ONCE(cpudata->perf);
830-
u32 nominal_freq, max_freq;
829+
u32 nominal_freq;
831830
int ret = 0;
832831

833832
nominal_freq = READ_ONCE(cpudata->nominal_freq);
834-
max_freq = perf_to_freq(perf, cpudata->nominal_freq, perf.highest_perf);
835833

836834
if (on)
837-
policy->cpuinfo.max_freq = max_freq;
835+
policy->cpuinfo.max_freq = cpudata->max_freq;
838836
else if (policy->cpuinfo.max_freq > nominal_freq)
839837
policy->cpuinfo.max_freq = nominal_freq;
840838

@@ -1021,13 +1019,15 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
10211019

10221020
WRITE_ONCE(cpudata->nominal_freq, nominal_freq);
10231021

1022+
/* max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf */
10241023
max_freq = perf_to_freq(perf, nominal_freq, perf.highest_perf);
1024+
WRITE_ONCE(cpudata->max_freq, max_freq);
1025+
10251026
lowest_nonlinear_freq = perf_to_freq(perf, nominal_freq, perf.lowest_nonlinear_perf);
10261027
WRITE_ONCE(cpudata->lowest_nonlinear_freq, lowest_nonlinear_freq);
10271028

10281029
/**
10291030
* Below values need to be initialized correctly, otherwise driver will fail to load
1030-
* max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf
10311031
* lowest_nonlinear_freq is a value between [min_freq, nominal_freq]
10321032
* Check _CPC in ACPI table objects if any values are incorrect
10331033
*/
@@ -1090,9 +1090,7 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
10901090
policy->cpuinfo.min_freq = policy->min = perf_to_freq(perf,
10911091
cpudata->nominal_freq,
10921092
perf.lowest_perf);
1093-
policy->cpuinfo.max_freq = policy->max = perf_to_freq(perf,
1094-
cpudata->nominal_freq,
1095-
perf.highest_perf);
1093+
policy->cpuinfo.max_freq = policy->max = cpudata->max_freq;
10961094

10971095
policy->driver_data = cpudata;
10981096
ret = amd_pstate_cppc_enable(policy);
@@ -1167,14 +1165,9 @@ static void amd_pstate_cpu_exit(struct cpufreq_policy *policy)
11671165
static ssize_t show_amd_pstate_max_freq(struct cpufreq_policy *policy,
11681166
char *buf)
11691167
{
1170-
struct amd_cpudata *cpudata;
1171-
union perf_cached perf;
1172-
1173-
cpudata = policy->driver_data;
1174-
perf = READ_ONCE(cpudata->perf);
1168+
struct amd_cpudata *cpudata = policy->driver_data;
11751169

1176-
return sysfs_emit(buf, "%u\n",
1177-
perf_to_freq(perf, cpudata->nominal_freq, perf.highest_perf));
1170+
return sysfs_emit(buf, "%u\n", cpudata->max_freq);
11781171
}
11791172

11801173
static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *policy,
@@ -1702,9 +1695,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
17021695
policy->cpuinfo.min_freq = policy->min = perf_to_freq(perf,
17031696
cpudata->nominal_freq,
17041697
perf.lowest_perf);
1705-
policy->cpuinfo.max_freq = policy->max = perf_to_freq(perf,
1706-
cpudata->nominal_freq,
1707-
perf.highest_perf);
1698+
policy->cpuinfo.max_freq = policy->max = cpudata->max_freq;
17081699
policy->driver_data = cpudata;
17091700

17101701
ret = amd_pstate_cppc_enable(policy);

drivers/cpufreq/amd-pstate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct amd_aperf_mperf {
7373
* @min_limit_freq: Cached value of policy->min (in khz)
7474
* @max_limit_freq: Cached value of policy->max (in khz)
7575
* @nominal_freq: the frequency (in khz) that mapped to nominal_perf
76+
* @max_freq: in ideal conditions the maximum frequency (in khz) possible frequency
7677
* @lowest_nonlinear_freq: the frequency (in khz) that mapped to lowest_nonlinear_perf
7778
* @floor_freq: Cached value of the user requested floor_freq
7879
* @cur: Difference of Aperf/Mperf/tsc count between last and current sample
@@ -103,6 +104,7 @@ struct amd_cpudata {
103104
u32 min_limit_freq;
104105
u32 max_limit_freq;
105106
u32 nominal_freq;
107+
u32 max_freq;
106108
u32 lowest_nonlinear_freq;
107109
u32 floor_freq;
108110

0 commit comments

Comments
 (0)