Re: [PATCH] drivers: thermal: step_wise: add support for hysteresis
From: Zhang Rui
Date: Thu Jul 26 2018 - 04:49:41 EST
Hi, Lina,
On ä, 2018-05-07 at 11:54 -0600, Lina Iyer wrote:
> From: Ram Chandrasekar <rkumbako@xxxxxxxxxxxxxx>
>
> From: Ram Chandrasekar <rkumbako@xxxxxxxxxxxxxx>
>
> Step wise governor increases the mitigation level when the
> temperature
> goes above a threshold and will decrease the mitigation when the
> temperature falls below the threshold. If it were a case, where the
> temperature hovers around a threshold, the mitigation will be applied
> and removed at every iteration. This reaction to the temperature is
> inefficient for performance.
>
> The use of hysteresis temperature could avoid this ping-pong of
> mitigation by relaxing the mitigation to happen only when the
> temperature goes below this lower hysteresis value.
>
the idea looks okay to me, just some minor comments.
> Signed-off-by: Ram Chandrasekar <rkumbako@xxxxxxxxxxxxxx>
> Signed-off-by: Lina Iyer <ilina@xxxxxxxxxxxxxx>
> ---
> Âdrivers/thermal/step_wise.c | 33 +++++++++++++++++++++++----------
> Â1 file changed, 23 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/thermal/step_wise.c
> b/drivers/thermal/step_wise.c
> index ee047ca43084..cf07e2269291 100644
> --- a/drivers/thermal/step_wise.c
> +++ b/drivers/thermal/step_wise.c
> @@ -36,7 +36,7 @@
> Â *ÂÂÂÂÂÂÂfor this trip point
> Â *ÂÂÂÂd. if the trend is THERMAL_TREND_DROP_FULL, use lower limit
> Â *ÂÂÂÂÂÂÂfor this trip point
> - * If the temperature is lower than a trip point,
> + * If the temperature is lower than a hysteresis temperature,
1. if you update this, you should update "if the temperature is higher
than ..." as well.
2. the updated comment does not fully match the code change you made
below.
> Â *ÂÂÂÂa. if the trend is THERMAL_TREND_RAISING, do nothing
> Â *ÂÂÂÂb. if the trend is THERMAL_TREND_DROPPING, use lower cooling
> Â *ÂÂÂÂÂÂÂstate for this trip point, if the cooling state already
> @@ -127,7 +127,7 @@ static void update_passive_instance(struct
> thermal_zone_device *tz,
> Â
> Âstatic void thermal_zone_trip_update(struct thermal_zone_device *tz,
> int trip)
> Â{
> - int trip_temp;
> + int trip_temp, hyst_temp;
> Â enum thermal_trip_type trip_type;
> Â enum thermal_trend trend;
> Â struct thermal_instance *instance;
> @@ -135,22 +135,23 @@ static void thermal_zone_trip_update(struct
> thermal_zone_device *tz, int trip)
> Â int old_target;
> Â
> Â if (trip == THERMAL_TRIPS_NONE) {
> - trip_temp = tz->forced_passive;
> + hyst_temp = trip_temp = tz->forced_passive;
> Â trip_type = THERMAL_TRIPS_NONE;
> Â } else {
> Â tz->ops->get_trip_temp(tz, trip, &trip_temp);
> + hyst_temp = trip_temp;
> + if (tz->ops->get_trip_hyst) {
> + tz->ops->get_trip_hyst(tz, trip,
> &hyst_temp);
> + hyst_temp = trip_temp - hyst_temp;
> + }
> Â tz->ops->get_trip_type(tz, trip, &trip_type);
> Â }
> Â
> Â trend = get_tz_trend(tz, trip);
> Â
> - if (tz->temperature >= trip_temp) {
> - throttle = true;
> - trace_thermal_zone_trip(tz, trip, trip_type);
> - }
> -
> - dev_dbg(&tz->device,
> "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n",
> - trip, trip_type, trip_temp, trend,
> throttle);
> + dev_dbg(&tz->device,
> + "Trip%d[type=%d,temp=%d,hyst=%d]:trend=%d,throttle=%
> d\n",
> + trip, trip_type, trip_temp, hyst_temp, trend,
> throttle);
> Â
throttle is not set properly here, so this debug message does not make
sense.
thanks,
rui
> Â mutex_lock(&tz->lock);
> Â
> @@ -159,6 +160,18 @@ static void thermal_zone_trip_update(struct
> thermal_zone_device *tz, int trip)
> Â continue;
> Â
> Â old_target = instance->target;
> + throttle = false;
> + /*
> + Â* Lower the mitigation only if the temperature
> + Â* goes below the hysteresis temperature.
> + Â*/
> + if (tz->temperature >= trip_temp ||
> + ÂÂÂ(tz->temperature >= hyst_temp &&
> + ÂÂÂold_target != THERMAL_NO_TARGET)) {
> + throttle = true;
> + trace_thermal_zone_trip(tz, trip,
> trip_type);
> + }
> +
> Â instance->target = get_target_state(instance, trend,
> throttle);
> Â dev_dbg(&instance->cdev->device, "old_target=%d,
> target=%d\n",
> Â old_target, (int)instance-
> >target);