Skip to contentSkip to conversation

CPUIDLE - A Framework for Idle CPU PM

PATCH In review Adam Belay 2 participants 2 messages Jul 26, 2007 – Aug 7, 2007

Subsystems (4)
lore
Share & tools
lore

Adam Belay

author
#0 lore raw

PATCH 1/1 CPUIDLE - A Framework for Idle CPU PM

Hi All,

Cpuidle is a generic framework for idle processor power management that Venki Pallipadi, Shaohua Li, and I developed collaboratively. It is a layered architecture that separates platform-specific processor power drivers from higher level policy governors. In this sense, it is analogous to cpufreq. However, it manages nonoperative idle states rather than frequency and voltage operating points.

I've attached the most recent version of cpuidle as a stand alone patch against 2.6.22. This new code is much lighter weight than the initial release. It includes the core cpuidle infrastructure, an ACPI processor driver, and some modifications to the tick implementation to help better predict the time remaining until the next break event. I look forward to any questions, comments, or suggestions.

Cheers,
Adam

Summary of changes:

 arch/i386/Kconfig                  |    2
 arch/x86_64/Kconfig                |    2
 drivers/Makefile                   |    1
 drivers/acpi/processor_core.c      |   22
 drivers/acpi/processor_idle.c      |  923 ++++++++++++++-----------------------
 drivers/cpuidle/Kconfig            |   39 +
 drivers/cpuidle/Makefile           |    5
 drivers/cpuidle/cpuidle.c          |  297 +++++++++++
 drivers/cpuidle/cpuidle.h          |   33 +
 drivers/cpuidle/driver.c           |   69 ++
 drivers/cpuidle/governor.c         |  141 +++++
 drivers/cpuidle/governors/Makefile |    6
 drivers/cpuidle/governors/ladder.c |  210 ++++++++
 drivers/cpuidle/governors/menu.c   |  147 +++++
 drivers/cpuidle/sysfs.c            |  364 ++++++++++++++
 include/acpi/processor.h           |    4
 include/linux/cpuidle.h            |  184 +++++++
 include/linux/tick.h               |    9
 kernel/time/tick-sched.c           |   16
 19 files changed, 1912 insertions(+), 562 deletions(-)

---

arch/i386/Kconfig +2 -0
diff -urN linux-2.6.22/arch/i386/Kconfig linux-cpuidle/arch/i386/Kconfig
@@ -1053,6 +1053,8 @@
 
 source "arch/i386/kernel/cpu/cpufreq/Kconfig"
 
+source "drivers/cpuidle/Kconfig"
+
 endmenu
 
 menu "Bus options (PCI, PCMCIA, EISA, MCA, ISA)"
arch/x86_64/Kconfig +2 -0
diff -urN linux-2.6.22/arch/x86_64/Kconfig linux-cpuidle/arch/x86_64/Kconfig
@@ -698,6 +698,8 @@
 
 source "arch/x86_64/kernel/cpufreq/Kconfig"
 
+source "drivers/cpuidle/Kconfig"
+
 endmenu
 
 menu "Bus options (PCI etc.)"
drivers/acpi/processor_core.c +17 -5
diff -urN linux-2.6.22/drivers/acpi/processor_core.c linux-cpuidle/drivers/acpi/processor_core.c
@@ -44,6 +44,7 @@
 #include <linux/seq_file.h>
 #include <linux/dmi.h>
 #include <linux/moduleparam.h>
+#include <linux/cpuidle.h>
 
 #include <asm/io.h>
 #include <asm/system.h>
@@ -1010,11 +1011,13 @@
 		return -ENOMEM;
 	acpi_processor_dir->owner = THIS_MODULE;
 
+	result = cpuidle_register_driver(&acpi_idle_driver);
+	if (result < 0)
+		goto out_proc;
+
 	result = acpi_bus_register_driver(&acpi_processor_driver);
-	if (result < 0) {
-		remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
-		return result;
-	}
+	if (result < 0)
+		goto out_cpuidle;
 
 	acpi_processor_install_hotplug_notify();
 
@@ -1023,11 +1026,18 @@
 	acpi_processor_ppc_init();
 
 	return 0;
+
+out_cpuidle:
+	cpuidle_unregister_driver(&acpi_idle_driver);
+
+out_proc:
+	remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
+
+	return result;
 }
 
 static void __exit acpi_processor_exit(void)
 {
-
 	acpi_processor_ppc_exit();
 
 	acpi_thermal_cpufreq_exit();
@@ -1036,6 +1046,8 @@
 
 	acpi_bus_unregister_driver(&acpi_processor_driver);
 
+	cpuidle_unregister_driver(&acpi_idle_driver);
+
 	remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
 
 	return;
drivers/acpi/processor_idle.c +366 -557

1,037 lines not on this page · raw message

drivers/cpuidle/cpuidle.c +297 -0

297 lines not on this page · raw message

drivers/cpuidle/cpuidle.h +33 -0
diff -urN linux-2.6.22/drivers/cpuidle/cpuidle.h linux-cpuidle/drivers/cpuidle/cpuidle.h
@@ -0,0 +1,33 @@
+/*
+ * cpuidle.h - The internal header file
+ */
+
+#ifndef __DRIVER_CPUIDLE_H
+#define __DRIVER_CPUIDLE_H
+
+#include <linux/sysdev.h>
+
+/* For internal use only */
+extern struct cpuidle_governor *cpuidle_curr_governor;
+extern struct cpuidle_driver *cpuidle_curr_driver;
+extern struct list_head cpuidle_governors;
+extern struct list_head cpuidle_detected_devices;
+extern struct mutex cpuidle_lock;
+extern spinlock_t cpuidle_driver_lock;
+
+/* idle loop */
+extern void cpuidle_install_idle_handler(void);
+extern void cpuidle_uninstall_idle_handler(void);
+
+/* governors */
+extern int cpuidle_switch_governor(struct cpuidle_governor *gov);
+
+/* sysfs */
+extern int cpuidle_add_class_sysfs(struct sysdev_class *cls);
+extern void cpuidle_remove_class_sysfs(struct sysdev_class *cls);
+extern int cpuidle_add_state_sysfs(struct cpuidle_device *device);
+extern void cpuidle_remove_state_sysfs(struct cpuidle_device *device);
+extern int cpuidle_add_sysfs(struct sys_device *sysdev);
+extern void cpuidle_remove_sysfs(struct sys_device *sysdev);
+
+#endif /* __DRIVER_CPUIDLE_H */
drivers/cpuidle/driver.c +69 -0

69 lines not on this page · raw message

drivers/cpuidle/governor.c +141 -0

141 lines not on this page · raw message

drivers/cpuidle/governors/ladder.c +210 -0

210 lines not on this page · raw message

drivers/cpuidle/governors/Makefile +6 -0
diff -urN linux-2.6.22/drivers/cpuidle/governors/Makefile linux-cpuidle/drivers/cpuidle/governors/Makefile
@@ -0,0 +1,6 @@
+#
+# Makefile for cpuidle governors.
+#
+
+obj-$(CONFIG_CPU_IDLE_GOV_LADDER) += ladder.o
+obj-$(CONFIG_CPU_IDLE_GOV_MENU) += menu.o
drivers/cpuidle/governors/menu.c +147 -0

147 lines not on this page · raw message

drivers/cpuidle/Kconfig +39 -0
diff -urN linux-2.6.22/drivers/cpuidle/Kconfig linux-cpuidle/drivers/cpuidle/Kconfig
@@ -0,0 +1,39 @@
+menu "CPU idle PM support"
+
+config CPU_IDLE
+	bool "CPU idle PM support"
+	help
+	  CPU idle is a generic framework for supporting software-controlled
+	  idle processor power management.  It includes modular cross-platform
+	  governors that can be swapped during runtime.
+
+	  If you're using a mobile platform that supports CPU idle PM (e.g.
+	  an ACPI-capable notebook), you should say Y here.
+
+if CPU_IDLE
+
+comment "Governors"
+
+config CPU_IDLE_GOV_LADDER
+	tristate "'ladder' governor"
+	depends on CPU_IDLE
+	default y
+	help
+	  This cpuidle governor promotes and demotes through the supported idle
+	  states using residency time and bus master activity as metrics.  This
+	  algorithm was originally introduced in the old ACPI processor driver.
+
+config CPU_IDLE_GOV_MENU
+	tristate "'menu' governor"
+	depends on CPU_IDLE && NO_HZ
+	default y
+	help
+	  This cpuidle governor evaluates all available states and chooses the
+	  deepest state that meets all of the following constraints: BM activity,
+	  expected time until next timer interrupt, and last break event time
+	  delta.  It is designed to minimize power consumption.  Currently
+	  dynticks is required.
+
+endif	# CPU_IDLE
+
+endmenu
drivers/cpuidle/Makefile +5 -0
diff -urN linux-2.6.22/drivers/cpuidle/Makefile linux-cpuidle/drivers/cpuidle/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for cpuidle.
+#
+
+obj-y += cpuidle.o driver.o governor.o sysfs.o governors/
drivers/cpuidle/sysfs.c +364 -0

364 lines not on this page · raw message

drivers/Makefile +1 -0
diff -urN linux-2.6.22/drivers/Makefile linux-cpuidle/drivers/Makefile
@@ -70,6 +70,7 @@
 obj-$(CONFIG_MCA)		+= mca/
 obj-$(CONFIG_EISA)		+= eisa/
 obj-$(CONFIG_CPU_FREQ)		+= cpufreq/
+obj-$(CONFIG_CPU_IDLE)		+= cpuidle/
 obj-$(CONFIG_MMC)		+= mmc/
 obj-$(CONFIG_NEW_LEDS)		+= leds/
 obj-$(CONFIG_INFINIBAND)	+= infiniband/
include/acpi/processor.h +4 -0
diff -urN linux-2.6.22/include/acpi/processor.h linux-cpuidle/include/acpi/processor.h
@@ -3,6 +3,7 @@
 
 #include <linux/kernel.h>
 #include <linux/cpu.h>
+#include <linux/cpuidle.h>
 
 #include <asm/acpi.h>
 
@@ -73,6 +74,7 @@
 };
 
 struct acpi_processor_power {
+	struct cpuidle_device dev;
 	struct acpi_processor_cx *state;
 	unsigned long bm_check_timestamp;
 	u32 default_state;
@@ -161,6 +163,7 @@
 	u8 bm_check:1;
 	u8 has_cst:1;
 	u8 power_setup_done:1;
+	u8 bm_rld_set:1;
 };
 
 struct acpi_processor {
@@ -279,6 +282,7 @@
 int acpi_processor_cst_has_changed(struct acpi_processor *pr);
 int acpi_processor_power_exit(struct acpi_processor *pr,
 			      struct acpi_device *device);
+extern struct cpuidle_driver acpi_idle_driver;
 
 /* in processor_thermal.c */
 int acpi_processor_get_limit_info(struct acpi_processor *pr);
include/linux/cpuidle.h +184 -0

184 lines not on this page · raw message

include/linux/tick.h +9 -0
diff -urN linux-2.6.22/include/linux/tick.h linux-cpuidle/include/linux/tick.h
@@ -40,6 +40,7 @@
  * @idle_sleeps:	Number of idle calls, where the sched tick was stopped
  * @idle_entrytime:	Time when the idle call was entered
  * @idle_sleeptime:	Sum of the time slept in idle with sched tick stopped
+ * @sleep_length:	Duration of the current idle sleep
  */
 struct tick_sched {
 	struct hrtimer			sched_timer;
@@ -52,6 +53,7 @@
 	unsigned long			idle_sleeps;
 	ktime_t				idle_entrytime;
 	ktime_t				idle_sleeptime;
+	ktime_t				sleep_length;
 	unsigned long			last_jiffies;
 	unsigned long			next_jiffies;
 	ktime_t				idle_expires;
@@ -100,10 +102,17 @@
 extern void tick_nohz_stop_sched_tick(void);
 extern void tick_nohz_restart_sched_tick(void);
 extern void tick_nohz_update_jiffies(void);
+extern ktime_t tick_nohz_get_sleep_length(void);
 # else
 static inline void tick_nohz_stop_sched_tick(void) { }
 static inline void tick_nohz_restart_sched_tick(void) { }
 static inline void tick_nohz_update_jiffies(void) { }
+static inline ktime_t tick_nohz_get_sleep_length(void)
+{
+	ktime_t len = { .tv64 = NSEC_PER_SEC/HZ };
+
+	return len;
+}
 # endif /* !NO_HZ */
 
 #endif
kernel/time/tick-sched.c +16 -0
diff -urN linux-2.6.22/kernel/time/tick-sched.c linux-cpuidle/kernel/time/tick-sched.c
@@ -153,6 +153,7 @@
 	unsigned long seq, last_jiffies, next_jiffies, delta_jiffies, flags;
 	struct tick_sched *ts;
 	ktime_t last_update, expires, now, delta;
+	struct clock_event_device *dev = __get_cpu_var(tick_cpu_device).evtdev;
 	int cpu;
 
 	local_irq_save(flags);
@@ -290,11 +291,26 @@
 out:
 	ts->next_jiffies = next_jiffies;
 	ts->last_jiffies = last_jiffies;
+	ts->sleep_length = ktime_sub(dev->next_event, now);
 end:
 	local_irq_restore(flags);
 }
 
 /**
+ * tick_nohz_get_sleep_length - return the length of the current sleep
+ *
+ * Called from power state control code with interrupts disabled
+ */
+ktime_t tick_nohz_get_sleep_length(void)
+{
+	struct tick_sched *ts = &__get_cpu_var(tick_cpu_sched);
+
+	return ts->sleep_length;
+}
+
+EXPORT_SYMBOL_GPL(tick_nohz_get_sleep_length);
+
+/**
  * nohz_restart_sched_tick - restart the idle tick from the idle task
  *
  * Restart the idle tick when the CPU is woken up from idle
#1 lore raw

Hi!

Quoted 11 lines

Cpuidle is a generic framework for idle processor power management that Venki Pallipadi, Shaohua Li, and I developed collaboratively. It is a layered architecture that separates platform-specific processor power drivers from higher level policy governors. In this sense, it is analogous to cpufreq. However, it manages nonoperative idle states rather than frequency and voltage operating points.

I've attached the most recent version of cpuidle as a stand alone patch against 2.6.22. This new code is much lighter weight than the initial release. It includes the core cpuidle infrastructure, an ACPI processor

Plus it is in -mm tree. Congratulations! :-).
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html