Skip to contentSkip to conversation

cpufreq: CPPC: add autonomous mode boot parameter support

PATCH Superseded Sumit Gupta 3 participants 7 messages Jun 23 – Nov 5

Subsystems (7)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Sumit Gupta

author reviewer
#0 lore raw

v5 cover cpufreq: CPPC: add autonomous mode boot parameter support

This series adds a kernel boot parameter 'cppc_cpufreq.auto_sel_mode' to enable CPPC autonomous performance selection on all CPUs at system startup, avoiding per-CPU sysfs scripting at every boot.

When autonomous mode is enabled, the hardware automatically adjusts CPU performance based on workload demands using Energy Performance Preference (EPP) hints.

Patch 1: Sets CPPC Enable Register for both OS-driven and autonomous CPPC control modes. It can be applied independently of patch 2.

Patch 2: Adds the auto_sel_mode boot parameter with three modes:
- performance (or 1): override EPP to performance (0x0)
- balance_performance (or 2): override EPP to balance_performance (0x80)
- default_epp (or 3): preserve EPP value programmed by
BIOS/firmware

Patch 2 relies on commit 8c83947c5dbb ("cpufreq: Use policy->min/max init as QoS request") so that policy->min/max set during cppc_cpufreq_cpu_init() are not overridden by cpufreq_set_policy().

v4[4] -> v5:
- Accept "disabled/0" and treat unrecognized auto_sel_mode as disabled.
- Rebased on the merged QoS-constraints and updated commit dependency.

v3[3] -> v4:
- Add 'balance_performance' mode which sets EPP to 0x80.
- Add CPPC_EPP_BALANCE_PERFORMANCE_PREF (0x80) constant in cppc_acpi.h.
- Clean up EPP mode selection with switch + boolean flag in cpu_init.
- Use local variable for kp->arg in auto_sel_mode_set/get to avoid repeated casts.

Sumit Gupta (2):
cpufreq: CPPC: Set CPPC Enable register in cpu_init
cpufreq: CPPC: add autonomous mode boot parameter support

 .../admin-guide/kernel-parameters.txt         |  22 +++
 drivers/cpufreq/cppc_cpufreq.c                | 159 +++++++++++++++++-
 include/acpi/cppc_acpi.h                      |   1 +
 3 files changed, 177 insertions(+), 5 deletions(-)

[1] v1: https://lore.kernel.org/lkml/[email protected]/
[2] v2: https://lore.kernel.org/lkml/[email protected]/
[3] v3: https://lore.kernel.org/lkml/[email protected]/
[4] v4: https://lore.kernel.org/lkml/[email protected]/

Signature · 1 line
2.34.1
author reviewer
#1 lore raw

PATCH v5 1/2 cpufreq: CPPC: Set CPPC Enable register in cpu_init

As per ACPI 6.x s8.4.6.1.4 (CPPC Enable register):
"If supported by the platform, OSPM writes a one to this register
to enable CPPC on this processor. If not implemented, OSPM assumes the platform always has CPPC enabled."

Call cppc_set_enable() at the start of cppc_cpufreq_cpu_init() so this is done for both OS-driven and autonomous CPPC control modes. Errors are logged but non-fatal as the register is optional.

---
 drivers/cpufreq/cppc_cpufreq.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/cpufreq/cppc_cpufreq.c +8 -0
index f6cea0c54dd9..f7a47576717a 100644
@@ -655,6 +655,14 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
 	caps = &cpu_data->perf_caps;
 	policy->driver_data = cpu_data;
 
+	/*
+	 * Enable CPPC for both OS-driven and autonomous modes.
+	 * The Enable register is optional - some platforms may not support it
+	 */
+	ret = cppc_set_enable(cpu, true);
+	if (ret && ret != -EOPNOTSUPP)
+		pr_warn("Failed to enable CPPC for CPU%d (%d)\n", cpu, ret);
+
 	/*
 	 * Set min to lowest nonlinear perf to avoid any efficiency penalty (see
 	 * Section 8.4.7.1.1.5 of ACPI 6.1 spec)
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v5 1/2] cpufreq: CPPC: Set CPPC Enable register in cpu_init

Quoted 8 lines · Sumit Gupta

As per ACPI 6.x s8.4.6.1.4 (CPPC Enable register):
"If supported by the platform, OSPM writes a one to this register
to enable CPPC on this processor. If not implemented, OSPM assumes the platform always has CPPC enabled."

Call cppc_set_enable() at the start of cppc_cpufreq_cpu_init() so this is done for both OS-driven and autonomous CPPC control modes. Errors are logged but non-fatal as the register is optional.

Sumit, given this is a bug fix to the CPPC driver (e.g. NVIDIA GB10 doesn't enable CPPC without writing the register, keeping the CPUs always at the lowest freq) and is largely unrelated to the autonomous mode feature, could you please resubmit this as a standalone patch?

Thanks!

Jiri

Quoted 24 lines
---
 drivers/cpufreq/cppc_cpufreq.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/cpufreq/cppc_cpufreq.c +8 -0
index f6cea0c54dd9..f7a47576717a 100644
@@ -655,6 +655,14 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
 	caps = &cpu_data->perf_caps;
 	policy->driver_data = cpu_data;
 
+	/*
+	 * Enable CPPC for both OS-driven and autonomous modes.
+	 * The Enable register is optional - some platforms may not support it
+	 */
+	ret = cppc_set_enable(cpu, true);
+	if (ret && ret != -EOPNOTSUPP)
+		pr_warn("Failed to enable CPPC for CPU%d (%d)\n", cpu, ret);
+
 	/*
 	 * Set min to lowest nonlinear perf to avoid any efficiency penalty (see
 	 * Section 8.4.7.1.1.5 of ACPI 6.1 spec)
author reviewer
#3 lore raw

Re: [PATCH v5 1/2] cpufreq: CPPC: Set CPPC Enable register in cpu_init

Quoted 13 lines · Jiri Benc

External email: Use caution opening links or attachments

Quoted 8 lines · Sumit Gupta

As per ACPI 6.x s8.4.6.1.4 (CPPC Enable register):
"If supported by the platform, OSPM writes a one to this register
to enable CPPC on this processor. If not implemented, OSPM assumes the platform always has CPPC enabled."

Call cppc_set_enable() at the start of cppc_cpufreq_cpu_init() so this is done for both OS-driven and autonomous CPPC control modes. Errors are logged but non-fatal as the register is optional.

Quoted 9 lines

Sumit, given this is a bug fix to the CPPC driver (e.g. NVIDIA GB10 doesn't enable CPPC without writing the register, keeping the CPUs always at the lowest freq) and is largely unrelated to the autonomous mode feature, could you please resubmit this as a standalone patch?

Thanks!

Jiri

Posted separately.

https://lore.kernel.org/lkml/[email protected]/

Thanks,
Sumit

Quoted 25 lines
Quoted 24 lines
---
  drivers/cpufreq/cppc_cpufreq.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/cpufreq/cppc_cpufreq.c +8 -0
index f6cea0c54dd9..f7a47576717a 100644
@@ -655,6 +655,14 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
       caps = &cpu_data->perf_caps;
       policy->driver_data = cpu_data;
 
+     /*
+      * Enable CPPC for both OS-driven and autonomous modes.
+      * The Enable register is optional - some platforms may not support it
+      */
+     ret = cppc_set_enable(cpu, true);
+     if (ret && ret != -EOPNOTSUPP)
+             pr_warn("Failed to enable CPPC for CPU%d (%d)\n", cpu, ret);
+
       /*
        * Set min to lowest nonlinear perf to avoid any efficiency penalty (see
        * Section 8.4.7.1.1.5 of ACPI 6.1 spec)
author reviewer
#4 lore raw

PATCH v5 2/2 cpufreq: CPPC: add autonomous mode boot parameter support

In reply to Sumit Gupta

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 the parameter is set:
- Configure all CPUs for autonomous operation on first init
- Use HW min/max_perf when available; otherwise initialize from caps
- Initialize desired_perf to max_perf as a starting hint
- Hardware controls frequency instead of the OS governor
- EPP behavior depends on parameter value:
- performance (or 1): override EPP to performance (0x0)
- balance_performance (or 2): override EPP to balance_performance

                                (0x80)

- default_epp (or 3): preserve EPP value programmed by
BIOS/firmware

Unset, "0"/"disabled", or an unrecognized value leaves autonomous selection disabled.

The boot parameter is applied only during first policy initialization. Skip applying it on CPU hotplug to preserve runtime sysfs configuration.

This relies on commit 8c83947c5dbb ("cpufreq: Use policy->min/max init as QoS request") so that the policy->min/max set in cppc_cpufreq_cpu_init() are used as the policy's QoS requests and not overridden by cpufreq_set_policy() during init.

---
 .../admin-guide/kernel-parameters.txt         |  22 +++
 drivers/cpufreq/cppc_cpufreq.c                | 151 +++++++++++++++++-
 include/acpi/cppc_acpi.h                      |   1 +
 3 files changed, 169 insertions(+), 5 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +22 -0
index b5493a7f8f22..88820d34d516 100644
@@ -1019,6 +1019,28 @@ 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.
+			Accepts:
+			  disabled, 0:
+				  cpufreq governors are used (auto_sel disabled)
+			  performance, 1:
+				  enable auto_sel + set EPP to performance (0x0)
+			  balance_performance, 2:
+				  enable auto_sel + set EPP to
+				  balance_performance (0x80)
+			  default_epp, 3:
+				  enable auto_sel, preserve EPP value programmed
+				  by BIOS/firmware
+			Unset or an unrecognized value is treated as disabled.
+
 	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 +146 -5

180 lines not on this page · raw message

include/acpi/cppc_acpi.h +1 -0
index 8693890a7275..9b18fb9aab7c 100644
@@ -42,6 +42,7 @@
 #define CPPC_AUTO_ACT_WINDOW_SIG_CARRY_THRESH 129
 
 #define CPPC_EPP_PERFORMANCE_PREF		0x00
+#define CPPC_EPP_BALANCE_PERFORMANCE_PREF	0x80
 #define CPPC_EPP_ENERGY_EFFICIENCY_PREF		0xFF
 
 #define CPPC_PERF_LIMITED_DESIRED_EXCURSION	BIT(0)
Signature · 1 line
2.34.1
#5 lore raw
Quoted 45 lines · Sumit Gupta

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 the parameter is set:
- Configure all CPUs for autonomous operation on first init
- Use HW min/max_perf when available; otherwise initialize from caps
- Initialize desired_perf to max_perf as a starting hint
- Hardware controls frequency instead of the OS governor
- EPP behavior depends on parameter value:
- performance (or 1): override EPP to performance (0x0)
- balance_performance (or 2): override EPP to balance_performance

                                 (0x80)

- default_epp (or 3): preserve EPP value programmed by
BIOS/firmware

Unset, "0"/"disabled", or an unrecognized value leaves autonomous selection disabled.

The boot parameter is applied only during first policy initialization. Skip applying it on CPU hotplug to preserve runtime sysfs configuration.

This relies on commit 8c83947c5dbb ("cpufreq: Use policy->min/max init as QoS request") so that the policy->min/max set in cppc_cpufreq_cpu_init() are used as the policy's QoS requests and not overridden by cpufreq_set_policy() during init.

---
  .../admin-guide/kernel-parameters.txt         |  22 +++
  drivers/cpufreq/cppc_cpufreq.c                | 151 +++++++++++++++++-
  include/acpi/cppc_acpi.h                      |   1 +
  3 files changed, 169 insertions(+), 5 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +1 -0
index b5493a7f8f22..88820d34d516 100644
@@ -1019,6 +1019,28 @@ Kernel parameters
  			policy to use. This governor must be registered in the
  			kernel before the cpufreq driver probes.
 
+	cppc_cpufreq.auto_sel_mode=

Documentation/admin-guide/kernel-parameters.txt Kernel parameters · line 1032

Quoted 10 lines
Documentation/admin-guide/kernel-parameters.txt +10 -0
+			[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.
+			Accepts:
+			  disabled, 0:

Just a question, but would it be worth only accepting strings ? If we want to have a thinner granularity later, it will be harder to introduce them if there are integer values already present.

Quoted 90 lines
Documentation/admin-guide/kernel-parameters.txt +11 -0
+				  cpufreq governors are used (auto_sel disabled)
+			  performance, 1:
+				  enable auto_sel + set EPP to performance (0x0)
+			  balance_performance, 2:
+				  enable auto_sel + set EPP to
+				  balance_performance (0x80)
+			  default_epp, 3:
+				  enable auto_sel, preserve EPP value programmed
+				  by BIOS/firmware
+			Unset or an unrecognized value is treated as disabled.
+
  	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 +51 -2
index f7a47576717a..efa673e3830c 100644
@@ -28,6 +28,55 @@
 
  static struct cpufreq_driver cppc_cpufreq_driver;
 
+/* Autonomous Selection boot parameter modes */
+enum {
+	AUTO_SEL_DISABLED = 0,
+	AUTO_SEL_PERFORMANCE = 1,
+	AUTO_SEL_BALANCE_PERFORMANCE = 2,
+	AUTO_SEL_DEFAULT_EPP = 3,
+};
+
+static int auto_sel_mode;
+
+static int auto_sel_mode_set(const char *val, const struct kernel_param *kp)
+{
+	int *mode = kp->arg;
+
+	*mode = AUTO_SEL_DISABLED;
+
+	if (sysfs_streq(val, "performance") || sysfs_streq(val, "1"))
+		*mode = AUTO_SEL_PERFORMANCE;
+	else if (sysfs_streq(val, "balance_performance") || sysfs_streq(val, "2"))
+		*mode = AUTO_SEL_BALANCE_PERFORMANCE;
+	else if (sysfs_streq(val, "default_epp") || sysfs_streq(val, "3"))
+		*mode = AUTO_SEL_DEFAULT_EPP;
+	else if (!sysfs_streq(val, "disabled") && !sysfs_streq(val, "0"))
+		pr_warn("Invalid auto_sel_mode \"%s\", disable auto select\n", val);
+
+	return 0;
+}
+
+static int auto_sel_mode_get(char *buffer, const struct kernel_param *kp)
+{
+	int *mode = kp->arg;
+
+	switch (*mode) {
+	case AUTO_SEL_PERFORMANCE:
+		return sysfs_emit(buffer, "performance\n");
+	case AUTO_SEL_BALANCE_PERFORMANCE:
+		return sysfs_emit(buffer, "balance_performance\n");
+	case AUTO_SEL_DEFAULT_EPP:
+		return sysfs_emit(buffer, "default_epp\n");
+	default:
+		return sysfs_emit(buffer, "disabled\n");
+	}
+}
+
+static const struct kernel_param_ops auto_sel_mode_ops = {
+	.set = auto_sel_mode_set,
+	.get = auto_sel_mode_get,
+};
+
  #ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE
  static enum {
  	FIE_UNSET = -1,
@@ -645,7 +694,9 @@ static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy)
  	unsigned int cpu = policy->cpu;
  	struct cppc_cpudata *cpu_data;
  	struct cppc_perf_caps *caps;
+	bool set_epp = true;
  	int ret;
+	u32 epp;
 
  	cpu_data = cppc_cpufreq_get_cpu_data(cpu);
  	if (!cpu_data) {
@@ -715,11 +766,87 @@ 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) {

drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 775

Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +7 -3
-		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 (auto_sel_mode && policy->last_governor[0] == '\0' &&
+	    !cpu_data->perf_ctrls.auto_sel) {

If an .online() callback is introduced, does it mean that we can remove the "policy->last_governor[0] == '\0'" check ?

Also maybe it would be worth creating a function for this "if" block ?

Also (bis), maybe we should check that auto_sel is supported before doing anything else.

drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 781

Quoted 6 lines
drivers/cpufreq/cppc_cpufreq.c +6 -0
+		/* Init min/max_perf from caps if not already set by HW. */
+		if (!cpu_data->perf_ctrls.min_perf)
+			cpu_data->perf_ctrls.min_perf = caps->lowest_nonlinear_perf;
+		if (!cpu_data->perf_ctrls.max_perf)
+			cpu_data->perf_ctrls.max_perf = policy->boost_enabled ?
+				caps->highest_perf : caps->nominal_perf;

Is it necessary to do that ?

- for min_perf, we are setting it to the lowest possible value

- for max_perf, we are setting it to the highest available value. If boost is disabled and we enabled it later, I don't think max_perf is updated accordingly, so we would limit the freq. to caps->nominal_perf

(If I m not missing something)

Quoted 39 lines
drivers/cpufreq/cppc_cpufreq.c +39 -0
+
+		/*
+		 * In autonomous mode desired_perf is only a hint; EPP and
+		 * the platform drive actual selection within [min, max].
+		 * Initialize it to max_perf so HW starts at the upper bound.
+		 */
+		cpu_data->perf_ctrls.desired_perf = cpu_data->perf_ctrls.max_perf;
+
+		policy->cur = cppc_perf_to_khz(caps,
+					       cpu_data->perf_ctrls.desired_perf);
+
+		/*
+		 * Set EPP per mode. 'default_epp' preserves the BIOS/firmware
+		 * programmed EPP value. EPP is optional - some platforms may
+		 * not support it.
+		 */
+		switch (auto_sel_mode) {
+		case AUTO_SEL_PERFORMANCE:
+			epp = CPPC_EPP_PERFORMANCE_PREF;
+			break;
+		case AUTO_SEL_BALANCE_PERFORMANCE:
+			epp = CPPC_EPP_BALANCE_PERFORMANCE_PREF;
+			break;
+		default:
+			set_epp = false;
+			break;
+		}
+
+		if (set_epp) {
+			ret = cppc_set_epp(cpu, epp);
+			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 = epp;
+		}
+
+		/* Program min/max/desired into CPPC regs (non-fatal on failure). */
+		ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls);
+		if (ret)

drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 830

Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +10 -0
+			pr_warn("set_perf failed CPU%d (%d); using HW values\n",
+				cpu, ret);
+
+		ret = cppc_set_auto_sel(cpu, true);
+		if (ret && ret != -EOPNOTSUPP)
+			pr_warn("auto_sel CPU%d failed (%d); using OS mode\n",
+				cpu, ret);
+		else if (!ret)
+			cpu_data->perf_ctrls.auto_sel = true;
+	}

(until here)

drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct cpufreq_policy *policy) · line 833

Quoted 3 lines
drivers/cpufreq/cppc_cpufreq.c +3 -0
+
+	if (cpu_data->perf_ctrls.auto_sel) {
+		/* Sync policy limits from HW when autonomous mode is active */

Similar comment as above, doesn't it fall into a similar case as:
521223d8b3ec ("cpufreq: Fix initialization of min and max frequency QoS request")

?

Quoted 20 lines
drivers/cpufreq/cppc_cpufreq.c +16 -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 ?:
+					       (policy->boost_enabled ?
+						caps->highest_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 1199

Quoted 7 lines
drivers/cpufreq/cppc_cpufreq.c +4 -0
@@ -1066,10 +1193,24 @@ 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);

I saw that this is being changed in:
[PATCH] cpufreq: CPPC: Preserve OSPM-set registers across hotplug and unload

But I think it would make more sense to have this patch comes before these patches:

[1] ACPI: CPPC: Add ospm_nominal_perf support

     https://lore.kernel.org/lkml/[email protected]/
 [2] cpufreq: CPPC: add autonomous mode boot parameter support
     https://lore.kernel.org/lkml/[email protected]/

to avoid making changes that are corrected in this last patch of the serie.

Quoted 29 lines
drivers/cpufreq/cppc_cpufreq.c +10 -0
+
  	cpufreq_unregister_driver(&cppc_cpufreq_driver);
  	cppc_freq_invariance_exit();
  }
 
+module_param_cb(auto_sel_mode, &auto_sel_mode_ops, &auto_sel_mode, 0444);
+MODULE_PARM_DESC(auto_sel_mode,
+		 "Enable CPPC autonomous performance selection at boot: "
+		 "disabled or 0 (use cpufreq governors), "
+		 "performance or 1 (EPP=performance), "
+		 "balance_performance or 2 (EPP=balance_performance), "
+		 "default_epp or 3 (preserve BIOS/firmware EPP); "
+		 "an unrecognized value is treated as disabled");
+
  module_exit(cppc_cpufreq_exit);
  MODULE_AUTHOR("Ashwin Chaugule");
  MODULE_DESCRIPTION("CPUFreq driver based on the ACPI CPPC v5.0+ spec");
include/acpi/cppc_acpi.h +1 -0
index 8693890a7275..9b18fb9aab7c 100644
@@ -42,6 +42,7 @@
  #define CPPC_AUTO_ACT_WINDOW_SIG_CARRY_THRESH 129
 
  #define CPPC_EPP_PERFORMANCE_PREF		0x00
+#define CPPC_EPP_BALANCE_PERFORMANCE_PREF	0x80
  #define CPPC_EPP_ENERGY_EFFICIENCY_PREF		0xFF
 
  #define CPPC_PERF_LIMITED_DESIRED_EXCURSION	BIT(0)
author reviewer
#6 lore raw
Quoted 60 lines · Pierre Gondois

External email: Use caution opening links or attachments

Quoted 56 lines · Sumit Gupta

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 the parameter is set:
- Configure all CPUs for autonomous operation on first init
- Use HW min/max_perf when available; otherwise initialize from caps
- Initialize desired_perf to max_perf as a starting hint
- Hardware controls frequency instead of the OS governor
- EPP behavior depends on parameter value:
   - performance (or 1):         override EPP to performance (0x0)
   - balance_performance (or 2): override EPP to balance_performance (0x80)
   - default_epp (or 3):         preserve EPP value programmed by BIOS/firmware

Unset, "0"/"disabled", or an unrecognized value leaves autonomous selection disabled.

The boot parameter is applied only during first policy initialization. Skip applying it on CPU hotplug to preserve runtime sysfs configuration.

This relies on commit 8c83947c5dbb ("cpufreq: Use policy->min/max init as QoS request") so that the policy->min/max set in cppc_cpufreq_cpu_init() are used as the policy's QoS requests and not overridden by cpufreq_set_policy() during init.

---
  .../admin-guide/kernel-parameters.txt         |  22 +++ drivers/cpufreq/cppc_cpufreq.c                | 151 +++++++++++++++++- include/acpi/cppc_acpi.h                      |   1 +

  3 files changed, 169 insertions(+), 5 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +0 -0
index b5493a7f8f22..88820d34d516 100644
@@ -1019,6 +1019,28 @@ 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

Quoted 8 lines
Quoted 3 lines

+                     support.
+                     Accepts:
+                       disabled, 0:

Just a question, but would it be worth only accepting strings ? If we want to have a thinner granularity later, it will be harder to introduce them if there are integer values already present.

Sure, will change to keep strings only for flexibility in future.

Quoted 115 lines
Quoted 101 lines

+                               cpufreq governors are used (auto_sel disabled)
+                       performance, 1:
+                               enable auto_sel + set EPP to performance (0x0)
+                       balance_performance, 2:
+                               enable auto_sel + set EPP to
+                               balance_performance (0x80)
+                       default_epp, 3:
+                               enable auto_sel, preserve EPP value programmed
+                               by BIOS/firmware
+                     Unset or an unrecognized value is treated as disabled.
+
      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 +29 -0
index f7a47576717a..efa673e3830c 100644
@@ -28,6 +28,55 @@
 
   static struct cpufreq_driver cppc_cpufreq_driver;
 
+/* Autonomous Selection boot parameter modes */
+enum {
+     AUTO_SEL_DISABLED = 0,
+     AUTO_SEL_PERFORMANCE = 1,
+     AUTO_SEL_BALANCE_PERFORMANCE = 2,
+     AUTO_SEL_DEFAULT_EPP = 3,
+};
+
+static int auto_sel_mode;
+
+static int auto_sel_mode_set(const char *val, const struct 
 kernel_param *kp)
+{
+     int *mode = kp->arg;
+
+     *mode = AUTO_SEL_DISABLED;
+
+     if (sysfs_streq(val, "performance") || sysfs_streq(val, "1"))
+             *mode = AUTO_SEL_PERFORMANCE;
+     else if (sysfs_streq(val, "balance_performance") || 
 sysfs_streq(val, "2"))
+             *mode = AUTO_SEL_BALANCE_PERFORMANCE;
+     else if (sysfs_streq(val, "default_epp") || sysfs_streq(val, "3"))
+             *mode = AUTO_SEL_DEFAULT_EPP;
+     else if (!sysfs_streq(val, "disabled") && !sysfs_streq(val, "0"))
+             pr_warn("Invalid auto_sel_mode \"%s\", disable auto 
 select\n", val);
+
+     return 0;
+}
+
+static int auto_sel_mode_get(char *buffer, const struct kernel_param 

*kp)

drivers/cpufreq/cppc_cpufreq.c +20 -0
+{
+     int *mode = kp->arg;
+
+     switch (*mode) {
+     case AUTO_SEL_PERFORMANCE:
+             return sysfs_emit(buffer, "performance\n");
+     case AUTO_SEL_BALANCE_PERFORMANCE:
+             return sysfs_emit(buffer, "balance_performance\n");
+     case AUTO_SEL_DEFAULT_EPP:
+             return sysfs_emit(buffer, "default_epp\n");
+     default:
+             return sysfs_emit(buffer, "disabled\n");
+     }
+}
+
+static const struct kernel_param_ops auto_sel_mode_ops = {
+     .set = auto_sel_mode_set,
+     .get = auto_sel_mode_get,
+};
+

  #ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE
  static enum {
      FIE_UNSET = -1,

drivers/cpufreq/cppc_cpufreq.c +2 -0
@@ -645,7 +694,9 @@ static int cppc_cpufreq_cpu_init(struct 
 cpufreq_policy *policy)
       unsigned int cpu = policy->cpu;
       struct cppc_cpudata *cpu_data;
       struct cppc_perf_caps *caps;
+     bool set_epp = true;
       int ret;
+     u32 epp;
 
       cpu_data = cppc_cpufreq_get_cpu_data(cpu);

      if (!cpu_data) {

drivers/cpufreq/cppc_cpufreq.c +0 -2
@@ -715,11 +766,87 @@ 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) {

drivers/cpufreq/cppc_cpufreq.c static int cppc_cpufreq_cpu_init(struct · line 776

Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +7 -3
-             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 (auto_sel_mode && policy->last_governor[0] == '\0' &&
+         !cpu_data->perf_ctrls.auto_sel) {

If an .online() callback is introduced, does it mean that we can remove the "policy->last_governor[0] == '\0'" check ?

Quoted 6 lines

Also maybe it would be worth creating a function for this "if" block ?

Also (bis), maybe we should check that auto_sel is supported before doing anything else.

Agreed. Will change in v6.

Quoted 13 lines
Quoted 10 lines
drivers/cpufreq/cppc_cpufreq.c +1 -0
+             /* Init min/max_perf from caps if not already set by 

HW. */
+             if (!cpu_data->perf_ctrls.min_perf)
+                     cpu_data->perf_ctrls.min_perf = caps->lowest_nonlinear_perf;
+             if (!cpu_data->perf_ctrls.max_perf)
+                     cpu_data->perf_ctrls.max_perf = policy->boost_enabled ?
+                             caps->highest_perf : caps->nominal_perf;

Is it necessary to do that ?

Quoted 8 lines

- for min_perf, we are setting it to the lowest possible value

- for max_perf, we are setting it to the highest available value. If boost is disabled and we enabled it later, I don't think max_perf is updated accordingly, so we would limit the freq. to caps->nominal_perf

(If I m not missing something)

The min/max seed is still needed so the HW has valid min/max limits when firmware leaves them unset.
Here, will keep max_perf capped to nominal while boost is off and change the second place below to set policy->max = highest_perf so the driver does not limit the max below highest, letting the core cap to nominal when boost is off.
Enabling boost then raises the HW max_perf to highest via ->target(), fixing this point too.

Quoted 63 lines
Quoted 49 lines

+
+             /*
+              * In autonomous mode desired_perf is only a hint; EPP and +              * the platform drive actual selection within [min, max]. +              * Initialize it to max_perf so HW starts at the upper bound.
+              */
+             cpu_data->perf_ctrls.desired_perf = cpu_data->perf_ctrls.max_perf;

drivers/cpufreq/cppc_cpufreq.c +6 -0
+
+             policy->cur = cppc_perf_to_khz(caps,
+ cpu_data->perf_ctrls.desired_perf);
+
+             /*
+              * Set EPP per mode. 'default_epp' preserves the 

BIOS/firmware
+              * programmed EPP value. EPP is optional - some platforms may
+              * not support it.
+              */
+             switch (auto_sel_mode) {
+             case AUTO_SEL_PERFORMANCE:
+                     epp = CPPC_EPP_PERFORMANCE_PREF;
+                     break;
+             case AUTO_SEL_BALANCE_PERFORMANCE:
+                     epp = CPPC_EPP_BALANCE_PERFORMANCE_PREF; +                     break;
+             default:
+                     set_epp = false;
+                     break;
+             }
+
+             if (set_epp) {
+                     ret = cppc_set_epp(cpu, epp);
+                     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 = epp;
+             }
+
+             /* Program min/max/desired into CPPC regs (non-fatal on failure). */
+             ret = cppc_set_perf(cpu, &cpu_data->perf_ctrls); +             if (ret)
+                     pr_warn("set_perf failed CPU%d (%d); using HW values\n",
+                             cpu, ret);
+

Quoted 8 lines

+             ret = cppc_set_auto_sel(cpu, true);
+             if (ret && ret != -EOPNOTSUPP)
+                     pr_warn("auto_sel CPU%d failed (%d); using OS mode\n",
+                             cpu, ret);
+             else if (!ret)
+                     cpu_data->perf_ctrls.auto_sel = true; +     }

(until here)

Quoted 4 lines

+
+     if (cpu_data->perf_ctrls.auto_sel) {
+             /* Sync policy limits from HW when autonomous mode is active */

Quoted 6 lines

Similar comment as above, doesn't it fall into a similar case as:
521223d8b3ec ("cpufreq: Fix initialization of min and max frequency QoS request")

?

Answered above.

Quoted 36 lines
Quoted 22 lines

+             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 ?:
+ (policy->boost_enabled ?
+ caps->highest_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 1199

Quoted 7 lines
drivers/cpufreq/cppc_cpufreq.c +4 -0
@@ -1066,10 +1193,24 @@ 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);

I saw that this is being changed in:
[PATCH] cpufreq: CPPC: Preserve OSPM-set registers across hotplug and unload

But I think it would make more sense to have this patch comes before these patches:

Quoted 7 lines

 [1] ACPI: CPPC: Add ospm_nominal_perf support
https://lore.kernel.org/lkml/[email protected]/
 [2] cpufreq: CPPC: add autonomous mode boot parameter support
https://lore.kernel.org/lkml/[email protected]/

to avoid making changes that are corrected in this last patch of the serie.

Sure, will reorder them.

Thanks,
Sumit

....