Skip to content

Commit 0a5fcc0

Browse files
rafaeljwgregkh
authored andcommitted
cpufreq: ACPI: Set cpuinfo.max_freq directly if max boost is known
commit 538b018 upstream. Commit 3c55e94 ("cpufreq: ACPI: Extend frequency tables to cover boost frequencies") attempted to address a performance issue involving acpi-cpufreq, the schedutil governor and scale-invariance on x86 by extending the frequency tables created by acpi-cpufreq to cover the entire range of "turbo" (or "boost") frequencies, but that caused frequencies reported via /proc/cpuinfo and the scaling_cur_freq attribute in sysfs to change which may confuse users and monitoring tools. For this reason, revert the part of commit 3c55e94 adding the extra entry to the frequency table and use the observation that in principle cpuinfo.max_freq need not be equal to the maximum frequency listed in the frequency table for the given policy. Namely, modify cpufreq_frequency_table_cpuinfo() to allow cpufreq drivers to set their own cpuinfo.max_freq above that frequency and change acpi-cpufreq to set cpuinfo.max_freq to the maximum boost frequency found via CPPC. This should be sufficient to let all of the cpufreq subsystem know the real maximum frequency of the CPU without changing frequency reporting. Link: https://bugzilla.kernel.org/show_bug.cgi?id=211305 Fixes: 3c55e94 ("cpufreq: ACPI: Extend frequency tables to cover boost frequencies") Reported-by: Matt McDonald <gardotd426@gmail.com> Tested-by: Matt McDonald <gardotd426@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Tested-by: Giovanni Gherdovich <ggherdovich@suse.cz> Tested-by: Michael Larabel <Michael@phoronix.com> Cc: 5.11+ <stable@vger.kernel.org> # 5.11+ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ff9dd52 commit 0a5fcc0

2 files changed

Lines changed: 23 additions & 47 deletions

File tree

‎drivers/cpufreq/acpi-cpufreq.c‎

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ struct acpi_cpufreq_data {
5454
unsigned int resume;
5555
unsigned int cpu_feature;
5656
unsigned int acpi_perf_cpu;
57-
unsigned int first_perf_state;
5857
cpumask_var_t freqdomain_cpus;
5958
void (*cpu_freq_write)(struct acpi_pct_register *reg, u32 val);
6059
u32 (*cpu_freq_read)(struct acpi_pct_register *reg);
@@ -223,10 +222,10 @@ static unsigned extract_msr(struct cpufreq_policy *policy, u32 msr)
223222

224223
perf = to_perf_data(data);
225224

226-
cpufreq_for_each_entry(pos, policy->freq_table + data->first_perf_state)
225+
cpufreq_for_each_entry(pos, policy->freq_table)
227226
if (msr == perf->states[pos->driver_data].status)
228227
return pos->frequency;
229-
return policy->freq_table[data->first_perf_state].frequency;
228+
return policy->freq_table[0].frequency;
230229
}
231230

232231
static unsigned extract_freq(struct cpufreq_policy *policy, u32 val)
@@ -365,7 +364,6 @@ static unsigned int get_cur_freq_on_cpu(unsigned int cpu)
365364
struct cpufreq_policy *policy;
366365
unsigned int freq;
367366
unsigned int cached_freq;
368-
unsigned int state;
369367

370368
pr_debug("%s (%d)\n", __func__, cpu);
371369

@@ -377,11 +375,7 @@ static unsigned int get_cur_freq_on_cpu(unsigned int cpu)
377375
if (unlikely(!data || !policy->freq_table))
378376
return 0;
379377

380-
state = to_perf_data(data)->state;
381-
if (state < data->first_perf_state)
382-
state = data->first_perf_state;
383-
384-
cached_freq = policy->freq_table[state].frequency;
378+
cached_freq = policy->freq_table[to_perf_data(data)->state].frequency;
385379
freq = extract_freq(policy, get_cur_val(cpumask_of(cpu), data));
386380
if (freq != cached_freq) {
387381
/*
@@ -680,7 +674,6 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
680674
struct cpuinfo_x86 *c = &cpu_data(cpu);
681675
unsigned int valid_states = 0;
682676
unsigned int result = 0;
683-
unsigned int state_count;
684677
u64 max_boost_ratio;
685678
unsigned int i;
686679
#ifdef CONFIG_SMP
@@ -795,28 +788,8 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
795788
goto err_unreg;
796789
}
797790

798-
state_count = perf->state_count + 1;
799-
800-
max_boost_ratio = get_max_boost_ratio(cpu);
801-
if (max_boost_ratio) {
802-
/*
803-
* Make a room for one more entry to represent the highest
804-
* available "boost" frequency.
805-
*/
806-
state_count++;
807-
valid_states++;
808-
data->first_perf_state = valid_states;
809-
} else {
810-
/*
811-
* If the maximum "boost" frequency is unknown, ask the arch
812-
* scale-invariance code to use the "nominal" performance for
813-
* CPU utilization scaling so as to prevent the schedutil
814-
* governor from selecting inadequate CPU frequencies.
815-
*/
816-
arch_set_max_freq_ratio(true);
817-
}
818-
819-
freq_table = kcalloc(state_count, sizeof(*freq_table), GFP_KERNEL);
791+
freq_table = kcalloc(perf->state_count + 1, sizeof(*freq_table),
792+
GFP_KERNEL);
820793
if (!freq_table) {
821794
result = -ENOMEM;
822795
goto err_unreg;
@@ -851,27 +824,25 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
851824
}
852825
freq_table[valid_states].frequency = CPUFREQ_TABLE_END;
853826

827+
max_boost_ratio = get_max_boost_ratio(cpu);
854828
if (max_boost_ratio) {
855-
unsigned int state = data->first_perf_state;
856-
unsigned int freq = freq_table[state].frequency;
829+
unsigned int freq = freq_table[0].frequency;
857830

858831
/*
859832
* Because the loop above sorts the freq_table entries in the
860833
* descending order, freq is the maximum frequency in the table.
861834
* Assume that it corresponds to the CPPC nominal frequency and
862-
* use it to populate the frequency field of the extra "boost"
863-
* frequency entry.
835+
* use it to set cpuinfo.max_freq.
864836
*/
865-
freq_table[0].frequency = freq * max_boost_ratio >> SCHED_CAPACITY_SHIFT;
837+
policy->cpuinfo.max_freq = freq * max_boost_ratio >> SCHED_CAPACITY_SHIFT;
838+
} else {
866839
/*
867-
* The purpose of the extra "boost" frequency entry is to make
868-
* the rest of cpufreq aware of the real maximum frequency, but
869-
* the way to request it is the same as for the first_perf_state
870-
* entry that is expected to cover the entire range of "boost"
871-
* frequencies of the CPU, so copy the driver_data value from
872-
* that entry.
840+
* If the maximum "boost" frequency is unknown, ask the arch
841+
* scale-invariance code to use the "nominal" performance for
842+
* CPU utilization scaling so as to prevent the schedutil
843+
* governor from selecting inadequate CPU frequencies.
873844
*/
874-
freq_table[0].driver_data = freq_table[state].driver_data;
845+
arch_set_max_freq_ratio(true);
875846
}
876847

877848
policy->freq_table = freq_table;
@@ -947,8 +918,7 @@ static void acpi_cpufreq_cpu_ready(struct cpufreq_policy *policy)
947918
{
948919
struct acpi_processor_performance *perf = per_cpu_ptr(acpi_perf_data,
949920
policy->cpu);
950-
struct acpi_cpufreq_data *data = policy->driver_data;
951-
unsigned int freq = policy->freq_table[data->first_perf_state].frequency;
921+
unsigned int freq = policy->freq_table[0].frequency;
952922

953923
if (perf->states[0].core_frequency * 1000 != freq)
954924
pr_warn(FW_WARN "P-state 0 is not max freq\n");

‎drivers/cpufreq/freq_table.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
5252
}
5353

5454
policy->min = policy->cpuinfo.min_freq = min_freq;
55-
policy->max = policy->cpuinfo.max_freq = max_freq;
55+
policy->max = max_freq;
56+
/*
57+
* If the driver has set its own cpuinfo.max_freq above max_freq, leave
58+
* it as is.
59+
*/
60+
if (policy->cpuinfo.max_freq < max_freq)
61+
policy->max = policy->cpuinfo.max_freq = max_freq;
5662

5763
if (policy->min == ~0)
5864
return -EINVAL;

0 commit comments

Comments
 (0)