Bug 61241

Summary: CPU frequency is stuck after suspend/resume using the intel_pstate driver on a Sandy Bridge CPU
Product: Power Management Reporter: Patrick Bartels (petzicus)
Component: OtherAssignee: Dirk Brandewie (dirk.brandewie)
Status: CLOSED CODE_FIX    
Severity: normal CC: aaron.lu, rui.zhang, tianyu.lan
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 3.11.0 Tree: Mainline
Regression: No

Description Patrick Bartels 2013-09-12 12:18:44 UTC
Hi there,

I have a ThinkPad X220 with a i7-2640M Sandy Bridge CPU and a serious problem with the intel_pstate driver. After booting up, everthing is fine. I use the powersave governor and run the following commands to throttle the CPU a bit and keep the machine cool and quiet:

root /sys/devices/system/cpu/intel_pstate # echo 70 > max_perf_pct 
root /sys/devices/system/cpu/intel_pstate # echo 0 > min_perf_pct 
root /sys/devices/system/cpu/intel_pstate # echo 1 > no_turbo 
root /sys/devices/system/cpu/intel_pstate # cat *
70
0
1

After suspending and resuming the CPU is stuck at 800 MHz and the frequency simply won't go up. The whole machine is significantly slower. Trying to run the same commands as above results in this:

root /sys/devices/system/cpu/intel_pstate # echo 70 > max_perf_pct
root /sys/devices/system/cpu/intel_pstate # echo 0 > min_perf_pct 
root /sys/devices/system/cpu/intel_pstate # echo 1 > no_turbo     
root /sys/devices/system/cpu/intel_pstate # cat *                 
31
0
1

There's simply no way I can get everything back to normal unless I do a reboot.
Is there any chance that this could be fixed in the next kernel version?

Thanks in advance.
Comment 1 Lan Tianyu 2013-09-12 12:30:16 UTC
Hi:
    This is a regression? Please provide the output of
"grep. /sys/bus/cpu/devices/cpu*/cpufreq/*" with root privilege.
Comment 2 Patrick Bartels 2013-09-12 12:39:10 UTC
I suppose you meant cat instead of "grep."?!
Here's the output (after having done a suspend/resume):

root ~ # cat /sys/bus/cpu/devices/cpu*/cpufreq/*
0
784000
3500000
800000
4294967295
0
performance powersave
intel_pstate
powersave
3500000
800000
<unsupported>
1
784000
3500000
800000
4294967295
1
performance powersave
intel_pstate
powersave
1900000
800000
<unsupported>
2
784000
3500000
800000
4294967295
2
performance powersave
intel_pstate
powersave
1500000
800000
<unsupported>
3
784000
3500000
800000
4294967295
3
performance powersave
intel_pstate
powersave
1100000
800000
<unsupported>
Comment 3 Lan Tianyu 2013-09-23 05:53:50 UTC
Sorry for later response.
Could you check this on the v3.12-rc1?

The intel pstate driver worked on x220 at last v3.9.3 from other reporter who tested on x220i . I guess this is triggered by recent change.
https://bugzilla.kernel.org/show_bug.cgi?id=58531
Comment 4 Patrick Bartels 2013-09-23 10:50:05 UTC
Hi there, I've just tested 3.12-rc1 but there's no improvement.
After a resume CPU frequency is still locked to 800 MHz and I cannot tweak the max_perf_pct value until I reboot.
Comment 5 Dirk Brandewie 2013-10-14 15:01:51 UTC
I have reproduced this bug a fix will follow shortly
Comment 6 Dirk Brandewie 2013-10-14 15:59:00 UTC
Please try the following patch:
commit a54717512211712e79604aa319a3100d5ff8baa0
Author: Dirk Brandewie <dirk.j.brandewie@intel.com>
Date:   Mon Oct 14 08:53:55 2013 -0700

    cpfreq/intel_pstate: Fix max_perf_pct on resume
    
    
    If the system is suspended while max_perf_pct is less than 100 percent
    or no_turbo set policy->{min,max} will be set incorrectly with scaled
    values which turn the scaled values into hard limits.
    
    Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com>
---
 drivers/cpufreq/intel_pstate.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 32b3479..3335f55 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -652,9 +652,8 @@ static int intel_pstate_cpu_init(struct cpufreq_policy *policy)
 	else
 		policy->policy = CPUFREQ_POLICY_POWERSAVE;
 
-	intel_pstate_get_min_max(cpu, &min_pstate, &max_pstate);
-	policy->min = min_pstate * 100000;
-	policy->max = max_pstate * 100000;
+	policy->min = cpu->pstate.min_pstate * 100000;
+	policy->max = cpu->pstate.turbo_pstate * 100000;
 
 	/* cpuinfo and default policy values */
 	policy->cpuinfo.min_freq = cpu->pstate.min_pstate * 100000;
Comment 7 Patrick Bartels 2013-10-15 16:37:24 UTC
Hi there,

I've been running a patched kernel with lots of suspends today. The patch has solved the issue. Thanks!
Comment 8 Aaron Lu 2013-11-04 05:44:37 UTC
commit 52e0a509e5d6f902ec26bc2a8bb02b137dc453be
Author: Dirk Brandewie <dirk.j.brandewie@intel.com>
Date:   Tue Oct 15 11:06:14 2013 -0700

    cpufreq / intel_pstate: Fix max_perf_pct on resume

Entered Linus' tree as of v3.12-rc6.