linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] thermal/core: Use clamp() helper in the stepwise governor
@ 2022-06-29 15:10 Daniel Lezcano
  2022-06-29 15:10 ` [PATCH 2/2] thermal/core: Remove DROP_FULL and RAISE_FULL Daniel Lezcano
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Daniel Lezcano @ 2022-06-29 15:10 UTC (permalink / raw)
  To: daniel.lezcano, rafael; +Cc: linux-kernel, linux-pm, Amit Kucheria, Zhang Rui

The code is actually clampling the next cooling device state using the
lowest and highest states of the thermal instance.

That code can be replaced by the clamp() macro which does exactly the
same. It results in a simpler routine to read.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/thermal/gov_step_wise.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/thermal/gov_step_wise.c b/drivers/thermal/gov_step_wise.c
index 12acb12aac50..6efbfaf014da 100644
--- a/drivers/thermal/gov_step_wise.c
+++ b/drivers/thermal/gov_step_wise.c
@@ -11,6 +11,7 @@
  */
 
 #include <linux/thermal.h>
+#include <linux/minmax.h>
 #include <trace/events/thermal.h>
 
 #include "thermal_core.h"
@@ -52,10 +53,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
 
 	if (!instance->initialized) {
 		if (throttle) {
-			next_target = (cur_state + 1) >= instance->upper ?
-					instance->upper :
-					((cur_state + 1) < instance->lower ?
-					instance->lower : (cur_state + 1));
+			next_target = clamp((cur_state + 1), instance->lower, instance->upper);
 		} else {
 			next_target = THERMAL_NO_TARGET;
 		}
@@ -66,10 +64,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
 	switch (trend) {
 	case THERMAL_TREND_RAISING:
 		if (throttle) {
-			next_target = cur_state < instance->upper ?
-				    (cur_state + 1) : instance->upper;
-			if (next_target < instance->lower)
-				next_target = instance->lower;
+			next_target = clamp((cur_state + 1), instance->lower, instance->upper);
 		}
 		break;
 	case THERMAL_TREND_RAISE_FULL:
@@ -82,9 +77,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
 				next_target = THERMAL_NO_TARGET;
 		} else {
 			if (!throttle) {
-				next_target = cur_state - 1;
-				if (next_target > instance->upper)
-					next_target = instance->upper;
+				next_target = clamp((cur_state - 1), instance->lower, instance->upper);
 			}
 		}
 		break;
-- 
2.25.1


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

* [PATCH 2/2] thermal/core: Remove DROP_FULL and RAISE_FULL
  2022-06-29 15:10 [PATCH 1/2] thermal/core: Use clamp() helper in the stepwise governor Daniel Lezcano
@ 2022-06-29 15:10 ` Daniel Lezcano
  2022-07-28 15:41   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
  2022-07-06 12:07 ` [PATCH 1/2] thermal/core: Use clamp() helper in the stepwise governor Daniel Lezcano
  2022-07-28 15:41 ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
  2 siblings, 1 reply; 7+ messages in thread
From: Daniel Lezcano @ 2022-06-29 15:10 UTC (permalink / raw)
  To: daniel.lezcano, rafael; +Cc: linux-kernel, linux-pm, Amit Kucheria, Zhang Rui

The trends DROP_FULL and RAISE_FULL are not used and were never used
in the past AFAICT. Remove these conditions as they seems to not be
handled anywhere.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/thermal/gov_step_wise.c | 11 -----------
 include/linux/thermal.h         |  2 --
 2 files changed, 13 deletions(-)

diff --git a/drivers/thermal/gov_step_wise.c b/drivers/thermal/gov_step_wise.c
index 6efbfaf014da..9729b46d0258 100644
--- a/drivers/thermal/gov_step_wise.c
+++ b/drivers/thermal/gov_step_wise.c
@@ -67,10 +67,6 @@ static unsigned long get_target_state(struct thermal_instance *instance,
 			next_target = clamp((cur_state + 1), instance->lower, instance->upper);
 		}
 		break;
-	case THERMAL_TREND_RAISE_FULL:
-		if (throttle)
-			next_target = instance->upper;
-		break;
 	case THERMAL_TREND_DROPPING:
 		if (cur_state <= instance->lower) {
 			if (!throttle)
@@ -81,13 +77,6 @@ static unsigned long get_target_state(struct thermal_instance *instance,
 			}
 		}
 		break;
-	case THERMAL_TREND_DROP_FULL:
-		if (cur_state == instance->lower) {
-			if (!throttle)
-				next_target = THERMAL_NO_TARGET;
-		} else
-			next_target = instance->lower;
-		break;
 	default:
 		break;
 	}
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 522c9180a08d..c8528bb6c01c 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -41,8 +41,6 @@ enum thermal_trend {
 	THERMAL_TREND_STABLE, /* temperature is stable */
 	THERMAL_TREND_RAISING, /* temperature is raising */
 	THERMAL_TREND_DROPPING, /* temperature is dropping */
-	THERMAL_TREND_RAISE_FULL, /* apply highest cooling action */
-	THERMAL_TREND_DROP_FULL, /* apply lowest cooling action */
 };
 
 /* Thermal notification reason */
-- 
2.25.1


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

* Re: [PATCH 1/2] thermal/core: Use clamp() helper in the stepwise governor
  2022-06-29 15:10 [PATCH 1/2] thermal/core: Use clamp() helper in the stepwise governor Daniel Lezcano
  2022-06-29 15:10 ` [PATCH 2/2] thermal/core: Remove DROP_FULL and RAISE_FULL Daniel Lezcano
@ 2022-07-06 12:07 ` Daniel Lezcano
  2022-07-06 12:26   ` Rafael J. Wysocki
  2022-07-28 15:41 ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
  2 siblings, 1 reply; 7+ messages in thread
From: Daniel Lezcano @ 2022-07-06 12:07 UTC (permalink / raw)
  To: rafael; +Cc: linux-kernel, linux-pm, Amit Kucheria, Zhang Rui

On 29/06/2022 17:10, Daniel Lezcano wrote:
> The code is actually clampling the next cooling device state using the
> lowest and highest states of the thermal instance.
> 
> That code can be replaced by the clamp() macro which does exactly the
> same. It results in a simpler routine to read.
> 
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> ---

I'll apply this series if nobody has comments


>   drivers/thermal/gov_step_wise.c | 15 ++++-----------
>   1 file changed, 4 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/thermal/gov_step_wise.c b/drivers/thermal/gov_step_wise.c
> index 12acb12aac50..6efbfaf014da 100644
> --- a/drivers/thermal/gov_step_wise.c
> +++ b/drivers/thermal/gov_step_wise.c
> @@ -11,6 +11,7 @@
>    */
>   
>   #include <linux/thermal.h>
> +#include <linux/minmax.h>
>   #include <trace/events/thermal.h>
>   
>   #include "thermal_core.h"
> @@ -52,10 +53,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
>   
>   	if (!instance->initialized) {
>   		if (throttle) {
> -			next_target = (cur_state + 1) >= instance->upper ?
> -					instance->upper :
> -					((cur_state + 1) < instance->lower ?
> -					instance->lower : (cur_state + 1));
> +			next_target = clamp((cur_state + 1), instance->lower, instance->upper);
>   		} else {
>   			next_target = THERMAL_NO_TARGET;
>   		}
> @@ -66,10 +64,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
>   	switch (trend) {
>   	case THERMAL_TREND_RAISING:
>   		if (throttle) {
> -			next_target = cur_state < instance->upper ?
> -				    (cur_state + 1) : instance->upper;
> -			if (next_target < instance->lower)
> -				next_target = instance->lower;
> +			next_target = clamp((cur_state + 1), instance->lower, instance->upper);
>   		}
>   		break;
>   	case THERMAL_TREND_RAISE_FULL:
> @@ -82,9 +77,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
>   				next_target = THERMAL_NO_TARGET;
>   		} else {
>   			if (!throttle) {
> -				next_target = cur_state - 1;
> -				if (next_target > instance->upper)
> -					next_target = instance->upper;
> +				next_target = clamp((cur_state - 1), instance->lower, instance->upper);
>   			}
>   		}
>   		break;


-- 
<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

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

* Re: [PATCH 1/2] thermal/core: Use clamp() helper in the stepwise governor
  2022-07-06 12:07 ` [PATCH 1/2] thermal/core: Use clamp() helper in the stepwise governor Daniel Lezcano
@ 2022-07-06 12:26   ` Rafael J. Wysocki
  2022-07-06 14:44     ` Daniel Lezcano
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2022-07-06 12:26 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: Rafael J. Wysocki, Linux Kernel Mailing List, Linux PM,
	Amit Kucheria, Zhang Rui

On Wed, Jul 6, 2022 at 2:07 PM Daniel Lezcano <daniel.lezcano@linaro.org> wrote:
>
> On 29/06/2022 17:10, Daniel Lezcano wrote:
> > The code is actually clampling the next cooling device state using the
> > lowest and highest states of the thermal instance.
> >
> > That code can be replaced by the clamp() macro which does exactly the
> > same. It results in a simpler routine to read.
> >
> > Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> > ---
>
> I'll apply this series if nobody has comments

Sounds good to me.

Please feel free to add ACKs from me to the patches.

>
> >   drivers/thermal/gov_step_wise.c | 15 ++++-----------
> >   1 file changed, 4 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/thermal/gov_step_wise.c b/drivers/thermal/gov_step_wise.c
> > index 12acb12aac50..6efbfaf014da 100644
> > --- a/drivers/thermal/gov_step_wise.c
> > +++ b/drivers/thermal/gov_step_wise.c
> > @@ -11,6 +11,7 @@
> >    */
> >
> >   #include <linux/thermal.h>
> > +#include <linux/minmax.h>
> >   #include <trace/events/thermal.h>
> >
> >   #include "thermal_core.h"
> > @@ -52,10 +53,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
> >
> >       if (!instance->initialized) {
> >               if (throttle) {
> > -                     next_target = (cur_state + 1) >= instance->upper ?
> > -                                     instance->upper :
> > -                                     ((cur_state + 1) < instance->lower ?
> > -                                     instance->lower : (cur_state + 1));
> > +                     next_target = clamp((cur_state + 1), instance->lower, instance->upper);
> >               } else {
> >                       next_target = THERMAL_NO_TARGET;
> >               }
> > @@ -66,10 +64,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
> >       switch (trend) {
> >       case THERMAL_TREND_RAISING:
> >               if (throttle) {
> > -                     next_target = cur_state < instance->upper ?
> > -                                 (cur_state + 1) : instance->upper;
> > -                     if (next_target < instance->lower)
> > -                             next_target = instance->lower;
> > +                     next_target = clamp((cur_state + 1), instance->lower, instance->upper);
> >               }
> >               break;
> >       case THERMAL_TREND_RAISE_FULL:
> > @@ -82,9 +77,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
> >                               next_target = THERMAL_NO_TARGET;
> >               } else {
> >                       if (!throttle) {
> > -                             next_target = cur_state - 1;
> > -                             if (next_target > instance->upper)
> > -                                     next_target = instance->upper;
> > +                             next_target = clamp((cur_state - 1), instance->lower, instance->upper);
> >                       }
> >               }
> >               break;
>
>
> --
> <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

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

* Re: [PATCH 1/2] thermal/core: Use clamp() helper in the stepwise governor
  2022-07-06 12:26   ` Rafael J. Wysocki
@ 2022-07-06 14:44     ` Daniel Lezcano
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Lezcano @ 2022-07-06 14:44 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux Kernel Mailing List, Linux PM, Amit Kucheria, Zhang Rui

On 06/07/2022 14:26, Rafael J. Wysocki wrote:
> On Wed, Jul 6, 2022 at 2:07 PM Daniel Lezcano <daniel.lezcano@linaro.org> wrote:
>>
>> On 29/06/2022 17:10, Daniel Lezcano wrote:
>>> The code is actually clampling the next cooling device state using the
>>> lowest and highest states of the thermal instance.
>>>
>>> That code can be replaced by the clamp() macro which does exactly the
>>> same. It results in a simpler routine to read.
>>>
>>> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
>>> ---
>>
>> I'll apply this series if nobody has comments
> 
> Sounds good to me.
> 
> Please feel free to add ACKs from me to the patches.
> 

Sure, thanks!



-- 
<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

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

* [thermal: thermal/next] thermal/core: Remove DROP_FULL and RAISE_FULL
  2022-06-29 15:10 ` [PATCH 2/2] thermal/core: Remove DROP_FULL and RAISE_FULL Daniel Lezcano
@ 2022-07-28 15:41   ` thermal-bot for Daniel Lezcano
  0 siblings, 0 replies; 7+ messages in thread
From: thermal-bot for Daniel Lezcano @ 2022-07-28 15:41 UTC (permalink / raw)
  To: linux-pm; +Cc: Daniel Lezcano, rui.zhang, amitk

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

Commit-ID:     4102c4042a33c682021683ec26c2dca3fd9d7cc2
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//4102c4042a33c682021683ec26c2dca3fd9d7cc2
Author:        Daniel Lezcano <daniel.lezcano@linaro.org>
AuthorDate:    Wed, 29 Jun 2022 17:10:12 +02:00
Committer:     Daniel Lezcano <daniel.lezcano@linaro.org>
CommitterDate: Thu, 28 Jul 2022 17:29:47 +02:00

thermal/core: Remove DROP_FULL and RAISE_FULL

The trends DROP_FULL and RAISE_FULL are not used and were never used
in the past AFAICT. Remove these conditions as they seems to not be
handled anywhere.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20220629151012.3115773-2-daniel.lezcano@linaro.org
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/thermal/gov_step_wise.c | 11 -----------
 include/linux/thermal.h         |  2 --
 2 files changed, 13 deletions(-)

diff --git a/drivers/thermal/gov_step_wise.c b/drivers/thermal/gov_step_wise.c
index 6efbfaf..9729b46 100644
--- a/drivers/thermal/gov_step_wise.c
+++ b/drivers/thermal/gov_step_wise.c
@@ -67,10 +67,6 @@ static unsigned long get_target_state(struct thermal_instance *instance,
 			next_target = clamp((cur_state + 1), instance->lower, instance->upper);
 		}
 		break;
-	case THERMAL_TREND_RAISE_FULL:
-		if (throttle)
-			next_target = instance->upper;
-		break;
 	case THERMAL_TREND_DROPPING:
 		if (cur_state <= instance->lower) {
 			if (!throttle)
@@ -81,13 +77,6 @@ static unsigned long get_target_state(struct thermal_instance *instance,
 			}
 		}
 		break;
-	case THERMAL_TREND_DROP_FULL:
-		if (cur_state == instance->lower) {
-			if (!throttle)
-				next_target = THERMAL_NO_TARGET;
-		} else
-			next_target = instance->lower;
-		break;
 	default:
 		break;
 	}
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 365733b..231bac2 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -40,8 +40,6 @@ enum thermal_trend {
 	THERMAL_TREND_STABLE, /* temperature is stable */
 	THERMAL_TREND_RAISING, /* temperature is raising */
 	THERMAL_TREND_DROPPING, /* temperature is dropping */
-	THERMAL_TREND_RAISE_FULL, /* apply highest cooling action */
-	THERMAL_TREND_DROP_FULL, /* apply lowest cooling action */
 };
 
 /* Thermal notification reason */

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

* [thermal: thermal/next] thermal/core: Use clamp() helper in the stepwise governor
  2022-06-29 15:10 [PATCH 1/2] thermal/core: Use clamp() helper in the stepwise governor Daniel Lezcano
  2022-06-29 15:10 ` [PATCH 2/2] thermal/core: Remove DROP_FULL and RAISE_FULL Daniel Lezcano
  2022-07-06 12:07 ` [PATCH 1/2] thermal/core: Use clamp() helper in the stepwise governor Daniel Lezcano
@ 2022-07-28 15:41 ` thermal-bot for Daniel Lezcano
  2 siblings, 0 replies; 7+ messages in thread
From: thermal-bot for Daniel Lezcano @ 2022-07-28 15:41 UTC (permalink / raw)
  To: linux-pm; +Cc: Daniel Lezcano, rui.zhang, amitk

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

Commit-ID:     25bff3ed9a8aaee45c3b554cca58673f1bea1bdc
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//25bff3ed9a8aaee45c3b554cca58673f1bea1bdc
Author:        Daniel Lezcano <daniel.lezcano@linaro.org>
AuthorDate:    Wed, 29 Jun 2022 17:10:11 +02:00
Committer:     Daniel Lezcano <daniel.lezcano@linaro.org>
CommitterDate: Thu, 28 Jul 2022 17:29:47 +02:00

thermal/core: Use clamp() helper in the stepwise governor

The code is actually clampling the next cooling device state using the
lowest and highest states of the thermal instance.

That code can be replaced by the clamp() macro which does exactly the
same. It results in a simpler routine to read.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20220629151012.3115773-1-daniel.lezcano@linaro.org
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/thermal/gov_step_wise.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/thermal/gov_step_wise.c b/drivers/thermal/gov_step_wise.c
index 12acb12..6efbfaf 100644
--- a/drivers/thermal/gov_step_wise.c
+++ b/drivers/thermal/gov_step_wise.c
@@ -11,6 +11,7 @@
  */
 
 #include <linux/thermal.h>
+#include <linux/minmax.h>
 #include <trace/events/thermal.h>
 
 #include "thermal_core.h"
@@ -52,10 +53,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
 
 	if (!instance->initialized) {
 		if (throttle) {
-			next_target = (cur_state + 1) >= instance->upper ?
-					instance->upper :
-					((cur_state + 1) < instance->lower ?
-					instance->lower : (cur_state + 1));
+			next_target = clamp((cur_state + 1), instance->lower, instance->upper);
 		} else {
 			next_target = THERMAL_NO_TARGET;
 		}
@@ -66,10 +64,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
 	switch (trend) {
 	case THERMAL_TREND_RAISING:
 		if (throttle) {
-			next_target = cur_state < instance->upper ?
-				    (cur_state + 1) : instance->upper;
-			if (next_target < instance->lower)
-				next_target = instance->lower;
+			next_target = clamp((cur_state + 1), instance->lower, instance->upper);
 		}
 		break;
 	case THERMAL_TREND_RAISE_FULL:
@@ -82,9 +77,7 @@ static unsigned long get_target_state(struct thermal_instance *instance,
 				next_target = THERMAL_NO_TARGET;
 		} else {
 			if (!throttle) {
-				next_target = cur_state - 1;
-				if (next_target > instance->upper)
-					next_target = instance->upper;
+				next_target = clamp((cur_state - 1), instance->lower, instance->upper);
 			}
 		}
 		break;

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

end of thread, other threads:[~2022-07-28 15:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-29 15:10 [PATCH 1/2] thermal/core: Use clamp() helper in the stepwise governor Daniel Lezcano
2022-06-29 15:10 ` [PATCH 2/2] thermal/core: Remove DROP_FULL and RAISE_FULL Daniel Lezcano
2022-07-28 15:41   ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano
2022-07-06 12:07 ` [PATCH 1/2] thermal/core: Use clamp() helper in the stepwise governor Daniel Lezcano
2022-07-06 12:26   ` Rafael J. Wysocki
2022-07-06 14:44     ` Daniel Lezcano
2022-07-28 15:41 ` [thermal: thermal/next] " thermal-bot for Daniel Lezcano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).