Lines Matching +full:sleep +full:- +full:hardware +full:- +full:state

1 .. SPDX-License-Identifier: GPL-2.0
23 Since part of the processor hardware is not used in idle states, entering them
27 CPU idle time management is an energy-efficiency feature concerned about using
31 ------------
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
44 enter an idle state, that applies to the processor as a whole.
46 Second, if the processor is multi-core, each core in it is able to follow at
51 time. The entire cores are CPUs in that case and if the hardware is asked to
52 enter an idle state, that applies to the core that asked for it in the first
57 remaining core asks the processor to enter an idle state, that may trigger it
58 to put the whole larger unit into an idle state which also will affect the
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
69 time management perspective and if the processor is asked to enter an idle state
70 by one of them, the hardware thread (or CPU) that asked for it is stopped, but
71 nothing more happens, unless all of the other hardware threads within the same
72 core also have asked the processor to enter an idle state. In that situation,
73 the core may be put into an idle state individually or a larger unit containing
74 it may be put into an idle state as a whole (if the other cores within the
78 ---------
106 idle states, or there is not enough time to spend in an idle state before the
112 .. _idle-loop:
119 idle time management subsystem called ``CPUIdle`` to select an idle state for
120 the CPU to ask the hardware to enter. Second, it invokes another code module
122 processor hardware to enter the idle state selected by the governor.
124 The role of the governor is to find an idle state most suitable for the
125 conditions at hand. For this purpose, idle states that the hardware can be
127 the platform or the processor architecture and organized in a one-dimensional
131 hardware and to work with any platforms that the Linux kernel can run on.
133 Each idle state present in that array is characterized by two parameters to be
134 taken into account by the governor, the *target residency* and the (worst-case)
135 *exit latency*. The target residency is the minimum time the hardware must
136 spend in the given state, including the time needed to enter it (which may be
138 the shallower idle states instead. [The "depth" of an idle state roughly
139 corresponds to the power drawn by the processor in that state.] The exit
141 hardware to enter an idle state to start executing the first instruction after a
142 wakeup from that state. Note that in general the exit latency also must cover
143 the time needed to enter the given state in case the wakeup occurs when the
144 hardware is entering it and it must be entered completely to be exited in an
150 when they will trigger, and it is the maximum time the hardware that the given
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
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
186 .. _idle-cpus-and-tick:
207 for them to ask the hardware to enter idle states with target residencies above
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
227 be harmful. Namely, in that case the governor will select an idle state with
228 the target residency within the time until the expected wakeup, so that state is
230 state then, as that would contradict its own expectation of a wakeup in short
232 waste of time and in this case the timer hardware would need to be reprogrammed,
234 does not occur any time soon, the hardware may spend indefinite amount of time
235 in the shallow idle state selected by the governor, which will be a waste of
238 governor will select a relatively deep idle state, so the tick should be stopped
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
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
270 idle duration and uses the predicted value for idle state selection.
273 that the scheduler tick will be stopped. That time, referred to as the *sleep
275 wakeup. It is used to determine the sleep length range, which in turn is needed
276 to get the sleep length correction factor.
278 The ``menu`` governor maintains two arrays of sleep length correction factors.
282 to different sleep length ranges organized so that each range represented in the
285 The correction factor for the given sleep length range (determined before
286 selecting the idle state for the CPU) is updated after the CPU has been woken
287 up and the closer the sleep length is to the observed idle duration, the closer
289 The sleep length is multiplied by the correction factor for the range that it
305 sleep length multiplied by the correction factor and the minimum of the two is
310 idle state is comparable with the predicted idle duration, the total time spent
311 in that state probably will be very short and the amount of energy to save by
313 overhead related to entering that state and exiting it. Thus selecting a
314 shallower state is likely to be a better option then. The first approximation
319 from the power management quality of service, or `PM QoS <cpu-pm-qos_>`_,
324 them. For this purpose, it compares the target residency of each state with
326 limit. It selects the state with the target residency closest to the predicted
330 In the final step the governor may still need to refine the idle state selection
331 if it has not decided to `stop the scheduler tick <idle-cpus-and-tick_>`_. That
334 loop). Then, the sleep length used in the previous computations may not reflect
336 that time, the governor may need to select a shallower state with a suitable
340 .. _teo-gov:
347 <menu-gov_>`_: it always tries to find the deepest idle state suitable for the
350 .. kernel-doc:: drivers/cpuidle/governors/teo.c
351 :doc: teo-description
353 .. _idle-states-representation:
359 supported by the processor have to be represented as a one-dimensional array of
361 the processor hardware to enter an idle state of certain properties. If there
365 of it <idle-loop_>`_, must reflect the properties of the idle state at the
366 deepest level (i.e. the idle state of the unit containing all of the other
370 a "module" and suppose that asking the hardware to enter a specific idle state
372 enter a specific idle state of its own (say "MX") if the other core is in idle
373 state "X" already. In other words, asking for idle state "X" at the "core"
374 level gives the hardware a license to go as deep as to idle state "MX" at the
376 asking for idle state "X" may just end up in that state by itself instead).
378 idle state "X" must reflect the minimum time to spend in idle state "MX" of
380 time the CPU needs to be idle to save any energy in case the hardware enters
381 that state. Analogously, the exit latency parameter of that object must cover
382 the exit time of idle state "MX" of the module (and usually its entry time too),
390 state at the "core" level does not automatically affect the "module" level, for
392 handling of the hierarchy. Then, the definition of the idle state objects is
393 entirely up to the driver, but still the physical properties of the idle state
394 that the processor hardware finally goes into must always follow the parameters
395 used by the governor for idle state selection (for instance, the actual exit
396 latency of that idle state must not exceed the exit latency parameter of the
397 idle state object selected by the governor).
399 In addition to the target residency and exit latency idle state parameters
401 parameters describing the idle state and a pointer to the function to run in
402 order to ask the hardware to enter that state. Also, for each
405 statistics of the given idle state. That information is exposed by the kernel
411 called :file:`state0`, :file:`state1` and so on, up to the number of idle state
413 corresponds to one idle state object and the larger the number in its name, the
414 deeper the (effective) idle state represented by it. Each of them contains
415 a number of files (attributes) representing the properties of the idle state
419 Total number of times this idle state had been asked for, but the
424 Total number of times this idle state had been asked for, but certainly
425 a deeper idle state would have been a better match for the observed idle
429 Description of the idle state.
432 Whether or not this idle state is disabled.
435 The default status of this state, "enabled" or "disabled".
438 Exit latency of the idle state in microseconds.
441 Name of the idle state.
444 Power drawn by hardware in this idle state in milliwatts (if specified,
448 Target residency of the idle state in microseconds.
451 Total time spent in this idle state by the given CPU (as measured by the
455 Total number of times the hardware has been asked by the given CPU to
456 enter this idle state.
459 Total number of times a request to enter this idle state on the given
468 given idle state is disabled for this particular CPU, which means that the
470 driver will never ask the hardware to enter it for that CPU as a result.
471 However, disabling an idle state for one CPU does not prevent it from being
474 governor is implemented, disabling an idle state prevents that governor from
477 If the :file:`disable` attribute contains 0, the given idle state is enabled for
479 CPUs in the system at the same time. Writing 1 to it causes the idle state to
482 unless that state was disabled globally in the driver (in which case it cannot
485 The :file:`power` attribute is not defined very well, especially for idle state
488 state power numbers for complex hardware, so :file:`power` often contains 0 (not
493 really spent by the given CPU in the given idle state, because it is measured by
494 the kernel and it may not cover the cases in which the hardware refused to enter
495 this idle state and entered a shallower one instead of it (or even it did not
496 enter any idle state at all). The kernel can only measure the time span between
497 asking the hardware to enter an idle state and the subsequent wakeup of the CPU
498 and it cannot say what really happened in the meantime at the hardware level.
499 Moreover, if the idle state object in question represents a combination of idle
501 the kernel can never say how deep the hardware went down the hierarchy in any
503 much time has been spent by the hardware in different idle states supported by
504 it is to use idle state residency counters in the hardware, if available.
506 Generally, an interrupt received when trying to enter an idle state causes the
507 idle state entry request to be rejected, in which case the ``CPUIdle`` driver
509 and :file:`rejected` files report the number of times the given idle state
512 .. _cpu-pm-qos:
519 energy-efficiency features of the kernel to prevent performance from dropping
528 signed 32-bit integer) to it. In turn, the resume latency constraint for a CPU
530 32-bit integer) to the :file:`power/pm_qos_resume_latency_us` file under
593 `disabled for individual CPUs <idle-states-representation_>`_, there are kernel
600 will ask the hardware to enter idle states on idle CPUs via the CPU architecture
604 however, so it is rather crude and not very energy-efficient. For this reason,
627 and causes the hardware to attempt to enter the shallowest available idle state)
632 For example, on Intel hardware it effectively prevents CPUs from using
633 P-states (see |cpufreq|) that require any number of CPUs in a package to be
634 idle, so it very well may hurt single-thread computations performance as well as
635 energy-efficiency. Thus using it for performance reasons may not be a good idea
646 In addition to the architecture-level kernel command line options affecting CPU
650 where ``<n>`` is an idle state index also used in the name of the given
651 state's directory in ``sysfs`` (see
652 `Representation of Idle States <idle-states-representation_>`_), causes the
654 idle states deeper than idle state ``<n>``. In that case, they will never ask