Skip to content

Commit 74da56c

Browse files
kaccardirafaeljw
authored andcommitted
intel_pstate: fix PCT_TO_HWP macro
PCT_TO_HWP does not take the actual range of pstates exported by HWP_CAPABILITIES in account, and is broken on most platforms. Remove the macro and set the min and max pstate for hwp by determining the range and adjusting by the min and max percent limits values. Signed-off-by: Kristen Carlson Accardi <kristen@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 43717aa commit 74da56c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

drivers/cpufreq/intel_pstate.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,24 +260,31 @@ static inline void update_turbo_state(void)
260260
cpu->pstate.max_pstate == cpu->pstate.turbo_pstate);
261261
}
262262

263-
#define PCT_TO_HWP(x) (x * 255 / 100)
264263
static void intel_pstate_hwp_set(void)
265264
{
266-
int min, max, cpu;
267-
u64 value, freq;
265+
int min, hw_min, max, hw_max, cpu, range, adj_range;
266+
u64 value, cap;
267+
268+
rdmsrl(MSR_HWP_CAPABILITIES, cap);
269+
hw_min = HWP_LOWEST_PERF(cap);
270+
hw_max = HWP_HIGHEST_PERF(cap);
271+
range = hw_max - hw_min;
268272

269273
get_online_cpus();
270274

271275
for_each_online_cpu(cpu) {
272276
rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value);
273-
min = PCT_TO_HWP(limits.min_perf_pct);
277+
adj_range = limits.min_perf_pct * range / 100;
278+
min = hw_min + adj_range;
274279
value &= ~HWP_MIN_PERF(~0L);
275280
value |= HWP_MIN_PERF(min);
276281

277-
max = PCT_TO_HWP(limits.max_perf_pct);
282+
adj_range = limits.max_perf_pct * range / 100;
283+
max = hw_min + adj_range;
278284
if (limits.no_turbo) {
279-
rdmsrl( MSR_HWP_CAPABILITIES, freq);
280-
max = HWP_GUARANTEED_PERF(freq);
285+
hw_max = HWP_GUARANTEED_PERF(cap);
286+
if (hw_max < max)
287+
max = hw_max;
281288
}
282289

283290
value &= ~HWP_MAX_PERF(~0L);

0 commit comments

Comments
 (0)