All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: daniel.lezcano@linaro.org, rafael@kernel.org
Cc: rui.zhang@intel.com, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, Amit Kucheria <amitk@kernel.org>
Subject: [PATCH 2/5] thermal/core: Rework the monitoring a bit
Date: Fri,  5 Aug 2022 17:38:31 +0200	[thread overview]
Message-ID: <20220805153834.2510142-2-daniel.lezcano@linaro.org> (raw)
In-Reply-To: <20220805153834.2510142-1-daniel.lezcano@linaro.org>

The should_stop_polling() function wraps the function
thermal_zone_device_is_enabled().

The monitor_thermal_zone() function checks if the thermal zone is
enabled via the should_stop_polling() function.

However, the instant after checking the thermal zone is enabled, this
one can be disabled, so even if that reduces the race window, it does
not prevent that and the monitoring can be set again with the thermal
zone disabled.

For this reason, the function should_stop_polling() is replaced by a
direct check of the thermal zone mode with the mutex locks held, that
prevents the situation described above.

As the semantic is clear with the thermal_zone_is_enabled() function,
we can remove the should_stop_polling() function and replace the check
with the former function.

While at it, reorder the checks to improve the readability of the
monitor_thermal_zone() function.

In the future, the thermal_zone_device_disable() and the
thermal_zone_device_enable() functions should unset / set the polling
timer directly instead of relying on the next
thermal_zone_device_update() call to do that. That will make a
synchronous thermal zone mode change but the locking scheme should be
double checked for that which out of the scope of this change.

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

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 4e1a83987b99..d7029fd1c112 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -295,25 +295,16 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz,
 		cancel_delayed_work(&tz->poll_queue);
 }
 
-static inline bool should_stop_polling(struct thermal_zone_device *tz)
-{
-	return !thermal_zone_device_is_enabled(tz);
-}
-
 static void monitor_thermal_zone(struct thermal_zone_device *tz)
 {
-	bool stop;
-
-	stop = should_stop_polling(tz);
-
 	mutex_lock(&tz->lock);
 
-	if (!stop && tz->passive)
+	if (tz->mode != THERMAL_DEVICE_ENABLED)
+		thermal_zone_device_set_polling(tz, 0);
+	else if (tz->passive)
 		thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies);
-	else if (!stop && tz->polling_delay_jiffies)
+	else if (tz->polling_delay_jiffies)
 		thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies);
-	else
-		thermal_zone_device_set_polling(tz, 0);
 
 	mutex_unlock(&tz->lock);
 }
@@ -480,7 +471,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz,
 {
 	int count;
 
-	if (should_stop_polling(tz))
+	if (!thermal_zone_device_is_enabled(tz))
 		return;
 
 	if (atomic_read(&in_suspend))
-- 
2.25.1


  reply	other threads:[~2022-08-05 15:38 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-05 15:38 [PATCH 1/5] thermal/core: Rearm the monitoring only one time Daniel Lezcano
2022-08-05 15:38 ` Daniel Lezcano [this message]
2022-08-23 12:42   ` [thermal: thermal/next] thermal/core: Rework the monitoring a bit thermal-bot for Daniel Lezcano
2022-08-05 15:38 ` [PATCH 3/5] thermal/governors: Group the thermal zone lock inside the throttle function Daniel Lezcano
2022-08-23 12:42   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
2022-08-05 15:38 ` [PATCH 4/5] thermal/core: Move the thermal zone lock out of the governors Daniel Lezcano
2022-08-23 12:42   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
2022-10-04 14:14   ` [PATCH 4/5] " Guenter Roeck
2022-10-04 14:21     ` Daniel Lezcano
2022-08-05 15:38 ` [PATCH 5/5] thermal/core: Move the mutex inside the thermal_zone_device_update() function Daniel Lezcano
     [not found]   ` <CGME20220812103956eucas1p1849443855b3537c3f5be2891fa50a50b@eucas1p1.samsung.com>
2022-08-12 10:39     ` Marek Szyprowski
2022-08-12 13:12       ` [PATCH] thermal/core: Fix lockdep_assert() warning Daniel Lezcano
2022-08-12 13:34         ` Marek Szyprowski
2022-08-12 13:54           ` Daniel Lezcano
2022-08-20 11:57             ` Rafael J. Wysocki
2022-08-12 13:17       ` [PATCH 5/5] thermal/core: Move the mutex inside the thermal_zone_device_update() function Daniel Lezcano
2022-08-23 12:42   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
2022-08-05 16:29 ` [PATCH 1/5] thermal/core: Rearm the monitoring only one time Rafael J. Wysocki
2022-08-05 16:37   ` Daniel Lezcano
2022-08-23 12:42 ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220805153834.2510142-2-daniel.lezcano@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=amitk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=rui.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.