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>,
Lukasz Luba <lukasz.luba@arm.com>
Subject: [PATCH 4/5] thermal/core: Move the thermal zone lock out of the governors
Date: Fri, 5 Aug 2022 17:38:33 +0200 [thread overview]
Message-ID: <20220805153834.2510142-4-daniel.lezcano@linaro.org> (raw)
In-Reply-To: <20220805153834.2510142-1-daniel.lezcano@linaro.org>
All the governors throttling ops are taking/releasing the lock at the
beginning and the end of the function.
We can move the mutex to the throttling call site instead.
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
drivers/thermal/gov_bang_bang.c | 4 +---
drivers/thermal/gov_fair_share.c | 4 +---
drivers/thermal/gov_power_allocator.c | 16 ++++++----------
drivers/thermal/gov_step_wise.c | 4 +---
drivers/thermal/thermal_core.c | 2 ++
5 files changed, 11 insertions(+), 19 deletions(-)
diff --git a/drivers/thermal/gov_bang_bang.c b/drivers/thermal/gov_bang_bang.c
index f0bff2e0475b..a08bbe33be96 100644
--- a/drivers/thermal/gov_bang_bang.c
+++ b/drivers/thermal/gov_bang_bang.c
@@ -96,15 +96,13 @@ static int bang_bang_control(struct thermal_zone_device *tz, int trip)
{
struct thermal_instance *instance;
- mutex_lock(&tz->lock);
+ lockdep_assert_held(&tz->lock);
thermal_zone_trip_update(tz, trip);
list_for_each_entry(instance, &tz->thermal_instances, tz_node)
thermal_cdev_update(instance->cdev);
- mutex_unlock(&tz->lock);
-
return 0;
}
diff --git a/drivers/thermal/gov_fair_share.c b/drivers/thermal/gov_fair_share.c
index 5d5ddd648cd2..a4ee4661e9cc 100644
--- a/drivers/thermal/gov_fair_share.c
+++ b/drivers/thermal/gov_fair_share.c
@@ -82,7 +82,7 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
int total_instance = 0;
int cur_trip_level = get_trip_level(tz);
- mutex_lock(&tz->lock);
+ lockdep_assert_held(&tz->lock);
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
if (instance->trip != trip)
@@ -112,8 +112,6 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
mutex_unlock(&cdev->lock);
}
- mutex_unlock(&tz->lock);
-
return 0;
}
diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c
index d3aca236e274..2d1aeaba38a8 100644
--- a/drivers/thermal/gov_power_allocator.c
+++ b/drivers/thermal/gov_power_allocator.c
@@ -697,19 +697,19 @@ static void power_allocator_unbind(struct thermal_zone_device *tz)
static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
{
- int ret = 0;
+ int ret;
int switch_on_temp, control_temp;
struct power_allocator_params *params = tz->governor_data;
bool update;
- mutex_lock(&tz->lock);
+ lockdep_assert_held(&tz->lock);
/*
* We get called for every trip point but we only need to do
* our calculations once
*/
if (trip != params->trip_max_desired_temperature)
- goto out;
+ return 0;
ret = tz->ops->get_trip_temp(tz, params->trip_switch_on,
&switch_on_temp);
@@ -718,7 +718,7 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
tz->passive = 0;
reset_pid_controller(params);
allow_maximum_power(tz, update);
- goto out;
+ return 0;
}
tz->passive = 1;
@@ -729,14 +729,10 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
dev_warn(&tz->device,
"Failed to get the maximum desired temperature: %d\n",
ret);
- goto out;
+ return ret;
}
- ret = allocate_power(tz, control_temp);
-
- mutex_unlock(&tz->lock);
-out:
- return ret;
+ return allocate_power(tz, control_temp);
}
static struct thermal_governor thermal_gov_power_allocator = {
diff --git a/drivers/thermal/gov_step_wise.c b/drivers/thermal/gov_step_wise.c
index 597a0ebec7a4..cdd3354bc27f 100644
--- a/drivers/thermal/gov_step_wise.c
+++ b/drivers/thermal/gov_step_wise.c
@@ -160,15 +160,13 @@ static int step_wise_throttle(struct thermal_zone_device *tz, int trip)
{
struct thermal_instance *instance;
- mutex_lock(&tz->lock);
+ lockdep_assert_held(&tz->lock);
thermal_zone_trip_update(tz, trip);
list_for_each_entry(instance, &tz->thermal_instances, tz_node)
thermal_cdev_update(instance->cdev);
- mutex_unlock(&tz->lock);
-
return 0;
}
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index d7029fd1c112..9d554f97e081 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -311,8 +311,10 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)
static void handle_non_critical_trips(struct thermal_zone_device *tz, int trip)
{
+ mutex_lock(&tz->lock);
tz->governor ? tz->governor->throttle(tz, trip) :
def_governor->throttle(tz, trip);
+ mutex_unlock(&tz->lock);
}
void thermal_zone_device_critical(struct thermal_zone_device *tz)
--
2.25.1
next prev parent reply other threads:[~2022-08-05 15:39 UTC|newest]
Thread overview: 15+ 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 ` [PATCH 2/5] thermal/core: Rework the monitoring a bit 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-05 15:38 ` Daniel Lezcano [this message]
2022-10-04 14:14 ` [PATCH 4/5] thermal/core: Move the thermal zone lock out of the governors 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-05 16:29 ` [PATCH 1/5] thermal/core: Rearm the monitoring only one time Rafael J. Wysocki
2022-08-05 16:37 ` 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-4-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=lukasz.luba@arm.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®