Skip to content

Commit d4da12f

Browse files
Perry Yuanrafaeljw
authored andcommitted
cpufreq: amd-pstate: implement amd pstate cpu online and offline callback
Adds online and offline driver callback support to allow cpu cores go offline and help to restore the previous working states when core goes back online later for EPP driver mode. Acked-by: Huang Rui <ray.huang@amd.com> Reviewed-by: Mario Limonciello <Mario.Limonciello@amd.com> Reviewed-by: Wyes Karny <wyes.karny@amd.com> Tested-by: Wyes Karny <wyes.karny@amd.com> Signed-off-by: Perry Yuan <Perry.Yuan@amd.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent ffa5096 commit d4da12f

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

drivers/cpufreq/amd-pstate.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,86 @@ static int amd_pstate_epp_set_policy(struct cpufreq_policy *policy)
10001000
return 0;
10011001
}
10021002

1003+
static void amd_pstate_epp_reenable(struct amd_cpudata *cpudata)
1004+
{
1005+
struct cppc_perf_ctrls perf_ctrls;
1006+
u64 value, max_perf;
1007+
int ret;
1008+
1009+
ret = amd_pstate_enable(true);
1010+
if (ret)
1011+
pr_err("failed to enable amd pstate during resume, return %d\n", ret);
1012+
1013+
value = READ_ONCE(cpudata->cppc_req_cached);
1014+
max_perf = READ_ONCE(cpudata->highest_perf);
1015+
1016+
if (boot_cpu_has(X86_FEATURE_CPPC)) {
1017+
wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value);
1018+
} else {
1019+
perf_ctrls.max_perf = max_perf;
1020+
perf_ctrls.energy_perf = AMD_CPPC_ENERGY_PERF_PREF(cpudata->epp_cached);
1021+
cppc_set_perf(cpudata->cpu, &perf_ctrls);
1022+
}
1023+
}
1024+
1025+
static int amd_pstate_epp_cpu_online(struct cpufreq_policy *policy)
1026+
{
1027+
struct amd_cpudata *cpudata = policy->driver_data;
1028+
1029+
pr_debug("AMD CPU Core %d going online\n", cpudata->cpu);
1030+
1031+
if (cppc_state == AMD_PSTATE_ACTIVE) {
1032+
amd_pstate_epp_reenable(cpudata);
1033+
cpudata->suspended = false;
1034+
}
1035+
1036+
return 0;
1037+
}
1038+
1039+
static void amd_pstate_epp_offline(struct cpufreq_policy *policy)
1040+
{
1041+
struct amd_cpudata *cpudata = policy->driver_data;
1042+
struct cppc_perf_ctrls perf_ctrls;
1043+
int min_perf;
1044+
u64 value;
1045+
1046+
min_perf = READ_ONCE(cpudata->lowest_perf);
1047+
value = READ_ONCE(cpudata->cppc_req_cached);
1048+
1049+
mutex_lock(&amd_pstate_limits_lock);
1050+
if (boot_cpu_has(X86_FEATURE_CPPC)) {
1051+
cpudata->epp_policy = CPUFREQ_POLICY_UNKNOWN;
1052+
1053+
/* Set max perf same as min perf */
1054+
value &= ~AMD_CPPC_MAX_PERF(~0L);
1055+
value |= AMD_CPPC_MAX_PERF(min_perf);
1056+
value &= ~AMD_CPPC_MIN_PERF(~0L);
1057+
value |= AMD_CPPC_MIN_PERF(min_perf);
1058+
wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value);
1059+
} else {
1060+
perf_ctrls.desired_perf = 0;
1061+
perf_ctrls.max_perf = min_perf;
1062+
perf_ctrls.energy_perf = AMD_CPPC_ENERGY_PERF_PREF(HWP_EPP_BALANCE_POWERSAVE);
1063+
cppc_set_perf(cpudata->cpu, &perf_ctrls);
1064+
}
1065+
mutex_unlock(&amd_pstate_limits_lock);
1066+
}
1067+
1068+
static int amd_pstate_epp_cpu_offline(struct cpufreq_policy *policy)
1069+
{
1070+
struct amd_cpudata *cpudata = policy->driver_data;
1071+
1072+
pr_debug("AMD CPU Core %d going offline\n", cpudata->cpu);
1073+
1074+
if (cpudata->suspended)
1075+
return 0;
1076+
1077+
if (cppc_state == AMD_PSTATE_ACTIVE)
1078+
amd_pstate_epp_offline(policy);
1079+
1080+
return 0;
1081+
}
1082+
10031083
static int amd_pstate_epp_verify_policy(struct cpufreq_policy_data *policy)
10041084
{
10051085
cpufreq_verify_within_cpu_limits(policy);
@@ -1026,6 +1106,8 @@ static struct cpufreq_driver amd_pstate_epp_driver = {
10261106
.setpolicy = amd_pstate_epp_set_policy,
10271107
.init = amd_pstate_epp_cpu_init,
10281108
.exit = amd_pstate_epp_cpu_exit,
1109+
.offline = amd_pstate_epp_cpu_offline,
1110+
.online = amd_pstate_epp_cpu_online,
10291111
.name = "amd_pstate_epp",
10301112
.attr = amd_pstate_epp_attr,
10311113
};

include/linux/amd-pstate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct amd_cpudata {
8787
s16 epp_cached;
8888
u32 policy;
8989
u64 cppc_cap1_cached;
90+
bool suspended;
9091
};
9192

9293
/*

0 commit comments

Comments
 (0)