aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2016-04-01 19:06:21 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2016-04-01 19:06:21 -0400
commitfebce40febcff3ccdb33f63456ffc4cfc61640c8 (patch)
treee631d4e2aa9251c36d63ff40c4fbb1ad02d005ae
parentbb6ab52f2befe1fb29ac198f27d8a6aadf510f81 (diff)
intel_pstate: Avoid extra invocation of intel_pstate_sample()
The initialization of intel_pstate for a given CPU involves populating the fields of its struct cpudata that represent the previous sample, but currently that is done in a problematic way. Namely, intel_pstate_init_cpu() makes an extra call to intel_pstate_sample() so it reads the current register values that will be used to populate the "previous sample" record during the next invocation of intel_pstate_sample(). However, after commit a4675fbc4a7a (cpufreq: intel_pstate: Replace timers with utilization update callbacks) that doesn't work for last_sample_time, because the time value is passed to intel_pstate_sample() as an argument now. Passing 0 to it from intel_pstate_init_cpu() is problematic, because that causes cpu->last_sample_time == 0 to be visible in get_target_pstate_use_performance() (and hence the extra cpu->last_sample_time > 0 check in there) and effectively allows the first invocation of intel_pstate_sample() from intel_pstate_update_util() to happen immediately after the initialization which may lead to a significant "turn on" effect in the governor algorithm. To mitigate that issue, rework the initialization to avoid the extra intel_pstate_sample() call from intel_pstate_init_cpu(). Instead, make intel_pstate_sample() return false if it has been called with cpu->sample.time equal to zero, which will make intel_pstate_update_util() skip the sample in that case, and reset cpu->sample.time from intel_pstate_set_update_util_hook() to make the algorithm start properly every time the hook is set. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/cpufreq/intel_pstate.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 81057e48c4de..9ae159631f52 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -910,7 +910,14 @@ static inline bool intel_pstate_sample(struct cpudata *cpu, u64 time)
910 cpu->prev_aperf = aperf; 910 cpu->prev_aperf = aperf;
911 cpu->prev_mperf = mperf; 911 cpu->prev_mperf = mperf;
912 cpu->prev_tsc = tsc; 912 cpu->prev_tsc = tsc;
913 return true; 913 /*
914 * First time this function is invoked in a given cycle, all of the
915 * previous sample data fields are equal to zero or stale and they must
916 * be populated with meaningful numbers for things to work, so assume
917 * that sample.time will always be reset before setting the utilization
918 * update hook and make the caller skip the sample then.
919 */
920 return !!cpu->last_sample_time;
914} 921}
915 922
916static inline int32_t get_avg_frequency(struct cpudata *cpu) 923static inline int32_t get_avg_frequency(struct cpudata *cpu)
@@ -984,8 +991,7 @@ static inline int32_t get_target_pstate_use_performance(struct cpudata *cpu)
984 * enough period of time to adjust our busyness. 991 * enough period of time to adjust our busyness.
985 */ 992 */
986 duration_ns = cpu->sample.time - cpu->last_sample_time; 993 duration_ns = cpu->sample.time - cpu->last_sample_time;
987 if ((s64)duration_ns > pid_params.sample_rate_ns * 3 994 if ((s64)duration_ns > pid_params.sample_rate_ns * 3) {
988 && cpu->last_sample_time > 0) {
989 sample_ratio = div_fp(int_tofp(pid_params.sample_rate_ns), 995 sample_ratio = div_fp(int_tofp(pid_params.sample_rate_ns),
990 int_tofp(duration_ns)); 996 int_tofp(duration_ns));
991 core_busy = mul_fp(core_busy, sample_ratio); 997 core_busy = mul_fp(core_busy, sample_ratio);
@@ -1100,7 +1106,6 @@ static int intel_pstate_init_cpu(unsigned int cpunum)
1100 intel_pstate_get_cpu_pstates(cpu); 1106 intel_pstate_get_cpu_pstates(cpu);
1101 1107
1102 intel_pstate_busy_pid_reset(cpu); 1108 intel_pstate_busy_pid_reset(cpu);
1103 intel_pstate_sample(cpu, 0);
1104 1109
1105 cpu->update_util.func = intel_pstate_update_util; 1110 cpu->update_util.func = intel_pstate_update_util;
1106 1111
@@ -1121,9 +1126,13 @@ static unsigned int intel_pstate_get(unsigned int cpu_num)
1121 return get_avg_frequency(cpu); 1126 return get_avg_frequency(cpu);
1122} 1127}
1123 1128
1124static void intel_pstate_set_update_util_hook(unsigned int cpu) 1129static void intel_pstate_set_update_util_hook(unsigned int cpu_num)
1125{ 1130{
1126 cpufreq_set_update_util_data(cpu, &all_cpu_data[cpu]->update_util); 1131 struct cpudata *cpu = all_cpu_data[cpu_num];
1132
1133 /* Prevent intel_pstate_update_util() from using stale data. */
1134 cpu->sample.time = 0;
1135 cpufreq_set_update_util_data(cpu_num, &cpu->update_util);
1127} 1136}
1128 1137
1129static void intel_pstate_clear_update_util_hook(unsigned int cpu) 1138static void intel_pstate_clear_update_util_hook(unsigned int cpu)