BACKPORT: FROMLIST: thermal/core/power_allocator: avoid thermal cdev can not be reset

Commit 0952177f2a ("thermal/core/power_allocator: Update once
cooling devices when temp is low") adds a update flag to avoid
the thermal event is triggered when there is no need, and
thermal cdev would be update once when temperature is low.

But when the trips are writable, and switch_on_temp is set
to be a higher value, the cooling device state may not be
reset to 0, because last_temperature is smaller than the
switch_on_temp.

For example:
First:
switch_on_temp=70 control_temp=85;
Then userspace change the trip_temp:
switch_on_temp=45 control_temp=55 cur_temp=54

Then userspace reset the trip_temp:
switch_on_temp=70 control_temp=85 cur_temp=57 last_temp=54

At this time, the cooling device state should be reset to 0.
However, because cur_temp(57) < switch_on_temp(70)
last_temp(54) < switch_on_temp(70)  ---->  update = false,
update is false, the cooling device state can not be reset.

This patch adds a function thermal_cdev_needs_update() to
renew the update flag value only when the trips are writable,
so that thermal cdev->state can be reset after switch_on_temp
changed from low to high.

Fixes: 0952177f2a ("thermal/core/power_allocator: Update once cooling devices when temp is low")
Signed-off-by: Di Shen <di.shen@unisoc.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>

Bug: 280955449
Link: https://lore.kernel.org/all/20230320095620.7480-1-di.shen@unisoc.com/
Link: https://lore.kernel.org/all/6055bc39-5c00-d12f-b5c3-fa21a9649d63@arm.com/
Change-Id: I4fc510da0cf16a10b3dc449db3c4cd12233d4e23
Signed-off-by: Di Shen <di.shen@unisoc.com>
[ resolved minor conflict in drivers/thermal/gov_power_allocator.c ]
This commit is contained in:
Di Shen
2023-05-05 16:06:51 +08:00
committed by Treehugger Robot
parent 424075e4ef
commit a881d6f4e5

View File

@@ -62,6 +62,8 @@ static inline s64 div_frac(s64 x, s64 y)
* governor switches on when this trip point is crossed.
* If the thermal zone only has one passive trip point,
* @trip_switch_on should be INVALID_TRIP.
* @last_switch_on_temp:Record the last switch_on_temp only when trips
are writable.
* @trip_max_desired_temperature: last passive trip point of the thermal
* zone. The temperature we are
* controlling for.
@@ -73,6 +75,9 @@ struct power_allocator_params {
s64 err_integral;
s32 prev_err;
int trip_switch_on;
#ifdef CONFIG_THERMAL_WRITABLE_TRIPS
int last_switch_on_temp;
#endif
int trip_max_desired_temperature;
u32 sustainable_power;
};
@@ -567,6 +572,25 @@ static void get_governor_trips(struct thermal_zone_device *tz,
}
}
#ifdef CONFIG_THERMAL_WRITABLE_TRIPS
static bool power_allocator_throttle_update(struct thermal_zone_device *tz, int switch_on_temp)
{
bool update;
struct power_allocator_params *params = tz->governor_data;
int last_switch_on_temp = params->last_switch_on_temp;
update = (tz->last_temperature >= last_switch_on_temp);
params->last_switch_on_temp = switch_on_temp;
return update;
}
#else
static inline bool power_allocator_throttle_update(struct thermal_zone_device *tz, int switch_on_temp)
{
return false;
}
#endif
static void reset_pid_controller(struct power_allocator_params *params)
{
params->err_integral = 0;
@@ -735,16 +759,18 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
* requirement.
*/
trace_android_vh_enable_thermal_power_throttle(&enable, &override);
ret = tz->ops->get_trip_temp(tz, params->trip_switch_on,
&switch_on_temp);
if (!enable || (!ret && (tz->temperature < switch_on_temp) &&
!override)) {
update = (tz->last_temperature >= switch_on_temp);
trace_android_vh_modify_thermal_throttle_update(tz, &update);
tz->passive = 0;
reset_pid_controller(params);
allow_maximum_power(tz, update);
return 0;
ret = tz->ops->get_trip_temp(tz, params->trip_switch_on, &switch_on_temp);
if (!ret) {
update = power_allocator_throttle_update(tz, switch_on_temp);
if (!enable || ((tz->temperature < switch_on_temp) && !override)) {
update |= (tz->last_temperature >= switch_on_temp);
trace_android_vh_modify_thermal_throttle_update(tz, &update);
tz->passive = 0;
reset_pid_controller(params);
allow_maximum_power(tz, update);
return 0;
}
}
tz->passive = 1;