Skip to content

Commit 5812989

Browse files
Sumit GuptajamieNguyenNVIDIA
authored andcommitted
NVIDIA: SAUCE: cpufreq: CPPC: add autonomous mode boot parameter support
Add a kernel boot parameter 'cppc_cpufreq.auto_sel_mode' to enable CPPC autonomous performance selection on all CPUs at system startup. 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_perf when available; otherwise initialize from 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. Skip applying it on CPU hotplug to preserve runtime sysfs configuration. This patch depends on patch [2] ("cpufreq: Set policy->min and max as real QoS constraints") so that the policy->min/max set in cppc_cpufreq_cpu_init() are not overridden by cpufreq_set_policy() during init. Reviewed-by: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Sumit Gupta <sumitg@nvidia.com> (backported from https://lore.kernel.org/lkml/20260424201814.230071-1-sumitg@nvidia.com/) Signed-off-by: Jamie Nguyen <jamien@nvidia.com>
1 parent 2ee1a0d commit 5812989

2 files changed

Lines changed: 97 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: 84 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,
@@ -656,6 +659,14 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
656659
caps = &cpu_data->perf_caps;
657660
policy->driver_data = cpu_data;
658661

662+
/*
663+
* Enable CPPC for both OS-driven and autonomous modes.
664+
* The Enable register is optional - some platforms may not support it
665+
*/
666+
ret = cppc_set_enable(cpu, true);
667+
if (ret && ret != -EOPNOTSUPP)
668+
pr_warn("Failed to enable CPPC for CPU%d (%d)\n", cpu, ret);
669+
659670
min = cppc_perf_to_khz(caps, caps->lowest_nonlinear_perf);
660671
max = cppc_perf_to_khz(caps, policy->boost_enabled ?
661672
caps->highest_perf : caps->nominal_perf);
@@ -711,11 +722,71 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
711722
policy->cur = cppc_perf_to_khz(caps, caps->highest_perf);
712723
cpu_data->perf_ctrls.desired_perf = caps->highest_perf;
713724

714-
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
715-
if (ret) {
716-
pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n",
717-
caps->highest_perf, cpu, ret);
718-
goto out;
725+
/*
726+
* Enable autonomous mode on first init if boot param is set.
727+
* Check last_governor to detect first init and skip if auto_sel
728+
* is already enabled.
729+
*/
730+
if (auto_sel_mode && policy->last_governor[0] == '\0' &&
731+
!cpu_data->perf_ctrls.auto_sel) {
732+
/* Init min/max_perf from caps if not already set by HW. */
733+
if (!cpu_data->perf_ctrls.min_perf)
734+
cpu_data->perf_ctrls.min_perf = caps->lowest_nonlinear_perf;
735+
if (!cpu_data->perf_ctrls.max_perf)
736+
cpu_data->perf_ctrls.max_perf = policy->boost_enabled ?
737+
caps->highest_perf : caps->nominal_perf;
738+
739+
cpu_data->perf_ctrls.desired_perf =
740+
clamp_t(u32, cpu_data->perf_ctrls.desired_perf,
741+
cpu_data->perf_ctrls.min_perf,
742+
cpu_data->perf_ctrls.max_perf);
743+
744+
policy->cur = cppc_perf_to_khz(caps,
745+
cpu_data->perf_ctrls.desired_perf);
746+
747+
/* EPP is optional - some platforms may not support it */
748+
ret = cppc_set_epp(cpu, CPPC_EPP_PERFORMANCE_PREF);
749+
if (ret && ret != -EOPNOTSUPP)
750+
pr_warn("Failed to set EPP for CPU%d (%d)\n", cpu, ret);
751+
else if (!ret)
752+
cpu_data->perf_ctrls.energy_perf = CPPC_EPP_PERFORMANCE_PREF;
753+
754+
/* Program min/max/desired into CPPC regs before enabling auto_sel. */
755+
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
756+
if (ret) {
757+
pr_debug("Err setting perf for autonomous mode CPU:%d ret:%d\n",
758+
cpu, ret);
759+
goto out;
760+
}
761+
762+
ret = cppc_set_auto_sel(cpu, true);
763+
if (ret && ret != -EOPNOTSUPP) {
764+
pr_warn("Failed autonomous config for CPU%d (%d)\n",
765+
cpu, ret);
766+
goto out;
767+
}
768+
if (!ret)
769+
cpu_data->perf_ctrls.auto_sel = true;
770+
}
771+
772+
if (cpu_data->perf_ctrls.auto_sel) {
773+
/* Sync policy limits from HW when autonomous mode is active */
774+
policy->min = cppc_perf_to_khz(caps,
775+
cpu_data->perf_ctrls.min_perf ?:
776+
caps->lowest_nonlinear_perf);
777+
policy->max = cppc_perf_to_khz(caps,
778+
cpu_data->perf_ctrls.max_perf ?:
779+
(policy->boost_enabled ?
780+
caps->highest_perf :
781+
caps->nominal_perf));
782+
} else {
783+
/* Normal mode: governors control frequency */
784+
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
785+
if (ret) {
786+
pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n",
787+
caps->highest_perf, cpu, ret);
788+
goto out;
789+
}
719790
}
720791

721792
cppc_cpufreq_cpu_fie_init(policy);
@@ -1035,10 +1106,18 @@ static int __init cppc_cpufreq_init(void)
10351106

10361107
static void __exit cppc_cpufreq_exit(void)
10371108
{
1109+
unsigned int cpu;
1110+
1111+
for_each_present_cpu(cpu)
1112+
cppc_set_auto_sel(cpu, false);
1113+
10381114
cpufreq_unregister_driver(&cppc_cpufreq_driver);
10391115
cppc_freq_invariance_exit();
10401116
}
10411117

1118+
module_param(auto_sel_mode, bool, 0444);
1119+
MODULE_PARM_DESC(auto_sel_mode, "Enable CPPC autonomous performance selection at boot");
1120+
10421121
module_exit(cppc_cpufreq_exit);
10431122
MODULE_AUTHOR("Ashwin Chaugule");
10441123
MODULE_DESCRIPTION("CPUFreq driver based on the ACPI CPPC v5.0+ spec");

0 commit comments

Comments
 (0)