public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Thermal: thermal zone governor fix
@ 2014-02-27  6:41 Zhang Rui
  2014-02-27  6:47 ` Zhang Rui
  0 siblings, 1 reply; 8+ messages in thread
From: Zhang Rui @ 2014-02-27  6:41 UTC (permalink / raw)
  To: Linux PM list; +Cc: eduardo, javi.merino, wni

>From cd587add3043ed7bf3347e5d956f65ec8adf04cf Mon Sep 17 00:00:00 2001
From: Zhang Rui <rui.zhang@intel.com>
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.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/thermal/thermal_core.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/thermal/thermal_core.c
b/drivers/thermal/thermal_core.c
index 338a88b..6bcf0628a 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -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);
 
-- 
1.7.9.5




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

* Re: [PATCH] Thermal: thermal zone governor fix
  2014-02-27  6:41 [PATCH] Thermal: thermal zone governor fix Zhang Rui
@ 2014-02-27  6:47 ` Zhang Rui
  2014-02-27 13:41   ` Javi Merino
  0 siblings, 1 reply; 8+ messages in thread
From: Zhang Rui @ 2014-02-27  6:47 UTC (permalink / raw)
  To: Linux PM list; +Cc: eduardo, javi.merino, wni

On Thu, 2014-02-27 at 14:41 +0800, Zhang Rui wrote:
> From cd587add3043ed7bf3347e5d956f65ec8adf04cf Mon Sep 17 00:00:00 2001
> From: Zhang Rui <rui.zhang@intel.com>
> 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 <rui.zhang@intel.com>
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.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/thermal/thermal_core.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 338a88b..9377487 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -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);
 
-- 
1.7.9.5




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

* Re: [PATCH] Thermal: thermal zone governor fix
  2014-02-27  6:47 ` Zhang Rui
@ 2014-02-27 13:41   ` Javi Merino
  2014-02-27 13:48     ` [PATCH 1/2] thermal: use the default governor if none was specified in the thermal zone parameters Javi Merino
  2014-02-27 14:21     ` [PATCH] " Zhang, Rui
  0 siblings, 2 replies; 8+ messages in thread
From: Javi Merino @ 2014-02-27 13:41 UTC (permalink / raw)
  To: Zhang Rui; +Cc: Linux PM list, eduardo, wni@nvidia.com

Hi Rui,

On Thu, Feb 27, 2014 at 06:47:48AM +0000, Zhang Rui wrote:
> On Thu, 2014-02-27 at 14:41 +0800, Zhang Rui wrote:
> > From cd587add3043ed7bf3347e5d956f65ec8adf04cf Mon Sep 17 00:00:00 2001
> > From: Zhang Rui <rui.zhang@intel.com>
> > 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 <rui.zhang@intel.com>
> 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.

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


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

* [PATCH 1/2] thermal: use the default governor if none was specified in the thermal zone parameters
  2014-02-27 13:41   ` Javi Merino
@ 2014-02-27 13:48     ` Javi Merino
  2014-02-27 13:48       ` [PATCH 2/2] Thermal: thermal zone governor fix Javi Merino
  2014-02-27 14:21     ` [PATCH] " Zhang, Rui
  1 sibling, 1 reply; 8+ messages in thread
From: Javi Merino @ 2014-02-27 13:48 UTC (permalink / raw)
  To: Zhang Rui, Linux PM list; +Cc: eduardo.valentin, wni, Javi Merino

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.

Signed-off-by: Javi Merino <javi.merino@arm.com>
---
 drivers/thermal/thermal_core.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 338a88b..9b655b0 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -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);
-- 
1.7.9.5



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

* [PATCH 2/2] Thermal: thermal zone governor fix
  2014-02-27 13:48     ` [PATCH 1/2] thermal: use the default governor if none was specified in the thermal zone parameters Javi Merino
@ 2014-02-27 13:48       ` Javi Merino
  0 siblings, 0 replies; 8+ messages in thread
From: Javi Merino @ 2014-02-27 13:48 UTC (permalink / raw)
  To: Zhang Rui, Linux PM list; +Cc: eduardo.valentin, wni

From: Zhang Rui <rui.zhang@intel.com>

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.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/thermal/thermal_core.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 9b655b0..cc9b420 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -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);
 
-- 
1.7.9.5



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

* RE: [PATCH] Thermal: thermal zone governor fix
  2014-02-27 13:41   ` Javi Merino
  2014-02-27 13:48     ` [PATCH 1/2] thermal: use the default governor if none was specified in the thermal zone parameters Javi Merino
@ 2014-02-27 14:21     ` Zhang, Rui
  1 sibling, 0 replies; 8+ messages in thread
From: Zhang, Rui @ 2014-02-27 14:21 UTC (permalink / raw)
  To: Javi Merino; +Cc: Linux PM list, eduardo, wni@nvidia.com

[-- Attachment #1: Type: text/plain, Size: 2074 bytes --]



> -----Original Message-----
> From: Javi Merino [mailto:javi.merino@arm.com]
> Sent: Thursday, February 27, 2014 9:41 PM
> To: Zhang, Rui
> Cc: Linux PM list; eduardo; wni@nvidia.com
> Subject: Re: [PATCH] Thermal: thermal zone governor fix
> Importance: High
> 
> Hi Rui,
> 
> On Thu, Feb 27, 2014 at 06:47:48AM +0000, Zhang Rui wrote:
> > On Thu, 2014-02-27 at 14:41 +0800, Zhang Rui wrote:
> > > From cd587add3043ed7bf3347e5d956f65ec8adf04cf Mon Sep 17 00:00:00
> > > 2001
> > > From: Zhang Rui <rui.zhang@intel.com>
> > > 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 <rui.zhang@intel.com>
> > 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.
> 
> 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

[-- Attachment #2: 0001-Thermal-thermal-zone-governor-fix.patch --]
[-- Type: application/octet-stream, Size: 3068 bytes --]

From 635a1f41a8f95a35d1bf24c9cc018ffb018a93e6 Mon Sep 17 00:00:00 2001
From: Zhang Rui <rui.zhang@intel.com>
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.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/thermal/thermal_core.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 338a88b..1346205 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -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);
 
-- 
1.7.9.5


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

* [PATCH] Thermal: thermal zone governor fix
@ 2014-03-03  5:46 Zhang Rui
  2014-03-03 10:00 ` Javi Merino
  0 siblings, 1 reply; 8+ messages in thread
From: Zhang Rui @ 2014-03-03  5:46 UTC (permalink / raw)
  To: Linux PM list; +Cc: javi.merino, eduardo, wni

>From 635a1f41a8f95a35d1bf24c9cc018ffb018a93e6 Mon Sep 17 00:00:00 2001
From: Zhang Rui <rui.zhang@intel.com>
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.

Signed-off-by: Zhang Rui <rui.zhang@intel.com>
---
 drivers/thermal/thermal_core.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 338a88b..1346205 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -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);
 
-- 
1.7.9.5




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

* Re: [PATCH] Thermal: thermal zone governor fix
  2014-03-03  5:46 Zhang Rui
@ 2014-03-03 10:00 ` Javi Merino
  0 siblings, 0 replies; 8+ messages in thread
From: Javi Merino @ 2014-03-03 10:00 UTC (permalink / raw)
  To: Zhang Rui; +Cc: Linux PM list, eduardo, wni@nvidia.com

Hi Rui,

On Mon, Mar 03, 2014 at 05:46:13AM +0000, Zhang Rui wrote:
> From 635a1f41a8f95a35d1bf24c9cc018ffb018a93e6 Mon Sep 17 00:00:00 2001
> From: Zhang Rui <rui.zhang@intel.com>
> 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.
> 
> Signed-off-by: Zhang Rui <rui.zhang@intel.com>

This solves my issue.  You can add my Acked-by.

I was a bit worried about dereferencing def_governor in
handle_non_critical_trips() without checking if it's initialised.  I
guess that all the thermal zones initialise in device_initcall or
later so by the time they run thermal_zone_device_update(),
thermal_register_governors() must have initialised the default
governor.  So it's not an issue.

Thanks,
Javi


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

end of thread, other threads:[~2014-03-03 10:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-27  6:41 [PATCH] Thermal: thermal zone governor fix Zhang Rui
2014-02-27  6:47 ` Zhang Rui
2014-02-27 13:41   ` Javi Merino
2014-02-27 13:48     ` [PATCH 1/2] thermal: use the default governor if none was specified in the thermal zone parameters Javi Merino
2014-02-27 13:48       ` [PATCH 2/2] Thermal: thermal zone governor fix Javi Merino
2014-02-27 14:21     ` [PATCH] " Zhang, Rui
  -- strict thread matches above, loose matches on Subject: below --
2014-03-03  5:46 Zhang Rui
2014-03-03 10:00 ` Javi Merino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox