Skip to content

Commit ea3db45

Browse files
Sumit Guptarafaeljw
authored andcommitted
cpufreq: cppc: Update MIN_PERF/MAX_PERF in target callbacks
Update MIN_PERF and MAX_PERF registers from policy->min and policy->max in the .target() and .fast_switch() callbacks. This allows controlling performance bounds via standard scaling_min_freq and scaling_max_freq sysfs interfaces. Similar to intel_cpufreq which updates HWP min/max limits in .target(), cppc_cpufreq now programs MIN_PERF/MAX_PERF along with DESIRED_PERF. Since MIN_PERF/MAX_PERF can be updated even when auto_sel is disabled, they are updated unconditionally. Also program MIN_PERF/MAX_PERF in store_auto_select() when enabling autonomous selection so the platform uses correct bounds immediately. Suggested-by: Rafael J. Wysocki <rafael@kernel.org> Signed-off-by: Sumit Gupta <sumitg@nvidia.com> Link: https://patch.msgid.link/20260206142658.72583-6-sumitg@nvidia.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 24ad4c6 commit ea3db45

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

drivers/cpufreq/cppc_cpufreq.c

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,21 @@ static inline void cppc_freq_invariance_exit(void)
287287
}
288288
#endif /* CONFIG_ACPI_CPPC_CPUFREQ_FIE */
289289

290+
static void cppc_cpufreq_update_perf_limits(struct cppc_cpudata *cpu_data,
291+
struct cpufreq_policy *policy)
292+
{
293+
struct cppc_perf_caps *caps = &cpu_data->perf_caps;
294+
u32 min_perf, max_perf;
295+
296+
min_perf = cppc_khz_to_perf(caps, policy->min);
297+
max_perf = cppc_khz_to_perf(caps, policy->max);
298+
299+
cpu_data->perf_ctrls.min_perf =
300+
clamp_t(u32, min_perf, caps->lowest_perf, caps->highest_perf);
301+
cpu_data->perf_ctrls.max_perf =
302+
clamp_t(u32, max_perf, caps->lowest_perf, caps->highest_perf);
303+
}
304+
290305
static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
291306
unsigned int target_freq,
292307
unsigned int relation)
@@ -298,6 +313,8 @@ static int cppc_cpufreq_set_target(struct cpufreq_policy *policy,
298313

299314
cpu_data->perf_ctrls.desired_perf =
300315
cppc_khz_to_perf(&cpu_data->perf_caps, target_freq);
316+
cppc_cpufreq_update_perf_limits(cpu_data, policy);
317+
301318
freqs.old = policy->cur;
302319
freqs.new = target_freq;
303320

@@ -322,8 +339,9 @@ static unsigned int cppc_cpufreq_fast_switch(struct cpufreq_policy *policy,
322339

323340
desired_perf = cppc_khz_to_perf(&cpu_data->perf_caps, target_freq);
324341
cpu_data->perf_ctrls.desired_perf = desired_perf;
325-
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
342+
cppc_cpufreq_update_perf_limits(cpu_data, policy);
326343

344+
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
327345
if (ret) {
328346
pr_debug("Failed to set target on CPU:%d. ret:%d\n",
329347
cpu, ret);
@@ -869,6 +887,27 @@ static ssize_t store_auto_select(struct cpufreq_policy *policy,
869887

870888
cpu_data->perf_ctrls.auto_sel = val;
871889

890+
if (val) {
891+
u32 old_min_perf = cpu_data->perf_ctrls.min_perf;
892+
u32 old_max_perf = cpu_data->perf_ctrls.max_perf;
893+
894+
/*
895+
* When enabling autonomous selection, program MIN_PERF and
896+
* MAX_PERF from current policy limits so that the platform
897+
* uses the correct performance bounds immediately.
898+
*/
899+
cppc_cpufreq_update_perf_limits(cpu_data, policy);
900+
901+
ret = cppc_set_perf(policy->cpu, &cpu_data->perf_ctrls);
902+
if (ret) {
903+
cpu_data->perf_ctrls.min_perf = old_min_perf;
904+
cpu_data->perf_ctrls.max_perf = old_max_perf;
905+
cppc_set_auto_sel(policy->cpu, false);
906+
cpu_data->perf_ctrls.auto_sel = false;
907+
return ret;
908+
}
909+
}
910+
872911
return count;
873912
}
874913

0 commit comments

Comments
 (0)