public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/3 linux-next] cpufreq: conservative: Use an inline function to evaluate freq_target
@ 2013-03-05 22:06 Stratos Karafotis
  2013-03-06 13:23 ` Viresh Kumar
  2013-03-06 13:31 ` Viresh Kumar
  0 siblings, 2 replies; 9+ messages in thread
From: Stratos Karafotis @ 2013-03-05 22:06 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Viresh Kumar, cpufreq, linux-pm, linux-kernel

Use an inline function to evaluate freq_target to avoid duplicate code.

Also, define a macro for the default frequency step and fix the
calculation of freq_target when the max freq is less that 100.

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
---
 drivers/cpufreq/cpufreq_conservative.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index 08be431..029de49 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -28,6 +28,7 @@
 /* Conservative governor macros */
 #define DEF_FREQUENCY_UP_THRESHOLD		(80)
 #define DEF_FREQUENCY_DOWN_THRESHOLD		(20)
+#define DEF_FREQUENCY_STEP			(5)
 #define DEF_SAMPLING_DOWN_FACTOR		(1)
 #define MAX_SAMPLING_DOWN_FACTOR		(10)
 
@@ -39,9 +40,20 @@ static struct cs_dbs_tuners cs_tuners = {
 	.down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD,
 	.sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
 	.ignore_nice = 0,
-	.freq_step = 5,
+	.freq_step = DEF_FREQUENCY_STEP,
 };
 
+static inline unsigned int get_freq_target(struct cpufreq_policy *policy)
+{
+	unsigned int freq_target = (cs_tuners.freq_step * policy->max) / 100;
+
+	/* max freq cannot be less than 100. But who knows... */
+	if (unlikely(freq_target == 0))
+		freq_target = DEF_FREQUENCY_STEP * 1000; /* frequency in KHz */
+
+	return freq_target;
+}
+
 /*
  * Every sampling_rate, we check, if current idle time is less than 20%
  * (default), then we try to increase frequency. Every sampling_rate *
@@ -55,7 +67,6 @@ static void cs_check_cpu(int cpu, unsigned int load)
 {
 	struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, cpu);
 	struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy;
-	unsigned int freq_target;
 
 	/*
 	 * break out if we 'cannot' reduce the speed as the user might
@@ -72,13 +83,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
 		if (dbs_info->requested_freq == policy->max)
 			return;
 
-		freq_target = (cs_tuners.freq_step * policy->max) / 100;
-
-		/* max freq cannot be less than 100. But who knows.... */
-		if (unlikely(freq_target == 0))
-			freq_target = 5;
-
-		dbs_info->requested_freq += freq_target;
+		dbs_info->requested_freq += get_freq_target(policy);
 		if (dbs_info->requested_freq > policy->max)
 			dbs_info->requested_freq = policy->max;
 
@@ -94,9 +99,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
 
 	/* Check for frequency decrease */
 	if (load < cs_tuners.down_threshold) {
-		freq_target = (cs_tuners.freq_step * policy->max) / 100;
-
-		dbs_info->requested_freq -= freq_target;
+		dbs_info->requested_freq -= get_freq_target(policy);
 		if (dbs_info->requested_freq < policy->min)
 			dbs_info->requested_freq = policy->min;
 
-- 
1.8.1.4


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

* Re: [PATCH 3/3 linux-next] cpufreq: conservative: Use an inline function to evaluate freq_target
  2013-03-05 22:06 [PATCH 3/3 linux-next] cpufreq: conservative: Use an inline function to evaluate freq_target Stratos Karafotis
@ 2013-03-06 13:23 ` Viresh Kumar
  2013-03-06 14:15   ` Stratos Karafotis
  2013-03-06 13:31 ` Viresh Kumar
  1 sibling, 1 reply; 9+ messages in thread
From: Viresh Kumar @ 2013-03-06 13:23 UTC (permalink / raw)
  To: Stratos Karafotis; +Cc: Rafael J. Wysocki, cpufreq, linux-pm, linux-kernel

On 6 March 2013 06:06, Stratos Karafotis <stratosk@semaphore.gr> wrote:
> Use an inline function to evaluate freq_target to avoid duplicate code.
>
> Also, define a macro for the default frequency step and fix the
> calculation of freq_target when the max freq is less that 100.

Atleast my poor mind can't make out how. To me it looks like broken now.

> Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
> ---
>  drivers/cpufreq/cpufreq_conservative.c | 27 +++++++++++++++------------
>  1 file changed, 15 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
> index 08be431..029de49 100644
> --- a/drivers/cpufreq/cpufreq_conservative.c
> +++ b/drivers/cpufreq/cpufreq_conservative.c
> @@ -28,6 +28,7 @@
>  /* Conservative governor macros */
>  #define DEF_FREQUENCY_UP_THRESHOLD             (80)
>  #define DEF_FREQUENCY_DOWN_THRESHOLD           (20)
> +#define DEF_FREQUENCY_STEP                     (5)
>  #define DEF_SAMPLING_DOWN_FACTOR               (1)
>  #define MAX_SAMPLING_DOWN_FACTOR               (10)
>
> @@ -39,9 +40,20 @@ static struct cs_dbs_tuners cs_tuners = {
>         .down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD,
>         .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
>         .ignore_nice = 0,
> -       .freq_step = 5,
> +       .freq_step = DEF_FREQUENCY_STEP,
>  };
>
> +static inline unsigned int get_freq_target(struct cpufreq_policy *policy)
> +{
> +       unsigned int freq_target = (cs_tuners.freq_step * policy->max) / 100;
> +
> +       /* max freq cannot be less than 100. But who knows... */
> +       if (unlikely(freq_target == 0))
> +               freq_target = DEF_FREQUENCY_STEP * 1000; /* frequency in KHz */

When can we enter this "if" block, probably only in case where max freq is
less than 100 KHz (And because we have freq unit in KHz in cpufreq, its exact
value is less than 100). Lets say its 90.

So, we will get into your "if" block now and would set freq_target to 90 - 5000.

So its broken, isn't it.

Rest is fine.

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

* Re: [PATCH 3/3 linux-next] cpufreq: conservative: Use an inline function to evaluate freq_target
  2013-03-05 22:06 [PATCH 3/3 linux-next] cpufreq: conservative: Use an inline function to evaluate freq_target Stratos Karafotis
  2013-03-06 13:23 ` Viresh Kumar
@ 2013-03-06 13:31 ` Viresh Kumar
  1 sibling, 0 replies; 9+ messages in thread
From: Viresh Kumar @ 2013-03-06 13:31 UTC (permalink / raw)
  To: Stratos Karafotis; +Cc: Rafael J. Wysocki, cpufreq, linux-pm, linux-kernel

On 6 March 2013 06:06, Stratos Karafotis <stratosk@semaphore.gr> wrote:
> Use an inline function to evaluate freq_target to avoid duplicate code.
>
> Also, define a macro for the default frequency step and fix the
> calculation of freq_target when the max freq is less that 100.

s/that/than :)

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

* Re: [PATCH 3/3 linux-next] cpufreq: conservative: Use an inline function to evaluate freq_target
  2013-03-06 13:23 ` Viresh Kumar
@ 2013-03-06 14:15   ` Stratos Karafotis
  2013-03-06 15:58     ` Viresh Kumar
  2013-03-21 23:51     ` Rafael J. Wysocki
  0 siblings, 2 replies; 9+ messages in thread
From: Stratos Karafotis @ 2013-03-06 14:15 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: Rafael J. Wysocki, cpufreq, linux-pm, linux-kernel

On 03/06/2013 03:23 PM, Viresh Kumar wrote:
> Atleast my poor mind can't make out how. To me it looks like broken now.
> 
> 
> When can we enter this "if" block, probably only in case where max freq is
> less than 100 KHz (And because we have freq unit in KHz in cpufreq, its exact
> value is less than 100). Lets say its 90.
> 
> So, we will get into your "if" block now and would set freq_target to 90 - 5000.
> 
> So its broken, isn't it.
> 
> Rest is fine.
> 

Of course your are right. I'm sorry for this confusion.

Below v2 of this patch.

Thanks,
Stratos

--------------------------------8<------------------------
Use an inline function to evaluate freq_target to avoid duplicate code.

Also, define a macro for the default frequency step.

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
---
 drivers/cpufreq/cpufreq_conservative.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index 08be431..3fb921d 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -28,6 +28,7 @@
 /* Conservative governor macros */
 #define DEF_FREQUENCY_UP_THRESHOLD		(80)
 #define DEF_FREQUENCY_DOWN_THRESHOLD		(20)
+#define DEF_FREQUENCY_STEP			(5)
 #define DEF_SAMPLING_DOWN_FACTOR		(1)
 #define MAX_SAMPLING_DOWN_FACTOR		(10)
 
@@ -39,9 +40,20 @@ static struct cs_dbs_tuners cs_tuners = {
 	.down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD,
 	.sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
 	.ignore_nice = 0,
-	.freq_step = 5,
+	.freq_step = DEF_FREQUENCY_STEP,
 };
 
+static inline unsigned int get_freq_target(struct cpufreq_policy *policy)
+{
+	unsigned int freq_target = (cs_tuners.freq_step * policy->max) / 100;
+
+	/* max freq cannot be less than 100. But who knows... */
+	if (unlikely(freq_target == 0))
+		freq_target = DEF_FREQUENCY_STEP;
+
+	return freq_target;
+}
+
 /*
  * Every sampling_rate, we check, if current idle time is less than 20%
  * (default), then we try to increase frequency. Every sampling_rate *
@@ -55,7 +67,6 @@ static void cs_check_cpu(int cpu, unsigned int load)
 {
 	struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, cpu);
 	struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy;
-	unsigned int freq_target;
 
 	/*
 	 * break out if we 'cannot' reduce the speed as the user might
@@ -72,13 +83,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
 		if (dbs_info->requested_freq == policy->max)
 			return;
 
-		freq_target = (cs_tuners.freq_step * policy->max) / 100;
-
-		/* max freq cannot be less than 100. But who knows.... */
-		if (unlikely(freq_target == 0))
-			freq_target = 5;
-
-		dbs_info->requested_freq += freq_target;
+		dbs_info->requested_freq += get_freq_target(policy);
 		if (dbs_info->requested_freq > policy->max)
 			dbs_info->requested_freq = policy->max;
 
@@ -94,9 +99,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
 
 	/* Check for frequency decrease */
 	if (load < cs_tuners.down_threshold) {
-		freq_target = (cs_tuners.freq_step * policy->max) / 100;
-
-		dbs_info->requested_freq -= freq_target;
+		dbs_info->requested_freq -= get_freq_target(policy);
 		if (dbs_info->requested_freq < policy->min)
 			dbs_info->requested_freq = policy->min;
 
-- 
1.8.1.4

 

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

* Re: [PATCH 3/3 linux-next] cpufreq: conservative: Use an inline function to evaluate freq_target
  2013-03-06 14:15   ` Stratos Karafotis
@ 2013-03-06 15:58     ` Viresh Kumar
  2013-03-11 16:21       ` Stratos Karafotis
  2013-03-21 23:51     ` Rafael J. Wysocki
  1 sibling, 1 reply; 9+ messages in thread
From: Viresh Kumar @ 2013-03-06 15:58 UTC (permalink / raw)
  To: Stratos Karafotis; +Cc: Rafael J. Wysocki, cpufreq, linux-pm, linux-kernel

On 6 March 2013 22:15, Stratos Karafotis <stratosk@semaphore.gr> wrote:
> Use an inline function to evaluate freq_target to avoid duplicate code.
>
> Also, define a macro for the default frequency step.
>
> Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
> ---
>  drivers/cpufreq/cpufreq_conservative.c | 27 +++++++++++++++------------
>  1 file changed, 15 insertions(+), 12 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

> diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
> index 08be431..3fb921d 100644
> --- a/drivers/cpufreq/cpufreq_conservative.c
> +++ b/drivers/cpufreq/cpufreq_conservative.c
> @@ -28,6 +28,7 @@
>  /* Conservative governor macros */
>  #define DEF_FREQUENCY_UP_THRESHOLD             (80)
>  #define DEF_FREQUENCY_DOWN_THRESHOLD           (20)
> +#define DEF_FREQUENCY_STEP                     (5)
>  #define DEF_SAMPLING_DOWN_FACTOR               (1)
>  #define MAX_SAMPLING_DOWN_FACTOR               (10)
>
> @@ -39,9 +40,20 @@ static struct cs_dbs_tuners cs_tuners = {
>         .down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD,
>         .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
>         .ignore_nice = 0,
> -       .freq_step = 5,
> +       .freq_step = DEF_FREQUENCY_STEP,
>  };
>
> +static inline unsigned int get_freq_target(struct cpufreq_policy *policy)
> +{
> +       unsigned int freq_target = (cs_tuners.freq_step * policy->max) / 100;
> +
> +       /* max freq cannot be less than 100. But who knows... */
> +       if (unlikely(freq_target == 0))
> +               freq_target = DEF_FREQUENCY_STEP;
> +
> +       return freq_target;
> +}
> +
>  /*
>   * Every sampling_rate, we check, if current idle time is less than 20%
>   * (default), then we try to increase frequency. Every sampling_rate *
> @@ -55,7 +67,6 @@ static void cs_check_cpu(int cpu, unsigned int load)
>  {
>         struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, cpu);
>         struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy;
> -       unsigned int freq_target;
>
>         /*
>          * break out if we 'cannot' reduce the speed as the user might
> @@ -72,13 +83,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
>                 if (dbs_info->requested_freq == policy->max)
>                         return;
>
> -               freq_target = (cs_tuners.freq_step * policy->max) / 100;
> -
> -               /* max freq cannot be less than 100. But who knows.... */
> -               if (unlikely(freq_target == 0))
> -                       freq_target = 5;
> -
> -               dbs_info->requested_freq += freq_target;
> +               dbs_info->requested_freq += get_freq_target(policy);
>                 if (dbs_info->requested_freq > policy->max)
>                         dbs_info->requested_freq = policy->max;
>
> @@ -94,9 +99,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
>
>         /* Check for frequency decrease */
>         if (load < cs_tuners.down_threshold) {
> -               freq_target = (cs_tuners.freq_step * policy->max) / 100;
> -
> -               dbs_info->requested_freq -= freq_target;
> +               dbs_info->requested_freq -= get_freq_target(policy);
>                 if (dbs_info->requested_freq < policy->min)
>                         dbs_info->requested_freq = policy->min;
>
> --
> 1.8.1.4
>
>

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

* Re: [PATCH 3/3 linux-next] cpufreq: conservative: Use an inline function to evaluate freq_target
  2013-03-06 15:58     ` Viresh Kumar
@ 2013-03-11 16:21       ` Stratos Karafotis
  0 siblings, 0 replies; 9+ messages in thread
From: Stratos Karafotis @ 2013-03-11 16:21 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Viresh Kumar, cpufreq, linux-pm, linux-kernel

> On 6 March 2013 22:15, Stratos Karafotis <stratosk@semaphore.gr> wrote:
>> Use an inline function to evaluate freq_target to avoid duplicate code.
>>
>> Also, define a macro for the default frequency step.
>>
>> Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
>> ---
>>   drivers/cpufreq/cpufreq_conservative.c | 27 +++++++++++++++------------
>>   1 file changed, 15 insertions(+), 12 deletions(-)
> 
> Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

Hi Rafael,

Could you please let me know if this patchset is going to be 
applied or not?

Thank you in advance for your time,
Stratos

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

* Re: [PATCH 3/3 linux-next] cpufreq: conservative: Use an inline function to evaluate freq_target
  2013-03-06 14:15   ` Stratos Karafotis
  2013-03-06 15:58     ` Viresh Kumar
@ 2013-03-21 23:51     ` Rafael J. Wysocki
  2013-03-22  8:03       ` Stratos Karafotis
  1 sibling, 1 reply; 9+ messages in thread
From: Rafael J. Wysocki @ 2013-03-21 23:51 UTC (permalink / raw)
  To: Stratos Karafotis; +Cc: Viresh Kumar, cpufreq, linux-pm, linux-kernel

On Wednesday, March 06, 2013 04:15:41 PM Stratos Karafotis wrote:
> On 03/06/2013 03:23 PM, Viresh Kumar wrote:
> > Atleast my poor mind can't make out how. To me it looks like broken now.
> > 
> > 
> > When can we enter this "if" block, probably only in case where max freq is
> > less than 100 KHz (And because we have freq unit in KHz in cpufreq, its exact
> > value is less than 100). Lets say its 90.
> > 
> > So, we will get into your "if" block now and would set freq_target to 90 - 5000.
> > 
> > So its broken, isn't it.
> > 
> > Rest is fine.
> > 
> 
> Of course your are right. I'm sorry for this confusion.
> 
> Below v2 of this patch.
> 
> Thanks,
> Stratos
> 
> --------------------------------8<------------------------
> Use an inline function to evaluate freq_target to avoid duplicate code.
> 
> Also, define a macro for the default frequency step.
> 
> Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>

This one didn't apply for me to linux-pm.git/bleeding-edge.  Care to rebase?

Rafael


> ---
>  drivers/cpufreq/cpufreq_conservative.c | 27 +++++++++++++++------------
>  1 file changed, 15 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
> index 08be431..3fb921d 100644
> --- a/drivers/cpufreq/cpufreq_conservative.c
> +++ b/drivers/cpufreq/cpufreq_conservative.c
> @@ -28,6 +28,7 @@
>  /* Conservative governor macros */
>  #define DEF_FREQUENCY_UP_THRESHOLD		(80)
>  #define DEF_FREQUENCY_DOWN_THRESHOLD		(20)
> +#define DEF_FREQUENCY_STEP			(5)
>  #define DEF_SAMPLING_DOWN_FACTOR		(1)
>  #define MAX_SAMPLING_DOWN_FACTOR		(10)
>  
> @@ -39,9 +40,20 @@ static struct cs_dbs_tuners cs_tuners = {
>  	.down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD,
>  	.sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
>  	.ignore_nice = 0,
> -	.freq_step = 5,
> +	.freq_step = DEF_FREQUENCY_STEP,
>  };
>  
> +static inline unsigned int get_freq_target(struct cpufreq_policy *policy)
> +{
> +	unsigned int freq_target = (cs_tuners.freq_step * policy->max) / 100;
> +
> +	/* max freq cannot be less than 100. But who knows... */
> +	if (unlikely(freq_target == 0))
> +		freq_target = DEF_FREQUENCY_STEP;
> +
> +	return freq_target;
> +}
> +
>  /*
>   * Every sampling_rate, we check, if current idle time is less than 20%
>   * (default), then we try to increase frequency. Every sampling_rate *
> @@ -55,7 +67,6 @@ static void cs_check_cpu(int cpu, unsigned int load)
>  {
>  	struct cs_cpu_dbs_info_s *dbs_info = &per_cpu(cs_cpu_dbs_info, cpu);
>  	struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy;
> -	unsigned int freq_target;
>  
>  	/*
>  	 * break out if we 'cannot' reduce the speed as the user might
> @@ -72,13 +83,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
>  		if (dbs_info->requested_freq == policy->max)
>  			return;
>  
> -		freq_target = (cs_tuners.freq_step * policy->max) / 100;
> -
> -		/* max freq cannot be less than 100. But who knows.... */
> -		if (unlikely(freq_target == 0))
> -			freq_target = 5;
> -
> -		dbs_info->requested_freq += freq_target;
> +		dbs_info->requested_freq += get_freq_target(policy);
>  		if (dbs_info->requested_freq > policy->max)
>  			dbs_info->requested_freq = policy->max;
>  
> @@ -94,9 +99,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
>  
>  	/* Check for frequency decrease */
>  	if (load < cs_tuners.down_threshold) {
> -		freq_target = (cs_tuners.freq_step * policy->max) / 100;
> -
> -		dbs_info->requested_freq -= freq_target;
> +		dbs_info->requested_freq -= get_freq_target(policy);
>  		if (dbs_info->requested_freq < policy->min)
>  			dbs_info->requested_freq = policy->min;
>  
> 
-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* Re: [PATCH 3/3 linux-next] cpufreq: conservative: Use an inline function to evaluate freq_target
  2013-03-21 23:51     ` Rafael J. Wysocki
@ 2013-03-22  8:03       ` Stratos Karafotis
  2013-03-22 10:25         ` Viresh Kumar
  0 siblings, 1 reply; 9+ messages in thread
From: Stratos Karafotis @ 2013-03-22  8:03 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Viresh Kumar, cpufreq, linux-pm, linux-kernel

Hi Rafael,

On 03/22/2013 01:51 AM, Rafael J. Wysocki wrote:
> This one didn't apply for me to linux-pm.git/bleeding-edge.  Care to rebase?
> 
> Rafael

Yes, of course. 
Bellow the rebased patched against latest linux-pm.git/bleeding-edge.

Thanks,
Stratos

--------------------------8<-------------------------------------------
Use an inline function to evaluate freq_target to avoid duplicate code.

Also, define a macro for the default frequency step.

Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
---
 drivers/cpufreq/cpufreq_conservative.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index fe17bd3..63499c8 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -29,11 +29,24 @@
 /* Conservative governor macros */
 #define DEF_FREQUENCY_UP_THRESHOLD		(80)
 #define DEF_FREQUENCY_DOWN_THRESHOLD		(20)
+#define DEF_FREQUENCY_STEP			(5)
 #define DEF_SAMPLING_DOWN_FACTOR		(1)
 #define MAX_SAMPLING_DOWN_FACTOR		(10)
 
 static DEFINE_PER_CPU(struct cs_cpu_dbs_info_s, cs_cpu_dbs_info);
 
+static inline unsigned int get_freq_target(struct cs_dbs_tuners *cs_tuners,
+					   struct cpufreq_policy *policy)
+{
+	unsigned int freq_target = (cs_tuners->freq_step * policy->max) / 100;
+
+	/* max freq cannot be less than 100. But who knows... */
+	if (unlikely(freq_target == 0))
+		freq_target = DEF_FREQUENCY_STEP;
+
+	return freq_target;
+}
+
 /*
  * Every sampling_rate, we check, if current idle time is less than 20%
  * (default), then we try to increase frequency. Every sampling_rate *
@@ -49,7 +62,6 @@ static void cs_check_cpu(int cpu, unsigned int load)
 	struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy;
 	struct dbs_data *dbs_data = policy->governor_data;
 	struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
-	unsigned int freq_target;
 
 	/*
 	 * break out if we 'cannot' reduce the speed as the user might
@@ -66,13 +78,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
 		if (dbs_info->requested_freq == policy->max)
 			return;
 
-		freq_target = (cs_tuners->freq_step * policy->max) / 100;
-
-		/* max freq cannot be less than 100. But who knows.... */
-		if (unlikely(freq_target == 0))
-			freq_target = 5;
-
-		dbs_info->requested_freq += freq_target;
+		dbs_info->requested_freq += get_freq_target(cs_tuners, policy);
 		if (dbs_info->requested_freq > policy->max)
 			dbs_info->requested_freq = policy->max;
 
@@ -94,9 +100,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
 		if (policy->cur == policy->min)
 			return;
 
-		freq_target = (cs_tuners->freq_step * policy->max) / 100;
-
-		dbs_info->requested_freq -= freq_target;
+		dbs_info->requested_freq -= get_freq_target(cs_tuners, policy);
 		if (dbs_info->requested_freq < policy->min)
 			dbs_info->requested_freq = policy->min;
 
@@ -323,7 +327,7 @@ static int cs_init(struct dbs_data *dbs_data)
 	tuners->down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD;
 	tuners->sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR;
 	tuners->ignore_nice = 0;
-	tuners->freq_step = 5;
+	tuners->freq_step = DEF_FREQUENCY_STEP;
 
 	dbs_data->tuners = tuners;
 	dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
-- 
1.8.1.4



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

* Re: [PATCH 3/3 linux-next] cpufreq: conservative: Use an inline function to evaluate freq_target
  2013-03-22  8:03       ` Stratos Karafotis
@ 2013-03-22 10:25         ` Viresh Kumar
  0 siblings, 0 replies; 9+ messages in thread
From: Viresh Kumar @ 2013-03-22 10:25 UTC (permalink / raw)
  To: Stratos Karafotis; +Cc: Rafael J. Wysocki, cpufreq, linux-pm, linux-kernel

On 22 March 2013 13:33, Stratos Karafotis <stratosk@semaphore.gr> wrote:
> Use an inline function to evaluate freq_target to avoid duplicate code.
>
> Also, define a macro for the default frequency step.
>
> Signed-off-by: Stratos Karafotis <stratosk@semaphore.gr>
> ---
>  drivers/cpufreq/cpufreq_conservative.c | 28 ++++++++++++++++------------
>  1 file changed, 16 insertions(+), 12 deletions(-)

Acked-by: Viresh Kumar <viresh.kumar@linaro.org>

> diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
> index fe17bd3..63499c8 100644
> --- a/drivers/cpufreq/cpufreq_conservative.c
> +++ b/drivers/cpufreq/cpufreq_conservative.c
> @@ -29,11 +29,24 @@
>  /* Conservative governor macros */
>  #define DEF_FREQUENCY_UP_THRESHOLD             (80)
>  #define DEF_FREQUENCY_DOWN_THRESHOLD           (20)
> +#define DEF_FREQUENCY_STEP                     (5)
>  #define DEF_SAMPLING_DOWN_FACTOR               (1)
>  #define MAX_SAMPLING_DOWN_FACTOR               (10)
>
>  static DEFINE_PER_CPU(struct cs_cpu_dbs_info_s, cs_cpu_dbs_info);
>
> +static inline unsigned int get_freq_target(struct cs_dbs_tuners *cs_tuners,
> +                                          struct cpufreq_policy *policy)
> +{
> +       unsigned int freq_target = (cs_tuners->freq_step * policy->max) / 100;
> +
> +       /* max freq cannot be less than 100. But who knows... */
> +       if (unlikely(freq_target == 0))
> +               freq_target = DEF_FREQUENCY_STEP;
> +
> +       return freq_target;
> +}
> +
>  /*
>   * Every sampling_rate, we check, if current idle time is less than 20%
>   * (default), then we try to increase frequency. Every sampling_rate *
> @@ -49,7 +62,6 @@ static void cs_check_cpu(int cpu, unsigned int load)
>         struct cpufreq_policy *policy = dbs_info->cdbs.cur_policy;
>         struct dbs_data *dbs_data = policy->governor_data;
>         struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
> -       unsigned int freq_target;
>
>         /*
>          * break out if we 'cannot' reduce the speed as the user might
> @@ -66,13 +78,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
>                 if (dbs_info->requested_freq == policy->max)
>                         return;
>
> -               freq_target = (cs_tuners->freq_step * policy->max) / 100;
> -
> -               /* max freq cannot be less than 100. But who knows.... */
> -               if (unlikely(freq_target == 0))
> -                       freq_target = 5;
> -
> -               dbs_info->requested_freq += freq_target;
> +               dbs_info->requested_freq += get_freq_target(cs_tuners, policy);
>                 if (dbs_info->requested_freq > policy->max)
>                         dbs_info->requested_freq = policy->max;
>
> @@ -94,9 +100,7 @@ static void cs_check_cpu(int cpu, unsigned int load)
>                 if (policy->cur == policy->min)
>                         return;
>
> -               freq_target = (cs_tuners->freq_step * policy->max) / 100;
> -
> -               dbs_info->requested_freq -= freq_target;
> +               dbs_info->requested_freq -= get_freq_target(cs_tuners, policy);
>                 if (dbs_info->requested_freq < policy->min)
>                         dbs_info->requested_freq = policy->min;
>
> @@ -323,7 +327,7 @@ static int cs_init(struct dbs_data *dbs_data)
>         tuners->down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD;
>         tuners->sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR;
>         tuners->ignore_nice = 0;
> -       tuners->freq_step = 5;
> +       tuners->freq_step = DEF_FREQUENCY_STEP;
>
>         dbs_data->tuners = tuners;
>         dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
> --
> 1.8.1.4
>
>

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

end of thread, other threads:[~2013-03-22 10:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-05 22:06 [PATCH 3/3 linux-next] cpufreq: conservative: Use an inline function to evaluate freq_target Stratos Karafotis
2013-03-06 13:23 ` Viresh Kumar
2013-03-06 14:15   ` Stratos Karafotis
2013-03-06 15:58     ` Viresh Kumar
2013-03-11 16:21       ` Stratos Karafotis
2013-03-21 23:51     ` Rafael J. Wysocki
2013-03-22  8:03       ` Stratos Karafotis
2013-03-22 10:25         ` Viresh Kumar
2013-03-06 13:31 ` Viresh Kumar

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