Skip to content

Commit 82d8936

Browse files
huangruirafaeljw
authored andcommitted
x86/ACPI: CPPC: Move AMD maximum frequency ratio setting function into x86 CPPC
The AMD maximum frequency ratio setting function depends on CPPC, so the x86 CPPC implementation file is better space for this function. Signed-off-by: Huang Rui <ray.huang@amd.com> [ rjw: Subject adjustment ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent fd8af34 commit 82d8936

3 files changed

Lines changed: 50 additions & 43 deletions

File tree

arch/x86/include/asm/topology.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,13 @@ void init_freq_invariance_cppc(void);
226226
#define init_freq_invariance_cppc init_freq_invariance_cppc
227227
#endif
228228

229+
#ifdef CONFIG_ACPI_CPPC_LIB
230+
bool amd_set_max_freq_ratio(u64 *ratio);
231+
#else
232+
static inline bool amd_set_max_freq_ratio(u64 *ratio)
233+
{
234+
return false;
235+
}
236+
#endif
237+
229238
#endif /* _ASM_X86_TOPOLOGY_H */

arch/x86/kernel/acpi/cppc.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include <acpi/cppc_acpi.h>
88
#include <asm/msr.h>
9+
#include <asm/processor.h>
10+
#include <asm/topology.h>
911

1012
/* Refer to drivers/acpi/cppc_acpi.c for the description of functions */
1113

@@ -47,3 +49,41 @@ int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)
4749
}
4850
return err;
4951
}
52+
53+
bool amd_set_max_freq_ratio(u64 *ratio)
54+
{
55+
struct cppc_perf_caps perf_caps;
56+
u64 highest_perf, nominal_perf;
57+
u64 perf_ratio;
58+
int rc;
59+
60+
if (!ratio)
61+
return false;
62+
63+
rc = cppc_get_perf_caps(0, &perf_caps);
64+
if (rc) {
65+
pr_debug("Could not retrieve perf counters (%d)\n", rc);
66+
return false;
67+
}
68+
69+
highest_perf = amd_get_highest_perf();
70+
nominal_perf = perf_caps.nominal_perf;
71+
72+
if (!highest_perf || !nominal_perf) {
73+
pr_debug("Could not retrieve highest or nominal performance\n");
74+
return false;
75+
}
76+
77+
perf_ratio = div_u64(highest_perf * SCHED_CAPACITY_SCALE, nominal_perf);
78+
/* midpoint between max_boost and max_P */
79+
perf_ratio = (perf_ratio + SCHED_CAPACITY_SCALE) >> 1;
80+
if (!perf_ratio) {
81+
pr_debug("Non-zero highest/nominal perf values led to a 0 ratio\n");
82+
return false;
83+
}
84+
85+
*ratio = perf_ratio;
86+
arch_set_max_freq_ratio(false);
87+
88+
return true;
89+
}

arch/x86/kernel/smpboot.c

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,48 +2097,6 @@ static bool intel_set_max_freq_ratio(void)
20972097
return true;
20982098
}
20992099

2100-
#ifdef CONFIG_ACPI_CPPC_LIB
2101-
static bool amd_set_max_freq_ratio(void)
2102-
{
2103-
struct cppc_perf_caps perf_caps;
2104-
u64 highest_perf, nominal_perf;
2105-
u64 perf_ratio;
2106-
int rc;
2107-
2108-
rc = cppc_get_perf_caps(0, &perf_caps);
2109-
if (rc) {
2110-
pr_debug("Could not retrieve perf counters (%d)\n", rc);
2111-
return false;
2112-
}
2113-
2114-
highest_perf = amd_get_highest_perf();
2115-
nominal_perf = perf_caps.nominal_perf;
2116-
2117-
if (!highest_perf || !nominal_perf) {
2118-
pr_debug("Could not retrieve highest or nominal performance\n");
2119-
return false;
2120-
}
2121-
2122-
perf_ratio = div_u64(highest_perf * SCHED_CAPACITY_SCALE, nominal_perf);
2123-
/* midpoint between max_boost and max_P */
2124-
perf_ratio = (perf_ratio + SCHED_CAPACITY_SCALE) >> 1;
2125-
if (!perf_ratio) {
2126-
pr_debug("Non-zero highest/nominal perf values led to a 0 ratio\n");
2127-
return false;
2128-
}
2129-
2130-
arch_turbo_freq_ratio = perf_ratio;
2131-
arch_set_max_freq_ratio(false);
2132-
2133-
return true;
2134-
}
2135-
#else
2136-
static bool amd_set_max_freq_ratio(void)
2137-
{
2138-
return false;
2139-
}
2140-
#endif
2141-
21422100
static void init_counter_refs(void)
21432101
{
21442102
u64 aperf, mperf;
@@ -2187,7 +2145,7 @@ static void init_freq_invariance(bool secondary, bool cppc_ready)
21872145
if (!cppc_ready) {
21882146
return;
21892147
}
2190-
ret = amd_set_max_freq_ratio();
2148+
ret = amd_set_max_freq_ratio(&arch_turbo_freq_ratio);
21912149
}
21922150

21932151
if (ret) {

0 commit comments

Comments
 (0)