Skip to contentSkip to conversation

cpufrequency change on AC-Adapter Event

PATCH In review Thomas Ogrisegg 3 participants 3 messages Feb 21, 2006 – Feb 22, 2006

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

PATCH 1/1 cpufrequency change on AC-Adapter Event

Problem Description:
Whenever the status of the AC-Adapter on my laptop changes, the CPU frequency automatically changes as well. For example, if the AC adapter is online my CPU has the highest frequency (3,06 GHz). When the adapter is unplugged, the frequency automatically decreases to 1,6 GHz. However, currently the Kernel simply doesn't notice. It looks like the system is still running at 3,06 GHz (/proc/cpuinfo and /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq both show that), but it doesn't like a simple test program showed.

My patch solves this problem: Whenever the status of the AC Adapter changes, it calls 'cpufreq_reinit' which in turn reinits the CPUfreq driver.

This, of course, only works if the ACPI AC driver is compiled in.

drivers/acpi/ac.c +3 -0
diff -uNr -X linux-2.6.15/Documentation/dontdiff linux-2.6.15/drivers/acpi/ac.c linux-2.6.15.4/drivers/acpi/ac.c
@@ -29,6 +29,7 @@
 #include <linux/types.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/cpufreq.h>
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
 
@@ -213,6 +214,8 @@
 		break;
 	}
 
+	cpufreq_reinit();
+
 	return_VOID;
 }
 
drivers/cpufreq/cpufreq.c +24 -0
diff -uNr -X linux-2.6.15/Documentation/dontdiff linux-2.6.15/drivers/cpufreq/cpufreq.c linux-2.6.15.4/drivers/cpufreq/cpufreq.c
@@ -863,6 +863,30 @@
 
 
 /**
+ * cpufreq_reinit - reinitialize CPU frequency of all CPUs
+ */
+
+int cpufreq_reinit(void)
+{
+	int cpu, ret;
+	struct cpufreq_policy *policy;
+
+	for_each_online_cpu (cpu) {
+		policy = cpufreq_cpu_get(cpu);
+		if (!policy)
+			return -EINVAL;
+		ret = cpufreq_driver->exit(policy);
+		if (ret)
+			return ret;
+		ret = cpufreq_driver->init(policy);
+		if (ret)
+			return ret;
+	}
+	return (0);
+}
+EXPORT_SYMBOL(cpufreq_reinit);
+
+/**
  *	cpufreq_suspend - let the low level driver prepare for suspend
  */
 
include/linux/cpufreq.h +5 -0
@@ -256,6 +256,11 @@
 /* query the current CPU frequency (in kHz). If zero, cpufreq couldn't detect it */
 unsigned int cpufreq_get(unsigned int cpu);
 
+#ifdef CONFIG_CPU_FREQ
+int cpu_freq_reinit(void);
+#else
+static inline int cpu_freq_reinit(void) { return 0; }
+#endif
 
 /*********************************************************************
  *                       CPUFREQ DEFAULT GOVERNOR                    *
#1 lore raw
Quoted 10 lines · Thomas Ogrisegg

Problem Description:
Whenever the status of the AC-Adapter on my laptop changes, the CPU frequency automatically changes as well. For example, if the AC adapter is online my CPU has the highest frequency (3,06 GHz). When the adapter is unplugged, the frequency automatically decreases to 1,6 GHz. However, currently the Kernel simply doesn't notice. It looks like the system is still running at 3,06 GHz (/proc/cpuinfo and /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq both show that), but it doesn't like a simple test program showed.

Quoted 5 lines

My patch solves this problem: Whenever the status of the AC Adapter changes, it calls 'cpufreq_reinit' which in turn reinits the CPUfreq driver.

This, of course, only works if the ACPI AC driver is compiled in.

Uh, no, this just wraps band-aid around the problem. First of all, not all cpufreq drivers like to be left and re-initialized. Secondly, the timing code might still not adapt to the new CPU frequency. And thirdly, we can solve these issues if we call

Quoted 15 lines

diff -uNr -X linux-2.6.15/Documentation/dontdiff linux-2.6.15/drivers/acpi/ac.c linux-2.6.15.4/drivers/acpi/ac.c

drivers/acpi/ac.c +1 -0
@@ -29,6 +29,7 @@
 #include <linux/types.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/cpufreq.h>
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
 

drivers/acpi/ac.c line 217

Quoted 4 lines
drivers/acpi/ac.c +1 -0
@@ -213,6 +214,8 @@
 		break;
 	}
 
+	cpufreq_reinit();
	cpufreq_update_policy();

here instead. (untested, but should work)

Thanks,
Dominik

#2 lore raw
In reply to Thomas Ogrisegg
Quoted 30 lines · Thomas Ogrisegg

Problem Description:
Whenever the status of the AC-Adapter on my laptop changes, the CPU frequency automatically changes as well. For example, if the AC adapter is online my CPU has the highest frequency (3,06 GHz). When the adapter is unplugged, the frequency automatically decreases to 1,6 GHz. However, currently the Kernel simply doesn't notice. It looks like the system is still running at 3,06 GHz (/proc/cpuinfo and /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq both show that), but it doesn't like a simple test program showed.

My patch solves this problem: Whenever the status of the AC Adapter changes, it calls 'cpufreq_reinit' which in turn reinits the CPUfreq driver.

This, of course, only works if the ACPI AC driver is compiled in.

diff -uNr -X linux-2.6.15/Documentation/dontdiff linux-2.6.15/drivers/acpi/ac.c linux-2.6.15.4/drivers/acpi/ac.c

drivers/acpi/ac.c +1 -0
@@ -29,6 +29,7 @@
 #include <linux/types.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/cpufreq.h>
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
 

drivers/acpi/ac.c line 221

Quoted 8 lines
drivers/acpi/ac.c +2 -0
@@ -213,6 +214,8 @@
 		break;
 	}
 
+	cpufreq_reinit();
+
 	return_VOID;
 }
 

Perhaps we need to call some notifier chain here? I think not only cpufreq is going to be interested...
Pavel

Signature · 1 line
Web maintainer for suspend.sf.net (www.sf.net/projects/suspend) wanted...