Skip to content

Commit 1d215f0

Browse files
huangruirafaeljw
authored andcommitted
cpufreq: amd-pstate: Add fast switch function for AMD P-State
Introduce the fast switch function for AMD P-State on the AMD processors which support the full MSR register control. It's able to decrease the latency on interrupt context. Signed-off-by: Huang Rui <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent ec437d7 commit 1d215f0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,39 @@ static int amd_pstate_target(struct cpufreq_policy *policy,
183183
return 0;
184184
}
185185

186+
static void amd_pstate_adjust_perf(unsigned int cpu,
187+
unsigned long _min_perf,
188+
unsigned long target_perf,
189+
unsigned long capacity)
190+
{
191+
unsigned long max_perf, min_perf, des_perf,
192+
cap_perf, lowest_nonlinear_perf;
193+
struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
194+
struct amd_cpudata *cpudata = policy->driver_data;
195+
196+
cap_perf = READ_ONCE(cpudata->highest_perf);
197+
lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);
198+
199+
des_perf = cap_perf;
200+
if (target_perf < capacity)
201+
des_perf = DIV_ROUND_UP(cap_perf * target_perf, capacity);
202+
203+
min_perf = READ_ONCE(cpudata->highest_perf);
204+
if (_min_perf < capacity)
205+
min_perf = DIV_ROUND_UP(cap_perf * _min_perf, capacity);
206+
207+
if (min_perf < lowest_nonlinear_perf)
208+
min_perf = lowest_nonlinear_perf;
209+
210+
max_perf = cap_perf;
211+
if (max_perf < min_perf)
212+
max_perf = min_perf;
213+
214+
des_perf = clamp_t(unsigned long, des_perf, min_perf, max_perf);
215+
216+
amd_pstate_update(cpudata, min_perf, des_perf, max_perf, true);
217+
}
218+
186219
static int amd_get_min_freq(struct amd_cpudata *cpudata)
187220
{
188221
struct cppc_perf_caps cppc_perf;
@@ -299,6 +332,8 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
299332
/* It will be updated by governor */
300333
policy->cur = policy->cpuinfo.min_freq;
301334

335+
policy->fast_switch_possible = true;
336+
302337
/* Initial processor data capability frequencies */
303338
cpudata->max_freq = max_freq;
304339
cpudata->min_freq = min_freq;
@@ -329,6 +364,7 @@ static struct cpufreq_driver amd_pstate_driver = {
329364
.flags = CPUFREQ_CONST_LOOPS | CPUFREQ_NEED_UPDATE_LIMITS,
330365
.verify = amd_pstate_verify,
331366
.target = amd_pstate_target,
367+
.adjust_perf = amd_pstate_adjust_perf,
332368
.init = amd_pstate_cpu_init,
333369
.exit = amd_pstate_cpu_exit,
334370
.name = "amd-pstate",

0 commit comments

Comments
 (0)