Commit bf8102228a8bf053051f311e5486042fe0542894

Authored by Doug Smythies
Committed by Rafael J. Wysocki
1 parent c4ee841f60

intel_pstate: Improve initial busy calculation

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

Cc: 3.14+ <stable@vger.kernel.org> # 3.14+
Signed-off-by: Doug Smythies <dsmythies@telus.net>
Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Showing 1 changed file with 8 additions and 5 deletions Side-by-side Diff

drivers/cpufreq/intel_pstate.c
... ... @@ -563,16 +563,19 @@
563 563 static inline void intel_pstate_calc_busy(struct cpudata *cpu,
564 564 struct sample *sample)
565 565 {
566   - int32_t core_pct;
  566 + int64_t core_pct;
  567 + int32_t rem;
567 568  
568   - core_pct = div_fp(int_tofp((sample->aperf)),
569   - int_tofp((sample->mperf)));
570   - core_pct = mul_fp(core_pct, int_tofp(100));
  569 + core_pct = int_tofp(sample->aperf) * int_tofp(100);
  570 + core_pct = div_u64_rem(core_pct, int_tofp(sample->mperf), &rem);
571 571  
  572 + if ((rem << 1) >= int_tofp(sample->mperf))
  573 + core_pct += 1;
  574 +
572 575 sample->freq = fp_toint(
573 576 mul_fp(int_tofp(cpu->pstate.max_pstate * 1000), core_pct));
574 577  
575   - sample->core_pct_busy = core_pct;
  578 + sample->core_pct_busy = (int32_t)core_pct;
576 579 }
577 580  
578 581 static inline void intel_pstate_sample(struct cpudata *cpu)