Lines Matching +full:cpu +full:- +full:idle +full:- +full:states

2  * cpuidle.c - core cpuidle infrastructure
4 * (C) 2006-2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
18 #include <linux/cpu.h>
52 return off || !initialized || !drv || !dev || !dev->enabled; in cpuidle_not_available()
56 * cpuidle_play_dead - cpu off-lining
67 return -ENODEV; in cpuidle_play_dead()
69 /* Find lowest-power state that supports long-term idle */ in cpuidle_play_dead()
70 for (i = drv->state_count - 1; i >= 0; i--) in cpuidle_play_dead()
71 if (drv->states[i].enter_dead) in cpuidle_play_dead()
72 return drv->states[i].enter_dead(dev, i); in cpuidle_play_dead()
74 return -ENODEV; in cpuidle_play_dead()
86 for (i = 1; i < drv->state_count; i++) { in find_deepest_state()
87 struct cpuidle_state *s = &drv->states[i]; in find_deepest_state()
89 if (dev->states_usage[i].disable || in find_deepest_state()
90 s->exit_latency_ns <= latency_req || in find_deepest_state()
91 s->exit_latency_ns > max_latency_ns || in find_deepest_state()
92 (s->flags & forbidden_flags) || in find_deepest_state()
93 (s2idle && !s->enter_s2idle)) in find_deepest_state()
96 latency_req = s->exit_latency_ns; in find_deepest_state()
103 * cpuidle_use_deepest_state - Set/unset governor override mode.
104 * @latency_limit_ns: Idle state exit latency limit (or no override if 0).
106 * If @latency_limit_ns is nonzero, set the current CPU to use the deepest idle
117 dev->forced_idle_latency_limit_ns = latency_limit_ns; in cpuidle_use_deepest_state()
122 * cpuidle_find_deepest_state - Find the deepest available idle state.
123 * @drv: cpuidle driver for the given CPU.
124 * @dev: cpuidle device for the given CPU.
125 * @latency_limit_ns: Idle state exit latency limit
127 * Return: the index of the deepest available idle state.
141 struct cpuidle_state *target_state = &drv->states[index]; in enter_s2idle_proper()
152 if (!(target_state->flags & CPUIDLE_FLAG_RCU_IDLE)) in enter_s2idle_proper()
154 target_state->enter_s2idle(dev, drv, index); in enter_s2idle_proper()
157 if (!(target_state->flags & CPUIDLE_FLAG_RCU_IDLE)) in enter_s2idle_proper()
164 dev->states_usage[index].s2idle_time += ktime_us_delta(time_end, time_start); in enter_s2idle_proper()
165 dev->states_usage[index].s2idle_usage++; in enter_s2idle_proper()
169 * cpuidle_enter_s2idle - Enter an idle state suitable for suspend-to-idle.
170 * @drv: cpuidle driver for the given CPU.
171 * @dev: cpuidle device for the given CPU.
173 * If there are states with the ->enter_s2idle callback, find the deepest of
181 * Find the deepest state with ->enter_s2idle present, which guarantees in cpuidle_enter_s2idle()
195 * cpuidle_enter_state - enter the state and update stats
196 * @dev: cpuidle device for this cpu
197 * @drv: cpuidle driver for this cpu
198 * @index: index into the states table in @drv of the state to enter
205 struct cpuidle_state *target_state = &drv->states[index]; in cpuidle_enter_state()
206 bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP); in cpuidle_enter_state()
212 * CPU as a broadcast timer, this call may fail if it is not available. in cpuidle_enter_state()
215 index = find_deepest_state(drv, dev, target_state->exit_latency_ns, in cpuidle_enter_state()
219 return -EBUSY; in cpuidle_enter_state()
221 target_state = &drv->states[index]; in cpuidle_enter_state()
225 if (target_state->flags & CPUIDLE_FLAG_TLB_FLUSHED) in cpuidle_enter_state()
226 leave_mm(dev->cpu); in cpuidle_enter_state()
228 /* Take note of the planned idle state. */ in cpuidle_enter_state()
231 trace_cpu_idle(index, dev->cpu); in cpuidle_enter_state()
235 if (!(target_state->flags & CPUIDLE_FLAG_RCU_IDLE)) in cpuidle_enter_state()
237 entered_state = target_state->enter(dev, drv, index); in cpuidle_enter_state()
238 if (!(target_state->flags & CPUIDLE_FLAG_RCU_IDLE)) in cpuidle_enter_state()
244 trace_cpu_idle(PWR_EVENT_EXIT, dev->cpu); in cpuidle_enter_state()
246 /* The cpu is no longer idle or about to enter idle. */ in cpuidle_enter_state()
260 s64 diff, delay = drv->states[entered_state].exit_latency_ns; in cpuidle_enter_state()
270 dev->last_residency_ns = diff; in cpuidle_enter_state()
271 dev->states_usage[entered_state].time_ns += diff; in cpuidle_enter_state()
272 dev->states_usage[entered_state].usage++; in cpuidle_enter_state()
274 if (diff < drv->states[entered_state].target_residency_ns) { in cpuidle_enter_state()
275 for (i = entered_state - 1; i >= 0; i--) { in cpuidle_enter_state()
276 if (dev->states_usage[i].disable) in cpuidle_enter_state()
279 /* Shallower states are enabled, so update. */ in cpuidle_enter_state()
280 dev->states_usage[entered_state].above++; in cpuidle_enter_state()
284 for (i = entered_state + 1; i < drv->state_count; i++) { in cpuidle_enter_state()
285 if (dev->states_usage[i].disable) in cpuidle_enter_state()
290 * better match for the observed idle duration. in cpuidle_enter_state()
292 if (diff - delay >= drv->states[i].target_residency_ns) in cpuidle_enter_state()
293 dev->states_usage[entered_state].below++; in cpuidle_enter_state()
299 dev->last_residency_ns = 0; in cpuidle_enter_state()
300 dev->states_usage[index].rejected++; in cpuidle_enter_state()
307 * cpuidle_select - ask the cpuidle framework to choose an idle state
313 * Returns the index of the idle state. The return value must not be negative.
322 return cpuidle_curr_governor->select(drv, dev, stop_tick); in cpuidle_select()
326 * cpuidle_enter - enter into the specified idle state
328 * @drv: the cpuidle driver tied with the cpu
330 * @index: the index in the idle state table
332 * Returns the index in the idle state, < 0 in case of error.
344 * ->select() callback have decided, whether to stop the tick or not. in cpuidle_enter()
346 WRITE_ONCE(dev->next_hrtimer, tick_nohz_get_next_hrtimer()); in cpuidle_enter()
353 WRITE_ONCE(dev->next_hrtimer, 0); in cpuidle_enter()
358 * cpuidle_reflect - tell the underlying governor what was the state
362 * @index: the index in the idle state table
367 if (cpuidle_curr_governor->reflect && index >= 0) in cpuidle_reflect()
368 cpuidle_curr_governor->reflect(dev, index); in cpuidle_reflect()
372 * cpuidle_poll_time - return amount of time to poll for,
373 * governors can override dev->poll_limit_ns if necessary
375 * @drv: the cpuidle driver tied with the cpu
385 if (dev->poll_limit_ns) in cpuidle_poll_time()
386 return dev->poll_limit_ns; in cpuidle_poll_time()
389 for (i = 1; i < drv->state_count; i++) { in cpuidle_poll_time()
390 if (dev->states_usage[i].disable) in cpuidle_poll_time()
393 limit_ns = drv->states[i].target_residency_ns; in cpuidle_poll_time()
397 dev->poll_limit_ns = limit_ns; in cpuidle_poll_time()
399 return dev->poll_limit_ns; in cpuidle_poll_time()
403 * cpuidle_install_idle_handler - installs the cpuidle idle loop handler
408 /* Make sure all changes finished before we switch to new idle */ in cpuidle_install_idle_handler()
415 * cpuidle_uninstall_idle_handler - uninstalls the cpuidle idle loop handler
426 * are done looking at pointed idle states. in cpuidle_uninstall_idle_handler()
432 * cpuidle_pause_and_lock - temporarily disables CPUIDLE
443 * cpuidle_resume_and_unlock - resumes CPUIDLE operation
470 * cpuidle_enable_device - enables idle PM for a CPU
471 * @dev: the CPU
482 return -EINVAL; in cpuidle_enable_device()
484 if (dev->enabled) in cpuidle_enable_device()
488 return -EIO; in cpuidle_enable_device()
493 return -EIO; in cpuidle_enable_device()
495 if (!dev->registered) in cpuidle_enable_device()
496 return -EINVAL; in cpuidle_enable_device()
502 if (cpuidle_curr_governor->enable) { in cpuidle_enable_device()
503 ret = cpuidle_curr_governor->enable(drv, dev); in cpuidle_enable_device()
510 dev->enabled = 1; in cpuidle_enable_device()
524 * cpuidle_disable_device - disables idle PM for a CPU
525 * @dev: the CPU
534 if (!dev || !dev->enabled) in cpuidle_disable_device()
540 dev->enabled = 0; in cpuidle_disable_device()
542 if (cpuidle_curr_governor->disable) in cpuidle_disable_device()
543 cpuidle_curr_governor->disable(drv, dev); in cpuidle_disable_device()
546 enabled_devices--; in cpuidle_disable_device()
555 list_del(&dev->device_list); in __cpuidle_unregister_device()
556 per_cpu(cpuidle_devices, dev->cpu) = NULL; in __cpuidle_unregister_device()
557 module_put(drv->owner); in __cpuidle_unregister_device()
559 dev->registered = 0; in __cpuidle_unregister_device()
564 memset(dev->states_usage, 0, sizeof(dev->states_usage)); in __cpuidle_device_init()
565 dev->last_residency_ns = 0; in __cpuidle_device_init()
566 dev->next_hrtimer = 0; in __cpuidle_device_init()
570 * __cpuidle_register_device - internal register function called before register
572 * @dev: the cpu
581 if (!try_module_get(drv->owner)) in __cpuidle_register_device()
582 return -EINVAL; in __cpuidle_register_device()
584 for (i = 0; i < drv->state_count; i++) { in __cpuidle_register_device()
585 if (drv->states[i].flags & CPUIDLE_FLAG_UNUSABLE) in __cpuidle_register_device()
586 dev->states_usage[i].disable |= CPUIDLE_STATE_DISABLED_BY_DRIVER; in __cpuidle_register_device()
588 if (drv->states[i].flags & CPUIDLE_FLAG_OFF) in __cpuidle_register_device()
589 dev->states_usage[i].disable |= CPUIDLE_STATE_DISABLED_BY_USER; in __cpuidle_register_device()
592 per_cpu(cpuidle_devices, dev->cpu) = dev; in __cpuidle_register_device()
593 list_add(&dev->device_list, &cpuidle_detected_devices); in __cpuidle_register_device()
599 dev->registered = 1; in __cpuidle_register_device()
605 * cpuidle_register_device - registers a CPU's idle PM feature
606 * @dev: the cpu
610 int ret = -EBUSY; in cpuidle_register_device()
613 return -EINVAL; in cpuidle_register_device()
617 if (dev->registered) in cpuidle_register_device()
651 * cpuidle_unregister_device - unregisters a CPU's idle PM feature
652 * @dev: the cpu
656 if (!dev || dev->registered == 0) in cpuidle_unregister_device()
683 int cpu; in cpuidle_unregister() local
686 for_each_cpu(cpu, drv->cpumask) { in cpuidle_unregister()
687 device = &per_cpu(cpuidle_dev, cpu); in cpuidle_unregister()
696 * cpuidle_register: registers the driver and the cpu devices with the
702 * @coupled_cpus: a cpumask for the coupled states
709 int ret, cpu; in cpuidle_register() local
718 for_each_cpu(cpu, drv->cpumask) { in cpuidle_register()
719 device = &per_cpu(cpuidle_dev, cpu); in cpuidle_register()
720 device->cpu = cpu; in cpuidle_register()
724 * On multiplatform for ARM, the coupled idle states could be in cpuidle_register()
729 device->coupled_cpus = *coupled_cpus; in cpuidle_register()
735 pr_err("Failed to register cpuidle device for cpu%d\n", cpu); in cpuidle_register()
746 * cpuidle_init - core initializer
751 return -ENODEV; in cpuidle_init()