]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
PM / suspend: Always use deepest C-state in the "freeze" sleep state
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Sun, 4 May 2014 22:51:54 +0000 (00:51 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 6 May 2014 23:49:28 +0000 (01:49 +0200)
If freeze_enter() is called, we want to bypass the current cpuidle
governor and always use the deepest available (that is, not disabled)
C-state, because we want to save as much energy as reasonably possible
then and runtime latency constraints don't matter at that point, since
the system is in a sleep state anyway.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Aubrey Li <aubrey.li@linux.intel.com>
drivers/cpuidle/cpuidle.c
include/linux/cpuidle.h
kernel/power/suspend.c

index f38359f64cc6bea50783fc603da274c0fff43fbd..cb7019977c50febbcd21b9ad49f4a9bfe1ca6271 100644 (file)
@@ -32,6 +32,7 @@ LIST_HEAD(cpuidle_detected_devices);
 static int enabled_devices;
 static int off __read_mostly;
 static int initialized __read_mostly;
+static bool use_deepest_state __read_mostly;
 
 int cpuidle_disabled(void)
 {
@@ -64,6 +65,45 @@ int cpuidle_play_dead(void)
        return -ENODEV;
 }
 
+/**
+ * cpuidle_use_deepest_state - Enable/disable the "deepest idle" mode.
+ * @enable: Whether enable or disable the feature.
+ *
+ * If the "deepest idle" mode is enabled, cpuidle will ignore the governor and
+ * always use the state with the greatest exit latency (out of the states that
+ * are not disabled).
+ *
+ * This function can only be called after cpuidle_pause() to avoid races.
+ */
+void cpuidle_use_deepest_state(bool enable)
+{
+       use_deepest_state = enable;
+}
+
+/**
+ * cpuidle_find_deepest_state - Find the state of the greatest exit latency.
+ * @drv: cpuidle driver for a given CPU.
+ * @dev: cpuidle device for a given CPU.
+ */
+static int cpuidle_find_deepest_state(struct cpuidle_driver *drv,
+                                     struct cpuidle_device *dev)
+{
+       unsigned int latency_req = 0;
+       int i, ret = CPUIDLE_DRIVER_STATE_START - 1;
+
+       for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) {
+               struct cpuidle_state *s = &drv->states[i];
+               struct cpuidle_state_usage *su = &dev->states_usage[i];
+
+               if (s->disabled || su->disable || s->exit_latency <= latency_req)
+                       continue;
+
+               latency_req = s->exit_latency;
+               ret = i;
+       }
+       return ret;
+}
+
 /**
  * cpuidle_enter_state - enter the state and update stats
  * @dev: cpuidle device for this cpu
@@ -124,6 +164,9 @@ int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
        if (!drv || !dev || !dev->enabled)
                return -EBUSY;
 
+       if (unlikely(use_deepest_state))
+               return cpuidle_find_deepest_state(drv, dev);
+
        return cpuidle_curr_governor->select(drv, dev);
 }
 
@@ -155,7 +198,7 @@ int cpuidle_enter(struct cpuidle_driver *drv, struct cpuidle_device *dev,
  */
 void cpuidle_reflect(struct cpuidle_device *dev, int index)
 {
-       if (cpuidle_curr_governor->reflect)
+       if (cpuidle_curr_governor->reflect && !unlikely(use_deepest_state))
                cpuidle_curr_governor->reflect(dev, index);
 }
 
index a8d5bd391a267524e935dd1f04a1f1bff6d32e4f..c51a436135c485ff354be3eec4d9a612b0822c8d 100644 (file)
@@ -143,6 +143,7 @@ extern void cpuidle_resume(void);
 extern int cpuidle_enable_device(struct cpuidle_device *dev);
 extern void cpuidle_disable_device(struct cpuidle_device *dev);
 extern int cpuidle_play_dead(void);
+extern void cpuidle_use_deepest_state(bool enable);
 
 extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev);
 #else
@@ -175,6 +176,7 @@ static inline int cpuidle_enable_device(struct cpuidle_device *dev)
 {return -ENODEV; }
 static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
 static inline int cpuidle_play_dead(void) {return -ENODEV; }
+static inline void cpuidle_use_deepest_state(bool enable) {}
 static inline struct cpuidle_driver *cpuidle_get_cpu_driver(
        struct cpuidle_device *dev) {return NULL; }
 #endif
index 8233cd4047d776c311ef71800479f1e2b637e5da..155721f7f9090dc9bdc97065a0a1daa1c10fafa8 100644 (file)
@@ -54,9 +54,11 @@ static void freeze_begin(void)
 
 static void freeze_enter(void)
 {
+       cpuidle_use_deepest_state(true);
        cpuidle_resume();
        wait_event(suspend_freeze_wait_head, suspend_freeze_wake);
        cpuidle_pause();
+       cpuidle_use_deepest_state(false);
 }
 
 void freeze_wake(void)