Skip to content

Commit 5c35041

Browse files
committed
cpuidle: menu: Update documentation after get_typical_interval() changes
The documentation of the menu cpuidle governor needs to be updated to match the code behavior after some changes made recently. No functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Christian Loehle <[email protected]> Link: https://patch.msgid.link/[email protected] [ rjw: More specific subject, two typos fixed in the changelog ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 85975da commit 5c35041

File tree

2 files changed

+27
-31
lines changed

2 files changed

+27
-31
lines changed

Documentation/admin-guide/pm/cpuidle.rst

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -275,20 +275,25 @@ values and, when predicting the idle duration next time, it computes the average
275275
and variance of them. If the variance is small (smaller than 400 square
276276
milliseconds) or it is small relative to the average (the average is greater
277277
that 6 times the standard deviation), the average is regarded as the "typical
278-
interval" value. Otherwise, the longest of the saved observed idle duration
278+
interval" value. Otherwise, either the longest or the shortest (depending on
279+
which one is farther from the average) of the saved observed idle duration
279280
values is discarded and the computation is repeated for the remaining ones.
281+
280282
Again, if the variance of them is small (in the above sense), the average is
281283
taken as the "typical interval" value and so on, until either the "typical
282-
interval" is determined or too many data points are disregarded, in which case
283-
the "typical interval" is assumed to equal "infinity" (the maximum unsigned
284-
integer value).
285-
286-
If the "typical interval" computed this way is long enough, the governor obtains
287-
the time until the closest timer event with the assumption that the scheduler
288-
tick will be stopped. That time, referred to as the *sleep length* in what follows,
289-
is the upper bound on the time before the next CPU wakeup. It is used to determine
290-
the sleep length range, which in turn is needed to get the sleep length correction
291-
factor.
284+
interval" is determined or too many data points are disregarded. In the latter
285+
case, if the size of the set of data points still under consideration is
286+
sufficiently large, the next idle duration is not likely to be above the largest
287+
idle duration value still in that set, so that value is taken as the predicted
288+
next idle duration. Finally, if the set of data points still under
289+
consideration is too small, no prediction is made.
290+
291+
If the preliminary prediction of the next idle duration computed this way is
292+
long enough, the governor obtains the time until the closest timer event with
293+
the assumption that the scheduler tick will be stopped. That time, referred to
294+
as the *sleep length* in what follows, is the upper bound on the time before the
295+
next CPU wakeup. It is used to determine the sleep length range, which in turn
296+
is needed to get the sleep length correction factor.
292297

293298
The ``menu`` governor maintains an array containing several correction factor
294299
values that correspond to different sleep length ranges organized so that each
@@ -302,7 +307,7 @@ to 1 the correction factor becomes (it must fall between 0 and 1 inclusive).
302307
The sleep length is multiplied by the correction factor for the range that it
303308
falls into to obtain an approximation of the predicted idle duration that is
304309
compared to the "typical interval" determined previously and the minimum of
305-
the two is taken as the idle duration prediction.
310+
the two is taken as the final idle duration prediction.
306311

307312
If the "typical interval" value is small, which means that the CPU is likely
308313
to be woken up soon enough, the sleep length computation is skipped as it may

drivers/cpuidle/governors/menu.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* the C state is required to actually break even on this cost. CPUIDLE
4242
* provides us this duration in the "target_residency" field. So all that we
4343
* need is a good prediction of how long we'll be idle. Like the traditional
44-
* menu governor, we start with the actual known "next timer event" time.
44+
* menu governor, we take the actual known "next timer event" time.
4545
*
4646
* Since there are other source of wakeups (interrupts for example) than
4747
* the next timer event, this estimation is rather optimistic. To get a
@@ -50,30 +50,21 @@
5050
* duration always was 50% of the next timer tick, the correction factor will
5151
* be 0.5.
5252
*
53-
* menu uses a running average for this correction factor, however it uses a
54-
* set of factors, not just a single factor. This stems from the realization
55-
* that the ratio is dependent on the order of magnitude of the expected
56-
* duration; if we expect 500 milliseconds of idle time the likelihood of
57-
* getting an interrupt very early is much higher than if we expect 50 micro
58-
* seconds of idle time. A second independent factor that has big impact on
59-
* the actual factor is if there is (disk) IO outstanding or not.
60-
* (as a special twist, we consider every sleep longer than 50 milliseconds
61-
* as perfect; there are no power gains for sleeping longer than this)
62-
*
63-
* For these two reasons we keep an array of 12 independent factors, that gets
64-
* indexed based on the magnitude of the expected duration as well as the
65-
* "is IO outstanding" property.
53+
* menu uses a running average for this correction factor, but it uses a set of
54+
* factors, not just a single factor. This stems from the realization that the
55+
* ratio is dependent on the order of magnitude of the expected duration; if we
56+
* expect 500 milliseconds of idle time the likelihood of getting an interrupt
57+
* very early is much higher than if we expect 50 micro seconds of idle time.
58+
* For this reason, menu keeps an array of 6 independent factors, that gets
59+
* indexed based on the magnitude of the expected duration.
6660
*
6761
* Repeatable-interval-detector
6862
* ----------------------------
6963
* There are some cases where "next timer" is a completely unusable predictor:
7064
* Those cases where the interval is fixed, for example due to hardware
71-
* interrupt mitigation, but also due to fixed transfer rate devices such as
72-
* mice.
65+
* interrupt mitigation, but also due to fixed transfer rate devices like mice.
7366
* For this, we use a different predictor: We track the duration of the last 8
74-
* intervals and if the stand deviation of these 8 intervals is below a
75-
* threshold value, we use the average of these intervals as prediction.
76-
*
67+
* intervals and use them to estimate the duration of the next one.
7768
*/
7869

7970
struct menu_device {

0 commit comments

Comments
 (0)