Skip to content

Commit 6812cd9

Browse files
superm1jamieNguyenNVIDIA
authored andcommitted
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> (backported from commit 8cdc494) [jamien: minor context-line drift in amd-pstate.c hunks from 3-way auto-merge; +/- content is byte-identical to upstream.] Signed-off-by: Jamie Nguyen <jamien@nvidia.com>
1 parent 6b43978 commit 6812cd9

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
@@ -757,15 +757,13 @@ static void amd_pstate_adjust_perf(unsigned int cpu,
757757
static int amd_pstate_cpu_boost_update(struct cpufreq_policy *policy, bool on)
758758
{
759759
struct amd_cpudata *cpudata = policy->driver_data;
760-
union perf_cached perf = READ_ONCE(cpudata->perf);
761-
u32 nominal_freq, max_freq;
760+
u32 nominal_freq;
762761
int ret = 0;
763762

764763
nominal_freq = READ_ONCE(cpudata->nominal_freq);
765-
max_freq = perf_to_freq(perf, cpudata->nominal_freq, perf.highest_perf);
766764

767765
if (on)
768-
policy->cpuinfo.max_freq = max_freq;
766+
policy->cpuinfo.max_freq = cpudata->max_freq;
769767
else if (policy->cpuinfo.max_freq > nominal_freq)
770768
policy->cpuinfo.max_freq = nominal_freq;
771769

@@ -950,13 +948,15 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
950948

951949
WRITE_ONCE(cpudata->nominal_freq, nominal_freq);
952950

951+
/* max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf */
953952
max_freq = perf_to_freq(perf, nominal_freq, perf.highest_perf);
953+
WRITE_ONCE(cpudata->max_freq, max_freq);
954+
954955
lowest_nonlinear_freq = perf_to_freq(perf, nominal_freq, perf.lowest_nonlinear_perf);
955956
WRITE_ONCE(cpudata->lowest_nonlinear_freq, lowest_nonlinear_freq);
956957

957958
/**
958959
* Below values need to be initialized correctly, otherwise driver will fail to load
959-
* max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf
960960
* lowest_nonlinear_freq is a value between [min_freq, nominal_freq]
961961
* Check _CPC in ACPI table objects if any values are incorrect
962962
*/
@@ -1019,9 +1019,7 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
10191019
policy->cpuinfo.min_freq = policy->min = perf_to_freq(perf,
10201020
cpudata->nominal_freq,
10211021
perf.lowest_perf);
1022-
policy->cpuinfo.max_freq = policy->max = perf_to_freq(perf,
1023-
cpudata->nominal_freq,
1024-
perf.highest_perf);
1022+
policy->cpuinfo.max_freq = policy->max = cpudata->max_freq;
10251023

10261024
ret = amd_pstate_cppc_enable(policy);
10271025
if (ret)
@@ -1088,14 +1086,9 @@ static void amd_pstate_cpu_exit(struct cpufreq_policy *policy)
10881086
static ssize_t show_amd_pstate_max_freq(struct cpufreq_policy *policy,
10891087
char *buf)
10901088
{
1091-
struct amd_cpudata *cpudata;
1092-
union perf_cached perf;
1093-
1094-
cpudata = policy->driver_data;
1095-
perf = READ_ONCE(cpudata->perf);
1089+
struct amd_cpudata *cpudata = policy->driver_data;
10961090

1097-
return sysfs_emit(buf, "%u\n",
1098-
perf_to_freq(perf, cpudata->nominal_freq, perf.highest_perf));
1091+
return sysfs_emit(buf, "%u\n", cpudata->max_freq);
10991092
}
11001093

11011094
static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *policy,
@@ -1501,9 +1494,7 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
15011494
policy->cpuinfo.min_freq = policy->min = perf_to_freq(perf,
15021495
cpudata->nominal_freq,
15031496
perf.lowest_perf);
1504-
policy->cpuinfo.max_freq = policy->max = perf_to_freq(perf,
1505-
cpudata->nominal_freq,
1506-
perf.highest_perf);
1497+
policy->cpuinfo.max_freq = policy->max = cpudata->max_freq;
15071498
policy->driver_data = cpudata;
15081499

15091500
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
@@ -68,6 +68,7 @@ struct amd_aperf_mperf {
6868
* @min_limit_freq: Cached value of policy->min (in khz)
6969
* @max_limit_freq: Cached value of policy->max (in khz)
7070
* @nominal_freq: the frequency (in khz) that mapped to nominal_perf
71+
* @max_freq: in ideal conditions the maximum frequency (in khz) possible frequency
7172
* @lowest_nonlinear_freq: the frequency (in khz) that mapped to lowest_nonlinear_perf
7273
* @cur: Difference of Aperf/Mperf/tsc count between last and current sample
7374
* @prev: Last Aperf/Mperf/tsc count value read from register
@@ -94,6 +95,7 @@ struct amd_cpudata {
9495
u32 min_limit_freq;
9596
u32 max_limit_freq;
9697
u32 nominal_freq;
98+
u32 max_freq;
9799
u32 lowest_nonlinear_freq;
98100

99101
struct amd_aperf_mperf cur;

0 commit comments

Comments
 (0)