mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-28 09:22:08 +00:00
cpufreq: ACPI: Fix max-frequency computation
Commit3c55e94c0a
("cpufreq: ACPI: Extend frequency tables to cover boost frequencies") introduced an assumption in acpi_cpufreq_cpu_init() that the first entry in the P-state table was the nominal frequency. This assumption is incorrect. The frequency corresponding to the P0 P-State need not be the same as the nominal frequency advertised via CPPC. Since the driver is using the CPPC.highest_perf and CPPC.nominal_perf to compute the boost-ratio, it makes sense to use CPPC.nominal_freq to compute the max-frequency. CPPC.nominal_freq is advertised on platforms supporting CPPC revisions 3 or higher. Hence, fallback to using the first entry in the P-State table only on platforms that do not advertise CPPC.nominal_freq. Fixes:3c55e94c0a
("cpufreq: ACPI: Extend frequency tables to cover boost frequencies") Tested-by: Dhananjay Ugwekar <Dhananjay.Ugwekar@amd.com> Signed-off-by: Gautham R. Shenoy <gautham.shenoy@amd.com> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com> Link: https://patch.msgid.link/20250113044107.566-1-gautham.shenoy@amd.com [ rjw: Retain reverse X-mas tree ordering of local variable declarations ] [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
7420a7e867
commit
0834667545
@ -623,7 +623,14 @@ static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_ACPI_CPPC_LIB
|
#ifdef CONFIG_ACPI_CPPC_LIB
|
||||||
static u64 get_max_boost_ratio(unsigned int cpu)
|
/*
|
||||||
|
* get_max_boost_ratio: Computes the max_boost_ratio as the ratio
|
||||||
|
* between the highest_perf and the nominal_perf.
|
||||||
|
*
|
||||||
|
* Returns the max_boost_ratio for @cpu. Returns the CPPC nominal
|
||||||
|
* frequency via @nominal_freq if it is non-NULL pointer.
|
||||||
|
*/
|
||||||
|
static u64 get_max_boost_ratio(unsigned int cpu, u64 *nominal_freq)
|
||||||
{
|
{
|
||||||
struct cppc_perf_caps perf_caps;
|
struct cppc_perf_caps perf_caps;
|
||||||
u64 highest_perf, nominal_perf;
|
u64 highest_perf, nominal_perf;
|
||||||
@ -652,6 +659,9 @@ static u64 get_max_boost_ratio(unsigned int cpu)
|
|||||||
|
|
||||||
nominal_perf = perf_caps.nominal_perf;
|
nominal_perf = perf_caps.nominal_perf;
|
||||||
|
|
||||||
|
if (nominal_freq)
|
||||||
|
*nominal_freq = perf_caps.nominal_freq;
|
||||||
|
|
||||||
if (!highest_perf || !nominal_perf) {
|
if (!highest_perf || !nominal_perf) {
|
||||||
pr_debug("CPU%d: highest or nominal performance missing\n", cpu);
|
pr_debug("CPU%d: highest or nominal performance missing\n", cpu);
|
||||||
return 0;
|
return 0;
|
||||||
@ -664,8 +674,12 @@ static u64 get_max_boost_ratio(unsigned int cpu)
|
|||||||
|
|
||||||
return div_u64(highest_perf << SCHED_CAPACITY_SHIFT, nominal_perf);
|
return div_u64(highest_perf << SCHED_CAPACITY_SHIFT, nominal_perf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
static inline u64 get_max_boost_ratio(unsigned int cpu) { return 0; }
|
static inline u64 get_max_boost_ratio(unsigned int cpu, u64 *nominal_freq)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
|
static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
|
||||||
@ -675,9 +689,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
|
|||||||
struct acpi_cpufreq_data *data;
|
struct acpi_cpufreq_data *data;
|
||||||
unsigned int cpu = policy->cpu;
|
unsigned int cpu = policy->cpu;
|
||||||
struct cpuinfo_x86 *c = &cpu_data(cpu);
|
struct cpuinfo_x86 *c = &cpu_data(cpu);
|
||||||
|
u64 max_boost_ratio, nominal_freq = 0;
|
||||||
unsigned int valid_states = 0;
|
unsigned int valid_states = 0;
|
||||||
unsigned int result = 0;
|
unsigned int result = 0;
|
||||||
u64 max_boost_ratio;
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
#ifdef CONFIG_SMP
|
#ifdef CONFIG_SMP
|
||||||
static int blacklisted;
|
static int blacklisted;
|
||||||
@ -827,16 +841,20 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
|
|||||||
}
|
}
|
||||||
freq_table[valid_states].frequency = CPUFREQ_TABLE_END;
|
freq_table[valid_states].frequency = CPUFREQ_TABLE_END;
|
||||||
|
|
||||||
max_boost_ratio = get_max_boost_ratio(cpu);
|
max_boost_ratio = get_max_boost_ratio(cpu, &nominal_freq);
|
||||||
if (max_boost_ratio) {
|
if (max_boost_ratio) {
|
||||||
unsigned int freq = freq_table[0].frequency;
|
unsigned int freq = nominal_freq;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Because the loop above sorts the freq_table entries in the
|
* The loop above sorts the freq_table entries in the
|
||||||
* descending order, freq is the maximum frequency in the table.
|
* descending order. If ACPI CPPC has not advertised
|
||||||
* Assume that it corresponds to the CPPC nominal frequency and
|
* the nominal frequency (this is possible in CPPC
|
||||||
* use it to set cpuinfo.max_freq.
|
* revisions prior to 3), then use the first entry in
|
||||||
|
* the pstate table as a proxy for nominal frequency.
|
||||||
*/
|
*/
|
||||||
|
if (!freq)
|
||||||
|
freq = freq_table[0].frequency;
|
||||||
|
|
||||||
policy->cpuinfo.max_freq = freq * max_boost_ratio >> SCHED_CAPACITY_SHIFT;
|
policy->cpuinfo.max_freq = freq * max_boost_ratio >> SCHED_CAPACITY_SHIFT;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user