Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH v4 0/2] cpufreq: CPPC: add autonomous mode boot parameter support
@ 2026-05-27 20:25 Sumit Gupta
  2026-05-27 20:25 ` [PATCH v4 1/2] cpufreq: CPPC: Set CPPC Enable register in cpu_init Sumit Gupta
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sumit Gupta @ 2026-05-27 20:25 UTC (permalink / raw)
  To: rafael, viresh.kumar, pierre.gondois, ionela.voinescu,
	zhenglifeng1, zhanjie9, corbet, skhan, rdunlap, mario.limonciello,
	linux-pm, linux-doc, linux-kernel
  Cc: linux-tegra, treding, jonathanh, vsethi, ksitaraman, sanjayc,
	mochs, bbasu, sumitg

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 depends on Pierre's series [4] ("cpufreq: Set policy->min and
max as real QoS constraints") so that policy->min/max set during
cppc_cpufreq_cpu_init() are not overridden by cpufreq_set_policy().

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         |  20 +++
 drivers/cpufreq/cppc_cpufreq.c                | 154 +++++++++++++++++-
 include/acpi/cppc_acpi.h                      |   1 +
 3 files changed, 170 insertions(+), 5 deletions(-)

[1] v1: https://lore.kernel.org/lkml/20260317151053.2361475-1-sumitg@nvidia.com/
[2] v2: https://lore.kernel.org/lkml/20260424201814.230071-1-sumitg@nvidia.com/
[3] v3: https://lore.kernel.org/lkml/20260515122624.1920637-1-sumitg@nvidia.com/
[4] https://lore.kernel.org/lkml/20260511135538.522653-1-pierre.gondois@arm.com/

-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v4 1/2] cpufreq: CPPC: Set CPPC Enable register in cpu_init
  2026-05-27 20:25 [PATCH v4 0/2] cpufreq: CPPC: add autonomous mode boot parameter support Sumit Gupta
@ 2026-05-27 20:25 ` Sumit Gupta
  2026-05-27 20:25 ` [PATCH v4 2/2] cpufreq: CPPC: add autonomous mode boot parameter support Sumit Gupta
  2026-06-16 12:52 ` [PATCH v4 0/2] " Sumit Gupta
  2 siblings, 0 replies; 4+ messages in thread
From: Sumit Gupta @ 2026-05-27 20:25 UTC (permalink / raw)
  To: rafael, viresh.kumar, pierre.gondois, ionela.voinescu,
	zhenglifeng1, zhanjie9, corbet, skhan, rdunlap, mario.limonciello,
	linux-pm, linux-doc, linux-kernel
  Cc: linux-tegra, treding, jonathanh, vsethi, ksitaraman, sanjayc,
	mochs, bbasu, sumitg

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.

Signed-off-by: Sumit Gupta <sumitg@nvidia.com>
---
 drivers/cpufreq/cppc_cpufreq.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index 64387b6587cc..7db33761e899 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -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)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v4 2/2] cpufreq: CPPC: add autonomous mode boot parameter support
  2026-05-27 20:25 [PATCH v4 0/2] cpufreq: CPPC: add autonomous mode boot parameter support Sumit Gupta
  2026-05-27 20:25 ` [PATCH v4 1/2] cpufreq: CPPC: Set CPPC Enable register in cpu_init Sumit Gupta
@ 2026-05-27 20:25 ` Sumit Gupta
  2026-06-16 12:52 ` [PATCH v4 0/2] " Sumit Gupta
  2 siblings, 0 replies; 4+ messages in thread
From: Sumit Gupta @ 2026-05-27 20:25 UTC (permalink / raw)
  To: rafael, viresh.kumar, pierre.gondois, ionela.voinescu,
	zhenglifeng1, zhanjie9, corbet, skhan, rdunlap, mario.limonciello,
	linux-pm, linux-doc, linux-kernel
  Cc: linux-tegra, treding, jonathanh, vsethi, ksitaraman, sanjayc,
	mochs, bbasu, sumitg

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

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 series [1] ("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.

Signed-off-by: Sumit Gupta <sumitg@nvidia.com>
---
[1] https://lore.kernel.org/lkml/20260511135538.522653-1-pierre.gondois@arm.com/
---
 .../admin-guide/kernel-parameters.txt         |  20 +++
 drivers/cpufreq/cppc_cpufreq.c                | 146 +++++++++++++++++-
 include/acpi/cppc_acpi.h                      |   1 +
 3 files changed, 162 insertions(+), 5 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 6f0910abdd25..5182905719ed 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1047,6 +1047,26 @@ 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:
+			  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: cpufreq governors are used (auto_sel 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
diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index 7db33761e899..5ae164fce557 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -28,6 +28,52 @@
 
 static struct cpufreq_driver cppc_cpufreq_driver;
 
+/* Autonomous Selection boot parameter modes */
+enum {
+	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;
+
+	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
+		return -EINVAL;
+
+	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 +691,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 +763,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) {
-		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) {
+		/* 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;
+
+		/*
+		 * 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)
+			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;
+	}
+
+	if (cpu_data->perf_ctrls.auto_sel) {
+		/* 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 ?:
+					       (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);
@@ -1126,10 +1250,22 @@ 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);
+
 	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: "
+		 "performance or 1 (EPP=performance), "
+		 "balance_performance or 2 (EPP=balance_performance), "
+		 "default_epp or 3 (preserve BIOS/firmware EPP)");
+
 module_exit(cppc_cpufreq_exit);
 MODULE_AUTHOR("Ashwin Chaugule");
 MODULE_DESCRIPTION("CPUFreq driver based on the ACPI CPPC v5.0+ spec");
diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h
index dc70a8215a3e..14c6d5d0ac12 100644
--- a/include/acpi/cppc_acpi.h
+++ b/include/acpi/cppc_acpi.h
@@ -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)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v4 0/2] cpufreq: CPPC: add autonomous mode boot parameter support
  2026-05-27 20:25 [PATCH v4 0/2] cpufreq: CPPC: add autonomous mode boot parameter support Sumit Gupta
  2026-05-27 20:25 ` [PATCH v4 1/2] cpufreq: CPPC: Set CPPC Enable register in cpu_init Sumit Gupta
  2026-05-27 20:25 ` [PATCH v4 2/2] cpufreq: CPPC: add autonomous mode boot parameter support Sumit Gupta
@ 2026-06-16 12:52 ` Sumit Gupta
  2 siblings, 0 replies; 4+ messages in thread
From: Sumit Gupta @ 2026-06-16 12:52 UTC (permalink / raw)
  To: rafael, viresh.kumar, pierre.gondois, ionela.voinescu,
	zhenglifeng1, zhanjie9, corbet, skhan, rdunlap, mario.limonciello,
	linux-pm, linux-doc, linux-kernel
  Cc: linux-tegra, treding, jonathanh, vsethi, ksitaraman, sanjayc,
	mochs, bbasu, sumitg


On 28/05/26 01:55, Sumit Gupta wrote:
> 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 depends on Pierre's series [4] ("cpufreq: Set policy->min and
> max as real QoS constraints") so that policy->min/max set during
> cppc_cpufreq_cpu_init() are not overridden by cpufreq_set_policy().
>
> 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         |  20 +++
>   drivers/cpufreq/cppc_cpufreq.c                | 154 +++++++++++++++++-
>   include/acpi/cppc_acpi.h                      |   1 +
>   3 files changed, 170 insertions(+), 5 deletions(-)
>
> [1] v1: https://lore.kernel.org/lkml/20260317151053.2361475-1-sumitg@nvidia.com/
> [2] v2: https://lore.kernel.org/lkml/20260424201814.230071-1-sumitg@nvidia.com/
> [3] v3: https://lore.kernel.org/lkml/20260515122624.1920637-1-sumitg@nvidia.com/
> [4] https://lore.kernel.org/lkml/20260511135538.522653-1-pierre.gondois@arm.com/
>

Gentle ping on this series.

The dependency it was waiting on, the "cpufreq: Set policy->min and
max as real QoS constraints" series, is now in linux-pm (linux-next).
I rebased on top and verified autonomous mode works as expected, and
it applies cleanly on the current linux-next.

The [1] reference in patch 2/2 points to v2 of that series; the merged
version is v3 [2].

If there are no further comments, please consider acking and queuing
this for the next cycle.

Thanks for your time.

[1] 
https://lore.kernel.org/lkml/20260511135538.522653-1-pierre.gondois@arm.com/
[2] 
https://lore.kernel.org/lkml/20260528090913.2759118-1-pierre.gondois@arm.com/

Regards,
Sumit



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-16 12:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-27 20:25 [PATCH v4 0/2] cpufreq: CPPC: add autonomous mode boot parameter support Sumit Gupta
2026-05-27 20:25 ` [PATCH v4 1/2] cpufreq: CPPC: Set CPPC Enable register in cpu_init Sumit Gupta
2026-05-27 20:25 ` [PATCH v4 2/2] cpufreq: CPPC: add autonomous mode boot parameter support Sumit Gupta
2026-06-16 12:52 ` [PATCH v4 0/2] " Sumit Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox