/* * cpuidle.c - core cpuidle infrastructure * * (C) 2006-2007 Venkatesh Pallipadi <[email protected]> * Shaohua Li <[email protected]> * Adam Belay <[email protected]> * * This code is licenced under the GPL. */ #include "linux/percpu-defs.h" #include <linux/clockchips.h> #include <linux/kernel.h> #include <linux/mutex.h> #include <linux/sched.h> #include <linux/sched/clock.h> #include <linux/sched/idle.h> #include <linux/notifier.h> #include <linux/pm_qos.h> #include <linux/cpu.h> #include <linux/cpuidle.h> #include <linux/ktime.h> #include <linux/hrtimer.h> #include <linux/module.h> #include <linux/suspend.h> #include <linux/tick.h> #include <linux/mmu_context.h> #include <linux/context_tracking.h> #include <trace/events/power.h> #include "cpuidle.h" DEFINE_PER_CPU(struct cpuidle_device *, cpuidle_devices); DEFINE_PER_CPU(struct cpuidle_device, cpuidle_dev); DEFINE_MUTEX(…) …; LIST_HEAD(…); static int enabled_devices; static int off __read_mostly; static int initialized __read_mostly; int cpuidle_disabled(void) { … } void disable_cpuidle(void) { … } bool cpuidle_not_available(struct cpuidle_driver *drv, struct cpuidle_device *dev) { … } /** * cpuidle_play_dead - cpu off-lining * * Returns in case of an error or no driver */ int cpuidle_play_dead(void) { … } static int find_deepest_state(struct cpuidle_driver *drv, struct cpuidle_device *dev, u64 max_latency_ns, unsigned int forbidden_flags, bool s2idle) { … } /** * cpuidle_use_deepest_state - Set/unset governor override mode. * @latency_limit_ns: Idle state exit latency limit (or no override if 0). * * If @latency_limit_ns is nonzero, set the current CPU to use the deepest idle * state with exit latency within @latency_limit_ns (override governors going * forward), or do not override governors if it is zero. */ void cpuidle_use_deepest_state(u64 latency_limit_ns) { … } /** * cpuidle_find_deepest_state - Find the deepest available idle state. * @drv: cpuidle driver for the given CPU. * @dev: cpuidle device for the given CPU. * @latency_limit_ns: Idle state exit latency limit * * Return: the index of the deepest available idle state. */ int cpuidle_find_deepest_state(struct cpuidle_driver *drv, struct cpuidle_device *dev, u64 latency_limit_ns) { … } #ifdef CONFIG_SUSPEND static noinstr void enter_s2idle_proper(struct cpuidle_driver *drv, struct cpuidle_device *dev, int index) { … } /** * cpuidle_enter_s2idle - Enter an idle state suitable for suspend-to-idle. * @drv: cpuidle driver for the given CPU. * @dev: cpuidle device for the given CPU. * * If there are states with the ->enter_s2idle callback, find the deepest of * them and enter it with frozen tick. */ int cpuidle_enter_s2idle(struct cpuidle_driver *drv, struct cpuidle_device *dev) { … } #endif /* CONFIG_SUSPEND */ /** * cpuidle_enter_state - enter the state and update stats * @dev: cpuidle device for this cpu * @drv: cpuidle driver for this cpu * @index: index into the states table in @drv of the state to enter */ noinstr int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index) { … } /** * cpuidle_select - ask the cpuidle framework to choose an idle state * * @drv: the cpuidle driver * @dev: the cpuidle device * @stop_tick: indication on whether or not to stop the tick * * Returns the index of the idle state. The return value must not be negative. * * The memory location pointed to by @stop_tick is expected to be written the * 'false' boolean value if the scheduler tick should not be stopped before * entering the returned state. */ int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, bool *stop_tick) { … } /** * cpuidle_enter - enter into the specified idle state * * @drv: the cpuidle driver tied with the cpu * @dev: the cpuidle device * @index: the index in the idle state table * * Returns the index in the idle state, < 0 in case of error. * The error code depends on the backend driver */ int cpuidle_enter(struct cpuidle_driver *drv, struct cpuidle_device *dev, int index) { … } /** * cpuidle_reflect - tell the underlying governor what was the state * we were in * * @dev : the cpuidle device * @index: the index in the idle state table * */ void cpuidle_reflect(struct cpuidle_device *dev, int index) { … } /* * Min polling interval of 10usec is a guess. It is assuming that * for most users, the time for a single ping-pong workload like * perf bench pipe would generally complete within 10usec but * this is hardware dependant. Actual time can be estimated with * * perf bench sched pipe -l 10000 * * Run multiple times to avoid cpufreq effects. */ #define CPUIDLE_POLL_MIN … #define CPUIDLE_POLL_MAX … /** * cpuidle_poll_time - return amount of time to poll for, * governors can override dev->poll_limit_ns if necessary * * @drv: the cpuidle driver tied with the cpu * @dev: the cpuidle device * */ __cpuidle u64 cpuidle_poll_time(struct cpuidle_driver *drv, struct cpuidle_device *dev) { … } /** * cpuidle_install_idle_handler - installs the cpuidle idle loop handler */ void cpuidle_install_idle_handler(void) { … } /** * cpuidle_uninstall_idle_handler - uninstalls the cpuidle idle loop handler */ void cpuidle_uninstall_idle_handler(void) { … } /** * cpuidle_pause_and_lock - temporarily disables CPUIDLE */ void cpuidle_pause_and_lock(void) { … } EXPORT_SYMBOL_GPL(…); /** * cpuidle_resume_and_unlock - resumes CPUIDLE operation */ void cpuidle_resume_and_unlock(void) { … } EXPORT_SYMBOL_GPL(…); /* Currently used in suspend/resume path to suspend cpuidle */ void cpuidle_pause(void) { … } /* Currently used in suspend/resume path to resume cpuidle */ void cpuidle_resume(void) { … } /** * cpuidle_enable_device - enables idle PM for a CPU * @dev: the CPU * * This function must be called between cpuidle_pause_and_lock and * cpuidle_resume_and_unlock when used externally. */ int cpuidle_enable_device(struct cpuidle_device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * cpuidle_disable_device - disables idle PM for a CPU * @dev: the CPU * * This function must be called between cpuidle_pause_and_lock and * cpuidle_resume_and_unlock when used externally. */ void cpuidle_disable_device(struct cpuidle_device *dev) { … } EXPORT_SYMBOL_GPL(…); static void __cpuidle_unregister_device(struct cpuidle_device *dev) { … } static void __cpuidle_device_init(struct cpuidle_device *dev) { … } /** * __cpuidle_register_device - internal register function called before register * and enable routines * @dev: the cpu * * cpuidle_lock mutex must be held before this is called */ static int __cpuidle_register_device(struct cpuidle_device *dev) { … } /** * cpuidle_register_device - registers a CPU's idle PM feature * @dev: the cpu */ int cpuidle_register_device(struct cpuidle_device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * cpuidle_unregister_device - unregisters a CPU's idle PM feature * @dev: the cpu */ void cpuidle_unregister_device(struct cpuidle_device *dev) { … } EXPORT_SYMBOL_GPL(…); /** * cpuidle_unregister: unregister a driver and the devices. This function * can be used only if the driver has been previously registered through * the cpuidle_register function. * * @drv: a valid pointer to a struct cpuidle_driver */ void cpuidle_unregister(struct cpuidle_driver *drv) { … } EXPORT_SYMBOL_GPL(…); /** * cpuidle_register: registers the driver and the cpu devices with the * coupled_cpus passed as parameter. This function is used for all common * initialization pattern there are in the arch specific drivers. The * devices is globally defined in this file. * * @drv : a valid pointer to a struct cpuidle_driver * @coupled_cpus: a cpumask for the coupled states * * Returns 0 on success, < 0 otherwise */ int cpuidle_register(struct cpuidle_driver *drv, const struct cpumask *const coupled_cpus) { … } EXPORT_SYMBOL_GPL(…); /** * cpuidle_init - core initializer */ static int __init cpuidle_init(void) { … } module_param(off, int, 0444); module_param_string(…); core_initcall(cpuidle_init);