linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 0/3] thermal: rework core to improve userspace interaction
@ 2015-12-17 19:13 Eduardo Valentin
  2015-12-17 19:13 ` [PATCHv2 1/3] thermal: setup monitor only once after handling trips Eduardo Valentin
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Eduardo Valentin @ 2015-12-17 19:13 UTC (permalink / raw)
  To: Rui Zhang; +Cc: Linux PM, LKML, Eduardo Valentin

Hello Rui, linux-pm

Changelog:
V1 -> V2: Fixes patch 2, and added Srivinas reviewed by on patch 1.

Please consider these three patches in the thermal core to improve
the interaction with userspace.

The first is already in its second version. It avoids reconfiguring
monitor period. Now the thermal core configures the monitor only
after handling all trip points.

The second is about improving emul_temp. The background here is to
allow using emul_temp, even if the thermal zone is not fully setup,
with a missing .get_temp().

The third is to improve hot trip points handling. Hot trip points
are described as notification entry points. However, we do very
little on them. This patch adds a uevent to propagate the event
to userspace. Today, we rely on thermal zone driver. I believe
having the same message coming on every thermal zone makes more
sense. However, I did not remove the .notify() callback, and it
should behave the same.

Eduardo Valentin (3):
  thermal: setup monitor only once after handling trips
  thermal: rework core to allow emul_temp to be treated as regular temp
  thermal: improve hot trip handling

 drivers/thermal/thermal_core.c | 96 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 78 insertions(+), 18 deletions(-)

-- 
2.5.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCHv2 1/3] thermal: setup monitor only once after handling trips
  2015-12-17 19:13 [PATCHv2 0/3] thermal: rework core to improve userspace interaction Eduardo Valentin
@ 2015-12-17 19:13 ` Eduardo Valentin
  2015-12-17 19:13 ` [PATCHv2 2/3] thermal: rework core to allow emul_temp to be treated as regular temp Eduardo Valentin
  2015-12-17 19:13 ` [PATCHv2 3/3] thermal: improve hot trip handling Eduardo Valentin
  2 siblings, 0 replies; 7+ messages in thread
From: Eduardo Valentin @ 2015-12-17 19:13 UTC (permalink / raw)
  To: Rui Zhang; +Cc: Linux PM, LKML, Eduardo Valentin

Instead of changing the monitoring setup every time after
handling each trip, this patch simplifies the monitoring
setup by moving the setup call to a place where all
trips have been treated already.

Cc: Zhang Rui <rui.zhang@intel.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: Pandruvada, Srinivas <srinivas.pandruvada@intel.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
---
V2: Added Srinivas reviewed by.
---
 drivers/thermal/thermal_core.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index d9e525c..8fa82c0 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -457,11 +457,6 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
 		handle_critical_trips(tz, trip, type);
 	else
 		handle_non_critical_trips(tz, trip, type);
-	/*
-	 * Alright, we handled this trip successfully.
-	 * So, start monitoring again.
-	 */
-	monitor_thermal_zone(tz);
 }
 
 /**
@@ -547,6 +542,12 @@ void thermal_zone_device_update(struct thermal_zone_device *tz)
 
 	for (count = 0; count < tz->trips; count++)
 		handle_thermal_trip(tz, count);
+
+	/*
+	 * Alright, we handled these trips successfully.
+	 * So, start monitoring again.
+	 */
+	monitor_thermal_zone(tz);
 }
 EXPORT_SYMBOL_GPL(thermal_zone_device_update);
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCHv2 2/3] thermal: rework core to allow emul_temp to be treated as regular temp
  2015-12-17 19:13 [PATCHv2 0/3] thermal: rework core to improve userspace interaction Eduardo Valentin
  2015-12-17 19:13 ` [PATCHv2 1/3] thermal: setup monitor only once after handling trips Eduardo Valentin
@ 2015-12-17 19:13 ` Eduardo Valentin
  2016-03-16  0:09   ` Pandruvada, Srinivas
  2015-12-17 19:13 ` [PATCHv2 3/3] thermal: improve hot trip handling Eduardo Valentin
  2 siblings, 1 reply; 7+ messages in thread
From: Eduardo Valentin @ 2015-12-17 19:13 UTC (permalink / raw)
  To: Rui Zhang; +Cc: Linux PM, LKML, Eduardo Valentin

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@intel.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
---
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);
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCHv2 3/3] thermal: improve hot trip handling
  2015-12-17 19:13 [PATCHv2 0/3] thermal: rework core to improve userspace interaction Eduardo Valentin
  2015-12-17 19:13 ` [PATCHv2 1/3] thermal: setup monitor only once after handling trips Eduardo Valentin
  2015-12-17 19:13 ` [PATCHv2 2/3] thermal: rework core to allow emul_temp to be treated as regular temp Eduardo Valentin
@ 2015-12-17 19:13 ` Eduardo Valentin
  2016-01-05  9:46   ` Geert Uytterhoeven
  2016-03-16  0:14   ` Pandruvada, Srinivas
  2 siblings, 2 replies; 7+ messages in thread
From: Eduardo Valentin @ 2015-12-17 19:13 UTC (permalink / raw)
  To: Rui Zhang; +Cc: Linux PM, LKML, Eduardo Valentin

The idea is to add the choice to be notified only when temperature
crosses trip points. The trip points affected are the non-passive
trip points.

It will check last temperature and current temperature against
the trip point temperature and its hysteresis.
In case the check shows temperature has changed enought indicating
a trip point crossing, a uevent will be sent to userspace.

The uevent contains the thermal zone type, the current temperature,
the last temperature and the trip point in which the current temperature
now resides.

The behavior of ops->notify() callback remains the same.

Cc: Zhang Rui <rui.zhang@intel.com>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
---
V1->V2: none
---
 drivers/thermal/thermal_core.c | 52 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index a229c84..e0f1f4e 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -423,6 +423,56 @@ static void handle_non_critical_trips(struct thermal_zone_device *tz,
 		       def_governor->throttle(tz, trip);
 }
 
+static void thermal_tripped_notify(struct thermal_zone_device *tz,
+				   int trip, enum thermal_trip_type trip_type,
+				   int trip_temp)
+{
+	char tuv_name[THERMAL_NAME_LENGTH + 15], tuv_temp[25],
+		tuv_ltemp[25], tuv_trip[25], tuv_type[25];
+	char *msg[6] = { tuv_name, tuv_temp, tuv_ltemp, tuv_trip, tuv_type,
+			NULL };
+	int upper_trip_hyst, upper_trip_temp, trip_hyst = 0;
+	int ret = 0;
+
+	snprintf(tuv_name, sizeof(tuv_name), "THERMAL_ZONE=%s", tz->type);
+	snprintf(tuv_temp, sizeof(tuv_temp), "TEMP=%d", tz->temperature);
+	snprintf(tuv_ltemp, sizeof(tuv_ltemp), "LAST_TEMP=%d",
+		 tz->last_temperature);
+	snprintf(tuv_trip, sizeof(tuv_trip), "TRIP=%d", trip);
+	snprintf(tuv_type, sizeof(tuv_type), "TRIP_TYPE=%d", trip_type);
+
+	mutex_lock(&tz->lock);
+
+	/* crossing up */
+	if (tz->last_temperature < trip_temp && trip_temp < tz->temperature)
+		kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, msg);
+
+	if (tz->ops->get_trip_hyst)
+		tz->ops->get_trip_hyst(tz, trip, &trip_hyst);
+
+	/* crossing down, check for hyst */
+	trip_temp -= trip_hyst;
+	if (tz->last_temperature > trip_temp && trip_temp > tz->temperature) {
+		snprintf(tuv_trip, sizeof(tuv_trip), "TRIP=%d", trip - 1);
+		kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, msg);
+	}
+
+	ret = tz->ops->get_trip_temp(tz, trip + 1, &upper_trip_temp);
+	if (ret)
+		goto unlock;
+
+	if (tz->ops->get_trip_hyst)
+		tz->ops->get_trip_hyst(tz, trip + 1, &upper_trip_hyst);
+
+	upper_trip_temp -= upper_trip_hyst;
+	if (tz->last_temperature > upper_trip_temp &&
+	    upper_trip_temp > tz->temperature)
+		kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, msg);
+
+unlock:
+	mutex_unlock(&tz->lock);
+}
+
 static void handle_critical_trips(struct thermal_zone_device *tz,
 				int trip, enum thermal_trip_type trip_type)
 {
@@ -430,6 +480,8 @@ static void handle_critical_trips(struct thermal_zone_device *tz,
 
 	tz->ops->get_trip_temp(tz, trip, &trip_temp);
 
+	thermal_tripped_notify(tz, trip, trip_type, trip_temp);
+
 	/* If we have not crossed the trip_temp, we do not care. */
 	if (trip_temp <= 0 || tz->temperature < trip_temp)
 		return;
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCHv2 3/3] thermal: improve hot trip handling
  2015-12-17 19:13 ` [PATCHv2 3/3] thermal: improve hot trip handling Eduardo Valentin
@ 2016-01-05  9:46   ` Geert Uytterhoeven
  2016-03-16  0:14   ` Pandruvada, Srinivas
  1 sibling, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2016-01-05  9:46 UTC (permalink / raw)
  To: Eduardo Valentin
  Cc: Kuninori Morimoto, Rui Zhang, Linux PM, LKML, Linux-sh list

Hi Eduardo,

On Thu, Dec 17, 2015 at 8:13 PM, Eduardo Valentin <edubezval@gmail.com> wrote:
> The idea is to add the choice to be notified only when temperature
> crosses trip points. The trip points affected are the non-passive
> trip points.
>
> It will check last temperature and current temperature against
> the trip point temperature and its hysteresis.
> In case the check shows temperature has changed enought indicating
> a trip point crossing, a uevent will be sent to userspace.
>
> The uevent contains the thermal zone type, the current temperature,
> the last temperature and the trip point in which the current temperature
> now resides.
>
> The behavior of ops->notify() callback remains the same.
>
> Cc: Zhang Rui <rui.zhang@intel.com>
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
> ---
> V1->V2: none
> ---
>  drivers/thermal/thermal_core.c | 52 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
>
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index a229c84..e0f1f4e 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -423,6 +423,56 @@ static void handle_non_critical_trips(struct thermal_zone_device *tz,
>                        def_governor->throttle(tz, trip);
>  }
>
> +static void thermal_tripped_notify(struct thermal_zone_device *tz,
> +                                  int trip, enum thermal_trip_type trip_type,
> +                                  int trip_temp)
> +{
> +       char tuv_name[THERMAL_NAME_LENGTH + 15], tuv_temp[25],
> +               tuv_ltemp[25], tuv_trip[25], tuv_type[25];
> +       char *msg[6] = { tuv_name, tuv_temp, tuv_ltemp, tuv_trip, tuv_type,
> +                       NULL };
> +       int upper_trip_hyst, upper_trip_temp, trip_hyst = 0;
> +       int ret = 0;
> +
> +       snprintf(tuv_name, sizeof(tuv_name), "THERMAL_ZONE=%s", tz->type);
> +       snprintf(tuv_temp, sizeof(tuv_temp), "TEMP=%d", tz->temperature);
> +       snprintf(tuv_ltemp, sizeof(tuv_ltemp), "LAST_TEMP=%d",
> +                tz->last_temperature);
> +       snprintf(tuv_trip, sizeof(tuv_trip), "TRIP=%d", trip);
> +       snprintf(tuv_type, sizeof(tuv_type), "TRIP_TYPE=%d", trip_type);
> +
> +       mutex_lock(&tz->lock);
> +
> +       /* crossing up */
> +       if (tz->last_temperature < trip_temp && trip_temp < tz->temperature)
> +               kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, msg);
> +
> +       if (tz->ops->get_trip_hyst)
> +               tz->ops->get_trip_hyst(tz, trip, &trip_hyst);
> +
> +       /* crossing down, check for hyst */
> +       trip_temp -= trip_hyst;
> +       if (tz->last_temperature > trip_temp && trip_temp > tz->temperature) {
> +               snprintf(tuv_trip, sizeof(tuv_trip), "TRIP=%d", trip - 1);
> +               kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, msg);
> +       }
> +
> +       ret = tz->ops->get_trip_temp(tz, trip + 1, &upper_trip_temp);

"trip + 1" may be equal to thermal_zone_device.trips and thus out-of-range,
in which case rcar_thermal_get_trip_temp() will print an error message:

    rcar_thermal e61f0000.thermal: rcar driver trip error

Is the "+ 1" (also below) intentional?
If yes, I think the related error messages in rcar_thermal.c should be reduced
to debug messages.

> +       if (ret)
> +               goto unlock;
> +
> +       if (tz->ops->get_trip_hyst)
> +               tz->ops->get_trip_hyst(tz, trip + 1, &upper_trip_hyst);

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCHv2 2/3] thermal: rework core to allow emul_temp to be treated as regular temp
  2015-12-17 19:13 ` [PATCHv2 2/3] thermal: rework core to allow emul_temp to be treated as regular temp Eduardo Valentin
@ 2016-03-16  0:09   ` Pandruvada, Srinivas
  0 siblings, 0 replies; 7+ messages in thread
From: Pandruvada, Srinivas @ 2016-03-16  0:09 UTC (permalink / raw)
  To: edubezval, Zhang, Rui; +Cc: linux-kernel, linux-pm

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@intel.com>
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>


> ---
> 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);
>  

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCHv2 3/3] thermal: improve hot trip handling
  2015-12-17 19:13 ` [PATCHv2 3/3] thermal: improve hot trip handling Eduardo Valentin
  2016-01-05  9:46   ` Geert Uytterhoeven
@ 2016-03-16  0:14   ` Pandruvada, Srinivas
  1 sibling, 0 replies; 7+ messages in thread
From: Pandruvada, Srinivas @ 2016-03-16  0:14 UTC (permalink / raw)
  To: edubezval, Zhang, Rui; +Cc: linux-kernel, linux-pm

On Thu, 2015-12-17 at 11:13 -0800, Eduardo Valentin wrote:
> The idea is to add the choice to be notified only when temperature
> crosses trip points. The trip points affected are the non-passive
> trip points.
> 
> It will check last temperature and current temperature against
> the trip point temperature and its hysteresis.
> In case the check shows temperature has changed enought indicating
> a trip point crossing, a uevent will be sent to userspace.
> 
> The uevent contains the thermal zone type, the current temperature,
> the last temperature and the trip point in which the current
> temperature
> now resides.
> 
> The behavior of ops->notify() callback remains the same.
> 
IMO we need to handle also passive/active trips. I have some comments
here
https://patchwork.kernel.org/patch/8583171/

Thanks,
Srinivas

> Cc: Zhang Rui <rui.zhang@intel.com>
> Cc: linux-pm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
> ---
> V1->V2: none
> ---
>  drivers/thermal/thermal_core.c | 52
> ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 52 insertions(+)
> 
> diff --git a/drivers/thermal/thermal_core.c
> b/drivers/thermal/thermal_core.c
> index a229c84..e0f1f4e 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -423,6 +423,56 @@ static void handle_non_critical_trips(struct
> thermal_zone_device *tz,
>  		       def_governor->throttle(tz, trip);
>  }
>  
> +static void thermal_tripped_notify(struct thermal_zone_device *tz,
> +				   int trip, enum thermal_trip_type
> trip_type,
> +				   int trip_temp)
> +{
> +	char tuv_name[THERMAL_NAME_LENGTH + 15], tuv_temp[25],
> +		tuv_ltemp[25], tuv_trip[25], tuv_type[25];
> +	char *msg[6] = { tuv_name, tuv_temp, tuv_ltemp, tuv_trip,
> tuv_type,
> +			NULL };
> +	int upper_trip_hyst, upper_trip_temp, trip_hyst = 0;
> +	int ret = 0;
> +
> +	snprintf(tuv_name, sizeof(tuv_name), "THERMAL_ZONE=%s", tz-
> >type);
> +	snprintf(tuv_temp, sizeof(tuv_temp), "TEMP=%d", tz-
> >temperature);
> +	snprintf(tuv_ltemp, sizeof(tuv_ltemp), "LAST_TEMP=%d",
> +		 tz->last_temperature);
> +	snprintf(tuv_trip, sizeof(tuv_trip), "TRIP=%d", trip);
> +	snprintf(tuv_type, sizeof(tuv_type), "TRIP_TYPE=%d",
> trip_type);
> +
> +	mutex_lock(&tz->lock);
> +
> +	/* crossing up */
> +	if (tz->last_temperature < trip_temp && trip_temp < tz-
> >temperature)
> +		kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE,
> msg);
> +
> +	if (tz->ops->get_trip_hyst)
> +		tz->ops->get_trip_hyst(tz, trip, &trip_hyst);
> +
> +	/* crossing down, check for hyst */
> +	trip_temp -= trip_hyst;
> +	if (tz->last_temperature > trip_temp && trip_temp > tz-
> >temperature) {
> +		snprintf(tuv_trip, sizeof(tuv_trip), "TRIP=%d", trip
> - 1);
> +		kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE,
> msg);
> +	}
> +
> +	ret = tz->ops->get_trip_temp(tz, trip + 1,
> &upper_trip_temp);
> +	if (ret)
> +		goto unlock;
> +
> +	if (tz->ops->get_trip_hyst)
> +		tz->ops->get_trip_hyst(tz, trip + 1,
> &upper_trip_hyst);
> +
> +	upper_trip_temp -= upper_trip_hyst;
> +	if (tz->last_temperature > upper_trip_temp &&
> +	    upper_trip_temp > tz->temperature)
> +		kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE,
> msg);
> +
> +unlock:
> +	mutex_unlock(&tz->lock);
> +}
> +
>  static void handle_critical_trips(struct thermal_zone_device *tz,
>  				int trip, enum thermal_trip_type
> trip_type)
>  {
> @@ -430,6 +480,8 @@ static void handle_critical_trips(struct
> thermal_zone_device *tz,
>  
>  	tz->ops->get_trip_temp(tz, trip, &trip_temp);
>  
> +	thermal_tripped_notify(tz, trip, trip_type, trip_temp);
> +
>  	/* If we have not crossed the trip_temp, we do not care. */
>  	if (trip_temp <= 0 || tz->temperature < trip_temp)
>  		return;

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-03-16  0:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-17 19:13 [PATCHv2 0/3] thermal: rework core to improve userspace interaction Eduardo Valentin
2015-12-17 19:13 ` [PATCHv2 1/3] thermal: setup monitor only once after handling trips Eduardo Valentin
2015-12-17 19:13 ` [PATCHv2 2/3] thermal: rework core to allow emul_temp to be treated as regular temp Eduardo Valentin
2016-03-16  0:09   ` Pandruvada, Srinivas
2015-12-17 19:13 ` [PATCHv2 3/3] thermal: improve hot trip handling Eduardo Valentin
2016-01-05  9:46   ` Geert Uytterhoeven
2016-03-16  0:14   ` Pandruvada, Srinivas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).