Skip to content

Commit 2db4bb3

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 ab20819 commit 2db4bb3

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
@@ -1052,6 +1052,19 @@ Kernel parameters
10521052
policy to use. This governor must be registered in the
10531053
kernel before the cpufreq driver probes.
10541054

1055+
cppc_cpufreq.auto_sel_mode=
1056+
[CPU_FREQ] Enable ACPI CPPC autonomous performance
1057+
selection. When enabled, hardware automatically adjusts
1058+
CPU frequency on all CPUs based on workload demands.
1059+
In Autonomous mode, Energy Performance Preference (EPP)
1060+
hints guide hardware toward performance (0x0) or energy
1061+
efficiency (0xff).
1062+
Requires ACPI CPPC autonomous selection register support.
1063+
Format: <bool>
1064+
Default: 0 (disabled)
1065+
0: use cpufreq governors
1066+
1: enable if supported by hardware
1067+
10551068
cpu_init_udelay=N
10561069
[X86,EARLY] Delay for N microsec between assert and de-assert
10571070
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,
@@ -708,11 +711,74 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
708711
policy->cur = cppc_perf_to_khz(caps, caps->highest_perf);
709712
cpu_data->perf_ctrls.desired_perf = caps->highest_perf;
710713

711-
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
712-
if (ret) {
713-
pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n",
714-
caps->highest_perf, cpu, ret);
715-
goto out;
714+
/*
715+
* Enable autonomous mode on first init if boot param is set.
716+
* Check last_governor to detect first init and skip if auto_sel
717+
* is already enabled.
718+
*/
719+
if (auto_sel_mode && policy->last_governor[0] == '\0' &&
720+
!cpu_data->perf_ctrls.auto_sel) {
721+
/* Enable CPPC - optional register, some platforms need it */
722+
ret = cppc_set_enable(cpu, true);
723+
if (ret && ret != -EOPNOTSUPP)
724+
pr_warn("Failed to enable CPPC for CPU%d (%d)\n", cpu, ret);
725+
726+
/*
727+
* Prefer HW min/max_perf when set; otherwise program from
728+
* policy limits derived earlier from caps.
729+
* Clamp desired_perf to bounds and sync policy->cur.
730+
*/
731+
if (!cpu_data->perf_ctrls.min_perf || !cpu_data->perf_ctrls.max_perf)
732+
cppc_cpufreq_update_perf_limits(cpu_data, policy);
733+
734+
cpu_data->perf_ctrls.desired_perf =
735+
clamp_t(u32, cpu_data->perf_ctrls.desired_perf,
736+
cpu_data->perf_ctrls.min_perf,
737+
cpu_data->perf_ctrls.max_perf);
738+
739+
policy->cur = cppc_perf_to_khz(caps,
740+
cpu_data->perf_ctrls.desired_perf);
741+
742+
/* EPP is optional - some platforms may not support it */
743+
ret = cppc_set_epp(cpu, CPPC_EPP_PERFORMANCE_PREF);
744+
if (ret && ret != -EOPNOTSUPP)
745+
pr_warn("Failed to set EPP for CPU%d (%d)\n", cpu, ret);
746+
else if (!ret)
747+
cpu_data->perf_ctrls.energy_perf = CPPC_EPP_PERFORMANCE_PREF;
748+
749+
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
750+
if (ret) {
751+
pr_debug("Err setting perf for autonomous mode CPU:%d ret:%d\n",
752+
cpu, ret);
753+
goto out;
754+
}
755+
756+
ret = cppc_set_auto_sel(cpu, true);
757+
if (ret && ret != -EOPNOTSUPP) {
758+
pr_warn("Failed autonomous config for CPU%d (%d)\n",
759+
cpu, ret);
760+
goto out;
761+
}
762+
if (!ret)
763+
cpu_data->perf_ctrls.auto_sel = true;
764+
}
765+
766+
if (cpu_data->perf_ctrls.auto_sel) {
767+
/* Sync policy limits from HW when autonomous mode is active */
768+
policy->min = cppc_perf_to_khz(caps,
769+
cpu_data->perf_ctrls.min_perf ?:
770+
caps->lowest_nonlinear_perf);
771+
policy->max = cppc_perf_to_khz(caps,
772+
cpu_data->perf_ctrls.max_perf ?:
773+
caps->nominal_perf);
774+
} else {
775+
/* Normal mode: governors control frequency */
776+
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
777+
if (ret) {
778+
pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n",
779+
caps->highest_perf, cpu, ret);
780+
goto out;
781+
}
716782
}
717783

718784
cppc_cpufreq_cpu_fie_init(policy);
@@ -1038,10 +1104,18 @@ static int __init cppc_cpufreq_init(void)
10381104

10391105
static void __exit cppc_cpufreq_exit(void)
10401106
{
1107+
unsigned int cpu;
1108+
1109+
for_each_present_cpu(cpu)
1110+
cppc_set_auto_sel(cpu, false);
1111+
10411112
cpufreq_unregister_driver(&cppc_cpufreq_driver);
10421113
cppc_freq_invariance_exit();
10431114
}
10441115

1116+
module_param(auto_sel_mode, bool, 0444);
1117+
MODULE_PARM_DESC(auto_sel_mode, "Enable CPPC autonomous performance selection at boot");
1118+
10451119
module_exit(cppc_cpufreq_exit);
10461120
MODULE_AUTHOR("Ashwin Chaugule");
10471121
MODULE_DESCRIPTION("CPUFreq driver based on the ACPI CPPC v5.0+ spec");

0 commit comments

Comments
 (0)