All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] thermal/core: Emit a warning if the thermal zone is updated without ops
@ 2020-12-10 12:15 Daniel Lezcano
  2020-12-10 12:15 ` [PATCH 2/5] thermal/core: Add critical and hot ops Daniel Lezcano
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Daniel Lezcano @ 2020-12-10 12:15 UTC (permalink / raw)
  To: daniel.lezcano, rui.zhang
  Cc: kai.heng.feng, lukasz.luba, srinivas.pandruvada, linux-kernel,
	linux-pm, Thara Gopinath, Amit Kucheria

The actual code is silently ignoring a thermal zone update when a
driver is requesting it without a get_temp ops set.

That looks not correct, as the caller should not have called this
function if the thermal zone is unable to read the temperature.

That makes the code less robust as the check won't detect the driver
is inconsistently using the thermal API and that does not help to
improve the framework as these circumvolutions hide the problem at the
source.

In order to detect the situation when it happens, let's add a warning
when the update is requested without the get_temp() ops set.

Any warning emitted will have to be fixed at the source of the
problem: the caller must not call thermal_zone_device_update if there
is not get_temp callback set.

Cc: Thara Gopinath <thara.gopinath@linaro.org>
Cc: Amit Kucheria <amitk@kernel.org>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
---
 drivers/thermal/thermal_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index dee40ff41177..e6771e5aeedb 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -548,7 +548,8 @@ void thermal_zone_device_update(struct thermal_zone_device *tz,
 	if (atomic_read(&in_suspend))
 		return;
 
-	if (!tz->ops->get_temp)
+	if (WARN_ONCE(!tz->ops->get_temp, "'%s' must not be called without "
+		      "'get_temp' ops set\n", __func__))
 		return;
 
 	update_temperature(tz);
-- 
2.17.1


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

* [PATCH 2/5] thermal/core: Add critical and hot ops
  2020-12-10 12:15 [PATCH 1/5] thermal/core: Emit a warning if the thermal zone is updated without ops Daniel Lezcano
@ 2020-12-10 12:15 ` Daniel Lezcano
  2020-12-10 12:44   ` Lukasz Luba
  2020-12-14 14:40   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
  2020-12-10 12:15 ` [PATCH 3/5] thermal/drivers/acpi: Use hot and critical ops Daniel Lezcano
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 18+ messages in thread
From: Daniel Lezcano @ 2020-12-10 12:15 UTC (permalink / raw)
  To: daniel.lezcano, rui.zhang
  Cc: kai.heng.feng, lukasz.luba, srinivas.pandruvada, linux-kernel,
	linux-pm, Amit Kucheria

Currently there is no way to the sensors to directly call an ops in
interrupt mode without calling thermal_zone_device_update assuming all
the trip points are defined.

A sensor may want to do something special if a trip point is hot or
critical.

This patch adds the critical and hot ops to the thermal zone device,
so a sensor can directly invoke them or let the thermal framework to
call the sensor specific ones.

Tested-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/thermal/thermal_core.c | 43 +++++++++++++++++++++-------------
 include/linux/thermal.h        |  3 +++
 2 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index e6771e5aeedb..cee0b31b5cd7 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -375,6 +375,25 @@ static void thermal_emergency_poweroff(void)
 			      msecs_to_jiffies(poweroff_delay_ms));
 }
 
+void thermal_zone_device_critical(struct thermal_zone_device *tz)
+{
+	dev_emerg(&tz->device, "%s: critical temperature reached, "
+		  "shutting down\n", tz->type);
+
+	mutex_lock(&poweroff_lock);
+	if (!power_off_triggered) {
+		/*
+		 * Queue a backup emergency shutdown in the event of
+		 * orderly_poweroff failure
+		 */
+		thermal_emergency_poweroff();
+		orderly_poweroff(true);
+		power_off_triggered = true;
+	}
+	mutex_unlock(&poweroff_lock);
+}
+EXPORT_SYMBOL(thermal_zone_device_critical);
+
 static void handle_critical_trips(struct thermal_zone_device *tz,
 				  int trip, enum thermal_trip_type trip_type)
 {
@@ -391,22 +410,10 @@ static void handle_critical_trips(struct thermal_zone_device *tz,
 	if (tz->ops->notify)
 		tz->ops->notify(tz, trip, trip_type);
 
-	if (trip_type == THERMAL_TRIP_CRITICAL) {
-		dev_emerg(&tz->device,
-			  "critical temperature reached (%d C), shutting down\n",
-			  tz->temperature / 1000);
-		mutex_lock(&poweroff_lock);
-		if (!power_off_triggered) {
-			/*
-			 * Queue a backup emergency shutdown in the event of
-			 * orderly_poweroff failure
-			 */
-			thermal_emergency_poweroff();
-			orderly_poweroff(true);
-			power_off_triggered = true;
-		}
-		mutex_unlock(&poweroff_lock);
-	}
+	if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot)
+		tz->ops->hot(tz);
+	else if (trip_type == THERMAL_TRIP_CRITICAL)
+		tz->ops->critical(tz);
 }
 
 static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
@@ -1331,6 +1338,10 @@ thermal_zone_device_register(const char *type, int trips, int mask,
 
 	tz->id = id;
 	strlcpy(tz->type, type, sizeof(tz->type));
+
+	if (!ops->critical)
+		ops->critical = thermal_zone_device_critical;
+
 	tz->ops = ops;
 	tz->tzp = tzp;
 	tz->device.class = &thermal_class;
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index f23a388ded15..125c8a4d52e6 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -79,6 +79,8 @@ struct thermal_zone_device_ops {
 			  enum thermal_trend *);
 	int (*notify) (struct thermal_zone_device *, int,
 		       enum thermal_trip_type);
+	void (*hot)(struct thermal_zone_device *);
+	void (*critical)(struct thermal_zone_device *);
 };
 
 struct thermal_cooling_device_ops {
@@ -399,6 +401,7 @@ void thermal_cdev_update(struct thermal_cooling_device *);
 void thermal_notify_framework(struct thermal_zone_device *, int);
 int thermal_zone_device_enable(struct thermal_zone_device *tz);
 int thermal_zone_device_disable(struct thermal_zone_device *tz);
+void thermal_zone_device_critical(struct thermal_zone_device *tz);
 #else
 static inline struct thermal_zone_device *thermal_zone_device_register(
 	const char *type, int trips, int mask, void *devdata,
-- 
2.17.1


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

* [PATCH 3/5] thermal/drivers/acpi: Use hot and critical ops
  2020-12-10 12:15 [PATCH 1/5] thermal/core: Emit a warning if the thermal zone is updated without ops Daniel Lezcano
  2020-12-10 12:15 ` [PATCH 2/5] thermal/core: Add critical and hot ops Daniel Lezcano
@ 2020-12-10 12:15 ` Daniel Lezcano
  2020-12-17  6:28   ` Daniel Lezcano
  2021-01-19 21:27   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
  2020-12-10 12:15 ` [PATCH 4/5] thermal/drivers/rcar: Remove notification usage Daniel Lezcano
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 18+ messages in thread
From: Daniel Lezcano @ 2020-12-10 12:15 UTC (permalink / raw)
  To: daniel.lezcano, rui.zhang
  Cc: kai.heng.feng, lukasz.luba, srinivas.pandruvada, linux-kernel,
	linux-pm, Rafael J. Wysocki, Len Brown,
	open list:ACPI THERMAL DRIVER

The acpi driver wants to do a netlink notification in case of a hot or
critical trip point. Implement the corresponding ops to be used for
the thermal zone and use them instead of the notify ops.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/acpi/thermal.c | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 12c0ece746f0..b5e4bc9e3282 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -677,27 +677,24 @@ static int thermal_get_trend(struct thermal_zone_device *thermal,
 	return 0;
 }
 
-
-static int thermal_notify(struct thermal_zone_device *thermal, int trip,
-			   enum thermal_trip_type trip_type)
+static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal)
 {
-	u8 type = 0;
 	struct acpi_thermal *tz = thermal->devdata;
 
-	if (trip_type == THERMAL_TRIP_CRITICAL)
-		type = ACPI_THERMAL_NOTIFY_CRITICAL;
-	else if (trip_type == THERMAL_TRIP_HOT)
-		type = ACPI_THERMAL_NOTIFY_HOT;
-	else
-		return 0;
-
 	acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
-					dev_name(&tz->device->dev), type, 1);
+					dev_name(&tz->device->dev),
+					ACPI_THERMAL_NOTIFY_HOT, 1);
+}
 
-	if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
-		return 1;
+static void acpi_thermal_zone_device_critical(struct thermal_zone_device *thermal)
+{
+	struct acpi_thermal *tz = thermal->devdata;
 
-	return 0;
+	acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
+					dev_name(&tz->device->dev),
+					ACPI_THERMAL_NOTIFY_CRITICAL, 1);
+
+	thermal_zone_device_critical(thermal);
 }
 
 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
@@ -812,7 +809,8 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
 	.get_trip_temp = thermal_get_trip_temp,
 	.get_crit_temp = thermal_get_crit_temp,
 	.get_trend = thermal_get_trend,
-	.notify = thermal_notify,
+	.hot = acpi_thermal_zone_device_hot,
+	.critical = acpi_thermal_zone_device_critical,
 };
 
 static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
-- 
2.17.1


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

* [PATCH 4/5] thermal/drivers/rcar: Remove notification usage
  2020-12-10 12:15 [PATCH 1/5] thermal/core: Emit a warning if the thermal zone is updated without ops Daniel Lezcano
  2020-12-10 12:15 ` [PATCH 2/5] thermal/core: Add critical and hot ops Daniel Lezcano
  2020-12-10 12:15 ` [PATCH 3/5] thermal/drivers/acpi: Use hot and critical ops Daniel Lezcano
@ 2020-12-10 12:15 ` Daniel Lezcano
  2020-12-10 16:10   ` Niklas Söderlund
  2020-12-15 18:17   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
  2020-12-10 12:15 ` [PATCH 5/5] thermal/core: Remove notify ops Daniel Lezcano
  2020-12-14 14:40 ` [thermal: thermal/next] thermal/core: Emit a warning if the thermal zone is updated without ops thermal-bot for Daniel Lezcano
  4 siblings, 2 replies; 18+ messages in thread
From: Daniel Lezcano @ 2020-12-10 12:15 UTC (permalink / raw)
  To: daniel.lezcano, rui.zhang
  Cc: kai.heng.feng, lukasz.luba, srinivas.pandruvada, linux-kernel,
	linux-pm, Niklas Söderlund, Amit Kucheria,
	open list:RENESAS R-CAR THERMAL DRIVERS

The ops is only showing a trace telling a critical trip point is
crossed. The same information is given by the thermal framework.

This is redundant, remove the code.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/thermal/rcar_thermal.c | 19 -------------------
 1 file changed, 19 deletions(-)

diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
index 6ae757d66f46..b49f04daaf47 100644
--- a/drivers/thermal/rcar_thermal.c
+++ b/drivers/thermal/rcar_thermal.c
@@ -323,24 +323,6 @@ static int rcar_thermal_get_trip_temp(struct thermal_zone_device *zone,
 	return 0;
 }
 
-static int rcar_thermal_notify(struct thermal_zone_device *zone,
-			       int trip, enum thermal_trip_type type)
-{
-	struct rcar_thermal_priv *priv = rcar_zone_to_priv(zone);
-	struct device *dev = rcar_priv_to_dev(priv);
-
-	switch (type) {
-	case THERMAL_TRIP_CRITICAL:
-		/* FIXME */
-		dev_warn(dev, "Thermal reached to critical temperature\n");
-		break;
-	default:
-		break;
-	}
-
-	return 0;
-}
-
 static const struct thermal_zone_of_device_ops rcar_thermal_zone_of_ops = {
 	.get_temp	= rcar_thermal_of_get_temp,
 };
@@ -349,7 +331,6 @@ static struct thermal_zone_device_ops rcar_thermal_zone_ops = {
 	.get_temp	= rcar_thermal_get_temp,
 	.get_trip_type	= rcar_thermal_get_trip_type,
 	.get_trip_temp	= rcar_thermal_get_trip_temp,
-	.notify		= rcar_thermal_notify,
 };
 
 /*
-- 
2.17.1


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

* [PATCH 5/5] thermal/core: Remove notify ops
  2020-12-10 12:15 [PATCH 1/5] thermal/core: Emit a warning if the thermal zone is updated without ops Daniel Lezcano
                   ` (2 preceding siblings ...)
  2020-12-10 12:15 ` [PATCH 4/5] thermal/drivers/rcar: Remove notification usage Daniel Lezcano
@ 2020-12-10 12:15 ` Daniel Lezcano
  2020-12-10 14:37   ` Lukasz Luba
  2021-01-19 21:27   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
  2020-12-14 14:40 ` [thermal: thermal/next] thermal/core: Emit a warning if the thermal zone is updated without ops thermal-bot for Daniel Lezcano
  4 siblings, 2 replies; 18+ messages in thread
From: Daniel Lezcano @ 2020-12-10 12:15 UTC (permalink / raw)
  To: daniel.lezcano, rui.zhang
  Cc: kai.heng.feng, lukasz.luba, srinivas.pandruvada, linux-kernel,
	linux-pm, Amit Kucheria

With the remove of the notify user in a previous patch, the ops is no
longer needed, remove it.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/thermal/thermal_core.c | 3 ---
 include/linux/thermal.h        | 2 --
 2 files changed, 5 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index cee0b31b5cd7..d7481fdf4e4c 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -407,9 +407,6 @@ static void handle_critical_trips(struct thermal_zone_device *tz,
 
 	trace_thermal_zone_trip(tz, trip, trip_type);
 
-	if (tz->ops->notify)
-		tz->ops->notify(tz, trip, trip_type);
-
 	if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot)
 		tz->ops->hot(tz);
 	else if (trip_type == THERMAL_TRIP_CRITICAL)
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 125c8a4d52e6..7e051b4cf715 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -77,8 +77,6 @@ struct thermal_zone_device_ops {
 	int (*set_emul_temp) (struct thermal_zone_device *, int);
 	int (*get_trend) (struct thermal_zone_device *, int,
 			  enum thermal_trend *);
-	int (*notify) (struct thermal_zone_device *, int,
-		       enum thermal_trip_type);
 	void (*hot)(struct thermal_zone_device *);
 	void (*critical)(struct thermal_zone_device *);
 };
-- 
2.17.1


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

* Re: [PATCH 2/5] thermal/core: Add critical and hot ops
  2020-12-10 12:15 ` [PATCH 2/5] thermal/core: Add critical and hot ops Daniel Lezcano
@ 2020-12-10 12:44   ` Lukasz Luba
  2020-12-10 13:37     ` Daniel Lezcano
  2020-12-14 14:40   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
  1 sibling, 1 reply; 18+ messages in thread
From: Lukasz Luba @ 2020-12-10 12:44 UTC (permalink / raw)
  To: Daniel Lezcano, rui.zhang
  Cc: kai.heng.feng, srinivas.pandruvada, linux-kernel, linux-pm,
	Amit Kucheria



On 12/10/20 12:15 PM, Daniel Lezcano wrote:
> Currently there is no way to the sensors to directly call an ops in
> interrupt mode without calling thermal_zone_device_update assuming all
> the trip points are defined.
> 
> A sensor may want to do something special if a trip point is hot or
> critical.
> 
> This patch adds the critical and hot ops to the thermal zone device,
> so a sensor can directly invoke them or let the thermal framework to
> call the sensor specific ones.
> 
> Tested-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> ---
>   drivers/thermal/thermal_core.c | 43 +++++++++++++++++++++-------------
>   include/linux/thermal.h        |  3 +++
>   2 files changed, 30 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index e6771e5aeedb..cee0b31b5cd7 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -375,6 +375,25 @@ static void thermal_emergency_poweroff(void)
>   			      msecs_to_jiffies(poweroff_delay_ms));
>   }
>   
> +void thermal_zone_device_critical(struct thermal_zone_device *tz)
> +{
> +	dev_emerg(&tz->device, "%s: critical temperature reached, "
> +		  "shutting down\n", tz->type);
> +
> +	mutex_lock(&poweroff_lock);
> +	if (!power_off_triggered) {
> +		/*
> +		 * Queue a backup emergency shutdown in the event of
> +		 * orderly_poweroff failure
> +		 */
> +		thermal_emergency_poweroff();
> +		orderly_poweroff(true);
> +		power_off_triggered = true;
> +	}
> +	mutex_unlock(&poweroff_lock);
> +}
> +EXPORT_SYMBOL(thermal_zone_device_critical);
> +
>   static void handle_critical_trips(struct thermal_zone_device *tz,
>   				  int trip, enum thermal_trip_type trip_type)
>   {
> @@ -391,22 +410,10 @@ static void handle_critical_trips(struct thermal_zone_device *tz,
>   	if (tz->ops->notify)
>   		tz->ops->notify(tz, trip, trip_type);
>   
> -	if (trip_type == THERMAL_TRIP_CRITICAL) {
> -		dev_emerg(&tz->device,
> -			  "critical temperature reached (%d C), shutting down\n",
> -			  tz->temperature / 1000);
> -		mutex_lock(&poweroff_lock);
> -		if (!power_off_triggered) {
> -			/*
> -			 * Queue a backup emergency shutdown in the event of
> -			 * orderly_poweroff failure
> -			 */
> -			thermal_emergency_poweroff();
> -			orderly_poweroff(true);
> -			power_off_triggered = true;
> -		}
> -		mutex_unlock(&poweroff_lock);
> -	}
> +	if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot)
> +		tz->ops->hot(tz);
> +	else if (trip_type == THERMAL_TRIP_CRITICAL)
> +		tz->ops->critical(tz);

I can see that in the patch 3/5 there driver .critical() callback
calls framework thermal_zone_device_critical() at the end.
I wonder if we could always call this framework function.

Something like a helper function always called:
void _handle_critical( *tz)
{
	if (tz->ops->critical)
		tz->ops->critical(tz);

	thermal_zone_device_critical(tz);
}

and then called:

	else if (trip_type == THERMAL_TRIP_CRITICAL)
		_handle_critical(tz);

>   }
>   
>   static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
> @@ -1331,6 +1338,10 @@ thermal_zone_device_register(const char *type, int trips, int mask,
>   
>   	tz->id = id;
>   	strlcpy(tz->type, type, sizeof(tz->type));
> +
> +	if (!ops->critical)
> +		ops->critical = thermal_zone_device_critical;

Then we could drop this default assignment.

> +
>   	tz->ops = ops;
>   	tz->tzp = tzp;
>   	tz->device.class = &thermal_class;
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index f23a388ded15..125c8a4d52e6 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -79,6 +79,8 @@ struct thermal_zone_device_ops {
>   			  enum thermal_trend *);
>   	int (*notify) (struct thermal_zone_device *, int,
>   		       enum thermal_trip_type);
> +	void (*hot)(struct thermal_zone_device *);
> +	void (*critical)(struct thermal_zone_device *);
>   };
>   
>   struct thermal_cooling_device_ops {
> @@ -399,6 +401,7 @@ void thermal_cdev_update(struct thermal_cooling_device *);
>   void thermal_notify_framework(struct thermal_zone_device *, int);
>   int thermal_zone_device_enable(struct thermal_zone_device *tz);
>   int thermal_zone_device_disable(struct thermal_zone_device *tz);
> +void thermal_zone_device_critical(struct thermal_zone_device *tz);
>   #else
>   static inline struct thermal_zone_device *thermal_zone_device_register(
>   	const char *type, int trips, int mask, void *devdata,
> 

I am just concerned about drivers which provide own .critical() callback
but forgot to call thermal_zone_device_critical() at the end and
framework could skip it.

Or we can make sure during the review that it's not an issue (and ignore
out of tree drivers)?

Regards,
Lukasz

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

* Re: [PATCH 2/5] thermal/core: Add critical and hot ops
  2020-12-10 12:44   ` Lukasz Luba
@ 2020-12-10 13:37     ` Daniel Lezcano
  2020-12-10 13:51       ` Lukasz Luba
  0 siblings, 1 reply; 18+ messages in thread
From: Daniel Lezcano @ 2020-12-10 13:37 UTC (permalink / raw)
  To: Lukasz Luba, rui.zhang
  Cc: kai.heng.feng, srinivas.pandruvada, linux-kernel, linux-pm,
	Amit Kucheria

On 10/12/2020 13:44, Lukasz Luba wrote:
> 
> 
> On 12/10/20 12:15 PM, Daniel Lezcano wrote:
>> Currently there is no way to the sensors to directly call an ops in
>> interrupt mode without calling thermal_zone_device_update assuming all
>> the trip points are defined.
>>
>> A sensor may want to do something special if a trip point is hot or
>> critical.
>>
>> This patch adds the critical and hot ops to the thermal zone device,
>> so a sensor can directly invoke them or let the thermal framework to
>> call the sensor specific ones.
>>
>> Tested-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
>> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
>> ---
>>   drivers/thermal/thermal_core.c | 43 +++++++++++++++++++++-------------
>>   include/linux/thermal.h        |  3 +++
>>   2 files changed, 30 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/thermal/thermal_core.c
>> b/drivers/thermal/thermal_core.c
>> index e6771e5aeedb..cee0b31b5cd7 100644
>> --- a/drivers/thermal/thermal_core.c
>> +++ b/drivers/thermal/thermal_core.c
>> @@ -375,6 +375,25 @@ static void thermal_emergency_poweroff(void)
>>                     msecs_to_jiffies(poweroff_delay_ms));
>>   }
>>   +void thermal_zone_device_critical(struct thermal_zone_device *tz)
>> +{
>> +    dev_emerg(&tz->device, "%s: critical temperature reached, "
>> +          "shutting down\n", tz->type);
>> +
>> +    mutex_lock(&poweroff_lock);
>> +    if (!power_off_triggered) {
>> +        /*
>> +         * Queue a backup emergency shutdown in the event of
>> +         * orderly_poweroff failure
>> +         */
>> +        thermal_emergency_poweroff();
>> +        orderly_poweroff(true);
>> +        power_off_triggered = true;
>> +    }
>> +    mutex_unlock(&poweroff_lock);
>> +}
>> +EXPORT_SYMBOL(thermal_zone_device_critical);
>> +
>>   static void handle_critical_trips(struct thermal_zone_device *tz,
>>                     int trip, enum thermal_trip_type trip_type)
>>   {
>> @@ -391,22 +410,10 @@ static void handle_critical_trips(struct
>> thermal_zone_device *tz,
>>       if (tz->ops->notify)
>>           tz->ops->notify(tz, trip, trip_type);
>>   -    if (trip_type == THERMAL_TRIP_CRITICAL) {
>> -        dev_emerg(&tz->device,
>> -              "critical temperature reached (%d C), shutting down\n",
>> -              tz->temperature / 1000);
>> -        mutex_lock(&poweroff_lock);
>> -        if (!power_off_triggered) {
>> -            /*
>> -             * Queue a backup emergency shutdown in the event of
>> -             * orderly_poweroff failure
>> -             */
>> -            thermal_emergency_poweroff();
>> -            orderly_poweroff(true);
>> -            power_off_triggered = true;
>> -        }
>> -        mutex_unlock(&poweroff_lock);
>> -    }
>> +    if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot)
>> +        tz->ops->hot(tz);
>> +    else if (trip_type == THERMAL_TRIP_CRITICAL)
>> +        tz->ops->critical(tz);
> 
> I can see that in the patch 3/5 there driver .critical() callback
> calls framework thermal_zone_device_critical() at the end.
> I wonder if we could always call this framework function.

It is actually done on purpose, we want to let the driver to handle the
critical routine which may not end up with an emergency shutdown.

[ ... ]

>>   #else
>>   static inline struct thermal_zone_device *thermal_zone_device_register(
>>       const char *type, int trips, int mask, void *devdata,
>>
> 
> I am just concerned about drivers which provide own .critical() callback
> but forgot to call thermal_zone_device_critical() at the end and
> framework could skip it.
> 
> Or we can make sure during the review that it's not an issue (and ignore
> out of tree drivers)?

Yes, the framework guarantees if the critical trip point is crossed we
call the emergency shutdown by default. If the driver choose to override
it, it takes responsibility of the change.



-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

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

* Re: [PATCH 2/5] thermal/core: Add critical and hot ops
  2020-12-10 13:37     ` Daniel Lezcano
@ 2020-12-10 13:51       ` Lukasz Luba
  0 siblings, 0 replies; 18+ messages in thread
From: Lukasz Luba @ 2020-12-10 13:51 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: rui.zhang, kai.heng.feng, srinivas.pandruvada, linux-kernel,
	linux-pm, Amit Kucheria



On 12/10/20 1:37 PM, Daniel Lezcano wrote:
> On 10/12/2020 13:44, Lukasz Luba wrote:
>>
>>
>> On 12/10/20 12:15 PM, Daniel Lezcano wrote:
>>> Currently there is no way to the sensors to directly call an ops in
>>> interrupt mode without calling thermal_zone_device_update assuming all
>>> the trip points are defined.
>>>
>>> A sensor may want to do something special if a trip point is hot or
>>> critical.
>>>
>>> This patch adds the critical and hot ops to the thermal zone device,
>>> so a sensor can directly invoke them or let the thermal framework to
>>> call the sensor specific ones.
>>>
>>> Tested-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
>>> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
>>> ---
>>>    drivers/thermal/thermal_core.c | 43 +++++++++++++++++++++-------------
>>>    include/linux/thermal.h        |  3 +++
>>>    2 files changed, 30 insertions(+), 16 deletions(-)
>>>
>>> diff --git a/drivers/thermal/thermal_core.c
>>> b/drivers/thermal/thermal_core.c
>>> index e6771e5aeedb..cee0b31b5cd7 100644
>>> --- a/drivers/thermal/thermal_core.c
>>> +++ b/drivers/thermal/thermal_core.c
>>> @@ -375,6 +375,25 @@ static void thermal_emergency_poweroff(void)
>>>                      msecs_to_jiffies(poweroff_delay_ms));
>>>    }
>>>    +void thermal_zone_device_critical(struct thermal_zone_device *tz)
>>> +{
>>> +    dev_emerg(&tz->device, "%s: critical temperature reached, "
>>> +          "shutting down\n", tz->type);
>>> +
>>> +    mutex_lock(&poweroff_lock);
>>> +    if (!power_off_triggered) {
>>> +        /*
>>> +         * Queue a backup emergency shutdown in the event of
>>> +         * orderly_poweroff failure
>>> +         */
>>> +        thermal_emergency_poweroff();
>>> +        orderly_poweroff(true);
>>> +        power_off_triggered = true;
>>> +    }
>>> +    mutex_unlock(&poweroff_lock);
>>> +}
>>> +EXPORT_SYMBOL(thermal_zone_device_critical);
>>> +
>>>    static void handle_critical_trips(struct thermal_zone_device *tz,
>>>                      int trip, enum thermal_trip_type trip_type)
>>>    {
>>> @@ -391,22 +410,10 @@ static void handle_critical_trips(struct
>>> thermal_zone_device *tz,
>>>        if (tz->ops->notify)
>>>            tz->ops->notify(tz, trip, trip_type);
>>>    -    if (trip_type == THERMAL_TRIP_CRITICAL) {
>>> -        dev_emerg(&tz->device,
>>> -              "critical temperature reached (%d C), shutting down\n",
>>> -              tz->temperature / 1000);
>>> -        mutex_lock(&poweroff_lock);
>>> -        if (!power_off_triggered) {
>>> -            /*
>>> -             * Queue a backup emergency shutdown in the event of
>>> -             * orderly_poweroff failure
>>> -             */
>>> -            thermal_emergency_poweroff();
>>> -            orderly_poweroff(true);
>>> -            power_off_triggered = true;
>>> -        }
>>> -        mutex_unlock(&poweroff_lock);
>>> -    }
>>> +    if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot)
>>> +        tz->ops->hot(tz);
>>> +    else if (trip_type == THERMAL_TRIP_CRITICAL)
>>> +        tz->ops->critical(tz);
>>
>> I can see that in the patch 3/5 there driver .critical() callback
>> calls framework thermal_zone_device_critical() at the end.
>> I wonder if we could always call this framework function.
> 
> It is actually done on purpose, we want to let the driver to handle the
> critical routine which may not end up with an emergency shutdown.

I see.

> 
> [ ... ]
> 
>>>    #else
>>>    static inline struct thermal_zone_device *thermal_zone_device_register(
>>>        const char *type, int trips, int mask, void *devdata,
>>>
>>
>> I am just concerned about drivers which provide own .critical() callback
>> but forgot to call thermal_zone_device_critical() at the end and
>> framework could skip it.
>>
>> Or we can make sure during the review that it's not an issue (and ignore
>> out of tree drivers)?
> 
> Yes, the framework guarantees if the critical trip point is crossed we
> call the emergency shutdown by default. If the driver choose to override
> it, it takes responsibility of the change.
> 

Fair enough. Thus, the patch LGTM

Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>

Regards,
Lukasz



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

* Re: [PATCH 5/5] thermal/core: Remove notify ops
  2020-12-10 12:15 ` [PATCH 5/5] thermal/core: Remove notify ops Daniel Lezcano
@ 2020-12-10 14:37   ` Lukasz Luba
  2021-01-19 21:27   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
  1 sibling, 0 replies; 18+ messages in thread
From: Lukasz Luba @ 2020-12-10 14:37 UTC (permalink / raw)
  To: Daniel Lezcano, rui.zhang
  Cc: kai.heng.feng, srinivas.pandruvada, linux-kernel, linux-pm,
	Amit Kucheria



On 12/10/20 12:15 PM, Daniel Lezcano wrote:
> With the remove of the notify user in a previous patch, the ops is no
> longer needed, remove it.
> 
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> ---
>   drivers/thermal/thermal_core.c | 3 ---
>   include/linux/thermal.h        | 2 --
>   2 files changed, 5 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index cee0b31b5cd7..d7481fdf4e4c 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -407,9 +407,6 @@ static void handle_critical_trips(struct thermal_zone_device *tz,
>   
>   	trace_thermal_zone_trip(tz, trip, trip_type);
>   
> -	if (tz->ops->notify)
> -		tz->ops->notify(tz, trip, trip_type);
> -
>   	if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot)
>   		tz->ops->hot(tz);
>   	else if (trip_type == THERMAL_TRIP_CRITICAL)
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index 125c8a4d52e6..7e051b4cf715 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -77,8 +77,6 @@ struct thermal_zone_device_ops {
>   	int (*set_emul_temp) (struct thermal_zone_device *, int);
>   	int (*get_trend) (struct thermal_zone_device *, int,
>   			  enum thermal_trend *);
> -	int (*notify) (struct thermal_zone_device *, int,
> -		       enum thermal_trip_type);
>   	void (*hot)(struct thermal_zone_device *);
>   	void (*critical)(struct thermal_zone_device *);
>   };
> 

I couldn't find other users apart from those in patch 3/5 and 4/5.
I will leave to someone else to review those patches.
This patch looks good

Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>

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

* Re: [PATCH 4/5] thermal/drivers/rcar: Remove notification usage
  2020-12-10 12:15 ` [PATCH 4/5] thermal/drivers/rcar: Remove notification usage Daniel Lezcano
@ 2020-12-10 16:10   ` Niklas Söderlund
  2020-12-15 18:17   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
  1 sibling, 0 replies; 18+ messages in thread
From: Niklas Söderlund @ 2020-12-10 16:10 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: rui.zhang, kai.heng.feng, lukasz.luba, srinivas.pandruvada,
	linux-kernel, linux-pm, Amit Kucheria,
	open list:RENESAS R-CAR THERMAL DRIVERS

Hi Daniel,

Thanks for your work.

On 2020-12-10 13:15:13 +0100, Daniel Lezcano wrote:
> The ops is only showing a trace telling a critical trip point is
> crossed. The same information is given by the thermal framework.
> 
> This is redundant, remove the code.
> 
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

> ---
>  drivers/thermal/rcar_thermal.c | 19 -------------------
>  1 file changed, 19 deletions(-)
> 
> diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
> index 6ae757d66f46..b49f04daaf47 100644
> --- a/drivers/thermal/rcar_thermal.c
> +++ b/drivers/thermal/rcar_thermal.c
> @@ -323,24 +323,6 @@ static int rcar_thermal_get_trip_temp(struct thermal_zone_device *zone,
>  	return 0;
>  }
>  
> -static int rcar_thermal_notify(struct thermal_zone_device *zone,
> -			       int trip, enum thermal_trip_type type)
> -{
> -	struct rcar_thermal_priv *priv = rcar_zone_to_priv(zone);
> -	struct device *dev = rcar_priv_to_dev(priv);
> -
> -	switch (type) {
> -	case THERMAL_TRIP_CRITICAL:
> -		/* FIXME */
> -		dev_warn(dev, "Thermal reached to critical temperature\n");
> -		break;
> -	default:
> -		break;
> -	}
> -
> -	return 0;
> -}
> -
>  static const struct thermal_zone_of_device_ops rcar_thermal_zone_of_ops = {
>  	.get_temp	= rcar_thermal_of_get_temp,
>  };
> @@ -349,7 +331,6 @@ static struct thermal_zone_device_ops rcar_thermal_zone_ops = {
>  	.get_temp	= rcar_thermal_get_temp,
>  	.get_trip_type	= rcar_thermal_get_trip_type,
>  	.get_trip_temp	= rcar_thermal_get_trip_temp,
> -	.notify		= rcar_thermal_notify,
>  };
>  
>  /*
> -- 
> 2.17.1
> 

-- 
Regards,
Niklas Söderlund

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

* [thermal: thermal/next] thermal/core: Emit a warning if the thermal zone is updated without ops
  2020-12-10 12:15 [PATCH 1/5] thermal/core: Emit a warning if the thermal zone is updated without ops Daniel Lezcano
                   ` (3 preceding siblings ...)
  2020-12-10 12:15 ` [PATCH 5/5] thermal/core: Remove notify ops Daniel Lezcano
@ 2020-12-14 14:40 ` thermal-bot for Daniel Lezcano
  4 siblings, 0 replies; 18+ messages in thread
From: thermal-bot for Daniel Lezcano @ 2020-12-14 14:40 UTC (permalink / raw)
  To: linux-pm
  Cc: Thara Gopinath, Amit Kucheria, linux-pm, linux-kernel,
	Daniel Lezcano, Lukasz Luba, rui.zhang

The following commit has been merged into the thermal/next branch of thermal:

Commit-ID:     433178e75834dc35f1ae79b56ec2cf396f2c6f3c
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//433178e75834dc35f1ae79b56ec2cf396f2c6f3c
Author:        Daniel Lezcano <daniel.lezcano@linaro.org>
AuthorDate:    Thu, 10 Dec 2020 13:15:10 +01:00
Committer:     Daniel Lezcano <daniel.lezcano@linaro.org>
CommitterDate: Fri, 11 Dec 2020 14:11:13 +01:00

thermal/core: Emit a warning if the thermal zone is updated without ops

The actual code is silently ignoring a thermal zone update when a
driver is requesting it without a get_temp ops set.

That looks not correct, as the caller should not have called this
function if the thermal zone is unable to read the temperature.

That makes the code less robust as the check won't detect the driver
is inconsistently using the thermal API and that does not help to
improve the framework as these circumvolutions hide the problem at the
source.

In order to detect the situation when it happens, let's add a warning
when the update is requested without the get_temp() ops set.

Any warning emitted will have to be fixed at the source of the
problem: the caller must not call thermal_zone_device_update if there
is not get_temp callback set.

Cc: Thara Gopinath <thara.gopinath@linaro.org>
Cc: Amit Kucheria <amitk@kernel.org>
Cc: linux-pm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://lore.kernel.org/r/20201210121514.25760-1-daniel.lezcano@linaro.org
---
 drivers/thermal/thermal_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 90e38cc..64de098 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -553,7 +553,8 @@ void thermal_zone_device_update(struct thermal_zone_device *tz,
 	if (atomic_read(&in_suspend))
 		return;
 
-	if (!tz->ops->get_temp)
+	if (WARN_ONCE(!tz->ops->get_temp, "'%s' must not be called without "
+		      "'get_temp' ops set\n", __func__))
 		return;
 
 	update_temperature(tz);

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

* [thermal: thermal/next] thermal/core: Add critical and hot ops
  2020-12-10 12:15 ` [PATCH 2/5] thermal/core: Add critical and hot ops Daniel Lezcano
  2020-12-10 12:44   ` Lukasz Luba
@ 2020-12-14 14:40   ` thermal-bot for Daniel Lezcano
  1 sibling, 0 replies; 18+ messages in thread
From: thermal-bot for Daniel Lezcano @ 2020-12-14 14:40 UTC (permalink / raw)
  To: linux-pm; +Cc: Kai-Heng Feng, Daniel Lezcano, Lukasz Luba, rui.zhang, amitk

The following commit has been merged into the thermal/next branch of thermal:

Commit-ID:     d7203eedf4f68e9909fd489453168a9d26bf0c3d
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//d7203eedf4f68e9909fd489453168a9d26bf0c3d
Author:        Daniel Lezcano <daniel.lezcano@linaro.org>
AuthorDate:    Thu, 10 Dec 2020 13:15:11 +01:00
Committer:     Daniel Lezcano <daniel.lezcano@linaro.org>
CommitterDate: Fri, 11 Dec 2020 14:11:13 +01:00

thermal/core: Add critical and hot ops

Currently there is no way to the sensors to directly call an ops in
interrupt mode without calling thermal_zone_device_update assuming all
the trip points are defined.

A sensor may want to do something special if a trip point is hot or
critical.

This patch adds the critical and hot ops to the thermal zone device,
so a sensor can directly invoke them or let the thermal framework to
call the sensor specific ones.

Tested-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://lore.kernel.org/r/20201210121514.25760-2-daniel.lezcano@linaro.org
---
 drivers/thermal/thermal_core.c | 43 ++++++++++++++++++++-------------
 include/linux/thermal.h        |  3 ++-
 2 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 64de098..4a291d2 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -380,6 +380,25 @@ static void thermal_emergency_poweroff(void)
 			      msecs_to_jiffies(poweroff_delay_ms));
 }
 
+void thermal_zone_device_critical(struct thermal_zone_device *tz)
+{
+	dev_emerg(&tz->device, "%s: critical temperature reached, "
+		  "shutting down\n", tz->type);
+
+	mutex_lock(&poweroff_lock);
+	if (!power_off_triggered) {
+		/*
+		 * Queue a backup emergency shutdown in the event of
+		 * orderly_poweroff failure
+		 */
+		thermal_emergency_poweroff();
+		orderly_poweroff(true);
+		power_off_triggered = true;
+	}
+	mutex_unlock(&poweroff_lock);
+}
+EXPORT_SYMBOL(thermal_zone_device_critical);
+
 static void handle_critical_trips(struct thermal_zone_device *tz,
 				  int trip, enum thermal_trip_type trip_type)
 {
@@ -396,22 +415,10 @@ static void handle_critical_trips(struct thermal_zone_device *tz,
 	if (tz->ops->notify)
 		tz->ops->notify(tz, trip, trip_type);
 
-	if (trip_type == THERMAL_TRIP_CRITICAL) {
-		dev_emerg(&tz->device,
-			  "critical temperature reached (%d C), shutting down\n",
-			  tz->temperature / 1000);
-		mutex_lock(&poweroff_lock);
-		if (!power_off_triggered) {
-			/*
-			 * Queue a backup emergency shutdown in the event of
-			 * orderly_poweroff failure
-			 */
-			thermal_emergency_poweroff();
-			orderly_poweroff(true);
-			power_off_triggered = true;
-		}
-		mutex_unlock(&poweroff_lock);
-	}
+	if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot)
+		tz->ops->hot(tz);
+	else if (trip_type == THERMAL_TRIP_CRITICAL)
+		tz->ops->critical(tz);
 }
 
 static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
@@ -1336,6 +1343,10 @@ thermal_zone_device_register(const char *type, int trips, int mask,
 
 	tz->id = id;
 	strlcpy(tz->type, type, sizeof(tz->type));
+
+	if (!ops->critical)
+		ops->critical = thermal_zone_device_critical;
+
 	tz->ops = ops;
 	tz->tzp = tzp;
 	tz->device.class = &thermal_class;
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index d07ea27..31b8440 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -79,6 +79,8 @@ struct thermal_zone_device_ops {
 			  enum thermal_trend *);
 	int (*notify) (struct thermal_zone_device *, int,
 		       enum thermal_trip_type);
+	void (*hot)(struct thermal_zone_device *);
+	void (*critical)(struct thermal_zone_device *);
 };
 
 struct thermal_cooling_device_ops {
@@ -399,6 +401,7 @@ void thermal_cdev_update(struct thermal_cooling_device *);
 void thermal_notify_framework(struct thermal_zone_device *, int);
 int thermal_zone_device_enable(struct thermal_zone_device *tz);
 int thermal_zone_device_disable(struct thermal_zone_device *tz);
+void thermal_zone_device_critical(struct thermal_zone_device *tz);
 #else
 static inline struct thermal_zone_device *thermal_zone_device_register(
 	const char *type, int trips, int mask, void *devdata,

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

* [thermal: thermal/next] thermal/drivers/rcar: Remove notification usage
  2020-12-10 12:15 ` [PATCH 4/5] thermal/drivers/rcar: Remove notification usage Daniel Lezcano
  2020-12-10 16:10   ` Niklas Söderlund
@ 2020-12-15 18:17   ` thermal-bot for Daniel Lezcano
  1 sibling, 0 replies; 18+ messages in thread
From: thermal-bot for Daniel Lezcano @ 2020-12-15 18:17 UTC (permalink / raw)
  To: linux-pm; +Cc: Daniel Lezcano, niklas.soderlund+renesas, rui.zhang, amitk

The following commit has been merged into the thermal/next branch of thermal:

Commit-ID:     1fa34e49e4b7e66214a1d15261c0224d60366eec
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//1fa34e49e4b7e66214a1d15261c0224d60366eec
Author:        Daniel Lezcano <daniel.lezcano@linaro.org>
AuthorDate:    Thu, 10 Dec 2020 13:15:13 +01:00
Committer:     Daniel Lezcano <daniel.lezcano@linaro.org>
CommitterDate: Tue, 15 Dec 2020 17:01:55 +01:00

thermal/drivers/rcar: Remove notification usage

The ops is only showing a trace telling a critical trip point is
crossed. The same information is given by the thermal framework.

This is redundant, remove the code.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Link: https://lore.kernel.org/r/20201210121514.25760-4-daniel.lezcano@linaro.org
---
 drivers/thermal/rcar_thermal.c | 19 -------------------
 1 file changed, 19 deletions(-)

diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
index 6ae757d..b49f04d 100644
--- a/drivers/thermal/rcar_thermal.c
+++ b/drivers/thermal/rcar_thermal.c
@@ -323,24 +323,6 @@ static int rcar_thermal_get_trip_temp(struct thermal_zone_device *zone,
 	return 0;
 }
 
-static int rcar_thermal_notify(struct thermal_zone_device *zone,
-			       int trip, enum thermal_trip_type type)
-{
-	struct rcar_thermal_priv *priv = rcar_zone_to_priv(zone);
-	struct device *dev = rcar_priv_to_dev(priv);
-
-	switch (type) {
-	case THERMAL_TRIP_CRITICAL:
-		/* FIXME */
-		dev_warn(dev, "Thermal reached to critical temperature\n");
-		break;
-	default:
-		break;
-	}
-
-	return 0;
-}
-
 static const struct thermal_zone_of_device_ops rcar_thermal_zone_of_ops = {
 	.get_temp	= rcar_thermal_of_get_temp,
 };
@@ -349,7 +331,6 @@ static struct thermal_zone_device_ops rcar_thermal_zone_ops = {
 	.get_temp	= rcar_thermal_get_temp,
 	.get_trip_type	= rcar_thermal_get_trip_type,
 	.get_trip_temp	= rcar_thermal_get_trip_temp,
-	.notify		= rcar_thermal_notify,
 };
 
 /*

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

* Re: [PATCH 3/5] thermal/drivers/acpi: Use hot and critical ops
  2020-12-10 12:15 ` [PATCH 3/5] thermal/drivers/acpi: Use hot and critical ops Daniel Lezcano
@ 2020-12-17  6:28   ` Daniel Lezcano
  2020-12-17 11:38     ` Srinivas Pandruvada
  2021-01-19 21:27   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
  1 sibling, 1 reply; 18+ messages in thread
From: Daniel Lezcano @ 2020-12-17  6:28 UTC (permalink / raw)
  To: rui.zhang
  Cc: kai.heng.feng, lukasz.luba, srinivas.pandruvada, linux-kernel,
	linux-pm, Rafael J. Wysocki, Len Brown,
	open list:ACPI THERMAL DRIVER

On 10/12/2020 13:15, Daniel Lezcano wrote:
> The acpi driver wants to do a netlink notification in case of a hot or
> critical trip point. Implement the corresponding ops to be used for
> the thermal zone and use them instead of the notify ops.
> 
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

Is there any comment on this patch ?

> ---
>  drivers/acpi/thermal.c | 30 ++++++++++++++----------------
>  1 file changed, 14 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
> index 12c0ece746f0..b5e4bc9e3282 100644
> --- a/drivers/acpi/thermal.c
> +++ b/drivers/acpi/thermal.c
> @@ -677,27 +677,24 @@ static int thermal_get_trend(struct thermal_zone_device *thermal,
>  	return 0;
>  }
>  
> -
> -static int thermal_notify(struct thermal_zone_device *thermal, int trip,
> -			   enum thermal_trip_type trip_type)
> +static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal)
>  {
> -	u8 type = 0;
>  	struct acpi_thermal *tz = thermal->devdata;
>  
> -	if (trip_type == THERMAL_TRIP_CRITICAL)
> -		type = ACPI_THERMAL_NOTIFY_CRITICAL;
> -	else if (trip_type == THERMAL_TRIP_HOT)
> -		type = ACPI_THERMAL_NOTIFY_HOT;
> -	else
> -		return 0;
> -
>  	acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
> -					dev_name(&tz->device->dev), type, 1);
> +					dev_name(&tz->device->dev),
> +					ACPI_THERMAL_NOTIFY_HOT, 1);
> +}
>  
> -	if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
> -		return 1;
> +static void acpi_thermal_zone_device_critical(struct thermal_zone_device *thermal)
> +{
> +	struct acpi_thermal *tz = thermal->devdata;
>  
> -	return 0;
> +	acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
> +					dev_name(&tz->device->dev),
> +					ACPI_THERMAL_NOTIFY_CRITICAL, 1);
> +
> +	thermal_zone_device_critical(thermal);
>  }
>  
>  static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
> @@ -812,7 +809,8 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
>  	.get_trip_temp = thermal_get_trip_temp,
>  	.get_crit_temp = thermal_get_crit_temp,
>  	.get_trend = thermal_get_trend,
> -	.notify = thermal_notify,
> +	.hot = acpi_thermal_zone_device_hot,
> +	.critical = acpi_thermal_zone_device_critical,
>  };
>  
>  static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
> 


-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

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

* Re: [PATCH 3/5] thermal/drivers/acpi: Use hot and critical ops
  2020-12-17  6:28   ` Daniel Lezcano
@ 2020-12-17 11:38     ` Srinivas Pandruvada
  2020-12-17 13:10       ` Daniel Lezcano
  0 siblings, 1 reply; 18+ messages in thread
From: Srinivas Pandruvada @ 2020-12-17 11:38 UTC (permalink / raw)
  To: Daniel Lezcano, rui.zhang
  Cc: kai.heng.feng, lukasz.luba, linux-kernel, linux-pm,
	Rafael J. Wysocki, Len Brown, open list:ACPI THERMAL DRIVER

On Thu, 2020-12-17 at 07:28 +0100, Daniel Lezcano wrote:
> On 10/12/2020 13:15, Daniel Lezcano wrote:
> > The acpi driver wants to do a netlink notification in case of a hot
> > or
> > critical trip point. Implement the corresponding ops to be used for
> > the thermal zone and use them instead of the notify ops.
> > 
> > Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> 
> Is there any comment on this patch ?

Looks good to me.

Thanks,
Srinivas

> 
> > ---
> >  drivers/acpi/thermal.c | 30 ++++++++++++++----------------
> >  1 file changed, 14 insertions(+), 16 deletions(-)
> > 
> > diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
> > index 12c0ece746f0..b5e4bc9e3282 100644
> > --- a/drivers/acpi/thermal.c
> > +++ b/drivers/acpi/thermal.c
> > @@ -677,27 +677,24 @@ static int thermal_get_trend(struct
> > thermal_zone_device *thermal,
> >         return 0;
> >  }
> >  
> > -
> > -static int thermal_notify(struct thermal_zone_device *thermal, int
> > trip,
> > -                          enum thermal_trip_type trip_type)
> > +static void acpi_thermal_zone_device_hot(struct
> > thermal_zone_device *thermal)
> >  {
> > -       u8 type = 0;
> >         struct acpi_thermal *tz = thermal->devdata;
> >  
> > -       if (trip_type == THERMAL_TRIP_CRITICAL)
> > -               type = ACPI_THERMAL_NOTIFY_CRITICAL;
> > -       else if (trip_type == THERMAL_TRIP_HOT)
> > -               type = ACPI_THERMAL_NOTIFY_HOT;
> > -       else
> > -               return 0;
> > -
> >         acpi_bus_generate_netlink_event(tz->device-
> > >pnp.device_class,
> > -                                       dev_name(&tz->device->dev),
> > type, 1);
> > +                                       dev_name(&tz->device->dev),
> > +                                       ACPI_THERMAL_NOTIFY_HOT,
> > 1);
> > +}
> >  
> > -       if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
> > -               return 1;
> > +static void acpi_thermal_zone_device_critical(struct
> > thermal_zone_device *thermal)
> > +{
> > +       struct acpi_thermal *tz = thermal->devdata;
> >  
> > -       return 0;
> > +       acpi_bus_generate_netlink_event(tz->device-
> > >pnp.device_class,
> > +                                       dev_name(&tz->device->dev),
> > +                                       ACPI_THERMAL_NOTIFY_CRITICA
> > L, 1);
> > +
> > +       thermal_zone_device_critical(thermal);
> >  }
> >  
> >  static int acpi_thermal_cooling_device_cb(struct
> > thermal_zone_device *thermal,
> > @@ -812,7 +809,8 @@ static struct thermal_zone_device_ops
> > acpi_thermal_zone_ops = {
> >         .get_trip_temp = thermal_get_trip_temp,
> >         .get_crit_temp = thermal_get_crit_temp,
> >         .get_trend = thermal_get_trend,
> > -       .notify = thermal_notify,
> > +       .hot = acpi_thermal_zone_device_hot,
> > +       .critical = acpi_thermal_zone_device_critical,
> >  };
> >  
> >  static int acpi_thermal_register_thermal_zone(struct acpi_thermal
> > *tz)
> > 
> 
> 



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

* Re: [PATCH 3/5] thermal/drivers/acpi: Use hot and critical ops
  2020-12-17 11:38     ` Srinivas Pandruvada
@ 2020-12-17 13:10       ` Daniel Lezcano
  0 siblings, 0 replies; 18+ messages in thread
From: Daniel Lezcano @ 2020-12-17 13:10 UTC (permalink / raw)
  To: Srinivas Pandruvada, rui.zhang
  Cc: kai.heng.feng, lukasz.luba, linux-kernel, linux-pm,
	Rafael J. Wysocki, Len Brown, open list:ACPI THERMAL DRIVER

On 17/12/2020 12:38, Srinivas Pandruvada wrote:
> On Thu, 2020-12-17 at 07:28 +0100, Daniel Lezcano wrote:
>> On 10/12/2020 13:15, Daniel Lezcano wrote:
>>> The acpi driver wants to do a netlink notification in case of a hot
>>> or
>>> critical trip point. Implement the corresponding ops to be used for
>>> the thermal zone and use them instead of the notify ops.
>>>
>>> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
>>
>> Is there any comment on this patch ?
> 
> Looks good to me.

Thanks for reviewing


-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

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

* [thermal: thermal/next] thermal/core: Remove notify ops
  2020-12-10 12:15 ` [PATCH 5/5] thermal/core: Remove notify ops Daniel Lezcano
  2020-12-10 14:37   ` Lukasz Luba
@ 2021-01-19 21:27   ` thermal-bot for Daniel Lezcano
  1 sibling, 0 replies; 18+ messages in thread
From: thermal-bot for Daniel Lezcano @ 2021-01-19 21:27 UTC (permalink / raw)
  To: linux-pm; +Cc: Daniel Lezcano, Lukasz Luba, rui.zhang, amitk

The following commit has been merged into the thermal/next branch of thermal:

Commit-ID:     04f111130e9afa41c10d7bcec14e00e3be8b6977
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//04f111130e9afa41c10d7bcec14e00e3be8b6977
Author:        Daniel Lezcano <daniel.lezcano@linaro.org>
AuthorDate:    Thu, 10 Dec 2020 13:15:14 +01:00
Committer:     Daniel Lezcano <daniel.lezcano@linaro.org>
CommitterDate: Thu, 07 Jan 2021 17:48:56 +01:00

thermal/core: Remove notify ops

With the removal of the notifys user in a previous patches, the ops is no
longer needed, remove it.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://lore.kernel.org/r/20201210121514.25760-5-daniel.lezcano@linaro.org
---
 drivers/thermal/thermal_core.c | 3 ---
 include/linux/thermal.h        | 2 --
 2 files changed, 5 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 4a291d2..567bc6f 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -412,9 +412,6 @@ static void handle_critical_trips(struct thermal_zone_device *tz,
 
 	trace_thermal_zone_trip(tz, trip, trip_type);
 
-	if (tz->ops->notify)
-		tz->ops->notify(tz, trip, trip_type);
-
 	if (trip_type == THERMAL_TRIP_HOT && tz->ops->hot)
 		tz->ops->hot(tz);
 	else if (trip_type == THERMAL_TRIP_CRITICAL)
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 31b8440..c800323 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -77,8 +77,6 @@ struct thermal_zone_device_ops {
 	int (*set_emul_temp) (struct thermal_zone_device *, int);
 	int (*get_trend) (struct thermal_zone_device *, int,
 			  enum thermal_trend *);
-	int (*notify) (struct thermal_zone_device *, int,
-		       enum thermal_trip_type);
 	void (*hot)(struct thermal_zone_device *);
 	void (*critical)(struct thermal_zone_device *);
 };

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

* [thermal: thermal/next] thermal/drivers/acpi: Use hot and critical ops
  2020-12-10 12:15 ` [PATCH 3/5] thermal/drivers/acpi: Use hot and critical ops Daniel Lezcano
  2020-12-17  6:28   ` Daniel Lezcano
@ 2021-01-19 21:27   ` thermal-bot for Daniel Lezcano
  1 sibling, 0 replies; 18+ messages in thread
From: thermal-bot for Daniel Lezcano @ 2021-01-19 21:27 UTC (permalink / raw)
  To: linux-pm; +Cc: Daniel Lezcano, Srinivas Pandruvada, rui.zhang, amitk

The following commit has been merged into the thermal/next branch of thermal:

Commit-ID:     a73cb2024caa3480263a009dce91fa581b3748bf
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//a73cb2024caa3480263a009dce91fa581b3748bf
Author:        Daniel Lezcano <daniel.lezcano@linaro.org>
AuthorDate:    Thu, 10 Dec 2020 13:15:12 +01:00
Committer:     Daniel Lezcano <daniel.lezcano@linaro.org>
CommitterDate: Thu, 07 Jan 2021 17:48:55 +01:00

thermal/drivers/acpi: Use hot and critical ops

The acpi driver wants to do a netlink notification in case of a hot or
critical trip point. Implement the corresponding ops to be used for
the thermal zone and use them instead of the notify ops.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Link: https://lore.kernel.org/r/20201210121514.25760-3-daniel.lezcano@linaro.org
---
 drivers/acpi/thermal.c | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 12c0ece..b5e4bc9 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -677,27 +677,24 @@ static int thermal_get_trend(struct thermal_zone_device *thermal,
 	return 0;
 }
 
-
-static int thermal_notify(struct thermal_zone_device *thermal, int trip,
-			   enum thermal_trip_type trip_type)
+static void acpi_thermal_zone_device_hot(struct thermal_zone_device *thermal)
 {
-	u8 type = 0;
 	struct acpi_thermal *tz = thermal->devdata;
 
-	if (trip_type == THERMAL_TRIP_CRITICAL)
-		type = ACPI_THERMAL_NOTIFY_CRITICAL;
-	else if (trip_type == THERMAL_TRIP_HOT)
-		type = ACPI_THERMAL_NOTIFY_HOT;
-	else
-		return 0;
-
 	acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
-					dev_name(&tz->device->dev), type, 1);
+					dev_name(&tz->device->dev),
+					ACPI_THERMAL_NOTIFY_HOT, 1);
+}
 
-	if (trip_type == THERMAL_TRIP_CRITICAL && nocrt)
-		return 1;
+static void acpi_thermal_zone_device_critical(struct thermal_zone_device *thermal)
+{
+	struct acpi_thermal *tz = thermal->devdata;
 
-	return 0;
+	acpi_bus_generate_netlink_event(tz->device->pnp.device_class,
+					dev_name(&tz->device->dev),
+					ACPI_THERMAL_NOTIFY_CRITICAL, 1);
+
+	thermal_zone_device_critical(thermal);
 }
 
 static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
@@ -812,7 +809,8 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = {
 	.get_trip_temp = thermal_get_trip_temp,
 	.get_crit_temp = thermal_get_crit_temp,
 	.get_trend = thermal_get_trend,
-	.notify = thermal_notify,
+	.hot = acpi_thermal_zone_device_hot,
+	.critical = acpi_thermal_zone_device_critical,
 };
 
 static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)

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

end of thread, other threads:[~2021-01-19 21:34 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-10 12:15 [PATCH 1/5] thermal/core: Emit a warning if the thermal zone is updated without ops Daniel Lezcano
2020-12-10 12:15 ` [PATCH 2/5] thermal/core: Add critical and hot ops Daniel Lezcano
2020-12-10 12:44   ` Lukasz Luba
2020-12-10 13:37     ` Daniel Lezcano
2020-12-10 13:51       ` Lukasz Luba
2020-12-14 14:40   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
2020-12-10 12:15 ` [PATCH 3/5] thermal/drivers/acpi: Use hot and critical ops Daniel Lezcano
2020-12-17  6:28   ` Daniel Lezcano
2020-12-17 11:38     ` Srinivas Pandruvada
2020-12-17 13:10       ` Daniel Lezcano
2021-01-19 21:27   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
2020-12-10 12:15 ` [PATCH 4/5] thermal/drivers/rcar: Remove notification usage Daniel Lezcano
2020-12-10 16:10   ` Niklas Söderlund
2020-12-15 18:17   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
2020-12-10 12:15 ` [PATCH 5/5] thermal/core: Remove notify ops Daniel Lezcano
2020-12-10 14:37   ` Lukasz Luba
2021-01-19 21:27   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
2020-12-14 14:40 ` [thermal: thermal/next] thermal/core: Emit a warning if the thermal zone is updated without ops thermal-bot for Daniel Lezcano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.