Lines Matching +full:timer +full:- +full:cannot +full:- +full:wake +full:- +full:cpu
1 .. SPDX-License-Identifier: GPL-2.0
5 .. |cpufreq| replace:: :doc:`CPU Performance Scaling <cpufreq>`
8 CPU Idle Time Management
27 CPU idle time management is an energy-efficiency feature concerned about using
31 ------------
33 CPU idle time management operates on CPUs as seen by the *CPU scheduler* (that
37 software as individual single-core processors. In other words, a CPU is an
43 program) at a time, it is a CPU. In that case, if the hardware is asked to
46 Second, if the processor is multi-core, each core in it is able to follow at
61 Finally, each core in a multi-core processor may be able to follow more than one
66 multiple individual single-core "processors", referred to as *hardware threads*
67 (or hyper-threads specifically on Intel hardware), that each can follow one
68 sequence of instructions. Then, the hardware threads are CPUs from the CPU idle
70 by one of them, the hardware thread (or CPU) that asked for it is stopped, but
78 ---------
84 Tasks are the CPU scheduler's representation of work. Each task consists of a
87 processor every time the task's code is run by a CPU. The CPU scheduler
91 no specific conditions preventing their code from being run by a CPU as long as
92 there is a CPU available for that (for example, they are not waiting for any
93 events to occur or similar). When a task becomes runnable, the CPU scheduler
95 tasks assigned to it, the CPU will load the given task's context and run its
97 another CPU). [If there are multiple runnable tasks assigned to one CPU
102 assigned to the given CPU and the CPU is then regarded as idle. In other words,
108 available idle states from being used, the CPU will simply execute more or less
112 .. _idle-loop:
118 calls into a code module referred to as the *governor* that belongs to the CPU
120 the CPU to ask the hardware to enter. Second, it invokes another code module
127 the platform or the processor architecture and organized in a one-dimensional
134 taken into account by the governor, the *target residency* and the (worst-case)
140 latency, in turn, is the maximum time it will take a CPU asking the processor
148 First of all, the governor knows the time until the closest timer event. That
151 CPU depends on can spend in an idle state, including the time necessary to enter
152 and exit it. However, the CPU may be woken up by a non-timer event at any time
153 (in particular, before the closest timer triggers) and it generally is not known
154 when that may happen. The governor can only see how much time the CPU actually
157 time until the closest timer to estimate the idle duration in future. How the
162 There are four ``CPUIdle`` governors available, ``menu``, `TEO <teo-gov_>`_,
165 tick can be `stopped by the idle loop <idle-cpus-and-tick_>`_. Available
169 :file:`current_governor` file under :file:`/sys/devices/system/cpu/cpuidle/`
178 driver chosen at the system initialization time cannot be replaced later, so the
183 file under :file:`/sys/devices/system/cpu/cpuidle/` in ``sysfs``.
186 .. _idle-cpus-and-tick:
191 The scheduler tick is a timer that triggers periodically in order to implement
192 the time sharing strategy of the CPU scheduler. Of course, if there are
193 multiple runnable tasks assigned to one CPU at the same time, the only way to
195 share the available CPU time. Namely, in rough approximation, each task is
196 given a slice of the CPU time to run its code, subject to the scheduling class,
197 prioritization and so on and when that time slice is used up, the CPU should be
199 may not want to give the CPU away voluntarily, however, and the scheduler tick
203 The scheduler tick is problematic from the CPU idle time management perspective,
208 the tick period length. Moreover, in that case the idle duration of any CPU
214 "idle" one. In other words, from the CPU scheduler perspective, the only user
215 of the CPU time on them is the idle loop. Since the time of an idle CPU need
217 tick goes away if the given CPU is idle. Consequently, it is possible to stop
223 (non-tick) timer due to trigger within the tick range, stopping the tick clearly
224 would be a waste of time, even though the timer hardware may not need to be
225 reprogrammed in that case. Second, if the governor is expecting a non-timer
229 going to be relatively shallow. The governor really cannot select a deep idle
232 waste of time and in this case the timer hardware would need to be reprogrammed,
239 so that it does not wake up the CPU too early.
247 loop altogether. That can be done through the build-time configuration of it
255 generally regarded as more energy-efficient than the systems running kernels in
256 which the tick cannot be stopped. If the given system is tickless, it will use
261 .. _menu-gov:
268 Namely, when invoked to select an idle state for a CPU (i.e. an idle state that
269 the CPU will ask the processor hardware to enter), it attempts to predict the
292 long enough, the governor obtains the time until the closest timer event with
295 next CPU wakeup. It is used to determine the sleep length range, which in turn
304 selecting the idle state for the CPU) is updated after the CPU has been woken
312 If the "typical interval" value is small, which means that the CPU is likely
320 limit coming from the power management quality of service, or `PM QoS <cpu-pm-qos_>`_,
326 if it has not decided to `stop the scheduler tick <idle-cpus-and-tick_>`_. That
330 the real time until the closest timer event and if it really is greater than
335 .. _teo-gov:
337 The Timer Events Oriented (TEO) Governor
340 The timer events oriented (TEO) governor is an alternative ``CPUIdle`` governor
342 <menu-gov_>`_: it always tries to find the deepest idle state suitable for the
345 .. kernel-doc:: drivers/cpuidle/governors/teo.c
346 :doc: teo-description
348 .. _idle-states-representation:
353 For the CPU idle time management purposes all of the physical idle states
354 supported by the processor have to be represented as a one-dimensional array of
355 |struct cpuidle_state| objects each allowing an individual (logical) CPU to ask
360 of it <idle-loop_>`_, must reflect the properties of the idle state at the
375 time the CPU needs to be idle to save any energy in case the hardware enters
378 because that is the maximum delay between a wakeup signal and the time the CPU
403 For each CPU in the system, there is a :file:`/sys/devices/system/cpu/cpu<N>/cpuidle/`
405 CPU at the initialization time. That directory contains a set of subdirectories
407 objects defined for the given CPU minus one. Each of these directories
446 Total time spent in this idle state by the given CPU (as measured by the
450 Total number of times the hardware has been asked by the given CPU to
455 CPU was rejected.
463 given idle state is disabled for this particular CPU, which means that the
464 governor will never select it for this particular CPU and the ``CPUIdle``
465 driver will never ask the hardware to enter it for that CPU as a result.
466 However, disabling an idle state for one CPU does not prevent it from being
473 this particular CPU, but it still may be disabled for some or all of the other
475 be disabled for this particular CPU and writing 0 to it allows the governor to
476 take it into consideration for the given CPU and the driver to ask for it,
477 unless that state was disabled globally in the driver (in which case it cannot
488 really spent by the given CPU in the given idle state, because it is measured by
492 asking the hardware to enter an idle state and the subsequent wakeup of the CPU
493 and it cannot say what really happened in the meantime at the hardware level.
507 .. _cpu-pm-qos:
514 energy-efficiency features of the kernel to prevent performance from dropping
517 CPU idle time management can be affected by PM QoS in two ways, through the
518 global CPU latency limit and through the resume latency constraints for
523 signed 32-bit integer) to it. In turn, the resume latency constraint for a CPU
525 32-bit integer) to the :file:`power/pm_qos_resume_latency_us` file under
526 :file:`/sys/devices/system/cpu/cpu<N>/` in ``sysfs``, where the CPU number
535 global CPU latency limit and for each individual CPU, aggregates them and
540 PM QoS request to be created and added to a global priority list of CPU latency
546 that effective value will be set as a new CPU latency limit. Thus requesting a
558 with that file descriptor to be removed from the global priority list of CPU
563 In turn, for each CPU there is one resume latency PM QoS request associated with
565 :file:`/sys/devices/system/cpu/cpu<N>/` in ``sysfs`` and writing to it causes
570 practice is to pin a process to the CPU in question and let it use the
574 CPU in question every time the list of requests is updated this way or another
577 CPU idle time governors are expected to regard the minimum of the global
578 (effective) CPU latency limit and the effective resume latency constraint for
579 the given CPU as the upper limit for the exit latency of the idle states that
580 they are allowed to select for that CPU. They should never select any idle
588 `disabled for individual CPUs <idle-states-representation_>`_, there are kernel
589 command line parameters affecting CPU idle time management.
592 CPU idle time management entirely. It does not prevent the idle loop from
593 running on idle CPUs, but it prevents the CPU idle time governors and drivers
595 will ask the hardware to enter idle states on idle CPUs via the CPU architecture
598 processors implementing the architecture (i.e. CPU instruction set) in question,
599 however, so it is rather crude and not very energy-efficient. For this reason,
609 The other kernel command line parameters controlling CPU idle time management
614 options related to CPU idle time management: ``idle=poll``, ``idle=halt``,
628 P-states (see |cpufreq|) that require any number of CPUs in a package to be
629 idle, so it very well may hurt single-thread computations performance as well as
630 energy-efficiency. Thus using it for performance reasons may not be a good idea
634 the CPU to enter idle states. When this option is used, the ``acpi_idle``
641 In addition to the architecture-level kernel command line options affecting CPU
647 `Representation of Idle States <idle-states-representation_>`_), causes the