Skip to content

Commit

Permalink
cpufreq: amd: add boost mode support for amd-pstate
Browse files Browse the repository at this point in the history
If the sbios supports the boost mode of amd-pstate, let's switch to
boost enabled by default.

Signed-off-by: Huang Rui <ray.huang@amd.com>
  • Loading branch information
huangrui authored and xanmod committed Nov 4, 2021
1 parent de13cc0 commit 9f1e5af
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions drivers/cpufreq/amd-pstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ struct amd_cpudata {
u32 min_freq;
u32 nominal_freq;
u32 lowest_nonlinear_freq;

bool boost_supported;
};

static inline int pstate_enable(bool enable)
Expand Down Expand Up @@ -349,6 +351,45 @@ static int amd_get_lowest_nonlinear_freq(struct amd_cpudata *cpudata)
return lowest_nonlinear_freq * 1000;
}

static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
{
struct amd_cpudata *cpudata = policy->driver_data;
int ret;

if (!cpudata->boost_supported) {
pr_err("Boost mode is not supported by this processor or SBIOS\n");
return -EINVAL;
}

if (state)
policy->cpuinfo.max_freq = cpudata->max_freq;
else
policy->cpuinfo.max_freq = cpudata->nominal_freq;

policy->max = policy->cpuinfo.max_freq;

ret = freq_qos_update_request(&cpudata->req[1],
policy->cpuinfo.max_freq);
if (ret < 0)
return ret;

return 0;
}

static void amd_pstate_boost_init(struct amd_cpudata *cpudata)
{
u32 highest_perf, nominal_perf;

highest_perf = READ_ONCE(cpudata->highest_perf);
nominal_perf = READ_ONCE(cpudata->nominal_perf);

if (highest_perf <= nominal_perf)
return;

cpudata->boost_supported = true;
amd_pstate_driver.boost_enabled = true;
}

static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
{
int min_freq, max_freq, nominal_freq, lowest_nonlinear_freq, ret;
Expand Down Expand Up @@ -419,6 +460,8 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)

policy->driver_data = cpudata;

amd_pstate_boost_init(cpudata);

return 0;

freq_qos_remove_request(&cpudata->req[1]);
Expand Down Expand Up @@ -448,6 +491,7 @@ static struct cpufreq_driver amd_pstate_driver = {
.target = amd_pstate_target,
.init = amd_pstate_cpu_init,
.exit = amd_pstate_cpu_exit,
.set_boost = amd_pstate_set_boost,
.name = "amd-pstate",
};

Expand Down

0 comments on commit 9f1e5af

Please sign in to comment.