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
287 the time until the closest timer event with the assumption that the scheduler
289 is the upper bound on the time before the next CPU wakeup. It is used to determine
299 selecting the idle state for the CPU) is updated after the CPU has been woken
307 If the "typical interval" value is small, which means that the CPU is likely
315 limit coming from the power management quality of service, or `PM QoS <cpu-pm-qos_>`_,
321 if it has not decided to `stop the scheduler tick <idle-cpus-and-tick_>`_. That
325 the real time until the closest timer event and if it really is greater than
330 .. _teo-gov:
332 The Timer Events Oriented (TEO) Governor
335 The timer events oriented (TEO) governor is an alternative ``CPUIdle`` governor
337 <menu-gov_>`_: it always tries to find the deepest idle state suitable for the
340 .. kernel-doc:: drivers/cpuidle/governors/teo.c
341 :doc: teo-description
343 .. _idle-states-representation:
348 For the CPU idle time management purposes all of the physical idle states
349 supported by the processor have to be represented as a one-dimensional array of
350 |struct cpuidle_state| objects each allowing an individual (logical) CPU to ask
355 of it <idle-loop_>`_, must reflect the properties of the idle state at the
370 time the CPU needs to be idle to save any energy in case the hardware enters
373 because that is the maximum delay between a wakeup signal and the time the CPU
398 For each CPU in the system, there is a :file:`/sys/devices/system/cpu/cpu<N>/cpuidle/`
400 CPU at the initialization time. That directory contains a set of subdirectories
402 objects defined for the given CPU minus one. Each of these directories
441 Total time spent in this idle state by the given CPU (as measured by the
445 Total number of times the hardware has been asked by the given CPU to
450 CPU was rejected.
458 given idle state is disabled for this particular CPU, which means that the
459 governor will never select it for this particular CPU and the ``CPUIdle``
460 driver will never ask the hardware to enter it for that CPU as a result.
461 However, disabling an idle state for one CPU does not prevent it from being
468 this particular CPU, but it still may be disabled for some or all of the other
470 be disabled for this particular CPU and writing 0 to it allows the governor to
471 take it into consideration for the given CPU and the driver to ask for it,
472 unless that state was disabled globally in the driver (in which case it cannot
483 really spent by the given CPU in the given idle state, because it is measured by
487 asking the hardware to enter an idle state and the subsequent wakeup of the CPU
488 and it cannot say what really happened in the meantime at the hardware level.
502 .. _cpu-pm-qos:
509 energy-efficiency features of the kernel to prevent performance from dropping
512 CPU idle time management can be affected by PM QoS in two ways, through the
513 global CPU latency limit and through the resume latency constraints for
518 signed 32-bit integer) to it. In turn, the resume latency constraint for a CPU
520 32-bit integer) to the :file:`power/pm_qos_resume_latency_us` file under
521 :file:`/sys/devices/system/cpu/cpu<N>/` in ``sysfs``, where the CPU number
530 global CPU latency limit and for each individual CPU, aggregates them and
535 PM QoS request to be created and added to a global priority list of CPU latency
541 that effective value will be set as a new CPU latency limit. Thus requesting a
553 with that file descriptor to be removed from the global priority list of CPU
558 In turn, for each CPU there is one resume latency PM QoS request associated with
560 :file:`/sys/devices/system/cpu/cpu<N>/` in ``sysfs`` and writing to it causes
565 practice is to pin a process to the CPU in question and let it use the
569 CPU in question every time the list of requests is updated this way or another
572 CPU idle time governors are expected to regard the minimum of the global
573 (effective) CPU latency limit and the effective resume latency constraint for
574 the given CPU as the upper limit for the exit latency of the idle states that
575 they are allowed to select for that CPU. They should never select any idle
583 `disabled for individual CPUs <idle-states-representation_>`_, there are kernel
584 command line parameters affecting CPU idle time management.
587 CPU idle time management entirely. It does not prevent the idle loop from
588 running on idle CPUs, but it prevents the CPU idle time governors and drivers
590 will ask the hardware to enter idle states on idle CPUs via the CPU architecture
593 processors implementing the architecture (i.e. CPU instruction set) in question,
594 however, so it is rather crude and not very energy-efficient. For this reason,
604 The other kernel command line parameters controlling CPU idle time management
609 options related to CPU idle time management: ``idle=poll``, ``idle=halt``,
623 P-states (see |cpufreq|) that require any number of CPUs in a package to be
624 idle, so it very well may hurt single-thread computations performance as well as
625 energy-efficiency. Thus using it for performance reasons may not be a good idea
629 the CPU to enter idle states. When this option is used, the ``acpi_idle``
636 In addition to the architecture-level kernel command line options affecting CPU
642 `Representation of Idle States <idle-states-representation_>`_), causes the