Skip to contentSkip to conversation

drivers/thermal: optimize the for circle to run a bit fast

PATCH Applied Bernard Zhao 3 participants 4 messages Oct 27, 2020 – Nov 24, 2020 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drivers/thermal: optimize the for circle to run a bit fast

Function thermal_zone_device_register, in the for circle, if the first if branch set the count bit in tz->trips_disabled, there is no need to set in the other if branch again.
This change is to make the code run a bit fast and readable.

Changes since V1:
*make the code more clear and readable

Link for V1:
*https://lore.kernel.org/patchwork/patch/1324507/

---
 drivers/thermal/thermal_core.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/thermal/thermal_core.c +3 -6
index c6d74bc1c90b..3d1e0033bf3e 100644
@@ -1446,12 +1446,9 @@ thermal_zone_device_register(const char *type, int trips, int mask,
 		goto release_device;
 
 	for (count = 0; count < trips; count++) {
-		if (tz->ops->get_trip_type(tz, count, &trip_type))
-			set_bit(count, &tz->trips_disabled);
-		if (tz->ops->get_trip_temp(tz, count, &trip_temp))
-			set_bit(count, &tz->trips_disabled);
-		/* Check for bogus trip points */
-		if (trip_temp == 0)
+		if (tz->ops->get_trip_type(tz, count, &trip_type) ||
+		    tz->ops->get_trip_temp(tz, count, &trip_temp) ||
+		    !trip_temp)
 			set_bit(count, &tz->trips_disabled);
 	}
 
Signature · 1 line
2.28.0
#1 lore raw
Quoted 5 lines · Bernard Zhao

Function thermal_zone_device_register, in the for circle, if the first if branch set the count bit in tz->trips_disabled, there is no need to set in the other if branch again.
This change is to make the code run a bit fast and readable.

Quoted 7 lines

Changes since V1:
*make the code more clear and readable

Link for V1:
*https://lore.kernel.org/patchwork/patch/1324507/

When adding a changelog, add it after the signed off separated with a '---' symbol. So when commiting the patch, the changelog is discarded.

Signature · 5 lines
<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
#2 lore raw
In reply to Bernard Zhao
Quoted 5 lines · Bernard Zhao

Function thermal_zone_device_register, in the for circle, if the first if branch set the count bit in tz->trips_disabled, there is no need to set in the other if branch again.
This change is to make the code run a bit fast and readable.

Quoted 8 lines

Changes since V1:
*make the code more clear and readable

Link for V1:
*https://lore.kernel.org/patchwork/patch/1324507/
---

Applied with the patch description massaged.

https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git/commit/?h=testing&id=37b2539e63d6570c9ee51b1d48bdecb334df367d

Signature · 5 lines
<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
#3 lore raw

[thermal: thermal/next] drivers/thermal/core: Optimize trip points check

In reply to Bernard Zhao
The following commit has been merged into the thermal/next branch of thermal:

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

Commit-ID:     37b2539e63d6570c9ee51b1d48bdecb334df367d
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//37b2539e63d6570c9ee51b1d48bdecb334df367d
Author:        Bernard Zhao <[email protected]>
AuthorDate:    Mon, 26 Oct 2020 18:37:42 -07:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Tue, 27 Oct 2020 09:53:19 +01:00

drivers/thermal/core: Optimize trip points check

The trip points are checked one by one with multiple condition branches where one condition is enough to disable the trip point.

Merge all these conditions in a single 'OR' statement.

[dlezcano] Changed patch description

---
 drivers/thermal/thermal_core.c |  9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/thermal/thermal_core.c +3 -6
index 96349ba..90e38cc 100644
@@ -1358,12 +1358,9 @@ thermal_zone_device_register(const char *type, int trips, int mask,
 		goto release_device;
 
 	for (count = 0; count < trips; count++) {
-		if (tz->ops->get_trip_type(tz, count, &trip_type))
-			set_bit(count, &tz->trips_disabled);
-		if (tz->ops->get_trip_temp(tz, count, &trip_temp))
-			set_bit(count, &tz->trips_disabled);
-		/* Check for bogus trip points */
-		if (trip_temp == 0)
+		if (tz->ops->get_trip_type(tz, count, &trip_type) ||
+		    tz->ops->get_trip_temp(tz, count, &trip_temp) ||
+		    !trip_temp)
 			set_bit(count, &tz->trips_disabled);
 	}