-
Notifications
You must be signed in to change notification settings - Fork 84
thermal: boost: phytium: Automatic enable/disable of BOOST feature #762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
thermal: boost: phytium: Automatic enable/disable of BOOST feature #762
Conversation
This patch provides auto disable/enable operation for boost. When the device temperature rises above 75% of the smallest trip point, the boost is disabled. In that moment thermal monitor workqueue will monitors if the device cools down. When the device temperature drops below 75% of the smallest trip point, the boost is enabled again. Mainline: NA Signed-off-by: Li Jiayi <[email protected]> Signed-off-by: Li Mingzhe <[email protected]> Signed-off-by: Wang Yinfeng <[email protected]> Signed-off-by: Malloy Liu <[email protected]>
Reviewer's Guide by SourceryThis pull request implements automatic enabling and disabling of the CPU boost feature based on thermal zone temperature. It introduces new helper functions No diagrams generated as the changes look simple and do not need a visual representation. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
deepin pr auto review代码审查意见:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ditvelo - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider making the 75% thermal threshold for boost disabling configurable instead of hardcoding it.
- Evaluate if this boost management logic belongs in the generic thermal core or closer to CPU-specific thermal/cpufreq drivers.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@@ -2794,10 +2793,14 @@ int cpufreq_boost_trigger_state(int state) | |||
return ret; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Return value inconsistency in cpufreq_boost_supported.
The function is declared as returning a bool, yet when cpufreq_driver is NULL it returns -EINVAL (a negative error code) which is non-zero and thus evaluates to true in C logical contexts. Consider returning false instead of -EINVAL so that callers relying on boolean logic won’t misinterpret the error state.
static void thermal_boost_disable(struct thermal_zone_device *tz) | ||
{ | ||
cpufreq_boost_trigger_state(0); | ||
|
||
/* | ||
* If no workqueue for monitoring is running - start one with | ||
* 1000 ms monitoring period | ||
* If workqueue already running - do not change its period and only | ||
* test if target CPU has cooled down | ||
*/ | ||
if (tz->mode != THERMAL_DEVICE_ENABLED) { | ||
tz->boost_polling = true; | ||
thermal_zone_device_set_polling(tz, 1000); | ||
} | ||
tz->overheated = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Inconsistent synchronization when updating thermal zone state.
The thermal_boost_enable function acquires tz->lock when modifying the overheated flag and boost_polling flag, while thermal_boost_disable updates these fields without locking. In concurrent environments this might lead to race conditions. Consider using the mutex when updating shared state in thermal_boost_disable as well.
static void thermal_boost_disable(struct thermal_zone_device *tz) | |
{ | |
cpufreq_boost_trigger_state(0); | |
/* | |
* If no workqueue for monitoring is running - start one with | |
* 1000 ms monitoring period | |
* If workqueue already running - do not change its period and only | |
* test if target CPU has cooled down | |
*/ | |
if (tz->mode != THERMAL_DEVICE_ENABLED) { | |
tz->boost_polling = true; | |
thermal_zone_device_set_polling(tz, 1000); | |
} | |
tz->overheated = true; | |
} | |
static void thermal_boost_disable(struct thermal_zone_device *tz) | |
{ | |
cpufreq_boost_trigger_state(0); | |
mutex_lock(&tz->lock); | |
/* | |
* If no workqueue for monitoring is running - start one with | |
* 1000 ms monitoring period | |
* If workqueue already running - do not change its period and only | |
* test if target CPU has cooled down | |
*/ | |
if (tz->mode != THERMAL_DEVICE_ENABLED) { | |
tz->boost_polling = true; | |
thermal_zone_device_set_polling(tz, 1000); | |
} | |
tz->overheated = true; | |
mutex_unlock(&tz->lock); | |
} |
@@ -341,6 +342,49 @@ | |||
tz->ops->critical(tz); | |||
} | |||
|
|||
static int thermal_boost_enable(struct thermal_zone_device *tz) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider refactoring the boost enable logic to use early returns to reduce nesting and improve readability.
Consider refactoring the boost enable logic to reduce nesting. In particular, use early returns to invert conditional checks. For example, modify thermal_boost_enable
as follows:
static int thermal_boost_enable(struct thermal_zone_device *tz)
{
enum thermal_trend trend = get_tz_trend(tz, 0);
struct thermal_trip trip;
if (!tz->overheated)
return -EPERM;
if (trend == THERMAL_TREND_RAISING)
return -EBUSY;
__thermal_zone_get_trip(tz, 0, &trip);
/* Return immediately if temperature is not high enough to disable boost. */
if ((tz->temperature + (trip.temperature >> 2)) >= trip.temperature)
return -EBUSY;
mutex_lock(&tz->lock);
tz->overheated = false;
if (tz->boost_polling) {
tz->boost_polling = false;
thermal_zone_device_set_polling(tz, 0);
}
mutex_unlock(&tz->lock);
cpufreq_boost_trigger_state(1);
return 0;
}
This minimizes nested conditions while preserving all functionality. The same approach for any similar nested logic (if applicable in other functions) will improve clarity.
drivers/cpufreq/cpufreq.c
Outdated
@@ -1224,7 +1224,6 @@ static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy) | |||
cmp = &policy->kobj_unregister; | |||
up_write(&policy->rwsem); | |||
kobject_put(kobj); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要无意义的删除空行
#include <linux/of.h> | ||
#include <linux/suspend.h> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要无意义的删除空行
b7d1d26
into
deepin-community:linux-6.6.y
…ature" It causes boot error in some phytium device. Reverts #762 This reverts commit b6c9d54. Signed-off-by: Wentao Guan <[email protected]>
This patch provides auto disable/enable operation for boost. When the device temperature rises above 75% of the smallest trip point, the boost is disabled.
In that moment thermal monitor workqueue will monitors if the device cools down. When the device temperature drops below 75% of the smallest trip point, the boost is enabled again.
Mainline: NA
Summary by Sourcery
Introduce automatic thermal management for CPU frequency boost. This disables the boost feature when the thermal zone temperature exceeds a threshold relative to the lowest trip point and re-enables it once the temperature drops below that threshold.
New Features: