Skip to contentSkip to conversation

cpufreq: intel_pstate: Use HWP capabilities in intel_cpufreq_adjust_perf()

PATCH In review Rafael J. Wysocki 2 participants 2 messages Jan 5, 2021 – Jan 6, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: intel_pstate: Use HWP capabilities in intel_cpufreq_adjust_perf()

From: Rafael J. Wysocki <[email protected]>

If turbo P-states cannot be used, either due to the configuration of the processor, or because intel_pstate is not allowed to used them, the maximum available P-state with HWP enabled corresponds to the HWP_CAP.GUARANTEED value which is not static. It can be adjusted by an out-of-band agent or during an Intel Speed Select performance level change, so long as it remains less than or equal to HWP_CAP.MAX.

However, if turbo P-states cannot be used, intel_cpufreq_adjust_perf() always uses pstate.max_pstate (set during the initialization of the driver only) as the maximum available P-state, so it may miss a change of the HWP_CAP.GUARANTEED value.

Prevent that from happening by modifyig intel_cpufreq_adjust_perf() to always read the "guaranteed" and "maximum turbo" performance levels from the cached HWP_CAP value.

---
 drivers/cpufreq/intel_pstate.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/cpufreq/intel_pstate.c +3 -2
Index: linux-pm/drivers/cpufreq/intel_pstate.c
===================================================================
@@ -2653,12 +2653,13 @@ static void intel_cpufreq_adjust_perf(un
 				      unsigned long capacity)
 {
 	struct cpudata *cpu = all_cpu_data[cpunum];
+	u64 hwp_cap = READ_ONCE(cpu->hwp_cap_cached);
 	int old_pstate = cpu->pstate.current_pstate;
 	int cap_pstate, min_pstate, max_pstate, target_pstate;
 
 	update_turbo_state();
-	cap_pstate = global.turbo_disabled ? cpu->pstate.max_pstate :
-					     cpu->pstate.turbo_pstate;
+	cap_pstate = global.turbo_disabled ? HWP_GUARANTEED_PERF(hwp_cap) :
+					     HWP_HIGHEST_PERF(hwp_cap);
 
 	/* Optimization: Avoid unnecessary divisions. */
 
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

If turbo P-states cannot be used, either due to the configuration of the processor, or because intel_pstate is not allowed to used them, the maximum available P-state with HWP enabled corresponds to the HWP_CAP.GUARANTEED value which is not static.  It can be adjusted by an out-of-band agent or during an Intel Speed Select performance level change, so long as it remains less than or equal to HWP_CAP.MAX.

However, if turbo P-states cannot be used, intel_cpufreq_adjust_perf()
always uses pstate.max_pstate (set during the initialization of the driver only) as the maximum available P-state, so it may miss a change
of the HWP_CAP.GUARANTEED value.

Quoted 5 lines

Prevent that from happening by modifyig intel_cpufreq_adjust_perf() to always read the "guaranteed" and "maximum turbo" performance levels from the cached HWP_CAP value.

Quoted 30 lines

---
 drivers/cpufreq/intel_pstate.c |    5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)

Index: linux-pm/drivers/cpufreq/intel_pstate.c
===================================================================

drivers/cpufreq/intel_pstate.c +1 -0
@@ -2653,12 +2653,13 @@ static void intel_cpufreq_adjust_perf(un
                                       unsigned long capacity)
  {
         struct cpudata *cpu = all_cpu_data[cpunum];
+       u64 hwp_cap = READ_ONCE(cpu->hwp_cap_cached);
         int old_pstate = cpu->pstate.current_pstate;
         int cap_pstate, min_pstate, max_pstate, target_pstate;


        update_turbo_state();
-       cap_pstate = global.turbo_disabled ? cpu->pstate.max_pstate :
-                                            cpu-

Quoted 1 line

pstate.turbo_pstate;

+       cap_pstate = global.turbo_disabled ? HWP_GUARANTEED_PERF(hwp_cap) :
+
HWP_HIGHEST_PERF(hwp_cap);

        /* Optimization: Avoid unnecessary divisions. */