mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v5 0/2] cpufreq: Keep global boost enabled after partial enable
@ 2026-11-30 11:13 Jiangtian Feng
  2026-11-30 11:13 ` [PATCH 1/2] cpufreq: Allow global boost updates with inactive capable policies Jiangtian Feng
  2026-11-30 11:13 ` [PATCH 2/2] cpufreq: Keep global boost enabled after partial enable Jiangtian Feng
  0 siblings, 2 replies; 5+ messages in thread
From: Jiangtian Feng @ 2026-11-30 11:13 UTC (permalink / raw)
  To: rafael, viresh.kumar
  Cc: linux-pm, linux-kernel, zhongqiu.han, christian.loehle,
	ananthu.cv, pierre.gondois, zhangpengjie2, zhenglifeng1,
	zhanjie9

This series treats global boost as a permission while preserving the
existing error when no registered policy supports boost.

The first patch allows the global setting to be recorded when a capable
policy is inactive or offline. Only active, boost-capable policies are
updated through policy_set_boost(); a complete lack of boost support still
returns -EOPNOTSUPP, and real driver failures are unchanged.

The second patch is the existing partial-enable change. If enabling at
least one policy succeeds before a later failure, global boost remains
enabled so that the valid mixed per-policy state remains locally
repairable. Disable and no-success failure paths retain their previous
behavior.

Base: Linux v7.4-rc5
  fe6ff8d5d675c01793b9f051d16055dd4aa75244

Changes in v5:
- Add the inactive-capable preparatory change, with links to the original
  no-policy discussion and 77cf053b041f.
- Rebase to Linux v7.4-rc5.
- Keep the partial-enable code logic from v4 unchanged.
- Link Pengjie's review below.

Previous version:
  https://lore.kernel.org/all/20261127090513.910723-1-jiangtianfeng@linux.alibaba.com/

Pengjie's review:
  https://lore.kernel.org/all/744b868b-55af-4a12-86a8-f4fd5d132e6a@huawei.com/

Validation:
- ARM64 defconfig W=1 build of drivers/cpufreq/cpufreq.o.
- Complete ARM64 Image build; size 53,234,176 bytes, SHA-256
  ce5519a4a9e498144908fc5d69f18376de23f8c80bc6ea2e2a424d35601e747a.
- Static state-matrix and policy-list locking/lifetime review covering
  no-policy, no-support, inactive-capable, active success/failure,
  partial-enable and subsequent online behavior.
- Independent review found no remaining High/Medium/Low code issue in the
  two-patch candidate.

NOT_RUN:
- CPU hotplug, suspend/resume, driver unregister/global-write concurrency,
  lockdep and KCSAN testing.
- CPPC, ACPI, AMD and ARM hardware frequency/QoS testing.
- Runtime fault injection for policy_set_boost() failures.

Qoder, an AI coding assistant, helped analyze the review history, design
and draft the preparatory change, and review the state matrix and failure
paths. The submitter reviewed the resulting changes and is responsible for
the final validation and submission.

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

* [PATCH 1/2] cpufreq: Allow global boost updates with inactive capable policies
  2026-11-30 11:13 [PATCH v5 0/2] cpufreq: Keep global boost enabled after partial enable Jiangtian Feng
@ 2026-11-30 11:13 ` Jiangtian Feng
  2026-11-30 13:49   ` Pengjie Zhang
  2026-11-30 11:13 ` [PATCH 2/2] cpufreq: Keep global boost enabled after partial enable Jiangtian Feng
  1 sibling, 1 reply; 5+ messages in thread
From: Jiangtian Feng @ 2026-11-30 11:13 UTC (permalink / raw)
  To: rafael, viresh.kumar
  Cc: linux-pm, linux-kernel, zhongqiu.han, christian.loehle,
	ananthu.cv, pierre.gondois, zhangpengjie2, zhenglifeng1,
	zhanjie9, Jiangtian Feng

Global boost is a permission to use boost, not a statement that boost is
currently active on every policy. A boost-capable policy can be inactive or
offline when the global knob is written. Rejecting the write in that case
loses the requested global setting and makes the policy list state affect
the result in a way that is not useful to userspace.

Track boost support across all registered policies under cpus_read_lock,
but continue to call policy_set_boost() only for active, boost-capable
policies. An inactive boost-capable policy therefore no longer makes the
global write fail, and the requested setting can be applied when it becomes
active again.

Preserve the -EOPNOTSUPP result when no registered policy supports boost,
as introduced by 77cf053b041f, and leave all real policy_set_boost()
failures unchanged.

Link: https://lore.kernel.org/all/744b868b-55af-4a12-86a8-f4fd5d132e6a@huawei.com/
Link: https://lore.kernel.org/all/wnnfdvp3r3bg5wztazoijei2uji5xypl4b4wlvlxuwxaizu6g7@2xxyrk7kdxhf/

Qoder, an AI coding assistant, helped analyze the 77cf history, review the
policy-list locking/lifetime and draft this change and description. The
policy state matrix and hardware/hotplug behavior remain subject to final
review and validation.

Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
---
 drivers/cpufreq/cpufreq.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 4332cb114070..f83fc6e40fbe 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2887,7 +2887,8 @@ static int cpufreq_boost_trigger_state(int state)
 	struct cpufreq_policy *policy;
 	unsigned long flags;
 	bool boost_enabled;
-	int ret = -EOPNOTSUPP;
+	bool any_boost_supported = false;
+	int ret = 0;
 
 	guard(mutex)(&cpufreq_boost_mutex);
 
@@ -2902,8 +2903,11 @@ static int cpufreq_boost_trigger_state(int state)
 	write_unlock_irqrestore(&cpufreq_driver_lock, flags);
 
 	cpus_read_lock();
-	for_each_active_policy(policy) {
-		if (!policy->boost_supported)
+	/* Track capability across inactive policies, but only update active ones. */
+	for_each_policy(policy) {
+		if (policy->boost_supported)
+			any_boost_supported = true;
+		if (policy_is_inactive(policy) || !policy->boost_supported)
 			continue;
 
 		guard(cpufreq_policy_write)(policy);
@@ -2913,6 +2917,9 @@ static int cpufreq_boost_trigger_state(int state)
 			break;
 	}
 
+	if (!any_boost_supported)
+		ret = -EOPNOTSUPP;
+
 	cpus_read_unlock();
 
 	if (likely(!ret))
-- 
2.47.3


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

* [PATCH 2/2] cpufreq: Keep global boost enabled after partial enable
  2026-11-30 11:13 [PATCH v5 0/2] cpufreq: Keep global boost enabled after partial enable Jiangtian Feng
  2026-11-30 11:13 ` [PATCH 1/2] cpufreq: Allow global boost updates with inactive capable policies Jiangtian Feng
@ 2026-11-30 11:13 ` Jiangtian Feng
  2026-11-30 13:51   ` Pengjie Zhang
  1 sibling, 1 reply; 5+ messages in thread
From: Jiangtian Feng @ 2026-11-30 11:13 UTC (permalink / raw)
  To: rafael, viresh.kumar
  Cc: linux-pm, linux-kernel, zhongqiu.han, christian.loehle,
	ananthu.cv, pierre.gondois, zhangpengjie2, zhenglifeng1,
	zhanjie9, Jiangtian Feng

When global boost is enabled from the disabled state, a failure after
one or more policies have been updated successfully currently restores
the global flag to 0 without rolling back those policies. This leaves
them locally enabled, with their boost-related driver/QoS updates
retained, while the global flag rejects per-policy sysfs writes.

Keep the global flag enabled if at least one policy_set_boost() call
succeeded, while preserving the existing error return path. Global
boost = 1 grants permission to boost; it does not require every policy
to have boost enabled. The mixed per-policy state is therefore valid
and individual policies remain accessible through per-policy sysfs.

Restore the previous global state on disable and when no policy was
enabled successfully. After a partial enable, keep global boost enabled
so users can repair individual policies through sysfs. Do not roll back
earlier policy updates.

Qoder, an AI coding assistant, helped analyze the issue, develop the fix
and state matrix, and draft this description.

Fixes: 218a06a79d9a ("cpufreq: Support per-policy performance boost")
Reviewed-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
---
 drivers/cpufreq/cpufreq.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index f83fc6e40fbe..3d8927cc9787 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2888,6 +2888,7 @@ static int cpufreq_boost_trigger_state(int state)
 	unsigned long flags;
 	bool boost_enabled;
 	bool any_boost_supported = false;
+	bool policy_success = false;
 	int ret = 0;
 
 	guard(mutex)(&cpufreq_boost_mutex);
@@ -2915,6 +2916,8 @@ static int cpufreq_boost_trigger_state(int state)
 		ret = policy_set_boost(policy, state);
 		if (unlikely(ret))
 			break;
+
+		policy_success = true;
 	}
 
 	if (!any_boost_supported)
@@ -2925,9 +2928,12 @@ static int cpufreq_boost_trigger_state(int state)
 	if (likely(!ret))
 		return 0;
 
-	write_lock_irqsave(&cpufreq_driver_lock, flags);
-	cpufreq_driver->boost_enabled = boost_enabled;
-	write_unlock_irqrestore(&cpufreq_driver_lock, flags);
+	/* On failure, restore old state unless partial enable needs local repair. */
+	if (!state || !policy_success) {
+		write_lock_irqsave(&cpufreq_driver_lock, flags);
+		cpufreq_driver->boost_enabled = boost_enabled;
+		write_unlock_irqrestore(&cpufreq_driver_lock, flags);
+	}
 
 	pr_err("%s: Cannot %s BOOST\n",
 	       __func__, str_enable_disable(state));
-- 
2.47.3


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

* Re: [PATCH 1/2] cpufreq: Allow global boost updates with inactive capable policies
  2026-11-30 11:13 ` [PATCH 1/2] cpufreq: Allow global boost updates with inactive capable policies Jiangtian Feng
@ 2026-11-30 13:49   ` Pengjie Zhang
  0 siblings, 0 replies; 5+ messages in thread
From: Pengjie Zhang @ 2026-11-30 13:49 UTC (permalink / raw)
  To: Jiangtian Feng, rafael, viresh.kumar
  Cc: linux-pm, linux-kernel, zhongqiu.han, christian.loehle,
	ananthu.cv, pierre.gondois, zhenglifeng1, zhanjie9

Hi Jiangtian,

Thanks for handling the offline case in v5.

With 5785772fe9e6 ("cpufreq: CPPC: Enable boost by default") [1] in
linux-pm/linux-next, the global boost knob can start at 1 on a CPPC
system where no registered policy supports boost. With the v5 core
changes applied on top, writing 0 would still return -EINVAL and
leave the knob at 1.

I understand that 77cf053b041f deliberately made this an error.
Since the global knob controls permission to boost, could we let
userspace write either 0 or 1 and read that value back even when
no policy supports boost? A successful write of 0 must leave boost
disabled on every active policy that supports it.

[1] 
https://lore.kernel.org/all/20261118013558.3075038-1-zhangpengjie2@huawei.com/

Thanks,
Pengjie

On 11/30/2026 7:13 PM, Jiangtian Feng wrote:
> Global boost is a permission to use boost, not a statement that boost is
> currently active on every policy. A boost-capable policy can be inactive or
> offline when the global knob is written. Rejecting the write in that case
> loses the requested global setting and makes the policy list state affect
> the result in a way that is not useful to userspace.
>
> Track boost support across all registered policies under cpus_read_lock,
> but continue to call policy_set_boost() only for active, boost-capable
> policies. An inactive boost-capable policy therefore no longer makes the
> global write fail, and the requested setting can be applied when it becomes
> active again.
>
> Preserve the -EOPNOTSUPP result when no registered policy supports boost,
> as introduced by 77cf053b041f, and leave all real policy_set_boost()
> failures unchanged.
>
> Link: https://lore.kernel.org/all/744b868b-55af-4a12-86a8-f4fd5d132e6a@huawei.com/
> Link: https://lore.kernel.org/all/wnnfdvp3r3bg5wztazoijei2uji5xypl4b4wlvlxuwxaizu6g7@2xxyrk7kdxhf/
>
> Qoder, an AI coding assistant, helped analyze the 77cf history, review the
> policy-list locking/lifetime and draft this change and description. The
> policy state matrix and hardware/hotplug behavior remain subject to final
> review and validation.
>
> Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
> ---
>   drivers/cpufreq/cpufreq.c | 13 ++++++++++---
>   1 file changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 4332cb114070..f83fc6e40fbe 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2887,7 +2887,8 @@ static int cpufreq_boost_trigger_state(int state)
>   	struct cpufreq_policy *policy;
>   	unsigned long flags;
>   	bool boost_enabled;
> -	int ret = -EOPNOTSUPP;
> +	bool any_boost_supported = false;
> +	int ret = 0;
>   
>   	guard(mutex)(&cpufreq_boost_mutex);
>   
> @@ -2902,8 +2903,11 @@ static int cpufreq_boost_trigger_state(int state)
>   	write_unlock_irqrestore(&cpufreq_driver_lock, flags);
>   
>   	cpus_read_lock();
> -	for_each_active_policy(policy) {
> -		if (!policy->boost_supported)
> +	/* Track capability across inactive policies, but only update active ones. */
> +	for_each_policy(policy) {
> +		if (policy->boost_supported)
> +			any_boost_supported = true;
> +		if (policy_is_inactive(policy) || !policy->boost_supported)
>   			continue;
>   
>   		guard(cpufreq_policy_write)(policy);
> @@ -2913,6 +2917,9 @@ static int cpufreq_boost_trigger_state(int state)
>   			break;
>   	}
>   
> +	if (!any_boost_supported)
> +		ret = -EOPNOTSUPP;
> +
>   	cpus_read_unlock();
>   
>   	if (likely(!ret))

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

* Re: [PATCH 2/2] cpufreq: Keep global boost enabled after partial enable
  2026-11-30 11:13 ` [PATCH 2/2] cpufreq: Keep global boost enabled after partial enable Jiangtian Feng
@ 2026-11-30 13:51   ` Pengjie Zhang
  0 siblings, 0 replies; 5+ messages in thread
From: Pengjie Zhang @ 2026-11-30 13:51 UTC (permalink / raw)
  To: Jiangtian Feng, rafael, viresh.kumar
  Cc: linux-pm, linux-kernel, zhongqiu.han, christian.loehle,
	ananthu.cv, pierre.gondois, zhenglifeng1, zhanjie9


On 11/30/2026 7:13 PM, Jiangtian Feng wrote:
> When global boost is enabled from the disabled state, a failure after
> one or more policies have been updated successfully currently restores
> the global flag to 0 without rolling back those policies. This leaves
> them locally enabled, with their boost-related driver/QoS updates
> retained, while the global flag rejects per-policy sysfs writes.
>
> Keep the global flag enabled if at least one policy_set_boost() call
> succeeded, while preserving the existing error return path. Global
> boost = 1 grants permission to boost; it does not require every policy
> to have boost enabled. The mixed per-policy state is therefore valid
> and individual policies remain accessible through per-policy sysfs.
>
> Restore the previous global state on disable and when no policy was
> enabled successfully. After a partial enable, keep global boost enabled
> so users can repair individual policies through sysfs. Do not roll back
> earlier policy updates.
>
> Qoder, an AI coding assistant, helped analyze the issue, develop the fix
> and state matrix, and draft this description.
>
> Fixes: 218a06a79d9a ("cpufreq: Support per-policy performance boost")
> Reviewed-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
> Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
> ---
>   drivers/cpufreq/cpufreq.c | 12 +++++++++---
>   1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index f83fc6e40fbe..3d8927cc9787 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2888,6 +2888,7 @@ static int cpufreq_boost_trigger_state(int state)
>   	unsigned long flags;
>   	bool boost_enabled;
>   	bool any_boost_supported = false;
> +	bool policy_success = false;
>   	int ret = 0;
>   
>   	guard(mutex)(&cpufreq_boost_mutex);
> @@ -2915,6 +2916,8 @@ static int cpufreq_boost_trigger_state(int state)
>   		ret = policy_set_boost(policy, state);
>   		if (unlikely(ret))
>   			break;
> +
> +		policy_success = true;
>   	}
>   
>   	if (!any_boost_supported)
> @@ -2925,9 +2928,12 @@ static int cpufreq_boost_trigger_state(int state)
>   	if (likely(!ret))
>   		return 0;
>   
> -	write_lock_irqsave(&cpufreq_driver_lock, flags);
> -	cpufreq_driver->boost_enabled = boost_enabled;
> -	write_unlock_irqrestore(&cpufreq_driver_lock, flags);
> +	/* On failure, restore old state unless partial enable needs local repair. */
> +	if (!state || !policy_success) {
> +		write_lock_irqsave(&cpufreq_driver_lock, flags);
> +		cpufreq_driver->boost_enabled = boost_enabled;
> +		write_unlock_irqrestore(&cpufreq_driver_lock, flags);
> +	}
>   
>   	pr_err("%s: Cannot %s BOOST\n",
>   	       __func__, str_enable_disable(state));

Reviewed-by: Pengjie Zhang<zhangpengjie2@huawei.com>


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

end of thread, other threads:[~2026-11-30 13:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 11:13 [PATCH v5 0/2] cpufreq: Keep global boost enabled after partial enable Jiangtian Feng
2026-11-30 11:13 ` [PATCH 1/2] cpufreq: Allow global boost updates with inactive capable policies Jiangtian Feng
2026-11-30 13:49   ` Pengjie Zhang
2026-11-30 11:13 ` [PATCH 2/2] cpufreq: Keep global boost enabled after partial enable Jiangtian Feng
2026-11-30 13:51   ` Pengjie Zhang

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

all inboxes | Powered by JetHome®