Skip to content

Commit 6e6f58a

Browse files
committed
thermal: gov_bang_bang: Use governor_data to reduce overhead
After running once, the for_each_trip_desc() loop in bang_bang_manage() is pure needless overhead because it is not going to make any changes unless a new cooling device has been bound to one of the trips in the thermal zone or the system is resuming from sleep. For this reason, make bang_bang_manage() set governor_data for the thermal zone and check it upfront to decide whether or not it needs to do anything. However, governor_data needs to be reset in some cases to let bang_bang_manage() know that it should walk the trips again, so add an .update_tz() callback to the governor and make the core additionally invoke it during system resume. To avoid affecting the other users of that callback unnecessarily, add a special notification reason for system resume, THERMAL_TZ_RESUME, and also pass it to __thermal_zone_device_update() called during system resume for consistency. Signed-off-by: Rafael J. Wysocki <[email protected]> Acked-by: Peter Kästle <[email protected]> Reviewed-by: Zhang Rui <[email protected]> Cc: 6.10+ <[email protected]> # 6.10+ Link: https://patch.msgid.link/[email protected]
1 parent 5f64b4a commit 6e6f58a

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

drivers/thermal/gov_bang_bang.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ static void bang_bang_manage(struct thermal_zone_device *tz)
8686
const struct thermal_trip_desc *td;
8787
struct thermal_instance *instance;
8888

89+
/* If the code below has run already, nothing needs to be done. */
90+
if (tz->governor_data)
91+
return;
92+
8993
for_each_trip_desc(tz, td) {
9094
const struct thermal_trip *trip = &td->trip;
9195

@@ -107,11 +111,25 @@ static void bang_bang_manage(struct thermal_zone_device *tz)
107111
bang_bang_set_instance_target(instance, 0);
108112
}
109113
}
114+
115+
tz->governor_data = (void *)true;
116+
}
117+
118+
static void bang_bang_update_tz(struct thermal_zone_device *tz,
119+
enum thermal_notify_event reason)
120+
{
121+
/*
122+
* Let bang_bang_manage() know that it needs to walk trips after binding
123+
* a new cdev and after system resume.
124+
*/
125+
if (reason == THERMAL_TZ_BIND_CDEV || reason == THERMAL_TZ_RESUME)
126+
tz->governor_data = NULL;
110127
}
111128

112129
static struct thermal_governor thermal_gov_bang_bang = {
113130
.name = "bang_bang",
114131
.trip_crossed = bang_bang_control,
115132
.manage = bang_bang_manage,
133+
.update_tz = bang_bang_update_tz,
116134
};
117135
THERMAL_GOVERNOR_DECLARE(thermal_gov_bang_bang);

drivers/thermal/thermal_core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,8 @@ static void thermal_zone_device_resume(struct work_struct *work)
17281728

17291729
thermal_debug_tz_resume(tz);
17301730
thermal_zone_device_init(tz);
1731-
__thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
1731+
thermal_governor_update_tz(tz, THERMAL_TZ_RESUME);
1732+
__thermal_zone_device_update(tz, THERMAL_TZ_RESUME);
17321733

17331734
complete(&tz->resume);
17341735
tz->resuming = false;

include/linux/thermal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ enum thermal_notify_event {
5555
THERMAL_TZ_BIND_CDEV, /* Cooling dev is bind to the thermal zone */
5656
THERMAL_TZ_UNBIND_CDEV, /* Cooling dev is unbind from the thermal zone */
5757
THERMAL_INSTANCE_WEIGHT_CHANGED, /* Thermal instance weight changed */
58+
THERMAL_TZ_RESUME, /* Thermal zone is resuming after system sleep */
5859
};
5960

6061
/**

0 commit comments

Comments
 (0)