linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/4] thermal: core: More cleanups after bind/unbind changes
@ 2024-08-26 16:29 Rafael J. Wysocki
  2024-08-26 16:30 ` [PATCH v1 1/4] thermal: core: Drop redundant lockdep_assert_held() Rafael J. Wysocki
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2024-08-26 16:29 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Daniel Lezcano, Lukasz Luba, Zhang Rui, Huisong Li

Hi Everyone,

These are additional cleanups that can be done on top of

https://lore.kernel.org/linux-pm/2205737.irdbgypaU6@rjwysocki.net/

and

https://lore.kernel.org/linux-pm/12516814.O9o76ZdvQC@rjwysocki.net/

Thanks!




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

* [PATCH v1 1/4] thermal: core: Drop redundant lockdep_assert_held()
  2024-08-26 16:29 [PATCH v1 0/4] thermal: core: More cleanups after bind/unbind changes Rafael J. Wysocki
@ 2024-08-26 16:30 ` Rafael J. Wysocki
  2024-08-26 16:31 ` [PATCH v1 2/4] thermal: core: Drop dead code from monitor_thermal_zone() Rafael J. Wysocki
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2024-08-26 16:30 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Daniel Lezcano, Lukasz Luba, Zhang Rui, Huisong Li

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Along the lines of commit 24aad192c671 ("thermal: core: Drop
redundant checks from thermal_bind_cdev_to_trip()") notice that
thermal_unbind_cdev_from_trip() is only called by
thermal_zone_cdev_unbind() under the thermal zone lock, so it
need not use lockdep_assert_held() for that lock.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/thermal/thermal_core.c |    2 --
 1 file changed, 2 deletions(-)

Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.c
+++ linux-pm/drivers/thermal/thermal_core.c
@@ -891,8 +891,6 @@ static void thermal_unbind_cdev_from_tri
 {
 	struct thermal_instance *pos, *next;
 
-	lockdep_assert_held(&tz->lock);
-
 	mutex_lock(&cdev->lock);
 	list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) {
 		if (pos->trip == trip && pos->cdev == cdev) {




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

* [PATCH v1 2/4] thermal: core: Drop dead code from monitor_thermal_zone()
  2024-08-26 16:29 [PATCH v1 0/4] thermal: core: More cleanups after bind/unbind changes Rafael J. Wysocki
  2024-08-26 16:30 ` [PATCH v1 1/4] thermal: core: Drop redundant lockdep_assert_held() Rafael J. Wysocki
@ 2024-08-26 16:31 ` Rafael J. Wysocki
  2024-08-26 16:32 ` [PATCH v1 3/4] thermal: core: Check passive delay in monitor_thermal_zone() Rafael J. Wysocki
  2024-08-26 16:37 ` [PATCH v1 4/4] thermal: core: Drop thermal_zone_device_is_enabled() Rafael J. Wysocki
  3 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2024-08-26 16:31 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Daniel Lezcano, Lukasz Luba, Zhang Rui, Huisong Li

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Since monitor_thermal_zone() is only called when the given thermal zone
has been enabled, as per the thermal_zone_device_is_enabled() check in
__thermal_zone_device_update(), the tz->mode check in it always
evaluates to "false" and the thermal_zone_device_set_polling()
invocation depending on it is dead code, so drop it.

No functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/thermal/thermal_core.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.c
+++ linux-pm/drivers/thermal/thermal_core.c
@@ -364,9 +364,7 @@ static void thermal_zone_recheck(struct
 
 static void monitor_thermal_zone(struct thermal_zone_device *tz)
 {
-	if (tz->mode != THERMAL_DEVICE_ENABLED)
-		thermal_zone_device_set_polling(tz, 0);
-	else if (tz->passive > 0)
+	if (tz->passive > 0)
 		thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies);
 	else if (tz->polling_delay_jiffies)
 		thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies);




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

* [PATCH v1 3/4] thermal: core: Check passive delay in monitor_thermal_zone()
  2024-08-26 16:29 [PATCH v1 0/4] thermal: core: More cleanups after bind/unbind changes Rafael J. Wysocki
  2024-08-26 16:30 ` [PATCH v1 1/4] thermal: core: Drop redundant lockdep_assert_held() Rafael J. Wysocki
  2024-08-26 16:31 ` [PATCH v1 2/4] thermal: core: Drop dead code from monitor_thermal_zone() Rafael J. Wysocki
@ 2024-08-26 16:32 ` Rafael J. Wysocki
  2024-08-26 16:37 ` [PATCH v1 4/4] thermal: core: Drop thermal_zone_device_is_enabled() Rafael J. Wysocki
  3 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2024-08-26 16:32 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Daniel Lezcano, Lukasz Luba, Zhang Rui, Huisong Li

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

The only case in which thermal_zone_device_set_polling() is called
with its second argument equal to zero is when passive cooling is
under way and passive_delay_jiffies is 0, which only happens when
the given thermal zone is not polled at all.

If monitor_thermal_zone() is modified to check passive_delay_jiffies
directly, the check of the thermal_zone_device_set_polling() second
argument against 0 can be dropped and a passive_delay check can be
dropped from thermal_zone_device_register_with_trips(), so change the
code accordingly.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/thermal/thermal_core.c |   16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.c
+++ linux-pm/drivers/thermal/thermal_core.c
@@ -323,11 +323,6 @@ static void thermal_zone_broken_disable(
 static void thermal_zone_device_set_polling(struct thermal_zone_device *tz,
 					    unsigned long delay)
 {
-	if (!delay) {
-		cancel_delayed_work(&tz->poll_queue);
-		return;
-	}
-
 	if (delay > HZ)
 		delay = round_jiffies_relative(delay);
 
@@ -364,7 +359,7 @@ static void thermal_zone_recheck(struct
 
 static void monitor_thermal_zone(struct thermal_zone_device *tz)
 {
-	if (tz->passive > 0)
+	if (tz->passive > 0 && tz->passive_delay_jiffies)
 		thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies);
 	else if (tz->polling_delay_jiffies)
 		thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies);
@@ -1411,13 +1406,8 @@ thermal_zone_device_register_with_trips(
 	if (num_trips > 0 && !trips)
 		return ERR_PTR(-EINVAL);
 
-	if (polling_delay) {
-		if (passive_delay > polling_delay)
-			return ERR_PTR(-EINVAL);
-
-		if (!passive_delay)
-			passive_delay = polling_delay;
-	}
+	if (polling_delay && passive_delay > polling_delay)
+		return ERR_PTR(-EINVAL);
 
 	if (!thermal_class)
 		return ERR_PTR(-ENODEV);




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

* [PATCH v1 4/4] thermal: core: Drop thermal_zone_device_is_enabled()
  2024-08-26 16:29 [PATCH v1 0/4] thermal: core: More cleanups after bind/unbind changes Rafael J. Wysocki
                   ` (2 preceding siblings ...)
  2024-08-26 16:32 ` [PATCH v1 3/4] thermal: core: Check passive delay in monitor_thermal_zone() Rafael J. Wysocki
@ 2024-08-26 16:37 ` Rafael J. Wysocki
  3 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2024-08-26 16:37 UTC (permalink / raw)
  To: Linux PM; +Cc: LKML, Daniel Lezcano, Lukasz Luba, Zhang Rui, Huisong Li

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

There are only two callers of thermal_zone_device_is_enabled()
and one of them call is under the zone lock and the other one uses
lockdep_assert_held() on that lock.  Thus the lockdep_assert_held()
in thermal_zone_device_is_enabled() is redundant and it could be
dropped, but then the function would merely become a wrapper around
a simple tz->mode check that is more convenient to do directly.

Accordingly, drop thermal_zone_device_is_enabled() altogether and update
its callers to check tz->mode directly as appropriate.

While at it, combine the tz->mode and tz->suspended checks in
__thermal_zone_device_update() because they are of a similar category
and if any of them evaluates to "true", the outcome is the same.

No intentinal functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/thermal/thermal_core.c  |   12 +-----------
 drivers/thermal/thermal_core.h  |    3 ---
 drivers/thermal/thermal_sysfs.c |    2 +-
 3 files changed, 2 insertions(+), 15 deletions(-)

Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.c
+++ linux-pm/drivers/thermal/thermal_core.c
@@ -547,10 +547,7 @@ void __thermal_zone_device_update(struct
 	int low = -INT_MAX, high = INT_MAX;
 	int temp, ret;
 
-	if (tz->suspended)
-		return;
-
-	if (!thermal_zone_device_is_enabled(tz))
+	if (tz->suspended || tz->mode != THERMAL_DEVICE_ENABLED)
 		return;
 
 	ret = __thermal_zone_get_temp(tz, &temp);
@@ -652,13 +649,6 @@ int thermal_zone_device_disable(struct t
 }
 EXPORT_SYMBOL_GPL(thermal_zone_device_disable);
 
-int thermal_zone_device_is_enabled(struct thermal_zone_device *tz)
-{
-	lockdep_assert_held(&tz->lock);
-
-	return tz->mode == THERMAL_DEVICE_ENABLED;
-}
-
 static bool thermal_zone_is_present(struct thermal_zone_device *tz)
 {
 	return !list_empty(&tz->node);
Index: linux-pm/drivers/thermal/thermal_core.h
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.h
+++ linux-pm/drivers/thermal/thermal_core.h
@@ -284,7 +284,4 @@ thermal_cooling_device_stats_update(stru
 				    unsigned long new_state) {}
 #endif /* CONFIG_THERMAL_STATISTICS */
 
-/* device tree support */
-int thermal_zone_device_is_enabled(struct thermal_zone_device *tz);
-
 #endif /* __THERMAL_CORE_H__ */
Index: linux-pm/drivers/thermal/thermal_sysfs.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_sysfs.c
+++ linux-pm/drivers/thermal/thermal_sysfs.c
@@ -53,7 +53,7 @@ mode_show(struct device *dev, struct dev
 	int enabled;
 
 	mutex_lock(&tz->lock);
-	enabled = thermal_zone_device_is_enabled(tz);
+	enabled = tz->mode == THERMAL_DEVICE_ENABLED;
 	mutex_unlock(&tz->lock);
 
 	return sprintf(buf, "%s\n", enabled ? "enabled" : "disabled");




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

end of thread, other threads:[~2024-08-26 16:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-26 16:29 [PATCH v1 0/4] thermal: core: More cleanups after bind/unbind changes Rafael J. Wysocki
2024-08-26 16:30 ` [PATCH v1 1/4] thermal: core: Drop redundant lockdep_assert_held() Rafael J. Wysocki
2024-08-26 16:31 ` [PATCH v1 2/4] thermal: core: Drop dead code from monitor_thermal_zone() Rafael J. Wysocki
2024-08-26 16:32 ` [PATCH v1 3/4] thermal: core: Check passive delay in monitor_thermal_zone() Rafael J. Wysocki
2024-08-26 16:37 ` [PATCH v1 4/4] thermal: core: Drop thermal_zone_device_is_enabled() Rafael J. Wysocki

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