Skip to contentSkip to conversation

speedstep-centrino: hanlde cpu p state propery when resume

PATCH In review Hiroshi Miura 2 participants 4 messages Sep 23, 2004 – Sep 24, 2004 1 message not in the archive CPU frequency scaling framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 speedstep-centrino: hanlde cpu p state propery when resume

Hi,

My note pc, Panasonic Let's Note CF-R3(Pentium M 1.1GHz), troubles when resume. BIOS set cpu p-state as of ac-line state.
Centrino driver can not detect change through suspend/resume.

This is patch to fix it. I think same things are occured on other machines.

#### AUTHOR [email protected]
#### COMMENT START
### Comments for ChangeSet
[CPUFreq] speedstep-centrino: handle cpu p-state properly when resume.

### Comments for arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c [CPUFreq] speedstep-centrino: handle cpu p-state properly when resume. #### COMMENT END

# This is a BitKeeper generated diff -Nru style patch. #
# ChangeSet
# 2004/09/23 14:08:30+09:00 [email protected]
# [CPUFreq] speedstep-centrino: handle cpu p-state properly when resume.
#
# Signed-off-by: Hiroshi Miura <[email protected]>
#

# arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
#   2004/09/23 14:08:19+09:00 [email protected] +15 -0
#   [CPUFreq] speedstep-centrino: handle cpu p-state properly when resume. 
# 
diff -Nru a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c b/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
--- a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c	2004-09-23 14:15:54 +09:00
+++ b/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c	2004-09-23 14:15:54 +09:00
@@ -386,6 +386,20 @@
 static inline int centrino_cpu_init_acpi(struct cpufreq_policy *policy) { return -ENODEV; }
 #endif

+static int centrino_resume(struct cpufreq_policy *policy) +{
+ unsigned long cur_freq;
+ int i;
+
+ cur_freq = get_cur_freq(0);
+
+ for (i=0; i<p.state_count; i++) {
+ if (cur_freq == centrino_model->op_points[i].frequency)
+ p.state = i;
+ }
+ return 0;
+}
+
static int centrino_cpu_init(struct cpufreq_policy *policy) {
struct cpuinfo_x86 *cpu = &cpu_data[policy->cpu];
@@ -553,6 +567,7 @@
.exit = centrino_cpu_exit,
.verify = centrino_verify,
.target = centrino_target,
+ .resume = centrino_resume,
.get = get_cur_freq,
.attr = centrino_attr,
.owner = THIS_MODULE,

Signature · 4 lines
Hiroshi Miura  --- http://www.da-cha.org/  --- [email protected]
NTTDATA Corp. OpenSource Software Center. --- [email protected] 
NTTDATA Intellilink Corp. OpenSource Engineering Dev. -- [email protected]
Key fingerprint = 9117 9407 5684 FBF1 4063  15B4 401D D077 04AB 8617

_______________________________________________
Cpufreq mailing list
[email protected]
http://www.linux.org.uk/mailman/listinfo/cpufreq

#1 lore raw
Quoted 5 lines · Hiroshi Miura

Hi,

My note pc, Panasonic Let's Note CF-R3(Pentium M 1.1GHz), troubles when resume. BIOS set cpu p-state as of ac-line state.
Centrino driver can not detect change through suspend/resume.

Actually, it should. Only the (deprecated) /proc/acpi/processor/*/performance interface may show a wrong current state, /sys/devices/system/cpu/cpu0/cpufreq/{scaling,cpuinfo}_cur_freq should be updated by doing a call to ->get().

Oh, and what suspend method are you using?

Dominik

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

PATCH 1/1 speedstep-centrino: fix cpu_cur_freq when resume.

Hi,

I tested and decide speedstep-centrino needs .resume function.

~# echo "1000000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed ~# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq 1000000
~# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 9
model name : Intel(R) Pentium(R) M processor 1100MHz
stepping : 5
cpu MHz : 997.561

<<<<SUSPEND and RESUME>>>>>

~# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 9
model name : Intel(R) Pentium(R) M processor 1100MHz
stepping : 5
cpu MHz : 598.548

~# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq 1000000
~# cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq 600000
~# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq 600000

This result tell me that after resume we should call /sys/.../cpuinfo_cur_freq, in other words, call "cur_freq = cpufreq_get(policy->cpu);" in cpufreq.c. "cpufreq_get()" is same as "get_cur_freq(unsigned int cpu)" in speedstep-centrino.c.

In my patch, .resume function calls get_cur_freq(0) and set internal state variable 'p.state' to proper value.

p.state is only for depricated /proc/acpi/.../performance interface. so what we need is just calling get_cur_freq(0).

At Thu, 23 Sep 2004 10:02:07 +0200,

Quoted 17 lines · Dominik Brodowski
Quoted 5 lines · Hiroshi Miura

Hi,

My note pc, Panasonic Let's Note CF-R3(Pentium M 1.1GHz), troubles when resume. BIOS set cpu p-state as of ac-line state.
Centrino driver can not detect change through suspend/resume.

Actually, it should. Only the (deprecated) /proc/acpi/processor/*/performance interface may show a wrong current state, /sys/devices/system/cpu/cpu0/cpufreq/{scaling,cpuinfo}_cur_freq should be updated by doing a call to ->get().

Oh, and what suspend method are you using?

Dominik

Signature · 4 lines
Hiroshi Miura  --- http://www.da-cha.org/  --- [email protected]
NTTDATA Corp. OpenSource Software Center. --- [email protected] 
NTTDATA Intellilink Corp. OpenSource Engineering Dev. -- [email protected]
Key fingerprint = 9117 9407 5684 FBF1 4063  15B4 401D D077 04AB 8617
#4 lore raw

Re: [PATCH] speedstep-centrino: fix cpu_cur_freq when resume.

Quoted 5 lines · Hiroshi Miura

In my patch, .resume function calls get_cur_freq(0) and set internal state variable 'p.state' to proper value.

p.state is only for depricated /proc/acpi/.../performance interface. so what we need is just calling get_cur_freq(0).

Actually, the problem lies in the userspace governor, and I'd prefer to fix it instead of all drivers. I'll push this change to Dave once he gets his computers back up and running.

Thanks,
Dominik

Sometimes, a user or userspace daemon wants a specific frequency is set, but that frequency is (temporarily) unavailable or becomes unavailable due to e.g. thermal considerations. As soon as this situation changes, the user wish should be re-evaluated. The attached patch saves the user wish in "cpu_set_freq", and re-uses that whenever appropriate.

Thanks to Thomas Renninger for testing.

Signed-off-by Dominik Brodowski <linuxbrodo.de>
drivers/cpufreq/cpufreq_userspace.c +11 -12
diff -ruN linux-original/drivers/cpufreq/cpufreq_userspace.c linux/drivers/cpufreq/cpufreq_userspace.c
@@ -68,7 +68,8 @@
  */
 static unsigned int	cpu_max_freq[NR_CPUS];
 static unsigned int	cpu_min_freq[NR_CPUS];
-static unsigned int	cpu_cur_freq[NR_CPUS];
+static unsigned int	cpu_cur_freq[NR_CPUS]; /* current CPU freq */
+static unsigned int	cpu_set_freq[NR_CPUS]; /* CPU freq desired by userspace */
 static unsigned int	cpu_is_managed[NR_CPUS];
 static struct cpufreq_policy current_policy[NR_CPUS];
 
@@ -82,13 +83,6 @@
 {
         struct cpufreq_freqs *freq = data;
 
-	/* Don't update cur_freq if CPU is managed and we're
-	 * waking up: else we won't remember what frequency 
-	 * we need to set the CPU to.
-	 */
-	if (cpu_is_managed[freq->cpu] && (val == CPUFREQ_RESUMECHANGE))
-		return 0;
-
 	cpu_cur_freq[freq->cpu] = freq->new;
 
         return 0;
@@ -114,6 +108,8 @@
 	if (!cpu_is_managed[cpu])
 		goto err;
 
+	cpu_set_freq[cpu] = freq;
+
 	if (freq < cpu_min_freq[cpu])
 		freq = cpu_min_freq[cpu];
 	if (freq > cpu_max_freq[cpu])
@@ -523,6 +519,7 @@
 		cpu_min_freq[cpu] = policy->min;
 		cpu_max_freq[cpu] = policy->max;
 		cpu_cur_freq[cpu] = policy->cur;
+		cpu_set_freq[cpu] = policy->cur;
 		sysfs_create_file (&policy->kobj, &freq_attr_scaling_setspeed.attr);
 		memcpy (&current_policy[cpu], policy, sizeof(struct cpufreq_policy));
 		up(&userspace_sem);
@@ -532,6 +529,7 @@
 		cpu_is_managed[cpu] = 0;
 		cpu_min_freq[cpu] = 0;
 		cpu_max_freq[cpu] = 0;
+		cpu_set_freq[cpu] = 0;
 		sysfs_remove_file (&policy->kobj, &freq_attr_scaling_setspeed.attr);
 		up(&userspace_sem);
 		break;
@@ -539,15 +537,16 @@
 		down(&userspace_sem);
 		cpu_min_freq[cpu] = policy->min;
 		cpu_max_freq[cpu] = policy->max;
-		if (policy->max < cpu_cur_freq[cpu])
+		if (policy->max < cpu_set_freq[cpu]) {
 			__cpufreq_driver_target(&current_policy[cpu], policy->max, 
 			      CPUFREQ_RELATION_H);
-		else if (policy->min > cpu_cur_freq[cpu])
+		} else if (policy->min > cpu_set_freq[cpu]) {
 			__cpufreq_driver_target(&current_policy[cpu], policy->min, 
 			      CPUFREQ_RELATION_L);
-		else
-			__cpufreq_driver_target(&current_policy[cpu], cpu_cur_freq[cpu],
+		} else {
+			__cpufreq_driver_target(&current_policy[cpu], cpu_set_freq[cpu],
 			      CPUFREQ_RELATION_L);
+		}
 		memcpy (&current_policy[cpu], policy, sizeof(struct cpufreq_policy));
 		up(&userspace_sem);
 		break;