Re: [PATCHv2 2/3] thermal: rework core to allow emul_temp to be treated as regular temp

From: Pandruvada, Srinivas
Date: Tue Mar 15 2016 - 20:09:45 EST


On Thu, 2015-12-17 at 11:13 -0800, Eduardo Valentin wrote:
> Change the way we handle emul_temp. This is to allow
> emul_temp to be used as input to exercise thermal core
> properly. Now, even if .get_temp is not available,
> the emul_temp can be used to emulate temperature.
>
> Cc: Zhang Rui <rui.zhang@xxxxxxxxx>
> Cc: linux-pm@xxxxxxxxxxxxxxx
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> Signed-off-by: Eduardo Valentin <edubezval@xxxxxxxxx>
Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@xxxxxxxxxxxxxxx>


> ---
> V1-> V2: fixed real_temp initial value.
> ---
> Âdrivers/thermal/thermal_core.c | 33 ++++++++++++++++++++----------
> ---
> Â1 file changed, 20 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/thermal/thermal_core.c
> b/drivers/thermal/thermal_core.c
> index 8fa82c0..a229c84 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -472,18 +472,25 @@ static void handle_thermal_trip(struct
> thermal_zone_device *tz, int trip)
> Âint thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
> Â{
> Â int ret = -EINVAL;
> - int count;
> - int crit_temp = INT_MAX;
> - enum thermal_trip_type type;
> + int crit_temp = INT_MAX, real_temp = INT_MIN;
> Â
> - if (!tz || IS_ERR(tz) || !tz->ops->get_temp)
> - goto exit;
> + if (!tz || IS_ERR(tz))
> + return ret;
> Â
> Â mutex_lock(&tz->lock);
> Â
> - ret = tz->ops->get_temp(tz, temp);
> + /* Allow emulation if .get_temp is still not available */
> + if (tz->ops->get_temp) {
> + ret = tz->ops->get_temp(tz, temp);
> + if (!ret)
> + real_temp = *temp;
> + }
> Â
> Â if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz-
> >emul_temperature) {
> + enum thermal_trip_type type;
> + int count;
> +
> + ret = 0;
> Â for (count = 0; count < tz->trips; count++) {
> Â ret = tz->ops->get_trip_type(tz, count,
> &type);
> Â if (!ret && type == THERMAL_TRIP_CRITICAL) {
> @@ -498,17 +505,17 @@ int thermal_zone_get_temp(struct
> thermal_zone_device *tz, int *temp)
> Â Â* is below the critical temperature so that the
> emulation code
> Â Â* cannot hide critical conditions.
> Â Â*/
> - if (!ret && *temp < crit_temp)
> + if (!ret && real_temp < crit_temp)
> Â *temp = tz->emul_temperature;
> Â }
> ÂÂ
> Â mutex_unlock(&tz->lock);
> -exit:
> +
> Â return ret;
> Â}
> ÂEXPORT_SYMBOL_GPL(thermal_zone_get_temp);
> Â
> -static void update_temperature(struct thermal_zone_device *tz)
> +static int update_temperature(struct thermal_zone_device *tz)
> Â{
> Â int temp, ret;
> Â
> @@ -518,7 +525,7 @@ static void update_temperature(struct
> thermal_zone_device *tz)
> Â dev_warn(&tz->device,
> Â Â"failed to read out thermal zone
> (%d)\n",
> Â Âret);
> - return;
> + return ret;
> Â }
> Â
> Â mutex_lock(&tz->lock);
> @@ -529,17 +536,17 @@ static void update_temperature(struct
> thermal_zone_device *tz)
> Â trace_thermal_temperature(tz);
> Â dev_dbg(&tz->device, "last_temperature=%d,
> current_temperature=%d\n",
> Â tz->last_temperature, tz-
> >temperature);
> +
> + return 0;
> Â}
> Â
> Âvoid thermal_zone_device_update(struct thermal_zone_device *tz)
> Â{
> Â int count;
> Â
> - if (!tz->ops->get_temp)
> + if (update_temperature(tz))
> Â return;
> Â
> - update_temperature(tz);
> -
> Â for (count = 0; count < tz->trips; count++)
> Â handle_thermal_trip(tz, count);
> Â