]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/3.14.7/intel_pstate-correct-rounding-in-busy-calculation.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.14.7 / intel_pstate-correct-rounding-in-busy-calculation.patch
CommitLineData
2515a526
GKH
1From f0fe3cd7e12d8290c82284b5c8aee723cbd0371a Mon Sep 17 00:00:00 2001
2From: Dirk Brandewie <dirk.j.brandewie@intel.com>
3Date: Thu, 29 May 2014 09:32:23 -0700
4Subject: intel_pstate: Correct rounding in busy calculation
5
6From: Dirk Brandewie <dirk.j.brandewie@intel.com>
7
8commit f0fe3cd7e12d8290c82284b5c8aee723cbd0371a upstream.
9
10Changing to fixed point math throughout the busy calculation in
11commit e66c1768 (Change busy calculation to use fixed point
12math.) Introduced some inaccuracies by rounding the busy value at two
13points in the calculation. This change removes roundings and moves
14the rounding to the output of the PID where the calculations are
15complete and the value returned as an integer.
16
17Fixes: e66c17683746 (intel_pstate: Change busy calculation to use fixed point math.)
18Reported-by: Doug Smythies <dsmythies@telus.net>
19Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com>
20Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
21Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
22
23---
24 drivers/cpufreq/intel_pstate.c | 12 +++++++-----
25 1 file changed, 7 insertions(+), 5 deletions(-)
26
27--- a/drivers/cpufreq/intel_pstate.c
28+++ b/drivers/cpufreq/intel_pstate.c
29@@ -40,10 +40,10 @@
30 #define BYT_TURBO_VIDS 0x66d
31
32
33-#define FRAC_BITS 6
34+#define FRAC_BITS 8
35 #define int_tofp(X) ((int64_t)(X) << FRAC_BITS)
36 #define fp_toint(X) ((X) >> FRAC_BITS)
37-#define FP_ROUNDUP(X) ((X) += 1 << FRAC_BITS)
38+
39
40 static inline int32_t mul_fp(int32_t x, int32_t y)
41 {
42@@ -198,7 +198,10 @@ static signed int pid_calc(struct _pid *
43 pid->last_err = fp_error;
44
45 result = pterm + mul_fp(pid->integral, pid->i_gain) + dterm;
46-
47+ if (result >= 0)
48+ result = result + (1 << (FRAC_BITS-1));
49+ else
50+ result = result - (1 << (FRAC_BITS-1));
51 return (signed int)fp_toint(result);
52 }
53
54@@ -563,7 +566,6 @@ static inline void intel_pstate_calc_bus
55 core_pct = div_fp(int_tofp((sample->aperf)),
56 int_tofp((sample->mperf)));
57 core_pct = mul_fp(core_pct, int_tofp(100));
58- FP_ROUNDUP(core_pct);
59
60 sample->freq = fp_toint(
61 mul_fp(int_tofp(cpu->pstate.max_pstate * 1000), core_pct));
62@@ -609,7 +611,7 @@ static inline int32_t intel_pstate_get_s
63 max_pstate = int_tofp(cpu->pstate.max_pstate);
64 current_pstate = int_tofp(cpu->pstate.current_pstate);
65 core_busy = mul_fp(core_busy, div_fp(max_pstate, current_pstate));
66- return FP_ROUNDUP(core_busy);
67+ return core_busy;
68 }
69
70 static inline void intel_pstate_adjust_busy_pstate(struct cpudata *cpu)