Skip to content

Commit 2819bfe

Browse files
committed
x86/amd: Move amd_get_highest_perf() out of amd-pstate
amd_pstate_get_highest_perf() is a helper used to get the highest perf value on AMD systems. It's used in amd-pstate as part of preferred core handling, but applicable for acpi-cpufreq as well. Move it out to cppc handling code as amd_get_highest_perf(). Reviewed-by: Perry Yuan <[email protected]> Reviewed-by: Gautham R. Shenoy <[email protected]> Signed-off-by: Mario Limonciello <[email protected]>
1 parent 21fb59a commit 2819bfe

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

arch/x86/kernel/acpi/cppc.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,36 @@ void init_freq_invariance_cppc(void)
116116
mutex_unlock(&freq_invariance_lock);
117117
}
118118

119+
/*
120+
* Get the highest performance register value.
121+
* @cpu: CPU from which to get highest performance.
122+
* @highest_perf: Return address for highest performance value.
123+
*
124+
* Return: 0 for success, negative error code otherwise.
125+
*/
126+
int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf)
127+
{
128+
u64 val;
129+
int ret;
130+
131+
if (cpu_feature_enabled(X86_FEATURE_CPPC)) {
132+
ret = rdmsrl_safe_on_cpu(cpu, MSR_AMD_CPPC_CAP1, &val);
133+
if (ret)
134+
goto out;
135+
136+
val = AMD_CPPC_HIGHEST_PERF(val);
137+
} else {
138+
ret = cppc_get_highest_perf(cpu, &val);
139+
if (ret)
140+
goto out;
141+
}
142+
143+
WRITE_ONCE(*highest_perf, (u32)val);
144+
out:
145+
return ret;
146+
}
147+
EXPORT_SYMBOL_GPL(amd_get_highest_perf);
148+
119149
/**
120150
* amd_get_boost_ratio_numerator: Get the numerator to use for boost ratio calculation
121151
* @cpu: CPU to get numerator for.

drivers/cpufreq/amd-pstate.c

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -811,44 +811,14 @@ static void amd_pstste_sched_prefcore_workfn(struct work_struct *work)
811811
}
812812
static DECLARE_WORK(sched_prefcore_work, amd_pstste_sched_prefcore_workfn);
813813

814-
/*
815-
* Get the highest performance register value.
816-
* @cpu: CPU from which to get highest performance.
817-
* @highest_perf: Return address.
818-
*
819-
* Return: 0 for success, -EIO otherwise.
820-
*/
821-
static int amd_pstate_get_highest_perf(int cpu, u32 *highest_perf)
822-
{
823-
int ret;
824-
825-
if (cpu_feature_enabled(X86_FEATURE_CPPC)) {
826-
u64 cap1;
827-
828-
ret = rdmsrl_safe_on_cpu(cpu, MSR_AMD_CPPC_CAP1, &cap1);
829-
if (ret)
830-
return ret;
831-
WRITE_ONCE(*highest_perf, AMD_CPPC_HIGHEST_PERF(cap1));
832-
} else {
833-
u64 cppc_highest_perf;
834-
835-
ret = cppc_get_highest_perf(cpu, &cppc_highest_perf);
836-
if (ret)
837-
return ret;
838-
WRITE_ONCE(*highest_perf, cppc_highest_perf);
839-
}
840-
841-
return (ret);
842-
}
843-
844814
#define CPPC_MAX_PERF U8_MAX
845815

846816
static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata)
847817
{
848818
int ret, prio;
849819
u32 highest_perf;
850820

851-
ret = amd_pstate_get_highest_perf(cpudata->cpu, &highest_perf);
821+
ret = amd_get_highest_perf(cpudata->cpu, &highest_perf);
852822
if (ret)
853823
return;
854824

@@ -892,7 +862,7 @@ static void amd_pstate_update_limits(unsigned int cpu)
892862
if ((!amd_pstate_prefcore) || (!cpudata->hw_prefcore))
893863
goto free_cpufreq_put;
894864

895-
ret = amd_pstate_get_highest_perf(cpu, &cur_high);
865+
ret = amd_get_highest_perf(cpu, &cur_high);
896866
if (ret)
897867
goto free_cpufreq_put;
898868

include/acpi/cppc_acpi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ extern int cppc_get_epp_perf(int cpunum, u64 *epp_perf);
159159
extern int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable);
160160
extern int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps);
161161
extern int cppc_set_auto_sel(int cpu, bool enable);
162+
extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf);
162163
extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator);
163164
#else /* !CONFIG_ACPI_CPPC_LIB */
164165
static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf)
@@ -233,6 +234,10 @@ static inline int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf
233234
{
234235
return -EOPNOTSUPP;
235236
}
237+
static inline int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf)
238+
{
239+
return -ENODEV;
240+
}
236241
static inline int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)
237242
{
238243
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)