Skip to content

Commit a9b9b4c

Browse files
committed
cpufreq/amd-pstate: Drop min and max cached frequencies
Use the perf_to_freq helpers to calculate this on the fly. As the members are no longer cached add an extra check into amd_pstate_epp_update_limit() to avoid unnecessary calls in amd_pstate_update_min_max_limit(). Reviewed-by: Gautham R. Shenoy <[email protected]> Reviewed-by: Dhananjay Ugwekar <[email protected]> Signed-off-by: Mario Limonciello <[email protected]>
1 parent a9ba0fd commit a9b9b4c

File tree

3 files changed

+20
-46
lines changed

3 files changed

+20
-46
lines changed

drivers/cpufreq/amd-pstate-ut.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ static void amd_pstate_ut_check_freq(u32 index)
214214
break;
215215
cpudata = policy->driver_data;
216216

217-
if (!((cpudata->max_freq >= cpudata->nominal_freq) &&
217+
if (!((policy->cpuinfo.max_freq >= cpudata->nominal_freq) &&
218218
(cpudata->nominal_freq > cpudata->lowest_nonlinear_freq) &&
219-
(cpudata->lowest_nonlinear_freq > cpudata->min_freq) &&
220-
(cpudata->min_freq > 0))) {
219+
(cpudata->lowest_nonlinear_freq > policy->cpuinfo.min_freq) &&
220+
(policy->cpuinfo.min_freq > 0))) {
221221
amd_pstate_ut_cases[index].result = AMD_PSTATE_UT_RESULT_FAIL;
222222
pr_err("%s cpu%d max=%d >= nominal=%d > lowest_nonlinear=%d > min=%d > 0, the formula is incorrect!\n",
223-
__func__, cpu, cpudata->max_freq, cpudata->nominal_freq,
224-
cpudata->lowest_nonlinear_freq, cpudata->min_freq);
223+
__func__, cpu, policy->cpuinfo.max_freq, cpudata->nominal_freq,
224+
cpudata->lowest_nonlinear_freq, policy->cpuinfo.min_freq);
225225
goto skip_test;
226226
}
227227

@@ -233,13 +233,13 @@ static void amd_pstate_ut_check_freq(u32 index)
233233
}
234234

235235
if (cpudata->boost_supported) {
236-
if ((policy->max == cpudata->max_freq) ||
236+
if ((policy->max == policy->cpuinfo.max_freq) ||
237237
(policy->max == cpudata->nominal_freq))
238238
amd_pstate_ut_cases[index].result = AMD_PSTATE_UT_RESULT_PASS;
239239
else {
240240
amd_pstate_ut_cases[index].result = AMD_PSTATE_UT_RESULT_FAIL;
241241
pr_err("%s cpu%d policy_max=%d should be equal cpu_max=%d or cpu_nominal=%d !\n",
242-
__func__, cpu, policy->max, cpudata->max_freq,
242+
__func__, cpu, policy->max, policy->cpuinfo.max_freq,
243243
cpudata->nominal_freq);
244244
goto skip_test;
245245
}

drivers/cpufreq/amd-pstate.c

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ static int amd_pstate_cpu_boost_update(struct cpufreq_policy *policy, bool on)
717717
int ret = 0;
718718

719719
nominal_freq = READ_ONCE(cpudata->nominal_freq);
720-
max_freq = READ_ONCE(cpudata->max_freq);
720+
max_freq = perf_to_freq(cpudata, READ_ONCE(cpudata->highest_perf));
721721

722722
if (on)
723723
policy->cpuinfo.max_freq = max_freq;
@@ -917,13 +917,10 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
917917
nominal_freq *= 1000;
918918

919919
WRITE_ONCE(cpudata->nominal_freq, nominal_freq);
920-
WRITE_ONCE(cpudata->min_freq, min_freq);
921920

922921
max_freq = perf_to_freq(cpudata, cpudata->highest_perf);
923922
lowest_nonlinear_freq = perf_to_freq(cpudata, cpudata->lowest_nonlinear_perf);
924-
925923
WRITE_ONCE(cpudata->lowest_nonlinear_freq, lowest_nonlinear_freq);
926-
WRITE_ONCE(cpudata->max_freq, max_freq);
927924

928925
/**
929926
* Below values need to be initialized correctly, otherwise driver will fail to load
@@ -948,9 +945,9 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata)
948945

949946
static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
950947
{
951-
int min_freq, max_freq, ret;
952-
struct device *dev;
953948
struct amd_cpudata *cpudata;
949+
struct device *dev;
950+
int ret;
954951

955952
/*
956953
* Resetting PERF_CTL_MSR will put the CPU in P0 frequency,
@@ -981,17 +978,11 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
981978
if (ret)
982979
goto free_cpudata1;
983980

984-
min_freq = READ_ONCE(cpudata->min_freq);
985-
max_freq = READ_ONCE(cpudata->max_freq);
986-
987981
policy->cpuinfo.transition_latency = amd_pstate_get_transition_latency(policy->cpu);
988982
policy->transition_delay_us = amd_pstate_get_transition_delay_us(policy->cpu);
989983

990-
policy->min = min_freq;
991-
policy->max = max_freq;
992-
993-
policy->cpuinfo.min_freq = min_freq;
994-
policy->cpuinfo.max_freq = max_freq;
984+
policy->cpuinfo.min_freq = policy->min = perf_to_freq(cpudata, cpudata->lowest_perf);
985+
policy->cpuinfo.max_freq = policy->max = perf_to_freq(cpudata, cpudata->highest_perf);
995986

996987
policy->boost_enabled = READ_ONCE(cpudata->boost_supported);
997988

@@ -1015,9 +1006,6 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
10151006
goto free_cpudata2;
10161007
}
10171008

1018-
cpudata->max_limit_freq = max_freq;
1019-
cpudata->min_limit_freq = min_freq;
1020-
10211009
policy->driver_data = cpudata;
10221010

10231011
if (!current_pstate_driver->adjust_perf)
@@ -1075,14 +1063,10 @@ static int amd_pstate_cpu_suspend(struct cpufreq_policy *policy)
10751063
static ssize_t show_amd_pstate_max_freq(struct cpufreq_policy *policy,
10761064
char *buf)
10771065
{
1078-
int max_freq;
10791066
struct amd_cpudata *cpudata = policy->driver_data;
10801067

1081-
max_freq = READ_ONCE(cpudata->max_freq);
1082-
if (max_freq < 0)
1083-
return max_freq;
10841068

1085-
return sysfs_emit(buf, "%u\n", max_freq);
1069+
return sysfs_emit(buf, "%u\n", perf_to_freq(cpudata, READ_ONCE(cpudata->highest_perf)));
10861070
}
10871071

10881072
static ssize_t show_amd_pstate_lowest_nonlinear_freq(struct cpufreq_policy *policy,
@@ -1440,10 +1424,10 @@ static bool amd_pstate_acpi_pm_profile_undefined(void)
14401424

14411425
static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
14421426
{
1443-
int min_freq, max_freq, ret;
14441427
struct amd_cpudata *cpudata;
14451428
struct device *dev;
14461429
u64 value;
1430+
int ret;
14471431

14481432
/*
14491433
* Resetting PERF_CTL_MSR will put the CPU in P0 frequency,
@@ -1474,19 +1458,13 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
14741458
if (ret)
14751459
goto free_cpudata1;
14761460

1477-
min_freq = READ_ONCE(cpudata->min_freq);
1478-
max_freq = READ_ONCE(cpudata->max_freq);
1479-
1480-
policy->cpuinfo.min_freq = min_freq;
1481-
policy->cpuinfo.max_freq = max_freq;
1461+
policy->cpuinfo.min_freq = policy->min = perf_to_freq(cpudata, cpudata->lowest_perf);
1462+
policy->cpuinfo.max_freq = policy->max = perf_to_freq(cpudata, cpudata->highest_perf);
14821463
/* It will be updated by governor */
14831464
policy->cur = policy->cpuinfo.min_freq;
14841465

14851466
policy->driver_data = cpudata;
14861467

1487-
policy->min = policy->cpuinfo.min_freq;
1488-
policy->max = policy->cpuinfo.max_freq;
1489-
14901468
policy->boost_enabled = READ_ONCE(cpudata->boost_supported);
14911469

14921470
/*
@@ -1544,7 +1522,8 @@ static int amd_pstate_epp_update_limit(struct cpufreq_policy *policy)
15441522
struct amd_cpudata *cpudata = policy->driver_data;
15451523
u8 epp;
15461524

1547-
amd_pstate_update_min_max_limit(policy);
1525+
if (policy->min != cpudata->min_limit_freq || policy->max != cpudata->max_limit_freq)
1526+
amd_pstate_update_min_max_limit(policy);
15481527

15491528
if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE)
15501529
epp = 0;

drivers/cpufreq/amd-pstate.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ struct amd_aperf_mperf {
4646
* @max_limit_perf: Cached value of the performance corresponding to policy->max
4747
* @min_limit_freq: Cached value of policy->min (in khz)
4848
* @max_limit_freq: Cached value of policy->max (in khz)
49-
* @max_freq: the frequency (in khz) that mapped to highest_perf
50-
* @min_freq: the frequency (in khz) that mapped to lowest_perf
5149
* @nominal_freq: the frequency (in khz) that mapped to nominal_perf
5250
* @lowest_nonlinear_freq: the frequency (in khz) that mapped to lowest_nonlinear_perf
5351
* @cur: Difference of Aperf/Mperf/tsc count between last and current sample
@@ -77,11 +75,8 @@ struct amd_cpudata {
7775
u8 prefcore_ranking;
7876
u8 min_limit_perf;
7977
u8 max_limit_perf;
80-
u32 min_limit_freq;
81-
u32 max_limit_freq;
82-
83-
u32 max_freq;
84-
u32 min_freq;
78+
u32 min_limit_freq;
79+
u32 max_limit_freq;
8580
u32 nominal_freq;
8681
u32 lowest_nonlinear_freq;
8782

0 commit comments

Comments
 (0)