cpufreq: CPPC: add autonomous mode boot parameter support
Subsystems (4)
Sumit Gupta
reviewerPATCH 1/1 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.
---
Part 1 [1] of this series was applied for 7.1 and present in next. Sending this patch as reworked version of 'patch 11' from [2] based on next.
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
--- .../admin-guide/kernel-parameters.txt | 13 +++ drivers/cpufreq/cppc_cpufreq.c | 84 +++++++++++++++++-- 2 files changed, 92 insertions(+), 5 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +13 -0
@@ -1060,6 +1060,19 @@ Kernel parameters policy to use. This governor must be registered in the kernel before the cpufreq driver probes. + cppc_cpufreq.auto_sel_mode= + [CPU_FREQ] Enable ACPI CPPC autonomous performance + selection. When enabled, hardware automatically adjusts + CPU frequency on all CPUs based on workload demands. + In Autonomous mode, Energy Performance Preference (EPP) + hints guide hardware toward performance (0x0) or energy + efficiency (0xff). + Requires ACPI CPPC autonomous selection register support. + Format: <bool> + Default: 0 (disabled) + 0: use cpufreq governors + 1: enable if supported by hardware + cpu_init_udelay=N [X86,EARLY] Delay for N microsec between assert and de-assert of APIC INIT to start processors. This delay occurs
drivers/cpufreq/cppc_cpufreq.c +79 -5
106 lines not on this page · raw message
Signature · 1 line
2.34.1
Hello Sumit,
Quoted 73 lines · Sumit Gupta
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)
- Clampdesired_perfto bounds before enabling autonomous mode
- Hardware controls frequency instead of the OS governorThe 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 <[email protected]> (Documentation)Signed-off-by Sumit Gupta <[email protected]>---
Part 1 [1] of this series was applied for 7.1 and present in next. Sending this patch as reworked version of 'patch 11' from [2] based on next.[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/--- .../admin-guide/kernel-parameters.txt | 13 +++ drivers/cpufreq/cppc_cpufreq.c | 84 +++++++++++++++++-- 2 files changed, 92 insertions(+), 5 deletions(-)Documentation/admin-guide/kernel-parameters.txt +13
-0@@ -1060,6 +1060,19 @@ Kernel parameters policy to use. This governor must be registered in the kernel before the cpufreq driver probes. + cppc_cpufreq.auto_sel_mode= + [CPU_FREQ] Enable ACPI CPPC autonomous performance + selection. When enabled, hardware automatically adjusts + CPU frequency on all CPUs based on workload demands. + In Autonomous mode, Energy Performance Preference (EPP) + hints guide hardware toward performance (0x0) or energy + efficiency (0xff). + Requires ACPI CPPC autonomous selection register support. + Format: <bool> + Default: 0 (disabled) + 0: use cpufreq governors + 1: enable if supported by hardware + cpu_init_udelay=N [X86,EARLY] Delay for N microsec between assert and de-assert of APIC INIT to start processors. This delay occursdrivers/cpufreq/cppc_cpufreq.c +3
-0@@ -28,6 +28,9 @@static struct cpufreq_driver cppc_cpufreq_driver; +/* Autonomous Selection boot parameter */ +static bool auto_sel_mode; + #ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE static enum { FIE_UNSET = -1,@@ -708,11 +711,74 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) policy->cur =cppc_perf_to_khz (caps, caps->highest_perf); cpu_data->perf_ctrls.desired_perf = caps->highest_perf;
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 718
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +5
-5- ret =cppc_set_perf (cpu, &cpu_data->perf_ctrls); -if (ret) { -pr_debug ("Err setting perf value:%d on CPU:%d. ret:%d\n" , - caps->highest_perf, cpu, ret); - goto out; +/* +* Enable autonomous mode on first init if boot param is set. +* Check last_governor to detect first init and skip if auto_sel +* is already enabled. +*/
If the goal is to set autosel only once at the driver init, shouldn't this be done in cppc_cpufreq_init() ?
I understand that cpu_data doesn't exist yet in cppc_cpufreq_init(), but this seems more appropriate to do it there IMO.
This means the cpudata should be updated accordingly in this cppc_cpufreq_cpu_init() function.
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 721
Quoted 3 lines
drivers/cpufreq/cppc_cpufreq.c +3
-0+if (auto_sel_mode && policy->last_governor[0 ] =='\0' && + !cpu_data->perf_ctrls.auto_sel) { +/* Enable CPPC - optional register, some platforms need it */
The documentation of the CPPC Enable Register is subject to interpretation, but IIUC the field should be set to use the CPPC controls, so I assume this should be set in cppc_cpufreq_init() instead ?
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 731
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +10
-0+ ret =cppc_set_enable (cpu, true); +if (ret && ret != -EOPNOTSUPP ) +pr_warn ("Failed to enable CPPC for CPU%d (%d)\n" , cpu, ret); + +/* +* Prefer HW min/max_perf when set; otherwise program from +* policy limits derived earlier from caps. +* Clamp desired_perf to bounds and sync policy->cur. +*/ +if (!cpu_data->perf_ctrls.min_perf || !cpu_data->perf_ctrls.max_perf)
The function doesn't seem to exist.
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 741
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +10
-0+cppc_cpufreq_update_perf_limits (cpu_data, policy); + + cpu_data->perf_ctrls.desired_perf = +clamp_t (u32, cpu_data->perf_ctrls.desired_perf, + cpu_data->perf_ctrls.min_perf, + cpu_data->perf_ctrls.max_perf); + + policy->cur =cppc_perf_to_khz (caps, + cpu_data->perf_ctrls.desired_perf); +
Maybe this should also be done in cppc_cpufreq_init() if the auto_sel_mode parameter is set ?
Quoted 15 lines
drivers/cpufreq/cppc_cpufreq.c +15
-0+/* EPP is optional - some platforms may not support it */ + ret =cppc_set_epp (cpu,CPPC_EPP_PERFORMANCE_PREF ); +if (ret && ret != -EOPNOTSUPP ) +pr_warn ("Failed to set EPP for CPU%d (%d)\n" , cpu, ret); +else if (!ret) + cpu_data->perf_ctrls.energy_perf =CPPC_EPP_PERFORMANCE_PREF ; + + ret =cppc_set_perf (cpu, &cpu_data->perf_ctrls); +if (ret) { +pr_debug ("Err setting perf for autonomous mode CPU:%d ret:%d\n" , + cpu, ret); + goto out; + } + + ret =cppc_set_auto_sel (cpu, true);
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 766
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +10
-0+if (ret && ret != -EOPNOTSUPP ) { +pr_warn ("Failed autonomous config for CPU%d (%d)\n" , + cpu, ret); + goto out; + } +if (!ret) + cpu_data->perf_ctrls.auto_sel = true; + } + +if (cpu_data->perf_ctrls.auto_sel) {
There is a patchset ongoing which tries to remove setting policy->min/max from driver initialization. Indeed, these values are only temporarily valid, until the governor override them.
It is not sure yet the patch will be accepted though.
Quoted 19 lines
drivers/cpufreq/cppc_cpufreq.c +15
-0+/* Sync policy limits from HW when autonomous mode is active */ + policy->min =cppc_perf_to_khz (caps, + cpu_data->perf_ctrls.min_perf ?: + caps->lowest_nonlinear_perf); + policy->max =cppc_perf_to_khz (caps, + cpu_data->perf_ctrls.max_perf ?: + caps->nominal_perf); + }else { +/* Normal mode: governors control frequency */ + ret =cppc_set_perf (cpu, &cpu_data->perf_ctrls); +if (ret) { +pr_debug ("Err setting perf value:%d on CPU:%d. ret:%d\n" , + caps->highest_perf, cpu, ret); + goto out; + } }cppc_cpufreq_cpu_fie_init (policy);
drivers/cpufreq/cppc_cpufreq.c static int __init cppc_cpufreq_init(void) · line 1110
Quoted 7 lines
drivers/cpufreq/cppc_cpufreq.c +4
-0@@ -1038,10 +1104,18 @@ static int __init cppc_cpufreq_init(void) static void __exit cppc_cpufreq_exit(void) { +unsigned int cpu; + +for_each_present_cpu (cpu) +cppc_set_auto_sel (cpu, false);
If the firmware has a default EPP value, it means that loading and the unloading the driver will reset this default EPP value. Maybe the initial EPP value and/or the auto_sel value should be cached somewhere and restored on exit ?
I don't know if this is actually an issue, this is just to signal it.
Quoted 11 lines
drivers/cpufreq/cppc_cpufreq.c +4
-0+cpufreq_unregister_driver (&cppc_cpufreq_driver);cppc_freq_invariance_exit (); } +module_param (auto_sel_mode, bool,0444 ); +MODULE_PARM_DESC (auto_sel_mode,"Enable CPPC autonomous performance selection at boot" ); +module_exit (cppc_cpufreq_exit);MODULE_AUTHOR ("Ashwin Chaugule" );MODULE_DESCRIPTION ("CPUFreq driver based on the ACPI CPPC v5.0+ spec" );
Sumit Gupta
reviewerHi Pierre,
Thank you for the comments.
Sorry for late reply as I was on vacation.
Quoted 101 lines · Pierre Gondois
External email: Use caution opening links or attachments
Hello Sumit,
Quoted 79 lines · Sumit Gupta
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)
- Clampdesired_perfto bounds before enabling autonomous mode
- Hardware controls frequency instead of the OS governorThe 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 <[email protected]> (Documentation)Signed-off-by Sumit Gupta <[email protected]>---
Part 1 [1] of this series was applied for 7.1 and present in next. Sending this patch as reworked version of 'patch 11' from [2] based on next.[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
---
.../admin-guide/kernel-parameters.txt | 13 +++ drivers/cpufreq/cppc_cpufreq.c | 84 +++++++++++++++++--2 files changed, 92 insertions(+), 5 deletions(-)Documentation/admin-guide/kernel-parameters.txt +0
-0@@ -1060,6 +1060,19 @@ Kernel parameterspolicy to use. This governor must be registered in the kernel before the cpufreq driver probes.
+ cppc_cpufreq.auto_sel_mode=
+ [CPU_FREQ] Enable ACPI CPPC autonomous performance + selection. When enabled, hardware automatically adjusts
+ CPU frequency on all CPUs based on workload demands.
+ In Autonomous mode, Energy Performance Preference (EPP)
+ hints guide hardware toward performance (0x0)
or energy
+ efficiency (0xff).
+ Requires ACPI CPPC autonomous selection
register support.
+ Format: <bool>
+ Default: 0 (disabled)
+ 0: use cpufreq governors
+ 1: enable if supported by hardware
+
cpu_init_udelay=N
[X86,EARLY] Delay for N microsec between assert and de-assert of APIC INIT to start processors. This delay occursdrivers/cpufreq/cppc_cpufreq.c +3
-0@@ -28,6 +28,9 @@ static struct cpufreq_driver cppc_cpufreq_driver; +/* Autonomous Selection boot parameter */ +static bool auto_sel_mode; + #ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE static enum { FIE_UNSET = -1,@@ -708,11 +711,74 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) policy->cur = cppc_perf_to_khz(caps, caps->highest_perf); cpu_data->perf_ctrls.desired_perf = caps->highest_perf;drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct · line 719
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +5
-5- ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls); - if (ret) { - pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n", - caps->highest_perf, cpu, ret); - goto out; + /* +* Enable autonomous mode on first init if boot param is set. +* Check last_governor to detect first init and skip if auto_sel +* is already enabled. +*/ If the goal is to set autosel only once at the driver init, shouldn't this be done in
cppc_cpufreq_init()?
I understand thatcpu_datadoesn't exist yet incppc_cpufreq_init(), but this seems more appropriate to do it there IMO.
Quoted 2 lines
This means the cpudata should be updated accordingly in this
cppc_cpufreq_cpu_init()function.
In an earlier version [1], the setup was in cppc_cpufreq_init() but was moved to cppc_cpufreq_cpu_init() to improve per-CPU error handling. Keeping the setup in cppc_cpufreq_init() helps to avoid the last_governor check. We can warn for a CPU failing to enable and continue so other CPUs keep autonomous mode.cppc_cpufreq_cpu_init() would then just check the auto_sel state from register and sync policy limits from min/max_perf registers when autonomous mode is active.
Please let me know your thoughts.
[1] https://lore.kernel.org/lkml/[email protected]/
Quoted 9 lines
Quoted 5 lines
drivers/cpufreq/cppc_cpufreq.c +3
-0+ if (auto_sel_mode && policy->last_governor[0] == '\0' && + !cpu_data->perf_ctrls.auto_sel) { + /* Enable CPPC - optional register, some platforms needit */
The documentation of the CPPC Enable Register is subject to interpretation, but IIUC the field should be set to use the CPPC controls, so I assume this should be set in
cppc_cpufreq_init()instead ?
Agree that the CPPC Enable is about using the CPPC control path in general and not only for autonomous selection.
Will move cppc_set_enable() into cppc_cpufreq_init() or outside the autonomous mode block in cppc_cpufreq_cpu_init() as per conclusion of previous comment.
Quoted 13 lines
Quoted 4 lines
+ ret =
cppc_set_enable(cpu, true);
+ if (ret && ret !=-EOPNOTSUPP)
+pr_warn("Failed to enable CPPC for CPU%d (%d)\n", cpu, ret);Quoted 8 lines
+
+ /*
+ * Prefer HW min/max_perf when set; otherwise program from + * policy limits derived earlier from caps.
+ * Clampdesired_perfto bounds and syncpolicy->cur. + */
+ if (!cpu_data->perf_ctrls.min_perf || !cpu_data->perf_ctrls.max_perf)
Quoted 1 line
The function doesn't seem to exist.
It is newly added in [2].
Don't need to call it if we move the setup to cppc_cpufreq_init().
Quoted 14 lines
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 741
Quoted 11 lines
+
cppc_cpufreq_update_perf_limits(cpu_data, policy);drivers/cpufreq/cppc_cpufreq.c +9
-0+ + cpu_data->perf_ctrls.desired_perf = + clamp_t(u32, cpu_data->perf_ctrls.desired_perf, + cpu_data->perf_ctrls.min_perf, + cpu_data->perf_ctrls.max_perf); + + policy->cur = cppc_perf_to_khz(caps, + cpu_data->perf_ctrls.desired_perf); +Maybe this should also be done in
cppc_cpufreq_init()if theauto_sel_modeparameter is set ?
Yes.
Quoted 37 lines
Quoted 22 lines
+ /* EPP is optional - some platforms may not support it */ + ret =
cppc_set_epp(cpu, CPPC_EPP_PERFORMANCE_PREF); + if (ret && ret !=-EOPNOTSUPP)
+pr_warn("Failed to set EPP for CPU%d (%d)\n", cpu, ret);
+ else if (!ret)
+cpu_data->perf_ctrls.energy_perf=CPPC_EPP_PERFORMANCE_PREF;
+
+ ret =cppc_set_perf(cpu, &cpu_data->perf_ctrls); + if (ret) {
+ pr_debug("Err setting perf for autonomous mode CPU:%d ret:%d\n",
+ cpu, ret);
+ goto out;
+ }
+
+ ret =cppc_set_auto_sel(cpu, true);
+ if (ret && ret !=-EOPNOTSUPP) {
+ pr_warn("Failed autonomous config for CPU%d (%d)\n",Quoted 8 lines
+ cpu, ret);
+ goto out;
+ }
+ if (!ret)
+cpu_data->perf_ctrls.auto_sel= true; + }
+
+ if (cpu_data->perf_ctrls.auto_sel) {There is a patchset ongoing which tries to remove setting policy->min/max from driver initialization. Indeed, these values are only temporarily valid, until the governor override them.
It is not sure yet the patch will be accepted though.
Quoted 2 lines
You are right that policy->min/max from .init() are temporary today as cpufreq_set_policy() overwrites them before the governor starts.
On my test platform (highest == nominal, lowest_nonlinear == lowest), this had no visible effect because the BIOS bounds and cpuinfo range end up identical. But on platforms where they differ, the governor would widen the range to full cpuinfo limits.
I think your patch [3] fixes this by giving these the right semantic as initial QoS requests. With it, cpufreq_set_policy() preserves the policy limits set from min/max_perf registers in .init(), which can either be BIOS values on first boot or last user configured values before hotplug.
I will update the comment in v2 to reflect QoS seeding intent.
I see that the first two patches of your series [3] is applied for 7.1. Do you plan to send the pending patch (3/4) from [3]?
[3] https://lore.kernel.org/lkml/[email protected]/
Quoted 24 lines
Quoted 24 lines
+ /* Sync policy limits from HW when autonomous mode is active */
+policy->min= cppc_perf_to_khz(caps,
+cpu_data->perf_ctrls.min_perf?:
+caps->lowest_nonlinear_perf);
+policy->max= cppc_perf_to_khz(caps,
+cpu_data->perf_ctrls.max_perf?:
+caps->nominal_perf);
+ } else {
+ /* Normal mode: governors control frequency */ + ret =cppc_set_perf(cpu, &cpu_data->perf_ctrls); + if (ret) {
+ pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n",
+caps->highest_perf, cpu, ret); + goto out;
+ }
}
cppc_cpufreq_cpu_fie_init(policy);drivers/cpufreq/cppc_cpufreq.c +0
-0@@ -1038,10 +1104,18 @@ static int __init cppc_cpufreq_init(void)
Quoted 12 lines
drivers/cpufreq/cppc_cpufreq.c static int __init cppc_cpufreq_init(void) · line 1110
Quoted 6 lines
drivers/cpufreq/cppc_cpufreq.c +4
-0static void __exit cppc_cpufreq_exit(void) { + unsigned int cpu; + + for_each_present_cpu(cpu) + cppc_set_auto_sel(cpu, false);If the firmware has a default EPP value, it means that loading and the unloading the driver will reset this default EPP value. Maybe the initial EPP value and/or the
auto_selvalue should be cached somewhere and restored on exit ?
I don't know if this is actually an issue, this is just to signal it.
The auto_sel_mode boot path programs EPP to performance preference(0), not the firmware’s previous value. On unload we only call cppc_set_auto_sel(false); we do not restore EPP, min/max perf, or other CPPC fields to firmware defaults.
Thank you,
Sumit Gupta
....
Hello Sumit,
Quoted 5 lines · Sumit Gupta
Hi Pierre,
Thank you for the comments.
Sorry for late reply as I was on vacation.
No worries
Quoted 108 lines · Pierre Gondois
Quoted 103 lines
External email: Use caution opening links or attachments
Hello Sumit,
Quoted 81 lines · Sumit Gupta
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)
- Clampdesired_perfto bounds before enabling autonomous mode
- Hardware controls frequency instead of the OS governorThe 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 <[email protected]> (Documentation)Signed-off-by Sumit Gupta <[email protected]>---
Part 1 [1] of this series was applied for 7.1 and present in next. Sending this patch as reworked version of 'patch 11' from [2] based on next.[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
---
.../admin-guide/kernel-parameters.txt | 13 +++ drivers/cpufreq/cppc_cpufreq.c | 84
+++++++++++++++++--2 files changed, 92 insertions(+), 5 deletions(-)Documentation/admin-guide/kernel-parameters.txt +0
-0@@ -1060,6 +1060,19 @@ Kernel parameterspolicy to use. This governor must be registered in the kernel before the cpufreq driver probes.
+ cppc_cpufreq.auto_sel_mode=
+ [CPU_FREQ] Enable ACPI CPPC autonomous performance
+ selection. When enabled, hardware
automatically adjusts
+ CPU frequency on all CPUs based on workload demands.
+ In Autonomous mode, Energy Performance Preference (EPP)
+ hints guide hardware toward performance (0x0)
or energy
+ efficiency (0xff).
+ Requires ACPI CPPC autonomous selection
register support.
+ Format: <bool>
+ Default: 0 (disabled)
+ 0: use cpufreq governors
+ 1: enable if supported by hardware
+
cpu_init_udelay=N
[X86,EARLY] Delay for N microsec between assert and de-assert of APIC INIT to start processors. This delay occursdrivers/cpufreq/cppc_cpufreq.c +3
-0@@ -28,6 +28,9 @@ static struct cpufreq_driver cppc_cpufreq_driver; +/* Autonomous Selection boot parameter */ +static bool auto_sel_mode; + #ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE static enum { FIE_UNSET = -1,@@ -708,11 +711,74 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) policy->cur = cppc_perf_to_khz(caps, caps->highest_perf); cpu_data->perf_ctrls.desired_perf = caps->highest_perf;drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct · line 719
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +5
-5- ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls); - if (ret) { - pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n", - caps->highest_perf, cpu, ret); - goto out; + /* +* Enable autonomous mode on first init if boot param is set. +* Check last_governor to detect first init and skip if auto_sel +* is already enabled. +*/ If the goal is to set autosel only once at the driver init, shouldn't this be done in
cppc_cpufreq_init()?
I understand thatcpu_datadoesn't exist yet incppc_cpufreq_init(), but this seems more appropriate to do it there IMO.Quoted 2 lines
This means the cpudata should be updated accordingly in this
cppc_cpufreq_cpu_init()function.
Quoted 9 lines
In an earlier version [1], the setup was in
cppc_cpufreq_init()but was moved tocppc_cpufreq_cpu_init()to improve per-CPU error handling. Keeping the setup incppc_cpufreq_init()helps to avoid thelast_governorcheck. We can warn for a CPU failing to enable and continue so other CPUs keep autonomous mode.cppc_cpufreq_cpu_init()would then just check theauto_selstate from register and sync policy limits from min/max_perf registers when autonomous mode is active.
Please let me know your thoughts.
FWIU the auto_sel_mode module parameter allows to configure the default auto_sel_mode when the driver is first loaded, so there should not need to check that again whenever cppc_cpufreq_cpu_init() is called.
Maybe Ionela saw something we didn't see ?
Also just to be sure, should it still be possible to change the auto_sel_mode through the sysfs if the driver was loaded with auto_sel_mode=1 ?
Quoted 34 lines
[1] https://lore.kernel.org/lkml/[email protected]/
Quoted 9 lines
Quoted 5 lines
drivers/cpufreq/cppc_cpufreq.c +3
-0+ if (auto_sel_mode && policy->last_governor[0] == '\0' && + !cpu_data->perf_ctrls.auto_sel) { + /* Enable CPPC - optional register, some platformsneed it */
The documentation of the CPPC Enable Register is subject to interpretation, but IIUC the field should be set to use the CPPC controls, so I assume this should be set in
cppc_cpufreq_init()instead ?Agree that the CPPC Enable is about using the CPPC control path in general and not only for autonomous selection.
Will movecppc_set_enable()intocppc_cpufreq_init()or outside the autonomous mode block incppc_cpufreq_cpu_init()as per conclusion of previous comment.Quoted 14 lines
Quoted 13 lines
+ ret =
cppc_set_enable(cpu, true);
+ if (ret && ret !=-EOPNOTSUPP)
+pr_warn("Failed to enable CPPC for CPU%d (%d)\n", cpu, ret);
+
+ /*
+ * Prefer HW min/max_perf when set; otherwise program from
+ * policy limits derived earlier from caps. + * Clampdesired_perfto bounds and syncpolicy->cur. + */
+ if (!cpu_data->perf_ctrls.min_perf || !cpu_data->perf_ctrls.max_perf)
Quoted 4 lines
Quoted 1 line
The function doesn't seem to exist.
It is newly added in [2].
Don't need to call it if we move the setup tocppc_cpufreq_init().
Ah ok right thanks.
Quoted 76 lines
Quoted 14 lines
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 741
Quoted 11 lines
+
cppc_cpufreq_update_perf_limits(cpu_data, policy);drivers/cpufreq/cppc_cpufreq.c +9
-0+ + cpu_data->perf_ctrls.desired_perf = + clamp_t(u32, cpu_data->perf_ctrls.desired_perf, + cpu_data->perf_ctrls.min_perf, + cpu_data->perf_ctrls.max_perf); + + policy->cur = cppc_perf_to_khz(caps, + cpu_data->perf_ctrls.desired_perf); +Maybe this should also be done in
cppc_cpufreq_init()if theauto_sel_modeparameter is set ?Yes.
Quoted 37 lines
Quoted 22 lines
+ /* EPP is optional - some platforms may not support it */ + ret =
cppc_set_epp(cpu, CPPC_EPP_PERFORMANCE_PREF); + if (ret && ret !=-EOPNOTSUPP)
+pr_warn("Failed to set EPP for CPU%d (%d)\n", cpu, ret);
+ else if (!ret)
+cpu_data->perf_ctrls.energy_perf=CPPC_EPP_PERFORMANCE_PREF;
+
+ ret =cppc_set_perf(cpu, &cpu_data->perf_ctrls); + if (ret) {
+ pr_debug("Err setting perf for autonomous mode CPU:%d ret:%d\n",
+ cpu, ret);
+ goto out;
+ }
+
+ ret =cppc_set_auto_sel(cpu, true);
+ if (ret && ret !=-EOPNOTSUPP) {
+ pr_warn("Failed autonomous config for CPU%d (%d)\n",Quoted 8 lines
+ cpu, ret);
+ goto out;
+ }
+ if (!ret)
+cpu_data->perf_ctrls.auto_sel= true; + }
+
+ if (cpu_data->perf_ctrls.auto_sel) {There is a patchset ongoing which tries to remove setting policy->min/max from driver initialization. Indeed, these values are only temporarily valid, until the governor override them.
It is not sure yet the patch will be accepted though.Quoted 2 lines
You are right that policy->min/max from .init() are temporary today as
cpufreq_set_policy()overwrites them before the governor starts.On my test platform (highest == nominal,
lowest_nonlinear== lowest), this had no visible effect because the BIOS bounds and cpuinfo range end up identical. But on platforms where they differ, the governor would widen the range to full cpuinfo limits.I think your patch [3] fixes this by giving these the right semantic as initial QoS requests. With it,
cpufreq_set_policy()preserves the policy limits set from min/max_perf registers in .init(), which can either be BIOS values on first boot or last user configured values before hotplug.
Quoted 5 lines
I will update the comment in v2 to reflect QoS seeding intent.
I see that the first two patches of your series [3] is applied for 7.1. Do you plan to send the pending patch (3/4) from [3]?
I need to ping Viresh to check if this is still relevant.
Quoted 40 lines
[3] https://lore.kernel.org/lkml/[email protected]/
Quoted 24 lines
Quoted 24 lines
+ /* Sync policy limits from HW when autonomous mode is active */
+policy->min= cppc_perf_to_khz(caps,
+cpu_data->perf_ctrls.min_perf?:
+caps->lowest_nonlinear_perf);
+policy->max= cppc_perf_to_khz(caps,
+cpu_data->perf_ctrls.max_perf?:
+caps->nominal_perf);
+ } else {
+ /* Normal mode: governors control frequency */ + ret =cppc_set_perf(cpu, &cpu_data->perf_ctrls); + if (ret) {
+ pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n",
+caps->highest_perf, cpu, ret); + goto out;
+ }
}
cppc_cpufreq_cpu_fie_init(policy);drivers/cpufreq/cppc_cpufreq.c +0
-0@@ -1038,10 +1104,18 @@ static int __init cppc_cpufreq_init(void)Quoted 12 lines
drivers/cpufreq/cppc_cpufreq.c static int __init cppc_cpufreq_init(void) · line 1110
Quoted 6 lines
drivers/cpufreq/cppc_cpufreq.c +4
-0static void __exit cppc_cpufreq_exit(void) { + unsigned int cpu; + + for_each_present_cpu(cpu) + cppc_set_auto_sel(cpu, false);If the firmware has a default EPP value, it means that loading and the unloading the driver will reset this default EPP value. Maybe the initial EPP value and/or the
auto_selvalue should be cached somewhere and restored on exit ?
I don't know if this is actually an issue, this is just to signal it.
Quoted 4 lines
The
auto_sel_modeboot path programs EPP to performance preference(0), not the firmware’s previous value. On unload we only callcppc_set_auto_sel(false); we do not restore EPP, min/max perf, or other CPPC fields to firmware defaults.
Yes right, so loading/unloading the driver might change the default EPP value.
Quoted 7 lines
Thank you,
Sumit Gupta....
Viresh Kumar
maintainerQuoted 1 line · Pierre Gondois
I need to ping Viresh to check if this is still relevant.
I think its okay to clear the min/max state in the kernel once and for all if you think it is not done nicely. As discussed earlier, try that in a fresh series which only does that part.
Signature · 1 line
viresh
Sumit Gupta
reviewerQuoted 11 lines · Viresh Kumar
External email: Use caution opening links or attachments
Quoted 1 line · Pierre Gondois
I need to ping Viresh to check if this is still relevant.
I think its okay to clear the min/max state in the kernel once and for all if you think it is not done nicely. As discussed earlier, try that in a fresh series which only does that part.
--
viresh
Thanks Pierre and Viresh.
In autonomous mode, the min/max_perf HW registers directly control the frequency range the hardware operates in, so the values programmed in .init() need to survive through the governor.
I verified this on a platform where lowest_nonlinear_perf != lowest_perf, the min_perf register ends up at lowest_perf instead of the intended lowest_nonlinear_perf.
Pierre's QoS seeding patch would fix this.
Happy to test once it's sent.
Thank you,
Sumit Gupta
Sumit Gupta
reviewerQuoted 117 lines
Quoted 108 lines
Quoted 106 lines · Sumit Gupta
Quoted 88 lines
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)
- Clampdesired_perfto bounds before enabling autonomous mode
- Hardware controls frequency instead of the OS governorThe 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 <[email protected]> (Documentation)Signed-off-by Sumit Gupta <[email protected]>---
Part 1 [1] of this series was applied for 7.1 and present in next. Sending this patch as reworked version of 'patch 11' from [2] based on next.[1]
https://lore.kernel.org/lkml/[email protected]/
[2]
https://lore.kernel.org/lkml/[email protected]/--- .../admin-guide/kernel-parameters.txt | 13 +++ drivers/cpufreq/cppc_cpufreq.c | 84 +++++++++++++++++-- 2 files changed, 92 insertions(+), 5 deletions(-)Documentation/admin-guide/kernel-parameters.txt +0
-0@@ -1060,6 +1060,19 @@ Kernel parameters policy to use. This governor must beregistered in the
kernel before the cpufreq driver probes.Documentation/admin-guide/kernel-parameters.txt +2
-0+ cppc_cpufreq.auto_sel_mode= + [CPU_FREQ] Enable ACPI CPPC autonomousperformance
+ selection. When enabled, hardware
automatically adjusts
+ CPU frequency on all CPUs based on workload
demands.
+ In Autonomous mode, Energy Performance
Preference (EPP)
+ hints guide hardware toward performance (0x0)
or energyDocumentation/admin-guide/kernel-parameters.txt +2
-0+ efficiency (0xff). + Requires ACPI CPPC autonomous selectionregister support.
Documentation/admin-guide/kernel-parameters.txt +5
-0+ Format: <bool> + Default: 0 (disabled) + 0: use cpufreq governors + 1: enable if supported by hardware + cpu_init_udelay=N [X86,EARLY] Delay for N microsec betweenassert and de-assert
of APIC INIT to start processors. This delay
occursdrivers/cpufreq/cppc_cpufreq.c +3
-0@@ -28,6 +28,9 @@static struct cpufreq_driver cppc_cpufreq_driver; +/* Autonomous Selection boot parameter */ +static bool auto_sel_mode; + #ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE static enum { FIE_UNSET = -1,@@ -708,11 +711,74 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) policy->cur = cppc_perf_to_khz(caps, caps->highest_perf); cpu_data->perf_ctrls.desired_perf = caps->highest_perf;drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct · line 719
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +5
-5- ret =cppc_set_perf (cpu, &cpu_data->perf_ctrls); -if (ret) { -pr_debug ("Err setting perf value:%d on CPU:%d. ret:%d\n" , - caps->highest_perf, cpu, ret); - goto out; +/* +* Enable autonomous mode on first init if boot param is set. +* Check last_governor to detect first init and skip if auto_sel +* is already enabled. +*/ If the goal is to set autosel only once at the driver init, shouldn't this be done in
cppc_cpufreq_init()?
I understand thatcpu_datadoesn't exist yet incppc_cpufreq_init(), but this seems more appropriate to do it there IMO.Quoted 2 lines
This means the cpudata should be updated accordingly in this
cppc_cpufreq_cpu_init()function.Quoted 9 lines
In an earlier version [1], the setup was in
cppc_cpufreq_init()but was moved tocppc_cpufreq_cpu_init()to improve per-CPU error handling. Keeping the setup incppc_cpufreq_init()helps to avoid thelast_governorcheck. We can warn for a CPU failing to enable and continue so other CPUs keep autonomous mode.cppc_cpufreq_cpu_init()would then just check theauto_selstate from register and sync policy limits from min/max_perf registers when autonomous mode is active.
Please let me know your thoughts.
Quoted 5 lines
FWIU the
auto_sel_modemodule parameter allows to configure the defaultauto_sel_modewhen the driver is first loaded, so there should not need to check that again whenevercppc_cpufreq_cpu_init()is called.
Maybe Ionela saw something we didn't see ?
AFAIU, the concern in that review [1] was about error handling as the earlier version disabled auto_sel on all CPUs if any single CPU failed. Per-CPU error handling in cppc_cpufreq_init() (warn and continue) addresses that. Can't think of more reason.
Do you have anything in mind?
Quoted 5 lines
Also just to be sure, should it still be possible to change the
auto_sel_modethrough the sysfs if the driver was loaded with auto_sel_mode=1 ?
Yes, the per-CPU auto_select sysfs attribute works independently of the boot param. Users can enable or disable auto_sel on any CPU at runtime via sysfs, regardless of how the driver was loaded. The boot param only sets the initial state.
Quoted 153 lines
Quoted 31 lines
[1]
https://lore.kernel.org/lkml/[email protected]/Quoted 8 lines
Quoted 4 lines
drivers/cpufreq/cppc_cpufreq.c +3
-0+if (auto_sel_mode && policy->last_governor[0 ] =='\0' && + !cpu_data->perf_ctrls.auto_sel) { +/* Enable CPPC - optional register, some platforms need it */
The documentation of the CPPC Enable Register is subject to interpretation, but IIUC the field should be set to use the CPPC controls, so I assume this should be set in
cppc_cpufreq_init()instead ?Agree that the CPPC Enable is about using the CPPC control path in general and not only for autonomous selection.
Will movecppc_set_enable()intocppc_cpufreq_init()or outside the autonomous mode block incppc_cpufreq_cpu_init()as per conclusion of previous comment.Quoted 13 lines
Quoted 13 lines
drivers/cpufreq/cppc_cpufreq.c +3
-0+ ret =cppc_set_enable (cpu, true); +if (ret && ret != -EOPNOTSUPP ) + pr_warn("Failed to enable CPPC for CPU%d(%d)\n", cpu, ret);
drivers/cpufreq/cppc_cpufreq.c +3
-0+ +/* +* Prefer HW min/max_perf when set; otherwise program from
drivers/cpufreq/cppc_cpufreq.c +4
-0+* policy limits derived earlier from caps. +* Clamp desired_perf to bounds and sync policy->cur. +*/ + if (!cpu_data->perf_ctrls.min_perf ||!cpu_data->perf_ctrls.max_perf)
Quoted 3 lines
Quoted 1 line
The function doesn't seem to exist.
It is newly added in [2].
Don't need to call it if we move the setup tocppc_cpufreq_init().Ah ok right thanks.
Quoted 70 lines
Quoted 4 lines
Quoted 4 lines
+
cppc_cpufreq_update_perf_limits(cpu_data, policy);drivers/cpufreq/cppc_cpufreq.c +3
-0+ + cpu_data->perf_ctrls.desired_perf = + clamp_t(u32, cpu_data->perf_ctrls.desired_perf,Quoted 8 lines
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 741
Quoted 6 lines
+
cpu_data->perf_ctrls.min_perf,
+cpu_data->perf_ctrls.max_perf);drivers/cpufreq/cppc_cpufreq.c +4
-0+ + policy->cur =cppc_perf_to_khz (caps, + cpu_data->perf_ctrls.desired_perf); +Maybe this should also be done in
cppc_cpufreq_init()if theauto_sel_modeparameter is set ?Yes.
Quoted 35 lines
Quoted 21 lines
drivers/cpufreq/cppc_cpufreq.c +4
-0+/* EPP is optional - some platforms may not support it */ + ret =cppc_set_epp (cpu,CPPC_EPP_PERFORMANCE_PREF ); +if (ret && ret != -EOPNOTSUPP ) + pr_warn("Failed to set EPP for CPU%d (%d)\n",cpu, ret);
drivers/cpufreq/cppc_cpufreq.c +2
-0+else if (!ret) + cpu_data->perf_ctrls.energy_perf =
CPPC_EPP_PERFORMANCE_PREF;drivers/cpufreq/cppc_cpufreq.c +4
-0+ + ret =cppc_set_perf (cpu, &cpu_data->perf_ctrls); +if (ret) { + pr_debug("Err setting perf for autonomous modeCPU:%d ret:%d\n",
drivers/cpufreq/cppc_cpufreq.c +7
-0+ cpu, ret); + goto out; + } + + ret =cppc_set_auto_sel (cpu, true); +if (ret && ret != -EOPNOTSUPP ) { + pr_warn("Failed autonomous config for CPU%d(%d)\n",
drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 766
Quoted 8 lines
drivers/cpufreq/cppc_cpufreq.c +8
-0+ cpu, ret); + goto out; + } +if (!ret) + cpu_data->perf_ctrls.auto_sel = true; + } + +if (cpu_data->perf_ctrls.auto_sel) {There is a patchset ongoing which tries to remove setting policy->min/max from driver initialization. Indeed, these values are only temporarily valid, until the governor override them.
It is not sure yet the patch will be accepted though.Quoted 2 lines
You are right that policy->min/max from .init() are temporary today as
cpufreq_set_policy()overwrites them before the governor starts.On my test platform (highest == nominal,
lowest_nonlinear== lowest), this had no visible effect because the BIOS bounds and cpuinfo range end up identical. But on platforms where they differ, the governor would widen the range to full cpuinfo limits.I think your patch [3] fixes this by giving these the right semantic as initial QoS requests. With it,
cpufreq_set_policy()preserves the policy limits set from min/max_perf registers in .init(), which can either be BIOS values on first boot or last user configured values before hotplug.Quoted 5 lines
I will update the comment in v2 to reflect QoS seeding intent.
I see that the first two patches of your series [3] is applied for 7.1. Do you plan to send the pending patch (3/4) from [3]?
I need to ping Viresh to check if this is still relevant.
Quoted 38 lines
[3]
https://lore.kernel.org/lkml/[email protected]/Quoted 34 lines
Quoted 22 lines
+ /* Sync policy limits from HW when autonomous mode is
active */drivers/cpufreq/cppc_cpufreq.c +11
-0+ policy->min =cppc_perf_to_khz (caps, + cpu_data->perf_ctrls.min_perf ?: + caps->lowest_nonlinear_perf); + policy->max =cppc_perf_to_khz (caps, + cpu_data->perf_ctrls.max_perf ?: + caps->nominal_perf); + }else { +/* Normal mode: governors control frequency */ + ret =cppc_set_perf (cpu, &cpu_data->perf_ctrls); +if (ret) { + pr_debug("Err setting perf value:%d on CPU:%d.ret:%d\n",
drivers/cpufreq/cppc_cpufreq.c +3
-0+ caps->highest_perf, cpu, ret); + goto out; + } }cppc_cpufreq_cpu_fie_init (policy);drivers/cpufreq/cppc_cpufreq.c static int __init cppc_cpufreq_init(void) · line 1110
Quoted 7 lines
drivers/cpufreq/cppc_cpufreq.c +4
-0@@ -1038,10 +1104,18 @@ static int __init cppc_cpufreq_init(void) static void __exit cppc_cpufreq_exit(void) { +unsigned int cpu; + +for_each_present_cpu (cpu) +cppc_set_auto_sel (cpu, false);If the firmware has a default EPP value, it means that loading and the unloading the driver will reset this default EPP value. Maybe the initial EPP value and/or the
auto_selvalue should be cached somewhere and restored on exit ?
I don't know if this is actually an issue, this is just to signal it.
Quoted 6 lines
Quoted 4 lines
The
auto_sel_modeboot path programs EPP to performance preference(0), not the firmware’s previous value. On unload we only callcppc_set_auto_sel(false); we do not restore EPP, min/max perf, or other CPPC fields to firmware defaults.Yes right, so loading/unloading the driver might change the default EPP value.
Acknowledged.
With auto_sel_mode, load/unload can leave EPP and other CPPC fields different from the firmware defaults at boot.
We can add explicit cache-and-restore on exit in a follow-up if that is desired.
Thank you,
Sumit Gupta
Sumit Gupta
reviewerQuoted 128 lines · Sumit Gupta
Quoted 122 lines
Quoted 113 lines
Quoted 111 lines · Sumit Gupta
Quoted 100 lines
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)
- Clampdesired_perfto bounds before enabling autonomous mode
- Hardware controls frequency instead of the OS governorThe 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 <[email protected]> (Documentation)Signed-off-by Sumit Gupta <[email protected]>---
Part 1 [1] of this series was applied for 7.1 and present in next. Sending this patch as reworked version of 'patch 11' from [2] based on next.[1]
https://lore.kernel.org/lkml/[email protected]/[2]
https://lore.kernel.org/lkml/[email protected]/---
.../admin-guide/kernel-parameters.txt | 13 +++ drivers/cpufreq/cppc_cpufreq.c | 84
+++++++++++++++++--2 files changed, 92 insertions(+), 5 deletions(-)Documentation/admin-guide/kernel-parameters.txt +0
-0@@ -1060,6 +1060,19 @@ Kernel parameterspolicy to use. This governor must be registered in the
kernel before the cpufreq driver probes.+ cppc_cpufreq.auto_sel_mode=
+ [CPU_FREQ] Enable ACPI CPPC autonomous performance
+ selection. When enabled, hardware automatically adjusts
+ CPU frequency on all CPUs based on workload demands.
+ In Autonomous mode, Energy Performance Preference (EPP)
+ hints guide hardware toward performance (0x0) or energy
+ efficiency (0xff).
+ Requires ACPI CPPC autonomous selection register support.
+ Format: <bool>
+ Default: 0 (disabled)
+ 0: use cpufreq governors
+ 1: enable if supported by hardware +
cpu_init_udelay=N
[X86,EARLY] Delay for N microsec between assert and de-assert
of APIC INIT to start processors. This delay occursdrivers/cpufreq/cppc_cpufreq.c +6
-5@@ -28,6 +28,9 @@ static struct cpufreq_driver cppc_cpufreq_driver; +/* Autonomous Selection boot parameter */ +static bool auto_sel_mode; + #ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE static enum { FIE_UNSET = -1,@@ -708,11 +711,74 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) policy->cur = cppc_perf_to_khz(caps, caps->highest_perf); cpu_data->perf_ctrls.desired_perf = caps->highest_perf; - ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls); - if (ret) { - pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n", - caps->highest_perf, cpu, ret); - goto out; + /* +* Enable autonomous mode on first init if boot param is set. +* Check last_governor to detect first init and skip if Quoted 3 lines
auto_sel
+ * is already enabled.
+ */If the goal is to set autosel only once at the driver init, shouldn't this be done in
cppc_cpufreq_init()?
I understand thatcpu_datadoesn't exist yet incppc_cpufreq_init(), but this seems more appropriate to do it there IMO.Quoted 2 lines
This means the cpudata should be updated accordingly in this
cppc_cpufreq_cpu_init()function.Quoted 9 lines
In an earlier version [1], the setup was in
cppc_cpufreq_init()but was moved tocppc_cpufreq_cpu_init()to improve per-CPU error handling. Keeping the setup incppc_cpufreq_init()helps to avoid thelast_governorcheck. We can warn for a CPU failing to enable and continue so other CPUs keep autonomous mode.cppc_cpufreq_cpu_init()would then just check theauto_selstate from register and sync policy limits from min/max_perf registers when autonomous mode is active.
Please let me know your thoughts.Quoted 5 lines
FWIU the
auto_sel_modemodule parameter allows to configure the defaultauto_sel_modewhen the driver is first loaded, so there should not need to check that again whenevercppc_cpufreq_cpu_init()is called.
Maybe Ionela saw something we didn't see ?
Quoted 6 lines
AFAIU, the concern in that review [1] was about error handling as the earlier version disabled
auto_selon all CPUs if any single CPU failed. Per-CPU error handling incppc_cpufreq_init()(warn and continue) addresses that. Can't think of more reason.
Do you have anything in mind?
Actually, one case where cppc_cpufreq_cpu_init() would be needed is when CPUs are offline at boot. So I will keep the setup in cppc_cpufreq_cpu_init() in v2 same as present in current version.
Thank you,
Sumit Gupta
....
Quoted 137 lines · Sumit Gupta
Quoted 128 lines · Sumit Gupta
Quoted 122 lines
Quoted 113 lines
Quoted 111 lines · Sumit Gupta
Quoted 100 lines
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)
- Clampdesired_perfto bounds before enabling autonomous mode
- Hardware controls frequency instead of the OS governorThe 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 <[email protected]> (Documentation)Signed-off-by Sumit Gupta <[email protected]>---
Part 1 [1] of this series was applied for 7.1 and present in next. Sending this patch as reworked version of 'patch 11' from [2] based on next.[1]
https://lore.kernel.org/lkml/[email protected]/[2]
https://lore.kernel.org/lkml/[email protected]/---
.../admin-guide/kernel-parameters.txt | 13 +++ drivers/cpufreq/cppc_cpufreq.c | 84
+++++++++++++++++--2 files changed, 92 insertions(+), 5 deletions(-)Documentation/admin-guide/kernel-parameters.txt +0
-0@@ -1060,6 +1060,19 @@ Kernel parameterspolicy to use. This governor must be registered in the
kernel before the cpufreq driver probes.+ cppc_cpufreq.auto_sel_mode=
+ [CPU_FREQ] Enable ACPI CPPC autonomous performance
+ selection. When enabled, hardware automatically adjusts
+ CPU frequency on all CPUs based on workload demands.
+ In Autonomous mode, Energy Performance Preference (EPP)
+ hints guide hardware toward performance (0x0) or energy
+ efficiency (0xff).
+ Requires ACPI CPPC autonomous selection register support.
+ Format: <bool>
+ Default: 0 (disabled)
+ 0: use cpufreq governors
+ 1: enable if supported by hardware +
cpu_init_udelay=N
[X86,EARLY] Delay for N microsec between assert and de-assert
of APIC INIT to start processors. This delay occursdrivers/cpufreq/cppc_cpufreq.c +6
-5@@ -28,6 +28,9 @@ static struct cpufreq_driver cppc_cpufreq_driver; +/* Autonomous Selection boot parameter */ +static bool auto_sel_mode; + #ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE static enum { FIE_UNSET = -1,@@ -708,11 +711,74 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) policy->cur = cppc_perf_to_khz(caps, caps->highest_perf); cpu_data->perf_ctrls.desired_perf = caps->highest_perf; - ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls); - if (ret) { - pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n", - caps->highest_perf, cpu, ret); - goto out; + /* +* Enable autonomous mode on first init if boot param is set. +* Check last_governor to detect first init and skip if Quoted 3 lines
auto_sel
+ * is already enabled.
+ */If the goal is to set autosel only once at the driver init, shouldn't this be done in
cppc_cpufreq_init()?
I understand thatcpu_datadoesn't exist yet incppc_cpufreq_init(), but this seems more appropriate to do it there IMO.Quoted 2 lines
This means the cpudata should be updated accordingly in this
cppc_cpufreq_cpu_init()function.Quoted 9 lines
In an earlier version [1], the setup was in
cppc_cpufreq_init()but was moved tocppc_cpufreq_cpu_init()to improve per-CPU error handling. Keeping the setup incppc_cpufreq_init()helps to avoid thelast_governorcheck. We can warn for a CPU failing to enable and continue so other CPUs keep autonomous mode.cppc_cpufreq_cpu_init()would then just check theauto_selstate from register and sync policy limits from min/max_perf registers when autonomous mode is active.
Please let me know your thoughts.Quoted 5 lines
FWIU the
auto_sel_modemodule parameter allows to configure the defaultauto_sel_modewhen the driver is first loaded, so there should not need to check that again whenevercppc_cpufreq_cpu_init()is called.
Maybe Ionela saw something we didn't see ?Quoted 6 lines
AFAIU, the concern in that review [1] was about error handling as the earlier version disabled
auto_selon all CPUs if any single CPU failed. Per-CPU error handling incppc_cpufreq_init()(warn and continue) addresses that. Can't think of more reason.
Do you have anything in mind?
Quoted 4 lines
Actually, one case where
cppc_cpufreq_cpu_init()would be needed is when CPUs are offline at boot. So I will keep the setup incppc_cpufreq_cpu_init()in v2 same as present in current version.
Wouldn't it be possible to loop over the "cpu_present_mask" as you currently do in cppc_cpufreq_exit() ?
------
Another issue about relying on "cpu_data->perf_ctrls.auto_sel" in:
"""
if (auto_sel_mode && policy->last_governor[0] == '\0' && !cpu_data->perf_ctrls.auto_sel) {
"""
is that the cpu_data struct is fresh memory coming from cppc_cpufreq_get_cpu_data(), so it might always be 0 I think.
Sumit Gupta
reviewerQuoted 149 lines · Pierre Gondois
External email: Use caution opening links or attachments
Quoted 145 lines · Sumit Gupta
Quoted 142 lines · Sumit Gupta
Quoted 130 lines
Quoted 119 lines
Quoted 117 lines · Sumit Gupta
Quoted 106 lines
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)
- Clampdesired_perfto bounds before enabling autonomous mode
- Hardware controls frequency instead of the OS governorThe 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 <[email protected]> (Documentation)Signed-off-by Sumit Gupta <[email protected]>---
Part 1 [1] of this series was applied for 7.1 and present in next. Sending this patch as reworked version of 'patch 11' from [2] based on next.[1]
https://lore.kernel.org/lkml/[email protected]/[2]
https://lore.kernel.org/lkml/[email protected]/---
.../admin-guide/kernel-parameters.txt | 13 +++ drivers/cpufreq/cppc_cpufreq.c | 84
+++++++++++++++++--2 files changed, 92 insertions(+), 5 deletions(-)Documentation/admin-guide/kernel-parameters.txt +0
-0@@ -1060,6 +1060,19 @@ Kernel parameterspolicy to use. This governor must be registered in the
kernel before the cpufreq driver probes.+ cppc_cpufreq.auto_sel_mode=
+ [CPU_FREQ] Enable ACPI CPPC autonomous performance
+ selection. When enabled, hardware automatically adjusts
+ CPU frequency on all CPUs based on workload demands.
+ In Autonomous mode, Energy Performance Preference (EPP)
+ hints guide hardware toward performance (0x0) or energy
+ efficiency (0xff).
+ Requires ACPI CPPC autonomous selection register support.
+ Format: <bool>
+ Default: 0 (disabled)
+ 0: use cpufreq governors
+ 1: enable if supported by hardware +
cpu_init_udelay=N
[X86,EARLY] Delay for N microsec between assert and de-assert
of APIC INIT to start processors. This delay occursdrivers/cpufreq/cppc_cpufreq.c +6
-5@@ -28,6 +28,9 @@ static struct cpufreq_driver cppc_cpufreq_driver; +/* Autonomous Selection boot parameter */ +static bool auto_sel_mode; + #ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE static enum { FIE_UNSET = -1,@@ -708,11 +711,74 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) policy->cur = cppc_perf_to_khz(caps, caps->highest_perf); cpu_data->perf_ctrls.desired_perf = caps->highest_perf; - ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls); - if (ret) { - pr_debug("Err setting perf value:%d on CPU:%d. ret:%d\n", - caps->highest_perf, cpu, ret); - goto out; + /* +* Enable autonomous mode on first init if boot param is set. +* Check last_governor to detect first init and skip if Quoted 3 lines
auto_sel
+ * is already enabled.
+ */If the goal is to set autosel only once at the driver init, shouldn't this be done in
cppc_cpufreq_init()?
I understand thatcpu_datadoesn't exist yet incppc_cpufreq_init(), but this seems more appropriate to do it there IMO.Quoted 2 lines
This means the cpudata should be updated accordingly in this
cppc_cpufreq_cpu_init()function.Quoted 11 lines
In an earlier version [1], the setup was in
cppc_cpufreq_init()but was moved tocppc_cpufreq_cpu_init()to improve per-CPU error handling.
Keeping the setup incppc_cpufreq_init()helps to avoid thelast_governor
check. We can warn for a CPU failing to enable and continue so other CPUs keep autonomous mode.cppc_cpufreq_cpu_init()would then just check theauto_selstate from register and sync policy limits from min/max_perf registers when autonomous mode is active.
Please let me know your thoughts.Quoted 5 lines
FWIU the
auto_sel_modemodule parameter allows to configure the defaultauto_sel_modewhen the driver is first loaded, so there should not need to check that again whenevercppc_cpufreq_cpu_init()is called.
Maybe Ionela saw something we didn't see ?AFAIU, the concern in that review [1] was about error handling as the earlier version disabled
auto_selon all CPUs if any single CPU failed. Per-CPU error handling incppc_cpufreq_init()(warn and continue) addresses that. Can't think of more reason.
Do you have anything in mind?
Quoted 6 lines
Quoted 4 lines
Actually, one case where
cppc_cpufreq_cpu_init()would be needed is when CPUs are offline at boot. So I will keep the setup incppc_cpufreq_cpu_init()in v2 same as present in current version.Wouldn't it be possible to loop over the "
cpu_present_mask" as you currently do incppc_cpufreq_exit()?
On ARM64 it works since registers go through PCC/SystemMemory which don't require the target CPU online. But cppc_cpufreq.c is also built for RISCV, where cpc_write_ffh() uses smp_call_function_single().
So setup in cppc_cpufreq_init() with for_each_present_cpu() would fail on RISCV+FFH platforms when CPUs are offline at boot. cppc_cpufreq_cpu_init() handles all cases naturally.
Quoted 5 lines
------
Another issue about relying on "
cpu_data->perf_ctrls.auto_sel" in:
Quoted 9 lines
"""
if (auto_sel_mode&& policy->last_governor[0] == '\0' && !cpu_data->perf_ctrls.auto_sel) {
"""is that the
cpu_datastruct is fresh memory coming fromcppc_cpufreq_get_cpu_data(), so it might always be 0 I think.
cppc_cpufreq_get_cpu_data() calls cppc_get_perf() (added in [1]) which reads perf_ctrls including auto_sel from the HW register. So, cpu_data->perf_ctrls.auto_sel reflects the actual HW state, not the zeroed kzalloc value.
[1] https://lore.kernel.org/lkml/[email protected]/
Thank you,
Sumit Gupta