Skip to contentSkip to conversation

cpufreq: intel_pstate: Fix EPP restore after offline/online

PATCH In review Srinivas Pandruvada 2 participants 3 messages Nov 15, 2021 – Nov 17, 2021

Subsystems (3)
lore
Share & tools
lore

Srinivas Pandruvada

author maintainer
#0 lore raw

PATCH 1/1 cpufreq: intel_pstate: Fix EPP restore after offline/online

When using performance policy, EPP value is restored to non "performance" mode EPP after offline and online.

For example:
cat /sys/devices/system/cpu/cpu1/cpufreq/energy_performance_preference performance
echo 0 > /sys/devices/system/cpu/cpu1/online
echo 1 > /sys/devices/system/cpu/cpu1/online
cat /sys/devices/system/cpu/cpu1/cpufreq/energy_performance_preference balance_performance

The commit 4adcf2e5829f ("cpufreq: intel_pstate: Add ->offline and ->online callbacks") optimized save restore path of the HWP request MSR, when there is no change in the policy. Also added special processing for performance mode EPP. If EPP has been set to "performance" by the active mode "performance" scaling algorithm, replace that value with the cached EPP. This ends up replacing with cached EPP during offline, which is restored during online again.

So add a change which will set cpu_data->epp_policy to zero, when in performance policy and has non zero epp. In this way EPP is set to zero again.

Fixes 4adcf2e5829f ("cpufreq: intel_pstate: Add ->offline and ->online callbacks")

---
Update: Minor optimization to skip non performance policy code path

 drivers/cpufreq/intel_pstate.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/cpufreq/intel_pstate.c +9 -3
index 815df3daae9d..6d7d73a0c66b 100644
@@ -936,11 +936,17 @@ static void intel_pstate_hwp_set(unsigned int cpu)
 	max = cpu_data->max_perf_ratio;
 	min = cpu_data->min_perf_ratio;
 
-	if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE)
-		min = max;
-
 	rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value);
 
+	if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE) {
+		min = max;
+		epp = 0;
+		if (boot_cpu_has(X86_FEATURE_HWP_EPP))
+			epp = (value >> 24) & 0xff;
+		if (epp)
+			cpu_data->epp_policy = 0;
+	}
+
 	value &= ~HWP_MIN_PERF(~0L);
 	value |= HWP_MIN_PERF(min);
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 44 lines · Srinivas Pandruvada

When using performance policy, EPP value is restored to non "performance" mode EPP after offline and online.

For example:
cat /sys/devices/system/cpu/cpu1/cpufreq/energy_performance_preference performance
echo 0 > /sys/devices/system/cpu/cpu1/online
echo 1 > /sys/devices/system/cpu/cpu1/online
cat /sys/devices/system/cpu/cpu1/cpufreq/energy_performance_preference balance_performance

The commit 4adcf2e5829f ("cpufreq: intel_pstate: Add ->offline and ->online callbacks") optimized save restore path of the HWP request MSR, when there is no change in the policy. Also added special processing for performance mode EPP. If EPP has been set to "performance" by the active mode "performance" scaling algorithm, replace that value with the cached EPP. This ends up replacing with cached EPP during offline, which is restored during online again.

So add a change which will set cpu_data->epp_policy to zero, when in performance policy and has non zero epp. In this way EPP is set to zero again.

Fixes 4adcf2e5829f ("cpufreq: intel_pstate: Add ->offline and ->online callbacks")

---
Update: Minor optimization to skip non performance policy code path

 drivers/cpufreq/intel_pstate.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/cpufreq/intel_pstate.c +0 -3
index 815df3daae9d..6d7d73a0c66b 100644
@@ -936,11 +936,17 @@ static void intel_pstate_hwp_set(unsigned int cpu)
        max = cpu_data->max_perf_ratio;
        min = cpu_data->min_perf_ratio;
 
-       if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE)
-               min = max;
-

drivers/cpufreq/intel_pstate.c static void intel_pstate_hwp_set(unsigned int cpu) · line 948

Quoted 10 lines
drivers/cpufreq/intel_pstate.c +8 -0
        rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value);
 
+       if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE) {
+               min = max;
+               epp = 0;
+               if (boot_cpu_has(X86_FEATURE_HWP_EPP))
+                       epp = (value >> 24) & 0xff;
+               if (epp)
+                       cpu_data->epp_policy = 0;
+       }

I understand the bug, but it should not be necessary to check this every time intel_pstate_hwp_set() runs.

drivers/cpufreq/intel_pstate.c static void intel_pstate_hwp_set(unsigned int cpu)

Quoted 5 lines
drivers/cpufreq/intel_pstate.c +1 -1
+
        value &= ~HWP_MIN_PERF(~0L);
        value |= HWP_MIN_PERF(min);
 
--

Isn't the following sufficient (modulo the gmail-induced whitespace damage)?

---
 drivers/cpufreq/intel_pstate.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/cpufreq/intel_pstate.c +6 -0
Index: linux-pm/drivers/cpufreq/intel_pstate.c
===================================================================
@@ -1006,6 +1006,12 @@ static void intel_pstate_hwp_offline(str
          */
         value &= ~GENMASK_ULL(31, 24);
         value |= HWP_ENERGY_PERF_PREFERENCE(cpu->epp_cached);
+        /*
+         * However, make sure that EPP will be set to "performance" when
+         * the CPU is brought back online again and the "performance"
+         * scaling algorithm is still in effect.
+         */
+        cpu->epp_policy = CPUFREQ_POLICY_UNKNOWN;
     }
 
     /*
author maintainer
#2 lore raw
Quoted 106 lines · Rafael J. Wysocki
Quoted 59 lines · Srinivas Pandruvada

When using performance policy, EPP value is restored to non "performance"
mode EPP after offline and online.

For example:
cat /sys/devices/system/cpu/cpu1/cpufreq/energy_performance_preference performance
echo 0 > /sys/devices/system/cpu/cpu1/online
echo 1 > /sys/devices/system/cpu/cpu1/online
cat /sys/devices/system/cpu/cpu1/cpufreq/energy_performance_preference balance_performance

The commit 4adcf2e5829f ("cpufreq: intel_pstate: Add ->offline and ->online callbacks")
optimized save restore path of the HWP request MSR, when there is no
change in the policy. Also added special processing for performance mode
EPP. If EPP has been set to "performance" by the active mode "performance"
scaling algorithm, replace that value with the cached EPP. This ends up
replacing with cached EPP during offline, which is restored during online
again.

So add a change which will set cpu_data->epp_policy to zero, when in
performance policy and has non zero epp. In this way EPP is set to zero
again.

Fixes 4adcf2e5829f ("cpufreq: intel_pstate: Add ->offline and -
Quoted 1 line

online callbacks")

Signed-off-by: Srinivas Pandruvada < [email protected]>
Cc: [email protected] # v5.9+
---
Update: Minor optimization to skip non performance policy code path

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

 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/cpufreq/intel_pstate.c +0 -3
index 815df3daae9d..6d7d73a0c66b 100644
@@ -936,11 +936,17 @@ static void intel_pstate_hwp_set(unsigned int
 cpu)
         max = cpu_data->max_perf_ratio;
         min = cpu_data->min_perf_ratio;
 
-       if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE)
-               min = max;
-

drivers/cpufreq/intel_pstate.c static void intel_pstate_hwp_set(unsigned int · line 949

Quoted 10 lines
drivers/cpufreq/intel_pstate.c +8 -0
         rdmsrl_on_cpu(cpu, MSR_HWP_REQUEST, &value);
 
+       if (cpu_data->policy == CPUFREQ_POLICY_PERFORMANCE) {
+               min = max;
+               epp = 0;
+               if (boot_cpu_has(X86_FEATURE_HWP_EPP))
+                       epp = (value >> 24) & 0xff;
+               if (epp)
+                       cpu_data->epp_policy = 0;
+       }

I understand the bug, but it should not be necessary to check this every time intel_pstate_hwp_set() runs.

drivers/cpufreq/intel_pstate.c static void intel_pstate_hwp_set(unsigned int

Quoted 5 lines
drivers/cpufreq/intel_pstate.c +1 -1
+
         value &= ~HWP_MIN_PERF(~0L);
         value |= HWP_MIN_PERF(min);
 
--

Isn't the following sufficient (modulo the gmail-induced whitespace damage)?

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

 1 file changed, 6 insertions(+)

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

drivers/cpufreq/intel_pstate.c +2 -0
@@ -1006,6 +1006,12 @@ static void intel_pstate_hwp_offline(str
           */
          value &= ~GENMASK_ULL(31, 24);
          value |= HWP_ENERGY_PERF_PREFERENCE(cpu->epp_cached);
+        /*
+         * However, make sure that EPP will be set to "performance"

when
+         * the CPU is brought back online again and the "performance"
+         * scaling algorithm is still in effect. +         */
+        cpu->epp_policy = CPUFREQ_POLICY_UNKNOWN; }

Quoted 1 line

     /*

This works also.

Thanks,
Srinivas