Skip to contentSkip to conversation

Thermal: thermal zone governor fix

PATCH In review Zhang Rui 2 participants 6 messages Feb 27, 2014 Thermal

lore
Share & tools
lore

Zhang Rui

author reviewer
#0 lore raw

PATCH 1/1 Thermal: thermal zone governor fix

Quoted 1 line

From cd587add3043ed7bf3347e5d956f65ec8adf04cf Mon Sep 17 00:00:00 2001

From: Zhang Rui <[email protected]>
Date: Fri, 24 Jan 2014 10:23:19 +0800
Subject: [PATCH] Thermal: thermal zone governor fix

This patch does a cleanup about the thermal zone governor, and make the following rules,
1. For thermal zone devices that are registered w/o tz->tzp, they can use the default thermal governor only.
2. For thermal zone devices w/ governor name specified in tz->tzp->governor_name, we will use the default governor if the governor specified is not available at the moment, and update tz->governor when the matched governor is registered.

---
 drivers/thermal/thermal_core.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
(quoted diff) +0 -0

b/drivers/thermal/thermal_core.c
index 338a88b..6bcf0628a 100644

drivers/thermal/thermal_core.c +5 -0
@@ -56,10 +56,15 @@ static LIST_HEAD(thermal_governor_list);
 static DEFINE_MUTEX(thermal_list_lock);
 static DEFINE_MUTEX(thermal_governor_lock);
 
+static struct thermal_governor *def_governor;
+
 static struct thermal_governor *__find_governor(const char *name)
 {
 	struct thermal_governor *pos;
 
+	if (!name)
+		return def_governor;
+
 	list_for_each_entry(pos, &thermal_governor_list, governor_list)
 		if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH))
 			return pos;
@@ -82,17 +87,23 @@ int thermal_register_governor(struct

thermal_governor *governor)
if (__find_governor(governor->name) == NULL) {
err = 0;
list_add(&governor->governor_list, &thermal_governor_list);
+ if (!def_governor && !strncmp(governor->name,
+ THERMAL_DEFAULT_GOVERNOR, THERMAL_NAME_LENGTH))
+ def_governor = governor;
}

mutex_lock(&thermal_list_lock);

list_for_each_entry(pos, &thermal_tz_list, node) {
+ /*
+ * only thermal zones with specified tz->tzp->governor_name
+ * may run with tz->govenor unset
+ */
if (pos->governor)
continue;
- if (pos->tzp)
- name = pos->tzp->governor_name;
- else
- name = DEFAULT_THERMAL_GOVERNOR;
+
+ name = pos->tzp->governor_name;
+
if (!strnicmp(name, governor->name, THERMAL_NAME_LENGTH))
pos->governor = governor;
}
@@ -342,8 +353,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)
static void handle_non_critical_trips(struct thermal_zone_device *tz,
int trip, enum thermal_trip_type trip_type)
{
- if (tz->governor)
- tz->governor->throttle(tz, trip);
+ tz->governor ?
+ tz->governor->throttle(tz, trip) : def_governor(tz, trip);
}

static void handle_critical_trips(struct thermal_zone_device *tz,
@@ -1533,7 +1544,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
if (tz->tzp)
tz->governor = __find_governor(tz->tzp->governor_name);
else
- tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR);
+ tz->governor = def_governor;

mutex_unlock(&thermal_governor_lock);

Signature · 1 line
1.7.9.5
author reviewer
#1 lore raw
Quoted 4 lines · Zhang Rui

From cd587add3043ed7bf3347e5d956f65ec8adf04cf Mon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Fri, 24 Jan 2014 10:23:19 +0800
Subject: [PATCH] Thermal: thermal zone governor fix

oops. forgot to attach the updated version.

thanks,
rui

Quoted 1 line

From dff1b207825609e73c7722bc79dda0ea29974931 Mon Sep 17 00:00:00 2001

From: Zhang Rui <[email protected]>
Date: Fri, 24 Jan 2014 10:23:19 +0800
Subject: [PATCH] Thermal: thermal zone governor fix

This patch does a cleanup about the thermal zone govenor, setting and make the following rule.
1. For thermal zone devices that are registered w/o tz->tzp, they can use the default thermal governor only.
2. For thermal zone devices w/ governor name specified in tz->tzp->governor_name, we will use the default govenor if the governor specified is not available at the moment, and update tz->governor when the matched governor is registered.

---
 drivers/thermal/thermal_core.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
drivers/thermal/thermal_core.c +18 -7
index 338a88b..9377487 100644
@@ -56,10 +56,15 @@ static LIST_HEAD(thermal_governor_list);
 static DEFINE_MUTEX(thermal_list_lock);
 static DEFINE_MUTEX(thermal_governor_lock);
 
+static struct thermal_governor *def_governor;
+
 static struct thermal_governor *__find_governor(const char *name)
 {
 	struct thermal_governor *pos;
 
+	if (!name)
+		return def_governor;
+
 	list_for_each_entry(pos, &thermal_governor_list, governor_list)
 		if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH))
 			return pos;
@@ -82,17 +87,23 @@ int thermal_register_governor(struct thermal_governor *governor)
 	if (__find_governor(governor->name) == NULL) {
 		err = 0;
 		list_add(&governor->governor_list, &thermal_governor_list);
+		if (!def_governor && !strncmp(governor->name,
+			DEFAULT_THERMAL_GOVERNOR, THERMAL_NAME_LENGTH))
+			def_governor = governor;
 	}
 
 	mutex_lock(&thermal_list_lock);
 
 	list_for_each_entry(pos, &thermal_tz_list, node) {
+		/*
+		 * only thermal zones with specified tz->tzp->governor_name
+		 * may run with tz->govenor unset
+		 */
 		if (pos->governor)
 			continue;
-		if (pos->tzp)
-			name = pos->tzp->governor_name;
-		else
-			name = DEFAULT_THERMAL_GOVERNOR;
+
+		name = pos->tzp->governor_name;
+
 		if (!strnicmp(name, governor->name, THERMAL_NAME_LENGTH))
 			pos->governor = governor;
 	}
@@ -342,8 +353,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)
 static void handle_non_critical_trips(struct thermal_zone_device *tz,
 			int trip, enum thermal_trip_type trip_type)
 {
-	if (tz->governor)
-		tz->governor->throttle(tz, trip);
+	tz->governor ? tz->governor->throttle(tz, trip) :
+		       def_governor->throttle(tz, trip);
 }
 
 static void handle_critical_trips(struct thermal_zone_device *tz,
@@ -1533,7 +1544,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
 	if (tz->tzp)
 		tz->governor = __find_governor(tz->tzp->governor_name);
 	else
-		tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR);
+		tz->governor = def_governor;
 
 	mutex_unlock(&thermal_governor_lock);
 
Signature · 1 line
1.7.9.5
#2 lore raw

Hi Rui,

Quoted 16 lines · Zhang Rui
Quoted 4 lines · Zhang Rui

From cd587add3043ed7bf3347e5d956f65ec8adf04cf Mon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Fri, 24 Jan 2014 10:23:19 +0800
Subject: [PATCH] Thermal: thermal zone governor fix

oops. forgot to attach the updated version.

thanks,
rui

From dff1b207825609e73c7722bc79dda0ea29974931 Mon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Fri, 24 Jan 2014 10:23:19 +0800
Subject: [PATCH] Thermal: thermal zone governor fix

Quoted 8 lines

This patch does a cleanup about the thermal zone govenor, setting and make the following rule.
1. For thermal zone devices that are registered w/o tz->tzp, they can use the default thermal governor only.
2. For thermal zone devices w/ governor name specified in tz->tzp->governor_name, we will use the default govenor if the governor specified is not available at the moment, and update tz->governor when the matched governor is registered.

Right, but this doesn't solve my problem. What I was trying to say was that we should get the default governor if tz->tzp->governor_name is not initialized. of_parse_thermal_zones() calls thermal_zone_device_register() with a tzp that has an empty governor_name and ends up with no governor.

I'll send a patch that gets you the default governor if you don't specify a governor_name in tzp and add your patch on top.

Cheers,
Javi

#3 lore raw

PATCH 1/2 thermal: use the default governor if none was specified in the thermal zone parameters

If you pass a thermal_zone_params to thermal_zone_device_register() without specifying the governor_name, use the default one. Currently of_parse_thermal_zones() is the only user of thermal_zone_params, but potentially other users of this function could do the same.

---
 drivers/thermal/thermal_core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/thermal/thermal_core.c +2 -2
index 338a88b..9b655b0 100644
@@ -89,7 +89,7 @@ int thermal_register_governor(struct thermal_governor *governor)
 	list_for_each_entry(pos, &thermal_tz_list, node) {
 		if (pos->governor)
 			continue;
-		if (pos->tzp)
+		if ((pos->tzp) && (pos->tzp->governor_name[0]))
 			name = pos->tzp->governor_name;
 		else
 			name = DEFAULT_THERMAL_GOVERNOR;
@@ -1530,7 +1530,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
 	/* Update 'this' zone's governor information */
 	mutex_lock(&thermal_governor_lock);
 
-	if (tz->tzp)
+	if ((tz->tzp) && (tz->tzp->governor_name[0]))
 		tz->governor = __find_governor(tz->tzp->governor_name);
 	else
 		tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR);
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH 2/2 Thermal: thermal zone governor fix

From: Zhang Rui <[email protected]>

This patch does a cleanup about the thermal zone govenor, setting and make the following rule.
1. For thermal zone devices that are registered w/o tz->tzp, they can use the default thermal governor only.
2. For thermal zone devices w/ governor name specified in tz->tzp->governor_name, we will use the default govenor if the governor specified is not available at the moment, and update tz->governor when the matched governor is registered.

---
 drivers/thermal/thermal_core.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
drivers/thermal/thermal_core.c +18 -7
index 9b655b0..cc9b420 100644
@@ -56,10 +56,15 @@ static LIST_HEAD(thermal_governor_list);
 static DEFINE_MUTEX(thermal_list_lock);
 static DEFINE_MUTEX(thermal_governor_lock);
 
+static struct thermal_governor *def_governor;
+
 static struct thermal_governor *__find_governor(const char *name)
 {
 	struct thermal_governor *pos;
 
+	if (!name)
+		return def_governor;
+
 	list_for_each_entry(pos, &thermal_governor_list, governor_list)
 		if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH))
 			return pos;
@@ -82,17 +87,23 @@ int thermal_register_governor(struct thermal_governor *governor)
 	if (__find_governor(governor->name) == NULL) {
 		err = 0;
 		list_add(&governor->governor_list, &thermal_governor_list);
+		if (!def_governor && !strncmp(governor->name,
+			DEFAULT_THERMAL_GOVERNOR, THERMAL_NAME_LENGTH))
+			def_governor = governor;
 	}
 
 	mutex_lock(&thermal_list_lock);
 
 	list_for_each_entry(pos, &thermal_tz_list, node) {
+		/*
+		 * only thermal zones with specified tz->tzp->governor_name
+		 * may run with tz->governor unset
+		 */
 		if (pos->governor)
 			continue;
-		if ((pos->tzp) && (pos->tzp->governor_name[0]))
-			name = pos->tzp->governor_name;
-		else
-			name = DEFAULT_THERMAL_GOVERNOR;
+
+		name = pos->tzp->governor_name;
+
 		if (!strnicmp(name, governor->name, THERMAL_NAME_LENGTH))
 			pos->governor = governor;
 	}
@@ -342,8 +353,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)
 static void handle_non_critical_trips(struct thermal_zone_device *tz,
 			int trip, enum thermal_trip_type trip_type)
 {
-	if (tz->governor)
-		tz->governor->throttle(tz, trip);
+	tz->governor ? tz->governor->throttle(tz, trip) :
+		       def_governor->throttle(tz, trip);
 }
 
 static void handle_critical_trips(struct thermal_zone_device *tz,
@@ -1533,7 +1544,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
 	if ((tz->tzp) && (tz->tzp->governor_name[0]))
 		tz->governor = __find_governor(tz->tzp->governor_name);
 	else
-		tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR);
+		tz->governor = def_governor;
 
 	mutex_unlock(&thermal_governor_lock);
 
Signature · 1 line
1.7.9.5
author reviewer
#5 lore raw
In reply to Javi Merino
Quoted 39 lines

-----Original Message-----
From: Javi Merino [mailto:[email protected]]
Sent: Thursday, February 27, 2014 9:41 PM
To: Zhang, Rui
Cc: Linux PM list; eduardo; [email protected]
Subject: Re: [PATCH] Thermal: thermal zone governor fix
Importance: High

Hi Rui,

Quoted 17 lines · Zhang Rui
Quoted 5 lines · Zhang Rui

From cd587add3043ed7bf3347e5d956f65ec8adf04cf Mon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Fri, 24 Jan 2014 10:23:19 +0800
Subject: [PATCH] Thermal: thermal zone governor fix

oops. forgot to attach the updated version.

thanks,
rui

From dff1b207825609e73c7722bc79dda0ea29974931 Mon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Fri, 24 Jan 2014 10:23:19 +0800
Subject: [PATCH] Thermal: thermal zone governor fix

Quoted 8 lines

This patch does a cleanup about the thermal zone govenor, setting and make the following rule.
1. For thermal zone devices that are registered w/o tz->tzp, they can use the default thermal governor only.
2. For thermal zone devices w/ governor name specified in tz->tzp->governor_name, we will use the default govenor if the governor specified is not available at the moment, and update tz->governor when the matched governor is registered.

Quoted 6 lines

Right, but this doesn't solve my problem. What I was trying to say was that we should get the default governor if tz->tzp->governor_name is not initialized. of_parse_thermal_zones() calls thermal_zone_device_register() with a tzp that has an empty governor_name and ends up with no governor.

I know, I tried to fix this by checking the input parameter in __find_governor, and apparently I did it wrong.
Refreshed patch attached. (My Linux machine is broken at the moment, thus I will resend the refreshed patch to the list later, if you think it fixes the problem for you this time.)

Thanks,
rui

From 635a1f41a8f95a35d1bf24c9cc018ffb018a93e6 Mon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Fri, 24 Jan 2014 10:23:19 +0800
Subject: [PATCH] Thermal: thermal zone governor fix

This patch does a cleanup about the thermal zone govenor, setting and make the following rule.
1. For thermal zone devices that are registered w/o tz->tzp, they can use the default thermal governor only.
2. For thermal zone devices w/ governor name specified in tz->tzp->governor_name, we will use the default govenor if the governor specified is not available at the moment, and update tz->governor when the matched governor is registered.

---
 drivers/thermal/thermal_core.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
drivers/thermal/thermal_core.c +18 -7
index 338a88b..1346205 100644
@@ -56,10 +56,15 @@ static LIST_HEAD(thermal_governor_list);
 static DEFINE_MUTEX(thermal_list_lock);
 static DEFINE_MUTEX(thermal_governor_lock);
 
+static struct thermal_governor *def_governor;
+
 static struct thermal_governor *__find_governor(const char *name)
 {
 	struct thermal_governor *pos;
 
+	if (!name || !name[0])
+		return def_governor;
+
 	list_for_each_entry(pos, &thermal_governor_list, governor_list)
 		if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH))
 			return pos;
@@ -82,17 +87,23 @@ int thermal_register_governor(struct thermal_governor *governor)
 	if (__find_governor(governor->name) == NULL) {
 		err = 0;
 		list_add(&governor->governor_list, &thermal_governor_list);
+		if (!def_governor && !strncmp(governor->name,
+			DEFAULT_THERMAL_GOVERNOR, THERMAL_NAME_LENGTH))
+			def_governor = governor;
 	}
 
 	mutex_lock(&thermal_list_lock);
 
 	list_for_each_entry(pos, &thermal_tz_list, node) {
+		/*
+		 * only thermal zones with specified tz->tzp->governor_name
+		 * may run with tz->govenor unset
+		 */
 		if (pos->governor)
 			continue;
-		if (pos->tzp)
-			name = pos->tzp->governor_name;
-		else
-			name = DEFAULT_THERMAL_GOVERNOR;
+
+		name = pos->tzp->governor_name;
+
 		if (!strnicmp(name, governor->name, THERMAL_NAME_LENGTH))
 			pos->governor = governor;
 	}
@@ -342,8 +353,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)
 static void handle_non_critical_trips(struct thermal_zone_device *tz,
 			int trip, enum thermal_trip_type trip_type)
 {
-	if (tz->governor)
-		tz->governor->throttle(tz, trip);
+	tz->governor ? tz->governor->throttle(tz, trip) :
+		       def_governor->throttle(tz, trip);
 }
 
 static void handle_critical_trips(struct thermal_zone_device *tz,
@@ -1533,7 +1544,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
 	if (tz->tzp)
 		tz->governor = __find_governor(tz->tzp->governor_name);
 	else
-		tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR);
+		tz->governor = def_governor;
 
 	mutex_unlock(&thermal_governor_lock);
 
Signature · 1 line
1.7.9.5