aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpuidle
diff options
context:
space:
mode:
authorLen Brown <len.brown@intel.com>2007-10-03 18:58:00 -0400
committerLen Brown <len.brown@intel.com>2007-10-10 00:12:41 -0400
commit4f86d3a8e297205780cca027e974fd5f81064780 (patch)
tree3c89624dea48a9de756256c935660ff7b24d5376 /drivers/cpuidle
parentbbf25010f1a6b761914430f5fca081ec8c7accd1 (diff)
cpuidle: consolidate 2.6.22 cpuidle branch into one patch
commit e5a16b1f9eec0af7cfa0830304b41c1c0833cf9f Author: Len Brown <len.brown@intel.com> Date: Tue Oct 2 23:44:44 2007 -0400 cpuidle: shrink diff processor_idle.c | 440 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 429 insertions(+), 11 deletions(-) Signed-off-by: Len Brown <len.brown@intel.com> commit dfbb9d5aedfb18848a3e0d6f6e3e4969febb209c Author: Len Brown <len.brown@intel.com> Date: Wed Sep 26 02:17:55 2007 -0400 cpuidle: reduce diff size Reduces the cpuidle processor_idle.c diff vs 2.6.22 from this processor_idle.c | 2006 ++++++++++++++++++++++++++----------------- 1 file changed, 1219 insertions(+), 787 deletions(-) to this: processor_idle.c | 502 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 458 insertions(+), 44 deletions(-) ...for the purpose of making the cpuilde patch less invasive and easier to review. no functional changes. build tested only. Signed-off-by: Len Brown <len.brown@intel.com> commit 889172fc915f5a7fe20f35b133cbd205ce69bf6c Author: Venki Pallipadi <venkatesh.pallipadi@intel.com> Date: Thu Sep 13 13:40:05 2007 -0700 cpuidle: Retain old ACPI policy for !CONFIG_CPU_IDLE Retain the old policy in processor_idle, so that when CPU_IDLE is not configured, old C-state policy will still be used. This provides a clean gradual migration path from old ACPI policy to new cpuidle based policy. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit 9544a8181edc7ecc33b3bfd69271571f98ed08bc Author: Venki Pallipadi <venkatesh.pallipadi@intel.com> Date: Thu Sep 13 13:39:17 2007 -0700 cpuidle: Configure governors by default Quoting Len "Do not give an option to users to shoot themselves in the foot". Remove the configurability of ladder and menu governors as they are needed for default policy of cpuidle. That way users will not be able to have cpuidle without any policy loosing all C-state power savings. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit 8975059a2c1e56cfe83d1bcf031bcf4cb39be743 Author: Adam Belay <abelay@novell.com> Date: Tue Aug 21 18:27:07 2007 -0400 CPUIDLE: load ACPI properly when CPUIDLE is disabled Change the registration return codes for when CPUIDLE support is not compiled into the kernel. As a result, the ACPI processor driver will load properly even if CPUIDLE is unavailable. However, it may be possible to cleanup the ACPI processor driver further and eliminate some dead code paths. Signed-off-by: Adam Belay <abelay@novell.com> Acked-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit e0322e2b58dd1b12ec669bf84693efe0dc2414a8 Author: Adam Belay <abelay@novell.com> Date: Tue Aug 21 18:26:06 2007 -0400 CPUIDLE: remove cpuidle_get_bm_activity() Remove cpuidle_get_bm_activity() and updates governors accordingly. Signed-off-by: Adam Belay <abelay@novell.com> Acked-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit 18a6e770d5c82ba26653e53d240caa617e09e9ab Author: Adam Belay <abelay@novell.com> Date: Tue Aug 21 18:25:58 2007 -0400 CPUIDLE: max_cstate fix Currently max_cstate is limited to 0, resulting in no idle processor power management on ACPI platforms. This patch restores the value to the array size. Signed-off-by: Adam Belay <abelay@novell.com> Acked-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit 1fdc0887286179b40ce24bcdbde663172e205ef0 Author: Adam Belay <abelay@novell.com> Date: Tue Aug 21 18:25:40 2007 -0400 CPUIDLE: handle BM detection inside the ACPI Processor driver Update the ACPI processor driver to detect BM activity and limit state entry depth internally, rather than exposing such requirements to CPUIDLE. As a result, CPUIDLE can drop this ACPI-specific interface and become more platform independent. BM activity is now handled much more aggressively than it was in the original implementation, so some testing coverage may be needed to verify that this doesn't introduce any DMA buffer under-run issues. Signed-off-by: Adam Belay <abelay@novell.com> Acked-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit 0ef38840db666f48e3cdd2b769da676c57228dd9 Author: Adam Belay <abelay@novell.com> Date: Tue Aug 21 18:25:14 2007 -0400 CPUIDLE: menu governor updates Tweak the menu governor to more effectively handle non-timer break events. Non-timer break events are detected by comparing the actual sleep time to the expected sleep time. In future revisions, it may be more reliable to use the timer data structures directly. Signed-off-by: Adam Belay <abelay@novell.com> Acked-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit bb4d74fca63fa96cf3ace644b15ae0f12b7df5a1 Author: Adam Belay <abelay@novell.com> Date: Tue Aug 21 18:24:40 2007 -0400 CPUIDLE: fix 'current_governor' sysfs entry Allow the "current_governor" sysfs entry to properly handle input terminated with '\n'. Signed-off-by: Adam Belay <abelay@novell.com> Acked-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit df3c71559bb69b125f1a48971bf0d17f78bbdf47 Author: Len Brown <len.brown@intel.com> Date: Sun Aug 12 02:00:45 2007 -0400 cpuidle: fix IA64 build (again) Signed-off-by: Len Brown <len.brown@intel.com> commit a02064579e3f9530fd31baae16b1fc46b5a7bca8 Author: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Date: Sun Aug 12 01:39:27 2007 -0400 cpuidle: Remove support for runtime changing of max_cstate Remove support for runtime changeability of max_cstate. Drivers can use use latency APIs. max_cstate can still be used as a boot time option and dmi override. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit 0912a44b13adf22f5e3f607d263aed23b4910d7e Author: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Date: Sun Aug 12 01:39:16 2007 -0400 cpuidle: Remove ACPI cstate_limit calls from ipw2100 ipw2100 already has code to use accetable_latency interfaces to limit the C-state. Remove the calls to acpi_set_cstate_limit and acpi_get_cstate_limit as they are redundant. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit c649a76e76be6bff1fd770d0a775798813a3f6e0 Author: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Date: Sun Aug 12 01:35:39 2007 -0400 cpuidle: compile fix for pause and resume functions Fix the compilation failure when cpuidle is not compiled in. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Acked-by: Adam Belay <adam.belay@novell.com> Signed-off-by: Len Brown <len.brown@intel.com> commit 2305a5920fb8ee6ccec1c62ade05aa8351091d71 Author: Adam Belay <abelay@novell.com> Date: Thu Jul 19 00:49:00 2007 -0400 cpuidle: re-write Some portions have been rewritten to make the code cleaner and lighter weight. The following is a list of changes: 1.) the state name is now included in the sysfs interface 2.) detection, hotplug, and available state modifications are handled by CPUIDLE drivers directly 3.) the CPUIDLE idle handler is only ever installed when at least one cpuidle_device is enabled and ready 4.) the menu governor BM code no longer overflows 5.) the sysfs attributes are now printed as unsigned integers, avoiding negative values 6.) a variety of other small cleanups Also, Idle drivers are no longer swappable during runtime through the CPUIDLE sysfs inteface. On i386 and x86_64 most idle handlers (e.g. poll, mwait, halt, etc.) don't benefit from an infrastructure that supports multiple states, so I think using a more general case idle handler selection mechanism would be cleaner. Signed-off-by: Adam Belay <abelay@novell.com> Acked-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Acked-by: Shaohua Li <shaohua.li@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit df25b6b56955714e6e24b574d88d1fd11f0c3ee5 Author: Len Brown <len.brown@intel.com> Date: Tue Jul 24 17:08:21 2007 -0400 cpuidle: fix IA64 buid Signed-off-by: Len Brown <len.brown@intel.com> commit fd6ada4c14488755ff7068860078c437431fbccd Author: Adrian Bunk <bunk@stusta.de> Date: Mon Jul 9 11:33:13 2007 -0700 cpuidle: static make cpuidle_replace_governor() static Signed-off-by: Adrian Bunk <bunk@stusta.de> Cc: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit c1d4a2cebcadf2429c0c72e1d29aa2a9684c32e0 Author: Adrian Bunk <bunk@stusta.de> Date: Tue Jul 3 00:54:40 2007 -0400 cpuidle: static This patch makes the needlessly global struct menu_governor static. Signed-off-by: Adrian Bunk <bunk@stusta.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit dbf8780c6e8d572c2c273da97ed1cca7608fd999 Author: Andrew Morton <akpm@linux-foundation.org> Date: Tue Jul 3 00:49:14 2007 -0400 export symbol tick_nohz_get_sleep_length ERROR: "tick_nohz_get_sleep_length" [drivers/cpuidle/governors/menu.ko] undefined! ERROR: "tick_nohz_get_idle_jiffies" [drivers/cpuidle/governors/menu.ko] undefined! And please be sure to get your changes to core kernel suitably reviewed. Cc: Adam Belay <abelay@novell.com> Cc: Venki Pallipadi <venkatesh.pallipadi@intel.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: john stultz <johnstul@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit 29f0e248e7017be15f99febf9143a2cef00b2961 Author: Andrew Morton <akpm@linux-foundation.org> Date: Tue Jul 3 00:43:04 2007 -0400 tick.h needs hrtimer.h It uses hrtimers. Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit e40cede7d63a029e92712a3fe02faee60cc38fb4 Author: Venki Pallipadi <venkatesh.pallipadi@intel.com> Date: Tue Jul 3 00:40:34 2007 -0400 cpuidle: first round of documentation updates Documentation changes based on Pavel's feedback. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit 83b42be2efece386976507555c29e7773a0dfcd1 Author: Venki Pallipadi <venkatesh.pallipadi@intel.com> Date: Tue Jul 3 00:39:25 2007 -0400 cpuidle: add rating to the governors and pick the one with highest rating by default Introduce a governor rating scheme to pick the right governor by default. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit d2a74b8c5e8f22def4709330d4bfc4a29209b71c Author: Venki Pallipadi <venkatesh.pallipadi@intel.com> Date: Tue Jul 3 00:38:08 2007 -0400 cpuidle: make cpuidle sysfs driver governor switch off by default Make default cpuidle sysfs to show current_governor and current_driver in read-only mode. More elaborate available_governors and available_drivers with writeable current_governor and current_driver interface only appear with "cpuidle_sysfs_switch" boot parameter. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit 1f60a0e80bf83cf6b55c8845bbe5596ed8f6307b Author: Venki Pallipadi <venkatesh.pallipadi@intel.com> Date: Tue Jul 3 00:37:00 2007 -0400 cpuidle: menu governor: change the early break condition Change the C-state early break out algorithm in menu governor. We only look at early breakouts that result in wakeups shorter than idle state's target_residency. If such a breakout is frequent enough, eliminate the particular idle state upto a timeout period. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit 45a42095cf64b003b4a69be3ce7f434f97d7af51 Author: Venki Pallipadi <venkatesh.pallipadi@intel.com> Date: Tue Jul 3 00:35:38 2007 -0400 cpuidle: fix uninitialized variable in sysfs routine Fix the uninitialized usage of ret. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit 80dca7cdba3e6ee13eae277660873ab9584eb3be Author: Venki Pallipadi <venkatesh.pallipadi@intel.com> Date: Tue Jul 3 00:34:16 2007 -0400 cpuidle: reenable /proc/acpi//power interface for the time being Keep /proc/acpi/processor/CPU*/power around for a while as powertop depends on it. It will be marked deprecated and removed in future. powertop can use cpuidle interfaces instead. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit 589c37c2646c5e3813a51255a5ee1159cb4c33fc Author: Venki Pallipadi <venkatesh.pallipadi@intel.com> Date: Tue Jul 3 00:32:37 2007 -0400 cpuidle: menu governor and hrtimer compile fix Compile fix for menu governor. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit 0ba80bd9ab3ed304cb4f19b722e4cc6740588b5e Author: Len Brown <len.brown@intel.com> Date: Thu May 31 22:51:43 2007 -0400 cpuidle: build fix - cpuidle vs ipw2100 module ERROR: "acpi_set_cstate_limit" [drivers/net/wireless/ipw2100.ko] undefined! Signed-off-by: Len Brown <len.brown@intel.com> commit d7d8fa7f96a7f7682be7c6cc0cc53fa7a18c3b58 Author: Adam Belay <abelay@novell.com> Date: Sat Mar 24 03:47:07 2007 -0400 cpuidle: add the 'menu' governor Here is my first take at implementing an idle PM governor that takes full advantage of NO_HZ. I call it the 'menu' governor because it considers the full list of idle states before each entry. I've kept the implementation fairly simple. It attempts to guess the next residency time and then chooses a state that would meet at least the break-even point between power savings and entry cost. To this end, it selects the deepest idle state that satisfies the following constraints: 1. If the idle time elapsed since bus master activity was detected is below a threshold (currently 20 ms), then limit the selection to C2-type or above. 2. Do not choose a state with a break-even residency that exceeds the expected time remaining until the next timer interrupt. 3. Do not choose a state with a break-even residency that exceeds the elapsed time between the last pair of break events, excluding timer interrupts. This governor has an advantage over "ladder" governor because it proactively checks how much time remains until the next timer interrupt using the tick infrastructure. Also, it handles device interrupt activity more intelligently by not including timer interrupts in break event calculations. Finally, it doesn't make policy decisions using the number of state entries, which can have variable residency times (NO_HZ makes these potentially very large), and instead only considers sleep time deltas. The menu governor can be selected during runtime using the cpuidle sysfs interface like so: "echo "menu" > /sys/devices/system/cpu/cpuidle/current_governor" Signed-off-by: Adam Belay <abelay@novell.com> Signed-off-by: Len Brown <len.brown@intel.com> commit a4bec7e65aa3b7488b879d971651cc99a6c410fe Author: Adam Belay <abelay@novell.com> Date: Sat Mar 24 03:47:03 2007 -0400 cpuidle: export time until next timer interrupt using NO_HZ Expose information about the time remaining until the next timer interrupt expires by utilizing the dynticks infrastructure. Also modify the main idle loop to allow dynticks to handle non-interrupt break events (e.g. DMA). Finally, expose sleep ticks information to external code. Thomas Gleixner is responsible for much of the code in this patch. However, I've made some additional changes, so I'm probably responsible if there are any bugs or oversights :) Signed-off-by: Adam Belay <abelay@novell.com> Signed-off-by: Len Brown <len.brown@intel.com> commit 2929d8996fbc77f41a5ff86bb67cdde3ca7d2d72 Author: Adam Belay <abelay@novell.com> Date: Sat Mar 24 03:46:58 2007 -0400 cpuidle: governor API changes This patch prepares cpuidle for the menu governor. It adds an optional stage after idle state entry to give the governor an opportunity to check why the state was exited. Also it makes sure the idle loop returns after each state entry, allowing the appropriate dynticks code to run. Signed-off-by: Adam Belay <abelay@novell.com> Signed-off-by: Len Brown <len.brown@intel.com> commit 3a7fd42f9825c3b03e364ca59baa751bb350775f Author: Venki Pallipadi <venkatesh.pallipadi@intel.com> Date: Thu Apr 26 00:03:59 2007 -0700 cpuidle: hang fix Prevent hang on x86-64, when ACPI processor driver is added as a module on a system that does not support C-states. x86-64 expects all idle handlers to enable interrupts before returning from idle handler. This is due to enter_idle(), exit_idle() races. Make cpuidle_idle_call() confirm to this when there is no pm_idle_old. Also, cpuidle look at the return values of attch_driver() and set current_driver to NULL if attach fails on all CPUs. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit 4893339a142afbd5b7c01ffadfd53d14746e858e Author: Shaohua Li <shaohua.li@intel.com> Date: Thu Apr 26 10:40:09 2007 +0800 cpuidle: add support for max_cstate limit With CPUIDLE framework, the max_cstate (to limit max cpu c-state) parameter is ingored. Some systems require it to ignore C2/C3 and some drivers like ipw require it too. Signed-off-by: Shaohua Li <shaohua.li@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit 43bbbbe1cb998cbd2df656f55bb3bfe30f30e7d1 Author: Shaohua Li <shaohua.li@intel.com> Date: Thu Apr 26 10:40:13 2007 +0800 cpuidle: add cpuidle_fore_redetect_devices API add cpuidle_force_redetect_devices API, which forces all CPU redetect idle states. Next patch will use it. Signed-off-by: Shaohua Li <shaohua.li@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit d1edadd608f24836def5ec483d2edccfb37b1d19 Author: Shaohua Li <shaohua.li@intel.com> Date: Thu Apr 26 10:40:01 2007 +0800 cpuidle: fix sysfs related issue Fix the cpuidle sysfs issue. a. make kobject dynamicaly allocated b. fixed sysfs init issue to avoid suspend/resume issue Signed-off-by: Shaohua Li <shaohua.li@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit 7169a5cc0d67b263978859672e86c13c23a5570d Author: Randy Dunlap <randy.dunlap@oracle.com> Date: Wed Mar 28 22:52:53 2007 -0400 cpuidle: 1-bit field must be unsigned A 1-bit bitfield has no room for a sign bit. drivers/cpuidle/governors/ladder.c:54:16: error: dubious bitfield without explicit `signed' or `unsigned' Signed-off-by: Randy Dunlap <randy.dunlap@oracle.com> Cc: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit 4658620158dc2fbd9e4bcb213c5b6fb5d05ba7d4 Author: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Date: Wed Mar 28 22:52:41 2007 -0400 cpuidle: fix boot hang Patch for cpuidle boot hang reported by Larry Finger here. http://www.ussg.iu.edu/hypermail/linux/kernel/0703.2/2025.html Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Cc: Larry Finger <larry.finger@lwfinger.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit c17e168aa6e5fe3851baaae8df2fbc1cf11443a9 Author: Len Brown <len.brown@intel.com> Date: Wed Mar 7 04:37:53 2007 -0500 cpuidle: ladder does not depend on ACPI build fix for CONFIG_ACPI=n In file included from drivers/cpuidle/governors/ladder.c:21: include/acpi/processor.h:88: error: expected specifier-qualifier-list before ‘acpi_integer’ include/acpi/processor.h:106: error: expected specifier-qualifier-list before ‘acpi_integer’ include/acpi/processor.h:168: error: expected specifier-qualifier-list before ‘acpi_handle’ Signed-off-by: Len Brown <len.brown@intel.com> commit 8c91d958246bde68db0c3f0c57b535962ce861cb Author: Adrian Bunk <bunk@stusta.de> Date: Tue Mar 6 02:29:40 2007 -0800 cpuidle: make code static This patch makes the following needlessly global code static: - driver.c: __cpuidle_find_driver() - governor.c: __cpuidle_find_governor() - ladder.c: struct ladder_governor Signed-off-by: Adrian Bunk <bunk@stusta.de> Cc: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Cc: Adam Belay <abelay@novell.com> Cc: Shaohua Li <shaohua.li@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit 0c39dc3187094c72c33ab65a64d2017b21f372d2 Author: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Date: Wed Mar 7 02:38:22 2007 -0500 cpu_idle: fix build break This patch fixes a build breakage with !CONFIG_HOTPLUG_CPU and CONFIG_CPU_IDLE. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Adrian Bunk <bunk@stusta.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit 8112e3b115659b07df340ef170515799c0105f82 Author: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Date: Tue Mar 6 02:29:39 2007 -0800 cpuidle: build fix for !CPU_IDLE Fix the compile issues when CPU_IDLE is not configured. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Cc: Adam Belay <abelay@novell.com> Cc: Shaohua Li <shaohua.li@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Len Brown <len.brown@intel.com> commit 1eb4431e9599cd25e0d9872f3c2c8986821839dd Author: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Date: Thu Feb 22 13:54:57 2007 -0800 cpuidle take2: Basic documentation for cpuidle Documentation for cpuidle infrastructure Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Adam Belay <abelay@novell.com> Signed-off-by: Shaohua Li <shaohua.li@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> commit ef5f15a8b79123a047285ec2e3899108661df779 Author: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Date: Thu Feb 22 13:54:03 2007 -0800 cpuidle take2: Hookup ACPI C-states driver with cpuidle Hookup ACPI C-states onto generic cpuidle infrastructure. drivers/acpi/procesor_idle.c is now a ACPI C-states driver that registers as a driver in cpuidle infrastructure and the policy part is removed from drivers/acpi/processor_idle.c. We use governor in cpuidle instead. Signed-off-by: Shaohua Li <shaohua.li@intel.com> Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Adam Belay <abelay@novell.com> Signed-off-by: Len Brown <len.brown@intel.com> commit 987196fa82d4db52c407e8c9d5dec884ba602183 Author: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Date: Thu Feb 22 13:52:57 2007 -0800 cpuidle take2: Core cpuidle infrastructure Announcing 'cpuidle', a new CPU power management infrastructure to manage idle CPUs in a clean and efficient manner. cpuidle separates out the drivers that can provide support for multiple types of idle states and policy governors that decide on what idle state to use at run time. A cpuidle driver can support multiple idle states based on parameters like varying power consumption, wakeup latency, etc (ACPI C-states for example). A cpuidle governor can be usage model specific (laptop, server, laptop on battery etc). Main advantage of the infrastructure being, it allows independent development of drivers and governors and allows for better CPU power management. A huge thanks to Adam Belay and Shaohua Li who were part of this mini-project since its beginning and are greatly responsible for this patchset. This patch: Core cpuidle infrastructure. Introduces a new abstraction layer for cpuidle: * which manages drivers that can support multiple idles states. Drivers can be generic or particular to specific hardware/platform * allows pluging in multiple policy governors that can take idle state policy decision * The core also has a set of sysfs interfaces with which administrato can know about supported drivers and governors and switch them at run time. Signed-off-by: Adam Belay <abelay@novell.com> Signed-off-by: Shaohua Li <shaohua.li@intel.com> Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Len Brown <len.brown@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/cpuidle')
-rw-r--r--drivers/cpuidle/Kconfig20
-rw-r--r--drivers/cpuidle/Makefile5
-rw-r--r--drivers/cpuidle/cpuidle.c295
-rw-r--r--drivers/cpuidle/cpuidle.h33
-rw-r--r--drivers/cpuidle/driver.c56
-rw-r--r--drivers/cpuidle/governor.c141
-rw-r--r--drivers/cpuidle/governors/Makefile6
-rw-r--r--drivers/cpuidle/governors/ladder.c166
-rw-r--r--drivers/cpuidle/governors/menu.c137
-rw-r--r--drivers/cpuidle/sysfs.c361
10 files changed, 1220 insertions, 0 deletions
diff --git a/drivers/cpuidle/Kconfig b/drivers/cpuidle/Kconfig
new file mode 100644
index 000000000000..3bed4127d4ad
--- /dev/null
+++ b/drivers/cpuidle/Kconfig
@@ -0,0 +1,20 @@
1
2config CPU_IDLE
3 bool "CPU idle PM support"
4 help
5 CPU idle is a generic framework for supporting software-controlled
6 idle processor power management. It includes modular cross-platform
7 governors that can be swapped during runtime.
8
9 If you're using a mobile platform that supports CPU idle PM (e.g.
10 an ACPI-capable notebook), you should say Y here.
11
12config CPU_IDLE_GOV_LADDER
13 bool
14 depends on CPU_IDLE
15 default y
16
17config CPU_IDLE_GOV_MENU
18 bool
19 depends on CPU_IDLE && NO_HZ
20 default y
diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile
new file mode 100644
index 000000000000..5634f88379df
--- /dev/null
+++ b/drivers/cpuidle/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for cpuidle.
3#
4
5obj-y += cpuidle.o driver.o governor.o sysfs.o governors/
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
new file mode 100644
index 000000000000..fdf4106b817b
--- /dev/null
+++ b/drivers/cpuidle/cpuidle.c
@@ -0,0 +1,295 @@
1/*
2 * cpuidle.c - core cpuidle infrastructure
3 *
4 * (C) 2006-2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
5 * Shaohua Li <shaohua.li@intel.com>
6 * Adam Belay <abelay@novell.com>
7 *
8 * This code is licenced under the GPL.
9 */
10
11#include <linux/kernel.h>
12#include <linux/mutex.h>
13#include <linux/sched.h>
14#include <linux/notifier.h>
15#include <linux/latency.h>
16#include <linux/cpu.h>
17#include <linux/cpuidle.h>
18
19#include "cpuidle.h"
20
21DEFINE_PER_CPU(struct cpuidle_device *, cpuidle_devices);
22EXPORT_PER_CPU_SYMBOL_GPL(cpuidle_devices);
23
24DEFINE_MUTEX(cpuidle_lock);
25LIST_HEAD(cpuidle_detected_devices);
26static void (*pm_idle_old)(void);
27
28static int enabled_devices;
29
30/**
31 * cpuidle_idle_call - the main idle loop
32 *
33 * NOTE: no locks or semaphores should be used here
34 */
35static void cpuidle_idle_call(void)
36{
37 struct cpuidle_device *dev = __get_cpu_var(cpuidle_devices);
38 struct cpuidle_state *target_state;
39 int next_state;
40
41 /* check if the device is ready */
42 if (!dev || !dev->enabled) {
43 if (pm_idle_old)
44 pm_idle_old();
45 else
46 local_irq_enable();
47 return;
48 }
49
50 /* ask the governor for the next state */
51 next_state = cpuidle_curr_governor->select(dev);
52 if (need_resched())
53 return;
54 target_state = &dev->states[next_state];
55
56 /* enter the state and update stats */
57 dev->last_residency = target_state->enter(dev, target_state);
58 dev->last_state = target_state;
59 target_state->time += dev->last_residency;
60 target_state->usage++;
61
62 /* give the governor an opportunity to reflect on the outcome */
63 if (cpuidle_curr_governor->reflect)
64 cpuidle_curr_governor->reflect(dev);
65}
66
67/**
68 * cpuidle_install_idle_handler - installs the cpuidle idle loop handler
69 */
70void cpuidle_install_idle_handler(void)
71{
72 if (enabled_devices && (pm_idle != cpuidle_idle_call)) {
73 /* Make sure all changes finished before we switch to new idle */
74 smp_wmb();
75 pm_idle = cpuidle_idle_call;
76 }
77}
78
79/**
80 * cpuidle_uninstall_idle_handler - uninstalls the cpuidle idle loop handler
81 */
82void cpuidle_uninstall_idle_handler(void)
83{
84 if (enabled_devices && (pm_idle != pm_idle_old)) {
85 pm_idle = pm_idle_old;
86 cpu_idle_wait();
87 }
88}
89
90/**
91 * cpuidle_pause_and_lock - temporarily disables CPUIDLE
92 */
93void cpuidle_pause_and_lock(void)
94{
95 mutex_lock(&cpuidle_lock);
96 cpuidle_uninstall_idle_handler();
97}
98
99EXPORT_SYMBOL_GPL(cpuidle_pause_and_lock);
100
101/**
102 * cpuidle_resume_and_unlock - resumes CPUIDLE operation
103 */
104void cpuidle_resume_and_unlock(void)
105{
106 cpuidle_install_idle_handler();
107 mutex_unlock(&cpuidle_lock);
108}
109
110EXPORT_SYMBOL_GPL(cpuidle_resume_and_unlock);
111
112/**
113 * cpuidle_enable_device - enables idle PM for a CPU
114 * @dev: the CPU
115 *
116 * This function must be called between cpuidle_pause_and_lock and
117 * cpuidle_resume_and_unlock when used externally.
118 */
119int cpuidle_enable_device(struct cpuidle_device *dev)
120{
121 int ret, i;
122
123 if (dev->enabled)
124 return 0;
125 if (!cpuidle_curr_driver || !cpuidle_curr_governor)
126 return -EIO;
127 if (!dev->state_count)
128 return -EINVAL;
129
130 if ((ret = cpuidle_add_state_sysfs(dev)))
131 return ret;
132
133 if (cpuidle_curr_governor->enable &&
134 (ret = cpuidle_curr_governor->enable(dev)))
135 goto fail_sysfs;
136
137 for (i = 0; i < dev->state_count; i++) {
138 dev->states[i].usage = 0;
139 dev->states[i].time = 0;
140 }
141 dev->last_residency = 0;
142 dev->last_state = NULL;
143
144 smp_wmb();
145
146 dev->enabled = 1;
147
148 enabled_devices++;
149 return 0;
150
151fail_sysfs:
152 cpuidle_remove_state_sysfs(dev);
153
154 return ret;
155}
156
157EXPORT_SYMBOL_GPL(cpuidle_enable_device);
158
159/**
160 * cpuidle_disable_device - disables idle PM for a CPU
161 * @dev: the CPU
162 *
163 * This function must be called between cpuidle_pause_and_lock and
164 * cpuidle_resume_and_unlock when used externally.
165 */
166void cpuidle_disable_device(struct cpuidle_device *dev)
167{
168 if (!dev->enabled)
169 return;
170 if (!cpuidle_curr_driver || !cpuidle_curr_governor)
171 return;
172
173 dev->enabled = 0;
174
175 if (cpuidle_curr_governor->disable)
176 cpuidle_curr_governor->disable(dev);
177
178 cpuidle_remove_state_sysfs(dev);
179 enabled_devices--;
180}
181
182EXPORT_SYMBOL_GPL(cpuidle_disable_device);
183
184/**
185 * cpuidle_register_device - registers a CPU's idle PM feature
186 * @dev: the cpu
187 */
188int cpuidle_register_device(struct cpuidle_device *dev)
189{
190 int ret;
191 struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu);
192
193 if (!sys_dev)
194 return -EINVAL;
195 if (!try_module_get(cpuidle_curr_driver->owner))
196 return -EINVAL;
197
198 init_completion(&dev->kobj_unregister);
199
200 mutex_lock(&cpuidle_lock);
201
202 per_cpu(cpuidle_devices, dev->cpu) = dev;
203 list_add(&dev->device_list, &cpuidle_detected_devices);
204 if ((ret = cpuidle_add_sysfs(sys_dev))) {
205 mutex_unlock(&cpuidle_lock);
206 module_put(cpuidle_curr_driver->owner);
207 return ret;
208 }
209
210 cpuidle_enable_device(dev);
211 cpuidle_install_idle_handler();
212
213 mutex_unlock(&cpuidle_lock);
214
215 return 0;
216
217}
218
219EXPORT_SYMBOL_GPL(cpuidle_register_device);
220
221/**
222 * cpuidle_unregister_device - unregisters a CPU's idle PM feature
223 * @dev: the cpu
224 */
225void cpuidle_unregister_device(struct cpuidle_device *dev)
226{
227 struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu);
228
229 cpuidle_pause_and_lock();
230
231 cpuidle_disable_device(dev);
232
233 cpuidle_remove_sysfs(sys_dev);
234 list_del(&dev->device_list);
235 wait_for_completion(&dev->kobj_unregister);
236 per_cpu(cpuidle_devices, dev->cpu) = NULL;
237
238 cpuidle_resume_and_unlock();
239
240 module_put(cpuidle_curr_driver->owner);
241}
242
243EXPORT_SYMBOL_GPL(cpuidle_unregister_device);
244
245#ifdef CONFIG_SMP
246
247static void smp_callback(void *v)
248{
249 /* we already woke the CPU up, nothing more to do */
250}
251
252/*
253 * This function gets called when a part of the kernel has a new latency
254 * requirement. This means we need to get all processors out of their C-state,
255 * and then recalculate a new suitable C-state. Just do a cross-cpu IPI; that
256 * wakes them all right up.
257 */
258static int cpuidle_latency_notify(struct notifier_block *b,
259 unsigned long l, void *v)
260{
261 smp_call_function(smp_callback, NULL, 0, 1);
262 return NOTIFY_OK;
263}
264
265static struct notifier_block cpuidle_latency_notifier = {
266 .notifier_call = cpuidle_latency_notify,
267};
268
269#define latency_notifier_init(x) do { register_latency_notifier(x); } while (0)
270
271#else /* CONFIG_SMP */
272
273#define latency_notifier_init(x) do { } while (0)
274
275#endif /* CONFIG_SMP */
276
277/**
278 * cpuidle_init - core initializer
279 */
280static int __init cpuidle_init(void)
281{
282 int ret;
283
284 pm_idle_old = pm_idle;
285
286 ret = cpuidle_add_class_sysfs(&cpu_sysdev_class);
287 if (ret)
288 return ret;
289
290 latency_notifier_init(&cpuidle_latency_notifier);
291
292 return 0;
293}
294
295core_initcall(cpuidle_init);
diff --git a/drivers/cpuidle/cpuidle.h b/drivers/cpuidle/cpuidle.h
new file mode 100644
index 000000000000..9476ba33ee2c
--- /dev/null
+++ b/drivers/cpuidle/cpuidle.h
@@ -0,0 +1,33 @@
1/*
2 * cpuidle.h - The internal header file
3 */
4
5#ifndef __DRIVER_CPUIDLE_H
6#define __DRIVER_CPUIDLE_H
7
8#include <linux/sysdev.h>
9
10/* For internal use only */
11extern struct cpuidle_governor *cpuidle_curr_governor;
12extern struct cpuidle_driver *cpuidle_curr_driver;
13extern struct list_head cpuidle_governors;
14extern struct list_head cpuidle_detected_devices;
15extern struct mutex cpuidle_lock;
16extern spinlock_t cpuidle_driver_lock;
17
18/* idle loop */
19extern void cpuidle_install_idle_handler(void);
20extern void cpuidle_uninstall_idle_handler(void);
21
22/* governors */
23extern int cpuidle_switch_governor(struct cpuidle_governor *gov);
24
25/* sysfs */
26extern int cpuidle_add_class_sysfs(struct sysdev_class *cls);
27extern void cpuidle_remove_class_sysfs(struct sysdev_class *cls);
28extern int cpuidle_add_state_sysfs(struct cpuidle_device *device);
29extern void cpuidle_remove_state_sysfs(struct cpuidle_device *device);
30extern int cpuidle_add_sysfs(struct sys_device *sysdev);
31extern void cpuidle_remove_sysfs(struct sys_device *sysdev);
32
33#endif /* __DRIVER_CPUIDLE_H */
diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
new file mode 100644
index 000000000000..2257004fe33d
--- /dev/null
+++ b/drivers/cpuidle/driver.c
@@ -0,0 +1,56 @@
1/*
2 * driver.c - driver support
3 *
4 * (C) 2006-2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
5 * Shaohua Li <shaohua.li@intel.com>
6 * Adam Belay <abelay@novell.com>
7 *
8 * This code is licenced under the GPL.
9 */
10
11#include <linux/mutex.h>
12#include <linux/module.h>
13#include <linux/cpuidle.h>
14
15#include "cpuidle.h"
16
17struct cpuidle_driver *cpuidle_curr_driver;
18DEFINE_SPINLOCK(cpuidle_driver_lock);
19
20/**
21 * cpuidle_register_driver - registers a driver
22 * @drv: the driver
23 */
24int cpuidle_register_driver(struct cpuidle_driver *drv)
25{
26 if (!drv)
27 return -EINVAL;
28
29 spin_lock(&cpuidle_driver_lock);
30 if (cpuidle_curr_driver) {
31 spin_unlock(&cpuidle_driver_lock);
32 return -EBUSY;
33 }
34 cpuidle_curr_driver = drv;
35 spin_unlock(&cpuidle_driver_lock);
36
37 return 0;
38}
39
40EXPORT_SYMBOL_GPL(cpuidle_register_driver);
41
42/**
43 * cpuidle_unregister_driver - unregisters a driver
44 * @drv: the driver
45 */
46void cpuidle_unregister_driver(struct cpuidle_driver *drv)
47{
48 if (!drv)
49 return;
50
51 spin_lock(&cpuidle_driver_lock);
52 cpuidle_curr_driver = NULL;
53 spin_unlock(&cpuidle_driver_lock);
54}
55
56EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);
diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
new file mode 100644
index 000000000000..bb699cb2dc5a
--- /dev/null
+++ b/drivers/cpuidle/governor.c
@@ -0,0 +1,141 @@
1/*
2 * governor.c - governor support
3 *
4 * (C) 2006-2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
5 * Shaohua Li <shaohua.li@intel.com>
6 * Adam Belay <abelay@novell.com>
7 *
8 * This code is licenced under the GPL.
9 */
10
11#include <linux/mutex.h>
12#include <linux/module.h>
13#include <linux/cpuidle.h>
14
15#include "cpuidle.h"
16
17LIST_HEAD(cpuidle_governors);
18struct cpuidle_governor *cpuidle_curr_governor;
19
20/**
21 * __cpuidle_find_governor - finds a governor of the specified name
22 * @str: the name
23 *
24 * Must be called with cpuidle_lock aquired.
25 */
26static struct cpuidle_governor * __cpuidle_find_governor(const char *str)
27{
28 struct cpuidle_governor *gov;
29
30 list_for_each_entry(gov, &cpuidle_governors, governor_list)
31 if (!strnicmp(str, gov->name, CPUIDLE_NAME_LEN))
32 return gov;
33
34 return NULL;
35}
36
37/**
38 * cpuidle_switch_governor - changes the governor
39 * @gov: the new target governor
40 *
41 * NOTE: "gov" can be NULL to specify disabled
42 * Must be called with cpuidle_lock aquired.
43 */
44int cpuidle_switch_governor(struct cpuidle_governor *gov)
45{
46 struct cpuidle_device *dev;
47
48 if (gov == cpuidle_curr_governor)
49 return 0;
50
51 cpuidle_uninstall_idle_handler();
52
53 if (cpuidle_curr_governor) {
54 list_for_each_entry(dev, &cpuidle_detected_devices, device_list)
55 cpuidle_disable_device(dev);
56 module_put(cpuidle_curr_governor->owner);
57 }
58
59 cpuidle_curr_governor = gov;
60
61 if (gov) {
62 if (!try_module_get(cpuidle_curr_governor->owner))
63 return -EINVAL;
64 list_for_each_entry(dev, &cpuidle_detected_devices, device_list)
65 cpuidle_enable_device(dev);
66 cpuidle_install_idle_handler();
67 printk(KERN_INFO "cpuidle: using governor %s\n", gov->name);
68 }
69
70 return 0;
71}
72
73/**
74 * cpuidle_register_governor - registers a governor
75 * @gov: the governor
76 */
77int cpuidle_register_governor(struct cpuidle_governor *gov)
78{
79 int ret = -EEXIST;
80
81 if (!gov || !gov->select)
82 return -EINVAL;
83
84 mutex_lock(&cpuidle_lock);
85 if (__cpuidle_find_governor(gov->name) == NULL) {
86 ret = 0;
87 list_add_tail(&gov->governor_list, &cpuidle_governors);
88 if (!cpuidle_curr_governor ||
89 cpuidle_curr_governor->rating < gov->rating)
90 cpuidle_switch_governor(gov);
91 }
92 mutex_unlock(&cpuidle_lock);
93
94 return ret;
95}
96
97EXPORT_SYMBOL_GPL(cpuidle_register_governor);
98
99/**
100 * cpuidle_replace_governor - find a replacement governor
101 * @exclude_rating: the rating that will be skipped while looking for
102 * new governor.
103 */
104static struct cpuidle_governor *cpuidle_replace_governor(int exclude_rating)
105{
106 struct cpuidle_governor *gov;
107 struct cpuidle_governor *ret_gov = NULL;
108 unsigned int max_rating = 0;
109
110 list_for_each_entry(gov, &cpuidle_governors, governor_list) {
111 if (gov->rating == exclude_rating)
112 continue;
113 if (gov->rating > max_rating) {
114 max_rating = gov->rating;
115 ret_gov = gov;
116 }
117 }
118
119 return ret_gov;
120}
121
122/**
123 * cpuidle_unregister_governor - unregisters a governor
124 * @gov: the governor
125 */
126void cpuidle_unregister_governor(struct cpuidle_governor *gov)
127{
128 if (!gov)
129 return;
130
131 mutex_lock(&cpuidle_lock);
132 if (gov == cpuidle_curr_governor) {
133 struct cpuidle_governor *new_gov;
134 new_gov = cpuidle_replace_governor(gov->rating);
135 cpuidle_switch_governor(new_gov);
136 }
137 list_del(&gov->governor_list);
138 mutex_unlock(&cpuidle_lock);
139}
140
141EXPORT_SYMBOL_GPL(cpuidle_unregister_governor);
diff --git a/drivers/cpuidle/governors/Makefile b/drivers/cpuidle/governors/Makefile
new file mode 100644
index 000000000000..1b512722689f
--- /dev/null
+++ b/drivers/cpuidle/governors/Makefile
@@ -0,0 +1,6 @@
1#
2# Makefile for cpuidle governors.
3#
4
5obj-$(CONFIG_CPU_IDLE_GOV_LADDER) += ladder.o
6obj-$(CONFIG_CPU_IDLE_GOV_MENU) += menu.o
diff --git a/drivers/cpuidle/governors/ladder.c b/drivers/cpuidle/governors/ladder.c
new file mode 100644
index 000000000000..eb666ecae7c9
--- /dev/null
+++ b/drivers/cpuidle/governors/ladder.c
@@ -0,0 +1,166 @@
1/*
2 * ladder.c - the residency ladder algorithm
3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 * Copyright (C) 2004, 2005 Dominik Brodowski <linux@brodo.de>
7 *
8 * (C) 2006-2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
9 * Shaohua Li <shaohua.li@intel.com>
10 * Adam Belay <abelay@novell.com>
11 *
12 * This code is licenced under the GPL.
13 */
14
15#include <linux/kernel.h>
16#include <linux/cpuidle.h>
17#include <linux/latency.h>
18#include <linux/moduleparam.h>
19#include <linux/jiffies.h>
20
21#include <asm/io.h>
22#include <asm/uaccess.h>
23
24#define PROMOTION_COUNT 4
25#define DEMOTION_COUNT 1
26
27struct ladder_device_state {
28 struct {
29 u32 promotion_count;
30 u32 demotion_count;
31 u32 promotion_time;
32 u32 demotion_time;
33 } threshold;
34 struct {
35 int promotion_count;
36 int demotion_count;
37 } stats;
38};
39
40struct ladder_device {
41 struct ladder_device_state states[CPUIDLE_STATE_MAX];
42 int last_state_idx;
43};
44
45static DEFINE_PER_CPU(struct ladder_device, ladder_devices);
46
47/**
48 * ladder_do_selection - prepares private data for a state change
49 * @ldev: the ladder device
50 * @old_idx: the current state index
51 * @new_idx: the new target state index
52 */
53static inline void ladder_do_selection(struct ladder_device *ldev,
54 int old_idx, int new_idx)
55{
56 ldev->states[old_idx].stats.promotion_count = 0;
57 ldev->states[old_idx].stats.demotion_count = 0;
58 ldev->last_state_idx = new_idx;
59}
60
61/**
62 * ladder_select_state - selects the next state to enter
63 * @dev: the CPU
64 */
65static int ladder_select_state(struct cpuidle_device *dev)
66{
67 struct ladder_device *ldev = &__get_cpu_var(ladder_devices);
68 struct ladder_device_state *last_state;
69 int last_residency, last_idx = ldev->last_state_idx;
70
71 if (unlikely(!ldev))
72 return 0;
73
74 last_state = &ldev->states[last_idx];
75
76 if (dev->states[last_idx].flags & CPUIDLE_FLAG_TIME_VALID)
77 last_residency = cpuidle_get_last_residency(dev) - dev->states[last_idx].exit_latency;
78 else
79 last_residency = last_state->threshold.promotion_time + 1;
80
81 /* consider promotion */
82 if (last_idx < dev->state_count - 1 &&
83 last_residency > last_state->threshold.promotion_time &&
84 dev->states[last_idx + 1].exit_latency <= system_latency_constraint()) {
85 last_state->stats.promotion_count++;
86 last_state->stats.demotion_count = 0;
87 if (last_state->stats.promotion_count >= last_state->threshold.promotion_count) {
88 ladder_do_selection(ldev, last_idx, last_idx + 1);
89 return last_idx + 1;
90 }
91 }
92
93 /* consider demotion */
94 if (last_idx > 0 &&
95 last_residency < last_state->threshold.demotion_time) {
96 last_state->stats.demotion_count++;
97 last_state->stats.promotion_count = 0;
98 if (last_state->stats.demotion_count >= last_state->threshold.demotion_count) {
99 ladder_do_selection(ldev, last_idx, last_idx - 1);
100 return last_idx - 1;
101 }
102 }
103
104 /* otherwise remain at the current state */
105 return last_idx;
106}
107
108/**
109 * ladder_enable_device - setup for the governor
110 * @dev: the CPU
111 */
112static int ladder_enable_device(struct cpuidle_device *dev)
113{
114 int i;
115 struct ladder_device *ldev = &per_cpu(ladder_devices, dev->cpu);
116 struct ladder_device_state *lstate;
117 struct cpuidle_state *state;
118
119 ldev->last_state_idx = 0;
120
121 for (i = 0; i < dev->state_count; i++) {
122 state = &dev->states[i];
123 lstate = &ldev->states[i];
124
125 lstate->stats.promotion_count = 0;
126 lstate->stats.demotion_count = 0;
127
128 lstate->threshold.promotion_count = PROMOTION_COUNT;
129 lstate->threshold.demotion_count = DEMOTION_COUNT;
130
131 if (i < dev->state_count - 1)
132 lstate->threshold.promotion_time = state->exit_latency;
133 if (i > 0)
134 lstate->threshold.demotion_time = state->exit_latency;
135 }
136
137 return 0;
138}
139
140static struct cpuidle_governor ladder_governor = {
141 .name = "ladder",
142 .rating = 10,
143 .enable = ladder_enable_device,
144 .select = ladder_select_state,
145 .owner = THIS_MODULE,
146};
147
148/**
149 * init_ladder - initializes the governor
150 */
151static int __init init_ladder(void)
152{
153 return cpuidle_register_governor(&ladder_governor);
154}
155
156/**
157 * exit_ladder - exits the governor
158 */
159static void __exit exit_ladder(void)
160{
161 cpuidle_unregister_governor(&ladder_governor);
162}
163
164MODULE_LICENSE("GPL");
165module_init(init_ladder);
166module_exit(exit_ladder);
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
new file mode 100644
index 000000000000..299d45c3bdd2
--- /dev/null
+++ b/drivers/cpuidle/governors/menu.c
@@ -0,0 +1,137 @@
1/*
2 * menu.c - the menu idle governor
3 *
4 * Copyright (C) 2006-2007 Adam Belay <abelay@novell.com>
5 *
6 * This code is licenced under the GPL.
7 */
8
9#include <linux/kernel.h>
10#include <linux/cpuidle.h>
11#include <linux/latency.h>
12#include <linux/time.h>
13#include <linux/ktime.h>
14#include <linux/hrtimer.h>
15#include <linux/tick.h>
16
17#define BREAK_FUZZ 4 /* 4 us */
18
19struct menu_device {
20 int last_state_idx;
21
22 unsigned int expected_us;
23 unsigned int predicted_us;
24 unsigned int last_measured_us;
25 unsigned int elapsed_us;
26};
27
28static DEFINE_PER_CPU(struct menu_device, menu_devices);
29
30/**
31 * menu_select - selects the next idle state to enter
32 * @dev: the CPU
33 */
34static int menu_select(struct cpuidle_device *dev)
35{
36 struct menu_device *data = &__get_cpu_var(menu_devices);
37 int i;
38
39 /* determine the expected residency time */
40 data->expected_us =
41 (u32) ktime_to_ns(tick_nohz_get_sleep_length()) / 1000;
42
43 /* find the deepest idle state that satisfies our constraints */
44 for (i = 1; i < dev->state_count; i++) {
45 struct cpuidle_state *s = &dev->states[i];
46
47 if (s->target_residency > data->expected_us)
48 break;
49 if (s->target_residency > data->predicted_us)
50 break;
51 if (s->exit_latency > system_latency_constraint())
52 break;
53 }
54
55 data->last_state_idx = i - 1;
56 return i - 1;
57}
58
59/**
60 * menu_reflect - attempts to guess what happened after entry
61 * @dev: the CPU
62 *
63 * NOTE: it's important to be fast here because this operation will add to
64 * the overall exit latency.
65 */
66static void menu_reflect(struct cpuidle_device *dev)
67{
68 struct menu_device *data = &__get_cpu_var(menu_devices);
69 int last_idx = data->last_state_idx;
70 unsigned int measured_us =
71 cpuidle_get_last_residency(dev) + data->elapsed_us;
72 struct cpuidle_state *target = &dev->states[last_idx];
73
74 /*
75 * Ugh, this idle state doesn't support residency measurements, so we
76 * are basically lost in the dark. As a compromise, assume we slept
77 * for one full standard timer tick. However, be aware that this
78 * could potentially result in a suboptimal state transition.
79 */
80 if (!(target->flags & CPUIDLE_FLAG_TIME_VALID))
81 measured_us = USEC_PER_SEC / HZ;
82
83 /* Predict time remaining until next break event */
84 if (measured_us + BREAK_FUZZ < data->expected_us - target->exit_latency) {
85 data->predicted_us = max(measured_us, data->last_measured_us);
86 data->last_measured_us = measured_us;
87 data->elapsed_us = 0;
88 } else {
89 if (data->elapsed_us < data->elapsed_us + measured_us)
90 data->elapsed_us = measured_us;
91 else
92 data->elapsed_us = -1;
93 data->predicted_us = max(measured_us, data->last_measured_us);
94 }
95}
96
97/**
98 * menu_enable_device - scans a CPU's states and does setup
99 * @dev: the CPU
100 */
101static int menu_enable_device(struct cpuidle_device *dev)
102{
103 struct menu_device *data = &per_cpu(menu_devices, dev->cpu);
104
105 memset(data, 0, sizeof(struct menu_device));
106
107 return 0;
108}
109
110static struct cpuidle_governor menu_governor = {
111 .name = "menu",
112 .rating = 20,
113 .enable = menu_enable_device,
114 .select = menu_select,
115 .reflect = menu_reflect,
116 .owner = THIS_MODULE,
117};
118
119/**
120 * init_menu - initializes the governor
121 */
122static int __init init_menu(void)
123{
124 return cpuidle_register_governor(&menu_governor);
125}
126
127/**
128 * exit_menu - exits the governor
129 */
130static void __exit exit_menu(void)
131{
132 cpuidle_unregister_governor(&menu_governor);
133}
134
135MODULE_LICENSE("GPL");
136module_init(init_menu);
137module_exit(exit_menu);
diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
new file mode 100644
index 000000000000..0f3515e77d4b
--- /dev/null
+++ b/drivers/cpuidle/sysfs.c
@@ -0,0 +1,361 @@
1/*
2 * sysfs.c - sysfs support
3 *
4 * (C) 2006-2007 Shaohua Li <shaohua.li@intel.com>
5 *
6 * This code is licenced under the GPL.
7 */
8
9#include <linux/kernel.h>
10#include <linux/cpuidle.h>
11#include <linux/sysfs.h>
12#include <linux/cpu.h>
13
14#include "cpuidle.h"
15
16static unsigned int sysfs_switch;
17static int __init cpuidle_sysfs_setup(char *unused)
18{
19 sysfs_switch = 1;
20 return 1;
21}
22__setup("cpuidle_sysfs_switch", cpuidle_sysfs_setup);
23
24static ssize_t show_available_governors(struct sys_device *dev, char *buf)
25{
26 ssize_t i = 0;
27 struct cpuidle_governor *tmp;
28
29 mutex_lock(&cpuidle_lock);
30 list_for_each_entry(tmp, &cpuidle_governors, governor_list) {
31 if (i >= (ssize_t) ((PAGE_SIZE/sizeof(char)) - CPUIDLE_NAME_LEN - 2))
32 goto out;
33 i += scnprintf(&buf[i], CPUIDLE_NAME_LEN, "%s ", tmp->name);
34 }
35
36out:
37 i+= sprintf(&buf[i], "\n");
38 mutex_unlock(&cpuidle_lock);
39 return i;
40}
41
42static ssize_t show_current_driver(struct sys_device *dev, char *buf)
43{
44 ssize_t ret;
45
46 spin_lock(&cpuidle_driver_lock);
47 if (cpuidle_curr_driver)
48 ret = sprintf(buf, "%s\n", cpuidle_curr_driver->name);
49 else
50 ret = sprintf(buf, "none\n");
51 spin_unlock(&cpuidle_driver_lock);
52
53 return ret;
54}
55
56static ssize_t show_current_governor(struct sys_device *dev, char *buf)
57{
58 ssize_t ret;
59
60 mutex_lock(&cpuidle_lock);
61 if (cpuidle_curr_governor)
62 ret = sprintf(buf, "%s\n", cpuidle_curr_governor->name);
63 else
64 ret = sprintf(buf, "none\n");
65 mutex_unlock(&cpuidle_lock);
66
67 return ret;
68}
69
70static ssize_t store_current_governor(struct sys_device *dev,
71 const char *buf, size_t count)
72{
73 char gov_name[CPUIDLE_NAME_LEN];
74 int ret = -EINVAL;
75 size_t len = count;
76 struct cpuidle_governor *gov;
77
78 if (!len || len >= sizeof(gov_name))
79 return -EINVAL;
80
81 memcpy(gov_name, buf, len);
82 gov_name[len] = '\0';
83 if (gov_name[len - 1] == '\n')
84 gov_name[--len] = '\0';
85
86 mutex_lock(&cpuidle_lock);
87
88 list_for_each_entry(gov, &cpuidle_governors, governor_list) {
89 if (strlen(gov->name) == len && !strcmp(gov->name, gov_name)) {
90 ret = cpuidle_switch_governor(gov);
91 break;
92 }
93 }
94
95 mutex_unlock(&cpuidle_lock);
96
97 if (ret)
98 return ret;
99 else
100 return count;
101}
102
103static SYSDEV_ATTR(current_driver, 0444, show_current_driver, NULL);
104static SYSDEV_ATTR(current_governor_ro, 0444, show_current_governor, NULL);
105
106static struct attribute *cpuclass_default_attrs[] = {
107 &attr_current_driver.attr,
108 &attr_current_governor_ro.attr,
109 NULL
110};
111
112static SYSDEV_ATTR(available_governors, 0444, show_available_governors, NULL);
113static SYSDEV_ATTR(current_governor, 0644, show_current_governor,
114 store_current_governor);
115
116static struct attribute *cpuclass_switch_attrs[] = {
117 &attr_available_governors.attr,
118 &attr_current_driver.attr,
119 &attr_current_governor.attr,
120 NULL
121};
122
123static struct attribute_group cpuclass_attr_group = {
124 .attrs = cpuclass_default_attrs,
125 .name = "cpuidle",
126};
127
128/**
129 * cpuidle_add_class_sysfs - add CPU global sysfs attributes
130 */
131int cpuidle_add_class_sysfs(struct sysdev_class *cls)
132{
133 if (sysfs_switch)
134 cpuclass_attr_group.attrs = cpuclass_switch_attrs;
135
136 return sysfs_create_group(&cls->kset.kobj, &cpuclass_attr_group);
137}
138
139/**
140 * cpuidle_remove_class_sysfs - remove CPU global sysfs attributes
141 */
142void cpuidle_remove_class_sysfs(struct sysdev_class *cls)
143{
144 sysfs_remove_group(&cls->kset.kobj, &cpuclass_attr_group);
145}
146
147struct cpuidle_attr {
148 struct attribute attr;
149 ssize_t (*show)(struct cpuidle_device *, char *);
150 ssize_t (*store)(struct cpuidle_device *, const char *, size_t count);
151};
152
153#define define_one_ro(_name, show) \
154 static struct cpuidle_attr attr_##_name = __ATTR(_name, 0444, show, NULL)
155#define define_one_rw(_name, show, store) \
156 static struct cpuidle_attr attr_##_name = __ATTR(_name, 0644, show, store)
157
158#define kobj_to_cpuidledev(k) container_of(k, struct cpuidle_device, kobj)
159#define attr_to_cpuidleattr(a) container_of(a, struct cpuidle_attr, attr)
160static ssize_t cpuidle_show(struct kobject * kobj, struct attribute * attr ,char * buf)
161{
162 int ret = -EIO;
163 struct cpuidle_device *dev = kobj_to_cpuidledev(kobj);
164 struct cpuidle_attr * cattr = attr_to_cpuidleattr(attr);
165
166 if (cattr->show) {
167 mutex_lock(&cpuidle_lock);
168 ret = cattr->show(dev, buf);
169 mutex_unlock(&cpuidle_lock);
170 }
171 return ret;
172}
173
174static ssize_t cpuidle_store(struct kobject * kobj, struct attribute * attr,
175 const char * buf, size_t count)
176{
177 int ret = -EIO;
178 struct cpuidle_device *dev = kobj_to_cpuidledev(kobj);
179 struct cpuidle_attr * cattr = attr_to_cpuidleattr(attr);
180
181 if (cattr->store) {
182 mutex_lock(&cpuidle_lock);
183 ret = cattr->store(dev, buf, count);
184 mutex_unlock(&cpuidle_lock);
185 }
186 return ret;
187}
188
189static struct sysfs_ops cpuidle_sysfs_ops = {
190 .show = cpuidle_show,
191 .store = cpuidle_store,
192};
193
194static void cpuidle_sysfs_release(struct kobject *kobj)
195{
196 struct cpuidle_device *dev = kobj_to_cpuidledev(kobj);
197
198 complete(&dev->kobj_unregister);
199}
200
201static struct kobj_type ktype_cpuidle = {
202 .sysfs_ops = &cpuidle_sysfs_ops,
203 .release = cpuidle_sysfs_release,
204};
205
206struct cpuidle_state_attr {
207 struct attribute attr;
208 ssize_t (*show)(struct cpuidle_state *, char *);
209 ssize_t (*store)(struct cpuidle_state *, const char *, size_t);
210};
211
212#define define_one_state_ro(_name, show) \
213static struct cpuidle_state_attr attr_##_name = __ATTR(_name, 0444, show, NULL)
214
215#define define_show_state_function(_name) \
216static ssize_t show_state_##_name(struct cpuidle_state *state, char *buf) \
217{ \
218 return sprintf(buf, "%u\n", state->_name);\
219}
220
221static ssize_t show_state_name(struct cpuidle_state *state, char *buf)
222{
223 return sprintf(buf, "%s\n", state->name);
224}
225
226define_show_state_function(exit_latency)
227define_show_state_function(power_usage)
228define_show_state_function(usage)
229define_show_state_function(time)
230define_one_state_ro(name, show_state_name);
231define_one_state_ro(latency, show_state_exit_latency);
232define_one_state_ro(power, show_state_power_usage);
233define_one_state_ro(usage, show_state_usage);
234define_one_state_ro(time, show_state_time);
235
236static struct attribute *cpuidle_state_default_attrs[] = {
237 &attr_name.attr,
238 &attr_latency.attr,
239 &attr_power.attr,
240 &attr_usage.attr,
241 &attr_time.attr,
242 NULL
243};
244
245#define kobj_to_state_obj(k) container_of(k, struct cpuidle_state_kobj, kobj)
246#define kobj_to_state(k) (kobj_to_state_obj(k)->state)
247#define attr_to_stateattr(a) container_of(a, struct cpuidle_state_attr, attr)
248static ssize_t cpuidle_state_show(struct kobject * kobj,
249 struct attribute * attr ,char * buf)
250{
251 int ret = -EIO;
252 struct cpuidle_state *state = kobj_to_state(kobj);
253 struct cpuidle_state_attr * cattr = attr_to_stateattr(attr);
254
255 if (cattr->show)
256 ret = cattr->show(state, buf);
257
258 return ret;
259}
260
261static struct sysfs_ops cpuidle_state_sysfs_ops = {
262 .show = cpuidle_state_show,
263};
264
265static void cpuidle_state_sysfs_release(struct kobject *kobj)
266{
267 struct cpuidle_state_kobj *state_obj = kobj_to_state_obj(kobj);
268
269 complete(&state_obj->kobj_unregister);
270}
271
272static struct kobj_type ktype_state_cpuidle = {
273 .sysfs_ops = &cpuidle_state_sysfs_ops,
274 .default_attrs = cpuidle_state_default_attrs,
275 .release = cpuidle_state_sysfs_release,
276};
277
278static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
279{
280 kobject_unregister(&device->kobjs[i]->kobj);
281 wait_for_completion(&device->kobjs[i]->kobj_unregister);
282 kfree(device->kobjs[i]);
283 device->kobjs[i] = NULL;
284}
285
286/**
287 * cpuidle_add_driver_sysfs - adds driver-specific sysfs attributes
288 * @device: the target device
289 */
290int cpuidle_add_state_sysfs(struct cpuidle_device *device)
291{
292 int i, ret = -ENOMEM;
293 struct cpuidle_state_kobj *kobj;
294
295 /* state statistics */
296 for (i = 0; i < device->state_count; i++) {
297 kobj = kzalloc(sizeof(struct cpuidle_state_kobj), GFP_KERNEL);
298 if (!kobj)
299 goto error_state;
300 kobj->state = &device->states[i];
301 init_completion(&kobj->kobj_unregister);
302
303 kobj->kobj.parent = &device->kobj;
304 kobj->kobj.ktype = &ktype_state_cpuidle;
305 kobject_set_name(&kobj->kobj, "state%d", i);
306 ret = kobject_register(&kobj->kobj);
307 if (ret) {
308 kfree(kobj);
309 goto error_state;
310 }
311 device->kobjs[i] = kobj;
312 }
313
314 return 0;
315
316error_state:
317 for (i = i - 1; i >= 0; i--)
318 cpuidle_free_state_kobj(device, i);
319 return ret;
320}
321
322/**
323 * cpuidle_remove_driver_sysfs - removes driver-specific sysfs attributes
324 * @device: the target device
325 */
326void cpuidle_remove_state_sysfs(struct cpuidle_device *device)
327{
328 int i;
329
330 for (i = 0; i < device->state_count; i++)
331 cpuidle_free_state_kobj(device, i);
332}
333
334/**
335 * cpuidle_add_sysfs - creates a sysfs instance for the target device
336 * @sysdev: the target device
337 */
338int cpuidle_add_sysfs(struct sys_device *sysdev)
339{
340 int cpu = sysdev->id;
341 struct cpuidle_device *dev;
342
343 dev = per_cpu(cpuidle_devices, cpu);
344 dev->kobj.parent = &sysdev->kobj;
345 dev->kobj.ktype = &ktype_cpuidle;
346 kobject_set_name(&dev->kobj, "%s", "cpuidle");
347 return kobject_register(&dev->kobj);
348}
349
350/**
351 * cpuidle_remove_sysfs - deletes a sysfs instance on the target device
352 * @sysdev: the target device
353 */
354void cpuidle_remove_sysfs(struct sys_device *sysdev)
355{
356 int cpu = sysdev->id;
357 struct cpuidle_device *dev;
358
359 dev = per_cpu(cpuidle_devices, cpu);
360 kobject_unregister(&dev->kobj);
361}