diff options
Diffstat (limited to 'drivers/cpuidle/cpuidle.c')
-rw-r--r-- | drivers/cpuidle/cpuidle.c | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index e4855c33f897..bf5092455a8f 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c | |||
@@ -161,6 +161,45 @@ void cpuidle_resume_and_unlock(void) | |||
161 | 161 | ||
162 | EXPORT_SYMBOL_GPL(cpuidle_resume_and_unlock); | 162 | EXPORT_SYMBOL_GPL(cpuidle_resume_and_unlock); |
163 | 163 | ||
164 | #ifdef CONFIG_ARCH_HAS_CPU_RELAX | ||
165 | static int poll_idle(struct cpuidle_device *dev, struct cpuidle_state *st) | ||
166 | { | ||
167 | ktime_t t1, t2; | ||
168 | s64 diff; | ||
169 | int ret; | ||
170 | |||
171 | t1 = ktime_get(); | ||
172 | local_irq_enable(); | ||
173 | while (!need_resched()) | ||
174 | cpu_relax(); | ||
175 | |||
176 | t2 = ktime_get(); | ||
177 | diff = ktime_to_us(ktime_sub(t2, t1)); | ||
178 | if (diff > INT_MAX) | ||
179 | diff = INT_MAX; | ||
180 | |||
181 | ret = (int) diff; | ||
182 | return ret; | ||
183 | } | ||
184 | |||
185 | static void poll_idle_init(struct cpuidle_device *dev) | ||
186 | { | ||
187 | struct cpuidle_state *state = &dev->states[0]; | ||
188 | |||
189 | cpuidle_set_statedata(state, NULL); | ||
190 | |||
191 | snprintf(state->name, CPUIDLE_NAME_LEN, "POLL"); | ||
192 | snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE"); | ||
193 | state->exit_latency = 0; | ||
194 | state->target_residency = 0; | ||
195 | state->power_usage = -1; | ||
196 | state->flags = 0; | ||
197 | state->enter = poll_idle; | ||
198 | } | ||
199 | #else | ||
200 | static void poll_idle_init(struct cpuidle_device *dev) {} | ||
201 | #endif /* CONFIG_ARCH_HAS_CPU_RELAX */ | ||
202 | |||
164 | /** | 203 | /** |
165 | * cpuidle_enable_device - enables idle PM for a CPU | 204 | * cpuidle_enable_device - enables idle PM for a CPU |
166 | * @dev: the CPU | 205 | * @dev: the CPU |
@@ -185,6 +224,8 @@ int cpuidle_enable_device(struct cpuidle_device *dev) | |||
185 | return ret; | 224 | return ret; |
186 | } | 225 | } |
187 | 226 | ||
227 | poll_idle_init(dev); | ||
228 | |||
188 | if ((ret = cpuidle_add_state_sysfs(dev))) | 229 | if ((ret = cpuidle_add_state_sysfs(dev))) |
189 | return ret; | 230 | return ret; |
190 | 231 | ||
@@ -239,45 +280,6 @@ void cpuidle_disable_device(struct cpuidle_device *dev) | |||
239 | 280 | ||
240 | EXPORT_SYMBOL_GPL(cpuidle_disable_device); | 281 | EXPORT_SYMBOL_GPL(cpuidle_disable_device); |
241 | 282 | ||
242 | #ifdef CONFIG_ARCH_HAS_CPU_RELAX | ||
243 | static int poll_idle(struct cpuidle_device *dev, struct cpuidle_state *st) | ||
244 | { | ||
245 | ktime_t t1, t2; | ||
246 | s64 diff; | ||
247 | int ret; | ||
248 | |||
249 | t1 = ktime_get(); | ||
250 | local_irq_enable(); | ||
251 | while (!need_resched()) | ||
252 | cpu_relax(); | ||
253 | |||
254 | t2 = ktime_get(); | ||
255 | diff = ktime_to_us(ktime_sub(t2, t1)); | ||
256 | if (diff > INT_MAX) | ||
257 | diff = INT_MAX; | ||
258 | |||
259 | ret = (int) diff; | ||
260 | return ret; | ||
261 | } | ||
262 | |||
263 | static void poll_idle_init(struct cpuidle_device *dev) | ||
264 | { | ||
265 | struct cpuidle_state *state = &dev->states[0]; | ||
266 | |||
267 | cpuidle_set_statedata(state, NULL); | ||
268 | |||
269 | snprintf(state->name, CPUIDLE_NAME_LEN, "C0"); | ||
270 | snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE"); | ||
271 | state->exit_latency = 0; | ||
272 | state->target_residency = 0; | ||
273 | state->power_usage = -1; | ||
274 | state->flags = CPUIDLE_FLAG_POLL; | ||
275 | state->enter = poll_idle; | ||
276 | } | ||
277 | #else | ||
278 | static void poll_idle_init(struct cpuidle_device *dev) {} | ||
279 | #endif /* CONFIG_ARCH_HAS_CPU_RELAX */ | ||
280 | |||
281 | /** | 283 | /** |
282 | * __cpuidle_register_device - internal register function called before register | 284 | * __cpuidle_register_device - internal register function called before register |
283 | * and enable routines | 285 | * and enable routines |
@@ -298,8 +300,6 @@ static int __cpuidle_register_device(struct cpuidle_device *dev) | |||
298 | 300 | ||
299 | init_completion(&dev->kobj_unregister); | 301 | init_completion(&dev->kobj_unregister); |
300 | 302 | ||
301 | poll_idle_init(dev); | ||
302 | |||
303 | /* | 303 | /* |
304 | * cpuidle driver should set the dev->power_specified bit | 304 | * cpuidle driver should set the dev->power_specified bit |
305 | * before registering the device if the driver provides | 305 | * before registering the device if the driver provides |