Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[safe/jmp/linux-2.6] / drivers / cpuidle / cpuidle.c
index 2e31484..1994885 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/cpuidle.h>
 #include <linux/ktime.h>
 #include <linux/hrtimer.h>
+#include <trace/events/power.h>
 
 #include "cpuidle.h"
 
@@ -57,31 +58,44 @@ static void cpuidle_idle_call(void)
                if (pm_idle_old)
                        pm_idle_old();
                else
+#if defined(CONFIG_ARCH_HAS_DEFAULT_IDLE)
+                       default_idle();
+#else
                        local_irq_enable();
+#endif
                return;
        }
 
+#if 0
+       /* shows regressions, re-enable for 2.6.29 */
        /*
         * run any timers that can be run now, at this point
         * before calculating the idle duration etc.
         */
        hrtimer_peek_ahead_timers();
-
+#endif
        /* ask the governor for the next state */
        next_state = cpuidle_curr_governor->select(dev);
-       if (need_resched())
+       if (need_resched()) {
+               local_irq_enable();
                return;
+       }
+
        target_state = &dev->states[next_state];
 
        /* enter the state and update stats */
-       dev->last_residency = target_state->enter(dev, target_state);
        dev->last_state = target_state;
+       dev->last_residency = target_state->enter(dev, target_state);
+       if (dev->last_state)
+               target_state = dev->last_state;
+
        target_state->time += (unsigned long long)dev->last_residency;
        target_state->usage++;
 
        /* give the governor an opportunity to reflect on the outcome */
        if (cpuidle_curr_governor->reflect)
                cpuidle_curr_governor->reflect(dev);
+       trace_power_end(0);
 }
 
 /**
@@ -142,7 +156,7 @@ int cpuidle_enable_device(struct cpuidle_device *dev)
 
        if (dev->enabled)
                return 0;
-       if (!cpuidle_curr_driver || !cpuidle_curr_governor)
+       if (!cpuidle_get_driver() || !cpuidle_curr_governor)
                return -EIO;
        if (!dev->state_count)
                return -EINVAL;
@@ -193,7 +207,7 @@ void cpuidle_disable_device(struct cpuidle_device *dev)
 {
        if (!dev->enabled)
                return;
-       if (!cpuidle_curr_driver || !cpuidle_curr_governor)
+       if (!cpuidle_get_driver() || !cpuidle_curr_governor)
                return;
 
        dev->enabled = 0;
@@ -257,10 +271,11 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
 {
        int ret;
        struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu);
+       struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver();
 
        if (!sys_dev)
                return -EINVAL;
-       if (!try_module_get(cpuidle_curr_driver->owner))
+       if (!try_module_get(cpuidle_driver->owner))
                return -EINVAL;
 
        init_completion(&dev->kobj_unregister);
@@ -270,7 +285,7 @@ static int __cpuidle_register_device(struct cpuidle_device *dev)
        per_cpu(cpuidle_devices, dev->cpu) = dev;
        list_add(&dev->device_list, &cpuidle_detected_devices);
        if ((ret = cpuidle_add_sysfs(sys_dev))) {
-               module_put(cpuidle_curr_driver->owner);
+               module_put(cpuidle_driver->owner);
                return ret;
        }
 
@@ -311,6 +326,7 @@ EXPORT_SYMBOL_GPL(cpuidle_register_device);
 void cpuidle_unregister_device(struct cpuidle_device *dev)
 {
        struct sys_device *sys_dev = get_cpu_sysdev((unsigned long)dev->cpu);
+       struct cpuidle_driver *cpuidle_driver = cpuidle_get_driver();
 
        if (dev->registered == 0)
                return;
@@ -326,7 +342,7 @@ void cpuidle_unregister_device(struct cpuidle_device *dev)
 
        cpuidle_resume_and_unlock();
 
-       module_put(cpuidle_curr_driver->owner);
+       module_put(cpuidle_driver->owner);
 }
 
 EXPORT_SYMBOL_GPL(cpuidle_unregister_device);