Skip to content

Commit 6c09e3b

Browse files
committed
x86/amd: Rename amd_get_highest_perf() to amd_get_boost_ratio_numerator()
The function name is ambiguous because it returns an intermediate value for calculating maximum frequency rather than the CPPC 'Highest Perf' register. Rename the function to clarify its use and allow the function to return errors. Adjust the consumer in acpi-cpufreq to catch errors. Reviewed-by: Gautham R. Shenoy <[email protected]> Signed-off-by: Mario Limonciello <[email protected]>
1 parent 01ced02 commit 6c09e3b

File tree

4 files changed

+46
-18
lines changed

4 files changed

+46
-18
lines changed

arch/x86/include/asm/processor.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,6 @@ static inline u32 per_cpu_l2c_id(unsigned int cpu)
691691
}
692692

693693
#ifdef CONFIG_CPU_SUP_AMD
694-
extern u32 amd_get_highest_perf(void);
695-
696694
/*
697695
* Issue a DIV 0/1 insn to clear any division data from previous DIV
698696
* operations.
@@ -705,7 +703,6 @@ static __always_inline void amd_clear_divider(void)
705703

706704
extern void amd_check_microcode(void);
707705
#else
708-
static inline u32 amd_get_highest_perf(void) { return 0; }
709706
static inline void amd_clear_divider(void) { }
710707
static inline void amd_check_microcode(void) { }
711708
#endif

arch/x86/kernel/acpi/cppc.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)
6969
static void amd_set_max_freq_ratio(void)
7070
{
7171
struct cppc_perf_caps perf_caps;
72-
u64 highest_perf, nominal_perf;
72+
u64 numerator, nominal_perf;
7373
u64 perf_ratio;
7474
int rc;
7575

@@ -79,15 +79,19 @@ static void amd_set_max_freq_ratio(void)
7979
return;
8080
}
8181

82-
highest_perf = amd_get_highest_perf();
82+
rc = amd_get_boost_ratio_numerator(0, &numerator);
83+
if (rc) {
84+
pr_debug("Could not retrieve highest performance (%d)\n", rc);
85+
return;
86+
}
8387
nominal_perf = perf_caps.nominal_perf;
8488

85-
if (!highest_perf || !nominal_perf) {
86-
pr_debug("Could not retrieve highest or nominal performance\n");
89+
if (!nominal_perf) {
90+
pr_debug("Could not retrieve nominal performance\n");
8791
return;
8892
}
8993

90-
perf_ratio = div_u64(highest_perf * SCHED_CAPACITY_SCALE, nominal_perf);
94+
perf_ratio = div_u64(numerator * SCHED_CAPACITY_SCALE, nominal_perf);
9195
/* midpoint between max_boost and max_P */
9296
perf_ratio = (perf_ratio + SCHED_CAPACITY_SCALE) >> 1;
9397
if (!perf_ratio) {
@@ -117,18 +121,34 @@ void init_freq_invariance_cppc(void)
117121
mutex_unlock(&freq_invariance_lock);
118122
}
119123

120-
u32 amd_get_highest_perf(void)
124+
/**
125+
* amd_get_boost_ratio_numerator: Get the numerator to use for boost ratio calculation
126+
* @cpu: CPU to get numerator for.
127+
* @numerator: Output variable for numerator.
128+
*
129+
* Determine the numerator to use for calculating the boost ratio on
130+
* a CPU. On systems that support preferred cores, this will be a hardcoded
131+
* value. On other systems this will the highest performance register value.
132+
*
133+
* Return: 0 for success, negative error code otherwise.
134+
*/
135+
int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)
121136
{
122137
struct cpuinfo_x86 *c = &boot_cpu_data;
123138

124139
if (c->x86 == 0x17 && ((c->x86_model >= 0x30 && c->x86_model < 0x40) ||
125-
(c->x86_model >= 0x70 && c->x86_model < 0x80)))
126-
return 166;
140+
(c->x86_model >= 0x70 && c->x86_model < 0x80))) {
141+
*numerator = 166;
142+
return 0;
143+
}
127144

128145
if (c->x86 == 0x19 && ((c->x86_model >= 0x20 && c->x86_model < 0x30) ||
129-
(c->x86_model >= 0x40 && c->x86_model < 0x70)))
130-
return 166;
146+
(c->x86_model >= 0x40 && c->x86_model < 0x70))) {
147+
*numerator = 166;
148+
return 0;
149+
}
150+
*numerator = 255;
131151

132-
return 255;
152+
return 0;
133153
}
134-
EXPORT_SYMBOL_GPL(amd_get_highest_perf);
154+
EXPORT_SYMBOL_GPL(amd_get_boost_ratio_numerator);

drivers/cpufreq/acpi-cpufreq.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,10 +642,16 @@ static u64 get_max_boost_ratio(unsigned int cpu)
642642
return 0;
643643
}
644644

645-
if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
646-
highest_perf = amd_get_highest_perf();
647-
else
645+
if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
646+
ret = amd_get_boost_ratio_numerator(cpu, &highest_perf);
647+
if (ret) {
648+
pr_debug("CPU%d: Unable to get boost ratio numerator (%d)\n",
649+
cpu, ret);
650+
return 0;
651+
}
652+
} else {
648653
highest_perf = perf_caps.highest_perf;
654+
}
649655

650656
nominal_perf = perf_caps.nominal_perf;
651657

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_boost_ratio_numerator(unsigned int cpu, u64 *numerator);
162163
#else /* !CONFIG_ACPI_CPPC_LIB */
163164
static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf)
164165
{
@@ -232,6 +233,10 @@ static inline int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf
232233
{
233234
return -EOPNOTSUPP;
234235
}
236+
static inline int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator)
237+
{
238+
return -EOPNOTSUPP;
239+
}
235240
#endif /* !CONFIG_ACPI_CPPC_LIB */
236241

237242
#endif /* _CPPC_ACPI_H*/

0 commit comments

Comments
 (0)