Skip to content

Commit 250c194

Browse files
Sumit GuptajamieNguyenNVIDIA
authored andcommitted
NVIDIA: SAUCE: cpufreq: CPPC: add autonomous mode boot parameter support
Add kernel boot parameter 'cppc_cpufreq.auto_sel_mode' to enable CPPC autonomous performance selection on all CPUs at system startup without requiring runtime sysfs manipulation. When autonomous mode is enabled, the hardware automatically adjusts CPU performance based on workload demands using Energy Performance Preference (EPP) hints. When auto_sel_mode=1: - Configure all CPUs for autonomous operation on first init - Set EPP to performance preference (0x0) - Use HW min/max when set; otherwise program from policy limits (caps) - Clamp desired_perf to bounds before enabling autonomous mode - Hardware controls frequency instead of the OS governor The boot parameter is applied only during first policy initialization. On hotplug, skip applying it so that the user's runtime sysfs configuration is preserved. Reviewed-by: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Sumit Gupta <sumitg@nvidia.com> (backported from https://lore.kernel.org/lkml/20260317151053.2361475-1-sumitg@nvidia.com/) Signed-off-by: Jamie Nguyen <jamien@nvidia.com>
1 parent cc3fad8 commit 250c194

2 files changed

Lines changed: 92 additions & 5 deletions

File tree

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,19 @@
925925
policy to use. This governor must be registered in the
926926
kernel before the cpufreq driver probes.
927927

928+
cppc_cpufreq.auto_sel_mode=
929+
[CPU_FREQ] Enable ACPI CPPC autonomous performance
930+
selection. When enabled, hardware automatically adjusts
931+
CPU frequency on all CPUs based on workload demands.
932+
In Autonomous mode, Energy Performance Preference (EPP)
933+
hints guide hardware toward performance (0x0) or energy
934+
efficiency (0xff).
935+
Requires ACPI CPPC autonomous selection register support.
936+
Format: <bool>
937+
Default: 0 (disabled)
938+
0: use cpufreq governors
939+
1: enable if supported by hardware
940+
928941
cpu_init_udelay=N
929942
[X86,EARLY] Delay for N microsec between assert and de-assert
930943
of APIC INIT to start processors. This delay occurs

drivers/cpufreq/cppc_cpufreq.c

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
static struct cpufreq_driver cppc_cpufreq_driver;
3030

31+
/* Autonomous Selection boot parameter */
32+
static bool auto_sel_mode;
33+
3134
#ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE
3235
static enum {
3336
FIE_UNSET = -1,
@@ -676,11 +679,74 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
676679
policy->cur = cppc_perf_to_khz(caps, caps->highest_perf);
677680
cpu_data->perf_ctrls.desired_perf = caps->highest_perf;
678681

679-
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
680-
if (ret) {
681-
pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n",
682-
caps->highest_perf, cpu, ret);
683-
goto out;
682+
/*
683+
* Enable autonomous mode on first init if boot param is set.
684+
* Check last_governor to detect first init and skip if auto_sel
685+
* is already enabled.
686+
*/
687+
if (auto_sel_mode && policy->last_governor[0] == '\0' &&
688+
!cpu_data->perf_ctrls.auto_sel) {
689+
/* Enable CPPC - optional register, some platforms need it */
690+
ret = cppc_set_enable(cpu, true);
691+
if (ret && ret != -EOPNOTSUPP)
692+
pr_warn("Failed to enable CPPC for CPU%d (%d)\n", cpu, ret);
693+
694+
/*
695+
* Prefer HW min/max_perf when set; otherwise program from
696+
* policy limits derived earlier from caps.
697+
* Clamp desired_perf to bounds and sync policy->cur.
698+
*/
699+
if (!cpu_data->perf_ctrls.min_perf || !cpu_data->perf_ctrls.max_perf)
700+
cppc_cpufreq_update_perf_limits(cpu_data, policy);
701+
702+
cpu_data->perf_ctrls.desired_perf =
703+
clamp_t(u32, cpu_data->perf_ctrls.desired_perf,
704+
cpu_data->perf_ctrls.min_perf,
705+
cpu_data->perf_ctrls.max_perf);
706+
707+
policy->cur = cppc_perf_to_khz(caps,
708+
cpu_data->perf_ctrls.desired_perf);
709+
710+
/* EPP is optional - some platforms may not support it */
711+
ret = cppc_set_epp(cpu, CPPC_EPP_PERFORMANCE_PREF);
712+
if (ret && ret != -EOPNOTSUPP)
713+
pr_warn("Failed to set EPP for CPU%d (%d)\n", cpu, ret);
714+
else if (!ret)
715+
cpu_data->perf_ctrls.energy_perf = CPPC_EPP_PERFORMANCE_PREF;
716+
717+
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
718+
if (ret) {
719+
pr_debug("Err setting perf for autonomous mode CPU:%d ret:%d\n",
720+
cpu, ret);
721+
goto out;
722+
}
723+
724+
ret = cppc_set_auto_sel(cpu, true);
725+
if (ret && ret != -EOPNOTSUPP) {
726+
pr_warn("Failed autonomous config for CPU%d (%d)\n",
727+
cpu, ret);
728+
goto out;
729+
}
730+
if (!ret)
731+
cpu_data->perf_ctrls.auto_sel = true;
732+
}
733+
734+
if (cpu_data->perf_ctrls.auto_sel) {
735+
/* Sync policy limits from HW when autonomous mode is active */
736+
policy->min = cppc_perf_to_khz(caps,
737+
cpu_data->perf_ctrls.min_perf ?:
738+
caps->lowest_nonlinear_perf);
739+
policy->max = cppc_perf_to_khz(caps,
740+
cpu_data->perf_ctrls.max_perf ?:
741+
caps->nominal_perf);
742+
} else {
743+
/* Normal mode: governors control frequency */
744+
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
745+
if (ret) {
746+
pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n",
747+
caps->highest_perf, cpu, ret);
748+
goto out;
749+
}
684750
}
685751

686752
cppc_cpufreq_cpu_fie_init(policy);
@@ -1010,10 +1076,18 @@ static int __init cppc_cpufreq_init(void)
10101076

10111077
static void __exit cppc_cpufreq_exit(void)
10121078
{
1079+
unsigned int cpu;
1080+
1081+
for_each_present_cpu(cpu)
1082+
cppc_set_auto_sel(cpu, false);
1083+
10131084
cpufreq_unregister_driver(&cppc_cpufreq_driver);
10141085
cppc_freq_invariance_exit();
10151086
}
10161087

1088+
module_param(auto_sel_mode, bool, 0444);
1089+
MODULE_PARM_DESC(auto_sel_mode, "Enable CPPC autonomous performance selection at boot");
1090+
10171091
module_exit(cppc_cpufreq_exit);
10181092
MODULE_AUTHOR("Ashwin Chaugule");
10191093
MODULE_DESCRIPTION("CPUFreq driver based on the ACPI CPPC v5.0+ spec");

0 commit comments

Comments
 (0)