Skip to content

Commit 9fa64d6

Browse files
committed
Merge back intel_pstate fixes for v4.6.
* pm-cpufreq: intel_pstate: Avoid extra invocation of intel_pstate_sample() intel_pstate: Do not set utilization update hook too early
2 parents f55532a + febce40 commit 9fa64d6

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

drivers/cpufreq/intel_pstate.c

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,14 @@ static inline bool intel_pstate_sample(struct cpudata *cpu, u64 time)
910910
cpu->prev_aperf = aperf;
911911
cpu->prev_mperf = mperf;
912912
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;
914921
}
915922

916923
static 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)
984991
* enough period of time to adjust our busyness.
985992
*/
986993
duration_ns = cpu->sample.time - cpu->last_sample_time;
987-
if ((s64)duration_ns > pid_params.sample_rate_ns * 3
988-
&& cpu->last_sample_time > 0) {
994+
if ((s64)duration_ns > pid_params.sample_rate_ns * 3) {
989995
sample_ratio = div_fp(int_tofp(pid_params.sample_rate_ns),
990996
int_tofp(duration_ns));
991997
core_busy = mul_fp(core_busy, sample_ratio);
@@ -1100,10 +1106,8 @@ static int intel_pstate_init_cpu(unsigned int cpunum)
11001106
intel_pstate_get_cpu_pstates(cpu);
11011107

11021108
intel_pstate_busy_pid_reset(cpu);
1103-
intel_pstate_sample(cpu, 0);
11041109

11051110
cpu->update_util.func = intel_pstate_update_util;
1106-
cpufreq_set_update_util_data(cpunum, &cpu->update_util);
11071111

11081112
pr_debug("intel_pstate: controlling: cpu %d\n", cpunum);
11091113

@@ -1122,18 +1126,33 @@ static unsigned int intel_pstate_get(unsigned int cpu_num)
11221126
return get_avg_frequency(cpu);
11231127
}
11241128

1129+
static void intel_pstate_set_update_util_hook(unsigned int cpu_num)
1130+
{
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);
1136+
}
1137+
1138+
static void intel_pstate_clear_update_util_hook(unsigned int cpu)
1139+
{
1140+
cpufreq_set_update_util_data(cpu, NULL);
1141+
synchronize_sched();
1142+
}
1143+
11251144
static int intel_pstate_set_policy(struct cpufreq_policy *policy)
11261145
{
11271146
if (!policy->cpuinfo.max_freq)
11281147
return -ENODEV;
11291148

1149+
intel_pstate_clear_update_util_hook(policy->cpu);
1150+
11301151
if (policy->policy == CPUFREQ_POLICY_PERFORMANCE &&
11311152
policy->max >= policy->cpuinfo.max_freq) {
11321153
pr_debug("intel_pstate: set performance\n");
11331154
limits = &performance_limits;
1134-
if (hwp_active)
1135-
intel_pstate_hwp_set(policy->cpus);
1136-
return 0;
1155+
goto out;
11371156
}
11381157

11391158
pr_debug("intel_pstate: set powersave\n");
@@ -1163,6 +1182,9 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)
11631182
limits->max_perf = div_fp(int_tofp(limits->max_perf_pct),
11641183
int_tofp(100));
11651184

1185+
out:
1186+
intel_pstate_set_update_util_hook(policy->cpu);
1187+
11661188
if (hwp_active)
11671189
intel_pstate_hwp_set(policy->cpus);
11681190

@@ -1187,8 +1209,7 @@ static void intel_pstate_stop_cpu(struct cpufreq_policy *policy)
11871209

11881210
pr_debug("intel_pstate: CPU %d exiting\n", cpu_num);
11891211

1190-
cpufreq_set_update_util_data(cpu_num, NULL);
1191-
synchronize_sched();
1212+
intel_pstate_clear_update_util_hook(cpu_num);
11921213

11931214
if (hwp_active)
11941215
return;
@@ -1455,8 +1476,7 @@ static int __init intel_pstate_init(void)
14551476
get_online_cpus();
14561477
for_each_online_cpu(cpu) {
14571478
if (all_cpu_data[cpu]) {
1458-
cpufreq_set_update_util_data(cpu, NULL);
1459-
synchronize_sched();
1479+
intel_pstate_clear_update_util_hook(cpu);
14601480
kfree(all_cpu_data[cpu]);
14611481
}
14621482
}

0 commit comments

Comments
 (0)