Skip to content

Commit 0834667

Browse files
gautshenrafaeljw
authored andcommitted
cpufreq: ACPI: Fix max-frequency computation
Commit 3c55e94 ("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: 3c55e94 ("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>
1 parent 7420a7e commit 0834667

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

drivers/cpufreq/acpi-cpufreq.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,14 @@ static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c)
623623
#endif
624624

625625
#ifdef CONFIG_ACPI_CPPC_LIB
626-
static u64 get_max_boost_ratio(unsigned int cpu)
626+
/*
627+
* get_max_boost_ratio: Computes the max_boost_ratio as the ratio
628+
* between the highest_perf and the nominal_perf.
629+
*
630+
* Returns the max_boost_ratio for @cpu. Returns the CPPC nominal
631+
* frequency via @nominal_freq if it is non-NULL pointer.
632+
*/
633+
static u64 get_max_boost_ratio(unsigned int cpu, u64 *nominal_freq)
627634
{
628635
struct cppc_perf_caps perf_caps;
629636
u64 highest_perf, nominal_perf;
@@ -652,6 +659,9 @@ static u64 get_max_boost_ratio(unsigned int cpu)
652659

653660
nominal_perf = perf_caps.nominal_perf;
654661

662+
if (nominal_freq)
663+
*nominal_freq = perf_caps.nominal_freq;
664+
655665
if (!highest_perf || !nominal_perf) {
656666
pr_debug("CPU%d: highest or nominal performance missing\n", cpu);
657667
return 0;
@@ -664,8 +674,12 @@ static u64 get_max_boost_ratio(unsigned int cpu)
664674

665675
return div_u64(highest_perf << SCHED_CAPACITY_SHIFT, nominal_perf);
666676
}
677+
667678
#else
668-
static inline u64 get_max_boost_ratio(unsigned int cpu) { return 0; }
679+
static inline u64 get_max_boost_ratio(unsigned int cpu, u64 *nominal_freq)
680+
{
681+
return 0;
682+
}
669683
#endif
670684

671685
static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
@@ -675,9 +689,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
675689
struct acpi_cpufreq_data *data;
676690
unsigned int cpu = policy->cpu;
677691
struct cpuinfo_x86 *c = &cpu_data(cpu);
692+
u64 max_boost_ratio, nominal_freq = 0;
678693
unsigned int valid_states = 0;
679694
unsigned int result = 0;
680-
u64 max_boost_ratio;
681695
unsigned int i;
682696
#ifdef CONFIG_SMP
683697
static int blacklisted;
@@ -827,16 +841,20 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
827841
}
828842
freq_table[valid_states].frequency = CPUFREQ_TABLE_END;
829843

830-
max_boost_ratio = get_max_boost_ratio(cpu);
844+
max_boost_ratio = get_max_boost_ratio(cpu, &nominal_freq);
831845
if (max_boost_ratio) {
832-
unsigned int freq = freq_table[0].frequency;
846+
unsigned int freq = nominal_freq;
833847

834848
/*
835-
* Because the loop above sorts the freq_table entries in the
836-
* descending order, freq is the maximum frequency in the table.
837-
* Assume that it corresponds to the CPPC nominal frequency and
838-
* use it to set cpuinfo.max_freq.
849+
* The loop above sorts the freq_table entries in the
850+
* descending order. If ACPI CPPC has not advertised
851+
* the nominal frequency (this is possible in CPPC
852+
* revisions prior to 3), then use the first entry in
853+
* the pstate table as a proxy for nominal frequency.
839854
*/
855+
if (!freq)
856+
freq = freq_table[0].frequency;
857+
840858
policy->cpuinfo.max_freq = freq * max_boost_ratio >> SCHED_CAPACITY_SHIFT;
841859
} else {
842860
/*

0 commit comments

Comments
 (0)