diff mbox

intel_pstate: Improve initial busy calculation

Message ID 1401469857-4908-1-git-send-email-dirk.j.brandewie@intel.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

dirk.brandewie@gmail.com May 30, 2014, 5:10 p.m. UTC
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(-)

Comments

Rafael J. Wysocki May 30, 2014, 9:35 p.m. UTC | #1
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)
>
diff mbox

Patch

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)