]>
Commit | Line | Data |
---|---|---|
2515a526 GKH |
1 | From f0fe3cd7e12d8290c82284b5c8aee723cbd0371a Mon Sep 17 00:00:00 2001 |
2 | From: Dirk Brandewie <dirk.j.brandewie@intel.com> | |
3 | Date: Thu, 29 May 2014 09:32:23 -0700 | |
4 | Subject: intel_pstate: Correct rounding in busy calculation | |
5 | ||
6 | From: Dirk Brandewie <dirk.j.brandewie@intel.com> | |
7 | ||
8 | commit f0fe3cd7e12d8290c82284b5c8aee723cbd0371a upstream. | |
9 | ||
10 | Changing to fixed point math throughout the busy calculation in | |
11 | commit e66c1768 (Change busy calculation to use fixed point | |
12 | math.) Introduced some inaccuracies by rounding the busy value at two | |
13 | points in the calculation. This change removes roundings and moves | |
14 | the rounding to the output of the PID where the calculations are | |
15 | complete and the value returned as an integer. | |
16 | ||
17 | Fixes: e66c17683746 (intel_pstate: Change busy calculation to use fixed point math.) | |
18 | Reported-by: Doug Smythies <dsmythies@telus.net> | |
19 | Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com> | |
20 | Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> | |
21 | Signed-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) |