Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH] intel_pstate: Improve initial busy calculation
       [not found] <1917099.8KOhsjZWCp@vostro.rjw.lan>
@ 2014-05-30 17:10 ` dirk.brandewie
  2014-05-30 21:35   ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: dirk.brandewie @ 2014-05-30 17:10 UTC (permalink / raw)
  To: linux-pm; +Cc: dirk.brandewie, rjw, dsmythies, stable, Dirk Brandewie

From: Doug Smythies <dsmythies@telus.net>

This change makes the busy calculation using 64 bit math which prevents
overflow for large values of aperf/mperf.

Cc: <stable@vger.kernel.org> # 3.14.x
Signed-off-by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com>
---
 drivers/cpufreq/intel_pstate.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 032efe4f7..c034cde 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -563,16 +563,19 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
 static inline void intel_pstate_calc_busy(struct cpudata *cpu,
 					struct sample *sample)
 {
-	int32_t core_pct;
+	int64_t core_pct;
+	int32_t rem;
 
-	core_pct = div_fp(int_tofp((sample->aperf)),
-			int_tofp((sample->mperf)));
-	core_pct = mul_fp(core_pct, int_tofp(100));
+	core_pct = int_tofp(sample->aperf) * int_tofp(100);
+	core_pct = div_u64_rem(core_pct, int_tofp(sample->mperf), &rem);
+
+	if ((rem << 1) >= int_tofp((sample->mperf)))
+		core_pct += 1;
 
 	sample->freq = fp_toint(
 		mul_fp(int_tofp(cpu->pstate.max_pstate * 1000), core_pct));
 
-	sample->core_pct_busy = core_pct;
+	sample->core_pct_busy = (int32_t)core_pct;
 }
 
 static inline void intel_pstate_sample(struct cpudata *cpu)
-- 
1.9.0


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

* Re: [PATCH] intel_pstate: Improve initial busy calculation
  2014-05-30 17:10 ` [PATCH] intel_pstate: Improve initial busy calculation dirk.brandewie
@ 2014-05-30 21:35   ` Rafael J. Wysocki
  2014-05-30 21:41     ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2014-05-30 21:35 UTC (permalink / raw)
  To: dirk.brandewie, Dirk Brandewie; +Cc: linux-pm, dsmythies

On Friday, May 30, 2014 10:10:57 AM dirk.brandewie@gmail.com wrote:
> From: Doug Smythies <dsmythies@telus.net>
> 
> This change makes the busy calculation using 64 bit math which prevents
> overflow for large values of aperf/mperf.
> 
> Cc: <stable@vger.kernel.org> # 3.14.x
> Signed-off-by: Doug Smythies <dsmythies@telus.net>
> Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com>

This doesn't apply for me on top of bleeding-edge.  Is there a patch missing?

Rafael


> ---
>  drivers/cpufreq/intel_pstate.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
> index 032efe4f7..c034cde 100644
> --- a/drivers/cpufreq/intel_pstate.c
> +++ b/drivers/cpufreq/intel_pstate.c
> @@ -563,16 +563,19 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
>  static inline void intel_pstate_calc_busy(struct cpudata *cpu,
>  					struct sample *sample)
>  {
> -	int32_t core_pct;
> +	int64_t core_pct;
> +	int32_t rem;
>  
> -	core_pct = div_fp(int_tofp((sample->aperf)),
> -			int_tofp((sample->mperf)));
> -	core_pct = mul_fp(core_pct, int_tofp(100));
> +	core_pct = int_tofp(sample->aperf) * int_tofp(100);
> +	core_pct = div_u64_rem(core_pct, int_tofp(sample->mperf), &rem);
> +
> +	if ((rem << 1) >= int_tofp((sample->mperf)))
> +		core_pct += 1;
>  
>  	sample->freq = fp_toint(
>  		mul_fp(int_tofp(cpu->pstate.max_pstate * 1000), core_pct));
>  
> -	sample->core_pct_busy = core_pct;
> +	sample->core_pct_busy = (int32_t)core_pct;
>  }
>  
>  static inline void intel_pstate_sample(struct cpudata *cpu)
> 

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* Re: [PATCH] intel_pstate: Improve initial busy calculation
  2014-05-30 21:35   ` Rafael J. Wysocki
@ 2014-05-30 21:41     ` Rafael J. Wysocki
  0 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2014-05-30 21:41 UTC (permalink / raw)
  To: dirk.brandewie; +Cc: Dirk Brandewie, linux-pm, dsmythies

On Friday, May 30, 2014 11:35:57 PM Rafael J. Wysocki wrote:
> On Friday, May 30, 2014 10:10:57 AM dirk.brandewie@gmail.com wrote:
> > From: Doug Smythies <dsmythies@telus.net>
> > 
> > This change makes the busy calculation using 64 bit math which prevents
> > overflow for large values of aperf/mperf.
> > 
> > Cc: <stable@vger.kernel.org> # 3.14.x
> > Signed-off-by: Doug Smythies <dsmythies@telus.net>
> > Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com>
> 
> This doesn't apply for me on top of bleeding-edge.  Is there a patch missing?

The one below does apply, however.  Is that what you meant?

---
drivers/cpufreq/intel_pstate.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 032efe4f7..c034cde 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -563,15 +563,19 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
 static inline void intel_pstate_calc_busy(struct cpudata *cpu)
 {
 	struct sample *sample = &cpu->sample;
-	int32_t core_pct;
+	int64_t core_pct;
+	int32_t rem;
 
-	core_pct = div_fp(int_tofp(sample->aperf), int_tofp(sample->mperf));
-	core_pct = mul_fp(core_pct, int_tofp(100));
+	core_pct = int_tofp(sample->aperf) * int_tofp(100);
+	core_pct = div_u64_rem(core_pct, int_tofp(sample->mperf), &rem);
+
+	if ((rem << 1) >= int_tofp(sample->mperf))
+		core_pct += 1;
 
 	sample->freq = fp_toint(
 		mul_fp(int_tofp(cpu->pstate.max_pstate * 1000), core_pct));
 
-	sample->core_pct_busy = core_pct;
+	sample->core_pct_busy = (int32_t)core_pct;
 }
 
 static inline void intel_pstate_sample(struct cpudata *cpu)


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

end of thread, other threads:[~2014-05-30 21:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1917099.8KOhsjZWCp@vostro.rjw.lan>
2014-05-30 17:10 ` [PATCH] intel_pstate: Improve initial busy calculation dirk.brandewie
2014-05-30 21:35   ` Rafael J. Wysocki
2014-05-30 21:41     ` Rafael J. Wysocki

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