Skip to content

Commit fdad114

Browse files
Sumit GuptajamieNguyenNVIDIA
authored andcommitted
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>
1 parent c0eebd8 commit fdad114

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
@@ -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: 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,
@@ -624,6 +627,14 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
624627
caps = &cpu_data->perf_caps;
625628
policy->driver_data = cpu_data;
626629

630+
/*
631+
* Enable CPPC for both OS-driven and autonomous modes.
632+
* The Enable register is optional - some platforms may not support it
633+
*/
634+
ret = cppc_set_enable(cpu, true);
635+
if (ret && ret != -EOPNOTSUPP)
636+
pr_warn("Failed to enable CPPC for CPU%d (%d)\n", cpu, ret);
637+
627638
min = cppc_perf_to_khz(caps, caps->lowest_nonlinear_perf);
628639
max = cppc_perf_to_khz(caps, policy->boost_enabled ?
629640
caps->highest_perf : caps->nominal_perf);
@@ -679,11 +690,71 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
679690
policy->cur = cppc_perf_to_khz(caps, caps->highest_perf);
680691
cpu_data->perf_ctrls.desired_perf = caps->highest_perf;
681692

682-
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
683-
if (ret) {
684-
pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n",
685-
caps->highest_perf, cpu, ret);
686-
goto out;
693+
/*
694+
* Enable autonomous mode on first init if boot param is set.
695+
* Check last_governor to detect first init and skip if auto_sel
696+
* is already enabled.
697+
*/
698+
if (auto_sel_mode && policy->last_governor[0] == '\0' &&
699+
!cpu_data->perf_ctrls.auto_sel) {
700+
/* Init min/max_perf from caps if not already set by HW. */
701+
if (!cpu_data->perf_ctrls.min_perf)
702+
cpu_data->perf_ctrls.min_perf = caps->lowest_nonlinear_perf;
703+
if (!cpu_data->perf_ctrls.max_perf)
704+
cpu_data->perf_ctrls.max_perf = policy->boost_enabled ?
705+
caps->highest_perf : caps->nominal_perf;
706+
707+
cpu_data->perf_ctrls.desired_perf =
708+
clamp_t(u32, cpu_data->perf_ctrls.desired_perf,
709+
cpu_data->perf_ctrls.min_perf,
710+
cpu_data->perf_ctrls.max_perf);
711+
712+
policy->cur = cppc_perf_to_khz(caps,
713+
cpu_data->perf_ctrls.desired_perf);
714+
715+
/* EPP is optional - some platforms may not support it */
716+
ret = cppc_set_epp(cpu, CPPC_EPP_PERFORMANCE_PREF);
717+
if (ret && ret != -EOPNOTSUPP)
718+
pr_warn("Failed to set EPP for CPU%d (%d)\n", cpu, ret);
719+
else if (!ret)
720+
cpu_data->perf_ctrls.energy_perf = CPPC_EPP_PERFORMANCE_PREF;
721+
722+
/* Program min/max/desired into CPPC regs before enabling auto_sel. */
723+
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
724+
if (ret) {
725+
pr_debug("Err setting perf for autonomous mode CPU:%d ret:%d\n",
726+
cpu, ret);
727+
goto out;
728+
}
729+
730+
ret = cppc_set_auto_sel(cpu, true);
731+
if (ret && ret != -EOPNOTSUPP) {
732+
pr_warn("Failed autonomous config for CPU%d (%d)\n",
733+
cpu, ret);
734+
goto out;
735+
}
736+
if (!ret)
737+
cpu_data->perf_ctrls.auto_sel = true;
738+
}
739+
740+
if (cpu_data->perf_ctrls.auto_sel) {
741+
/* Sync policy limits from HW when autonomous mode is active */
742+
policy->min = cppc_perf_to_khz(caps,
743+
cpu_data->perf_ctrls.min_perf ?:
744+
caps->lowest_nonlinear_perf);
745+
policy->max = cppc_perf_to_khz(caps,
746+
cpu_data->perf_ctrls.max_perf ?:
747+
(policy->boost_enabled ?
748+
caps->highest_perf :
749+
caps->nominal_perf));
750+
} else {
751+
/* Normal mode: governors control frequency */
752+
ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
753+
if (ret) {
754+
pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n",
755+
caps->highest_perf, cpu, ret);
756+
goto out;
757+
}
687758
}
688759

689760
cppc_cpufreq_cpu_fie_init(policy);
@@ -1013,10 +1084,18 @@ static int __init cppc_cpufreq_init(void)
10131084

10141085
static void __exit cppc_cpufreq_exit(void)
10151086
{
1087+
unsigned int cpu;
1088+
1089+
for_each_present_cpu(cpu)
1090+
cppc_set_auto_sel(cpu, false);
1091+
10161092
cpufreq_unregister_driver(&cppc_cpufreq_driver);
10171093
cppc_freq_invariance_exit();
10181094
}
10191095

1096+
module_param(auto_sel_mode, bool, 0444);
1097+
MODULE_PARM_DESC(auto_sel_mode, "Enable CPPC autonomous performance selection at boot");
1098+
10201099
module_exit(cppc_cpufreq_exit);
10211100
MODULE_AUTHOR("Ashwin Chaugule");
10221101
MODULE_DESCRIPTION("CPUFreq driver based on the ACPI CPPC v5.0+ spec");

0 commit comments

Comments
 (0)