diff options
Diffstat (limited to 'drivers/cpuidle/cpuidle.c')
| -rw-r--r-- | drivers/cpuidle/cpuidle.c | 61 |
1 files changed, 26 insertions, 35 deletions
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 4d534582514e..080bd2dbde4b 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c | |||
| @@ -44,6 +44,12 @@ void disable_cpuidle(void) | |||
| 44 | off = 1; | 44 | off = 1; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | bool cpuidle_not_available(struct cpuidle_driver *drv, | ||
| 48 | struct cpuidle_device *dev) | ||
| 49 | { | ||
| 50 | return off || !initialized || !drv || !dev || !dev->enabled; | ||
| 51 | } | ||
| 52 | |||
| 47 | /** | 53 | /** |
| 48 | * cpuidle_play_dead - cpu off-lining | 54 | * cpuidle_play_dead - cpu off-lining |
| 49 | * | 55 | * |
| @@ -66,14 +72,8 @@ int cpuidle_play_dead(void) | |||
| 66 | return -ENODEV; | 72 | return -ENODEV; |
| 67 | } | 73 | } |
| 68 | 74 | ||
| 69 | /** | 75 | static int find_deepest_state(struct cpuidle_driver *drv, |
| 70 | * cpuidle_find_deepest_state - Find deepest state meeting specific conditions. | 76 | struct cpuidle_device *dev, bool freeze) |
| 71 | * @drv: cpuidle driver for the given CPU. | ||
| 72 | * @dev: cpuidle device for the given CPU. | ||
| 73 | * @freeze: Whether or not the state should be suitable for suspend-to-idle. | ||
| 74 | */ | ||
| 75 | static int cpuidle_find_deepest_state(struct cpuidle_driver *drv, | ||
| 76 | struct cpuidle_device *dev, bool freeze) | ||
| 77 | { | 77 | { |
| 78 | unsigned int latency_req = 0; | 78 | unsigned int latency_req = 0; |
| 79 | int i, ret = freeze ? -1 : CPUIDLE_DRIVER_STATE_START - 1; | 79 | int i, ret = freeze ? -1 : CPUIDLE_DRIVER_STATE_START - 1; |
| @@ -92,6 +92,17 @@ static int cpuidle_find_deepest_state(struct cpuidle_driver *drv, | |||
| 92 | return ret; | 92 | return ret; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | /** | ||
| 96 | * cpuidle_find_deepest_state - Find the deepest available idle state. | ||
| 97 | * @drv: cpuidle driver for the given CPU. | ||
| 98 | * @dev: cpuidle device for the given CPU. | ||
| 99 | */ | ||
| 100 | int cpuidle_find_deepest_state(struct cpuidle_driver *drv, | ||
| 101 | struct cpuidle_device *dev) | ||
| 102 | { | ||
| 103 | return find_deepest_state(drv, dev, false); | ||
| 104 | } | ||
| 105 | |||
| 95 | static void enter_freeze_proper(struct cpuidle_driver *drv, | 106 | static void enter_freeze_proper(struct cpuidle_driver *drv, |
| 96 | struct cpuidle_device *dev, int index) | 107 | struct cpuidle_device *dev, int index) |
| 97 | { | 108 | { |
| @@ -113,15 +124,14 @@ static void enter_freeze_proper(struct cpuidle_driver *drv, | |||
| 113 | 124 | ||
| 114 | /** | 125 | /** |
| 115 | * cpuidle_enter_freeze - Enter an idle state suitable for suspend-to-idle. | 126 | * cpuidle_enter_freeze - Enter an idle state suitable for suspend-to-idle. |
| 127 | * @drv: cpuidle driver for the given CPU. | ||
| 128 | * @dev: cpuidle device for the given CPU. | ||
| 116 | * | 129 | * |
| 117 | * If there are states with the ->enter_freeze callback, find the deepest of | 130 | * If there are states with the ->enter_freeze callback, find the deepest of |
| 118 | * them and enter it with frozen tick. Otherwise, find the deepest state | 131 | * them and enter it with frozen tick. |
| 119 | * available and enter it normally. | ||
| 120 | */ | 132 | */ |
| 121 | void cpuidle_enter_freeze(void) | 133 | int cpuidle_enter_freeze(struct cpuidle_driver *drv, struct cpuidle_device *dev) |
| 122 | { | 134 | { |
| 123 | struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices); | ||
| 124 | struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); | ||
| 125 | int index; | 135 | int index; |
| 126 | 136 | ||
| 127 | /* | 137 | /* |
| @@ -129,24 +139,11 @@ void cpuidle_enter_freeze(void) | |||
| 129 | * that interrupts won't be enabled when it exits and allows the tick to | 139 | * that interrupts won't be enabled when it exits and allows the tick to |
| 130 | * be frozen safely. | 140 | * be frozen safely. |
| 131 | */ | 141 | */ |
| 132 | index = cpuidle_find_deepest_state(drv, dev, true); | 142 | index = find_deepest_state(drv, dev, true); |
| 133 | if (index >= 0) { | ||
| 134 | enter_freeze_proper(drv, dev, index); | ||
| 135 | return; | ||
| 136 | } | ||
| 137 | |||
| 138 | /* | ||
| 139 | * It is not safe to freeze the tick, find the deepest state available | ||
| 140 | * at all and try to enter it normally. | ||
| 141 | */ | ||
| 142 | index = cpuidle_find_deepest_state(drv, dev, false); | ||
| 143 | if (index >= 0) | 143 | if (index >= 0) |
| 144 | cpuidle_enter(drv, dev, index); | 144 | enter_freeze_proper(drv, dev, index); |
| 145 | else | ||
| 146 | arch_cpu_idle(); | ||
| 147 | 145 | ||
| 148 | /* Interrupts are enabled again here. */ | 146 | return index; |
| 149 | local_irq_disable(); | ||
| 150 | } | 147 | } |
| 151 | 148 | ||
| 152 | /** | 149 | /** |
| @@ -205,12 +202,6 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, | |||
| 205 | */ | 202 | */ |
| 206 | int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) | 203 | int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) |
| 207 | { | 204 | { |
| 208 | if (off || !initialized) | ||
| 209 | return -ENODEV; | ||
| 210 | |||
| 211 | if (!drv || !dev || !dev->enabled) | ||
| 212 | return -EBUSY; | ||
| 213 | |||
| 214 | return cpuidle_curr_governor->select(drv, dev); | 205 | return cpuidle_curr_governor->select(drv, dev); |
| 215 | } | 206 | } |
| 216 | 207 | ||
