cpufreq: Keep global boost enabled after partial enable
RFC PATCH 1/1 cpufreq: Keep global boost enabled after partial enable
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.
Retain global-state restoration for enable failures without a successful policy update, same-state resynchronization failures, and disable failures. 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.
---
Validation:
- mainline ARM64 defconfig build of the complete Image
- checkpatch.pl
- eight-case old-global/request/success state matrix
- independent static control-flow and locking review
NOT_RUN:
- runtime fault injection or reproduction with multiple policies
- global/local concurrency, hotplug, lockdep or KCSAN testing
- CPPC, SW frequency-table, ACPI or AMD hardware frequency/QoS testing
drivers/cpufreq/cpufreq.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/cpufreq/cpufreq.c +8 -0
@@ -2887,6 +2887,7 @@ static int cpufreq_boost_trigger_state(int state)struct cpufreq_policy *policy;unsigned long flags;bool boost_enabled; +bool policy_success = false;int ret = -EOPNOTSUPP ;guard (mutex)(&cpufreq_boost_mutex);
@@ -2911,6 +2912,8 @@ static int cpufreq_boost_trigger_state(int state) ret =policy_set_boost (policy, state);if (unlikely (ret))break ; + + policy_success = true; }cpus_read_unlock ();
@@ -2918,10 +2921,15 @@ static int cpufreq_boost_trigger_state(int state)if (likely (!ret))return 0 ; +/* Keep partial enable usable and repairable through local sysfs. */ +if (state && !boost_enabled && policy_success) + goto out_err; +write_lock_irqsave (&cpufreq_driver_lock, flags); cpufreq_driver->boost_enabled = boost_enabled;write_unlock_irqrestore (&cpufreq_driver_lock, flags); +out_err:pr_err ("%s: Cannot %s BOOST\n" , __func__,str_enable_disable (state));
Signature · 1 line
2.47.3
Quoted 16 lines · 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.Retain global-state restoration for enable failures without a successful policy update, same-state resynchronization failures, and disable failures. Do not roll back earlier policy updates.
Quoted 5 lines
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")Signed-off-by Jiangtian Feng <[email protected]>
What's the RFC part for specifically?
FWIW I broadly agree with the direction of that patch.
Quoted 53 lines
---
Validation:
- mainline ARM64 defconfig build of the complete Image
- checkpatch.pl
- eight-case old-global/request/success state matrix
- independent static control-flow and locking review
NOT_RUN:
- runtime fault injection or reproduction with multiple policies
- global/local concurrency, hotplug, lockdep or KCSAN testing
- CPPC, SW frequency-table, ACPI or AMD hardware frequency/QoS testingdrivers/cpufreq/cpufreq.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/cpufreq/cpufreq.c +8
-0@@ -2887,6 +2887,7 @@ static int cpufreq_boost_trigger_state(int state)struct cpufreq_policy *policy;unsigned long flags;bool boost_enabled; +bool policy_success = false;int ret = -EOPNOTSUPP ;guard (mutex)(&cpufreq_boost_mutex);@@ -2911,6 +2912,8 @@ static int cpufreq_boost_trigger_state(int state) ret =policy_set_boost (policy, state);if (unlikely (ret))break ; + + policy_success = true; }cpus_read_unlock ();@@ -2918,10 +2921,15 @@ static int cpufreq_boost_trigger_state(int state)if (likely (!ret))return 0 ; +/* Keep partial enable usable and repairable through local sysfs. */ +if (state && !boost_enabled && policy_success) + goto out_err; +write_lock_irqsave (&cpufreq_driver_lock, flags); cpufreq_driver->boost_enabled = boost_enabled;write_unlock_irqrestore (&cpufreq_driver_lock, flags); +out_err:pr_err ("%s: Cannot %s BOOST\n" , __func__,str_enable_disable (state));
Quoted 10 lines · 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
Yeah, it is a real issue, global boost "only means a permission to use the frequency boost mechanism" (cpufreq.rst), and "per-policy boost can then be enabled or disabled individually" while "disabling global boost makes the per-policy boost interface illegal" (commit 218a06a79d9a).
Quoted 49 lines
and individual policies remain accessible through per-policy sysfs.
Retain global-state restoration for enable failures without a successful policy update, same-state resynchronization failures, and disable failures. 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")Signed-off-by Jiangtian Feng <[email protected]>---
Validation:
- mainline ARM64 defconfig build of the complete Image
- checkpatch.pl
- eight-case old-global/request/success state matrix
- independent static control-flow and locking review
NOT_RUN:
- runtime fault injection or reproduction with multiple policies
- global/local concurrency, hotplug, lockdep or KCSAN testing
- CPPC, SW frequency-table, ACPI or AMD hardware frequency/QoS testingdrivers/cpufreq/cpufreq.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/cpufreq/cpufreq.c +3
-0@@ -2887,6 +2887,7 @@ static int cpufreq_boost_trigger_state(int state)struct cpufreq_policy *policy;unsigned long flags;bool boost_enabled; +bool policy_success = false;int ret = -EOPNOTSUPP ;guard (mutex)(&cpufreq_boost_mutex);@@ -2911,6 +2912,8 @@ static int cpufreq_boost_trigger_state(int state) ret =policy_set_boost (policy, state);if (unlikely (ret))break ; + + policy_success = true; }cpus_read_unlock ();
drivers/cpufreq/cpufreq.c static int cpufreq_boost_trigger_state(int state) · line 2926
Quoted 6 lines
drivers/cpufreq/cpufreq.c +3
-0@@ -2918,10 +2921,15 @@ static int cpufreq_boost_trigger_state(int state)if (likely (!ret))return 0 ; +/* Keep partial enable usable and repairable through local sysfs. */ +if (state && !boost_enabled && policy_success) + goto out_err;
This function uses guard(), and cleanup.h says "usage of "goto" and cleanup helpers is never mixed in the same function".
Besides, the !boost_enabled check is redundant, right? so maybe:
if (!state || !policy_success) {
write_lock_irqsave(&cpufreq_driver_lock, flags);
cpufreq_driver->boost_enabled = boost_enabled;
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
}drivers/cpufreq/cpufreq.c static int cpufreq_boost_trigger_state(int state) · line 2935
Quoted 9 lines
drivers/cpufreq/cpufreq.c +2
-0+write_lock_irqsave (&cpufreq_driver_lock, flags); cpufreq_driver->boost_enabled = boost_enabled;write_unlock_irqrestore (&cpufreq_driver_lock, flags); +out_err:pr_err ("%s: Cannot %s BOOST\n" , __func__,str_enable_disable (state));
Separately, the disable side can end up in a similar state: if global boost is already 0 and a resync write of 0 fails on some policy, that policy stays boosted under global boost = 0. That's outside the scope of this patch, though.
Signature · 2 lines
Thx and BRs, Zhongqiu Han
RFC PATCH v2 1/1 cpufreq: Keep global boost enabled after partial enable
In reply to Jiangtian FengWhen 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.
Retain global-state restoration for enable failures without a successful policy update, same-state resynchronization failures, and disable failures. 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.
--- drivers/cpufreq/cpufreq.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/cpufreq/cpufreq.c +9 -3
@@ -2887,6 +2887,7 @@ static int cpufreq_boost_trigger_state(int state)struct cpufreq_policy *policy;unsigned long flags;bool boost_enabled; +bool policy_success = false;int ret = -EOPNOTSUPP ;guard (mutex)(&cpufreq_boost_mutex);
@@ -2911,6 +2912,8 @@ static int cpufreq_boost_trigger_state(int state) ret =policy_set_boost (policy, state);if (unlikely (ret))break ; + + policy_success = true; }cpus_read_unlock ();
@@ -2918,9 +2921,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); +/* Keep partial enable usable and repairable through local sysfs. */ +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));
Signature · 1 line
2.47.3
Quoted 12 lines · 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.
Quoted 3 lines
Retain global-state restoration for enable failures without a successful policy update, same-state resynchronization failures, and disable failures. Do not roll back earlier policy updates.
The "same-state resynchronization failures" part of the changelog is left over from v1. With v2's condition, if global boost is already 1, writing 1 again fails, and some policy was boosted before the failure, the restore is skipped. This is harmless because the restore would write 1 anyway, but the changelog no longer matches the code. Please update that sentence along with the comment.
Quoted 7 lines
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")Signed-off-by Jiangtian Feng <[email protected]>---
When posting a new version of a patch, such as this v2, please describe what changed since the previous version below the "---" line, with a link to the previous posting. See Documentation/process/submitting-patches.rst for details.
Please also reply to the review comments on the previous version before posting a new one, so reviewers know whether each comment was accepted, and if not, why.
Quoted 25 lines
drivers/cpufreq/cpufreq.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)drivers/cpufreq/cpufreq.c +3
-0@@ -2887,6 +2887,7 @@ static int cpufreq_boost_trigger_state(int state)struct cpufreq_policy *policy;unsigned long flags;bool boost_enabled; +bool policy_success = false;int ret = -EOPNOTSUPP ;guard (mutex)(&cpufreq_boost_mutex);@@ -2911,6 +2912,8 @@ static int cpufreq_boost_trigger_state(int state) ret =policy_set_boost (policy, state);if (unlikely (ret))break ; + + policy_success = true; }cpus_read_unlock ();
drivers/cpufreq/cpufreq.c static int cpufreq_boost_trigger_state(int state) · line 2924
Quoted 7 lines
drivers/cpufreq/cpufreq.c +1
-3@@ -2918,9 +2921,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); +/* Keep partial enable usable and repairable through local sysfs. */
This comment is left over from v1's goto branch. In v2 it sits above the restore path but only describes the skipped case, so please reword it to say when the previous state is restored and why a partial enable keeps global boost set.
Quoted 8 lines
drivers/cpufreq/cpufreq.c +5
-0+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));
Signature · 2 lines
Thx and BRs, Zhongqiu Han