@@ -269,61 +269,56 @@ Namely, when invoked to select an idle state for a CPU (i.e. an idle state that
269269the CPU will ask the processor hardware to enter), it attempts to predict the
270270idle duration and uses the predicted value for idle state selection.
271271
272- It first obtains the time until the closest timer event with the assumption
273- that the scheduler tick will be stopped. That time, referred to as the *sleep
274- length * in what follows, is the upper bound on the time before the next CPU
275- wakeup. It is used to determine the sleep length range, which in turn is needed
276- to get the sleep length correction factor.
277-
278- The ``menu `` governor maintains two arrays of sleep length correction factors.
279- One of them is used when tasks previously running on the given CPU are waiting
280- for some I/O operations to complete and the other one is used when that is not
281- the case. Each array contains several correction factor values that correspond
282- to different sleep length ranges organized so that each range represented in the
283- array is approximately 10 times wider than the previous one.
284-
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
288- to 1 the correction factor becomes (it must fall between 0 and 1 inclusive).
289- The sleep length is multiplied by the correction factor for the range that it
290- falls into to obtain the first approximation of the predicted idle duration.
291-
292- Next, the governor uses a simple pattern recognition algorithm to refine its
272+ It first uses a simple pattern recognition algorithm to obtain a preliminary
293273idle duration prediction. Namely, it saves the last 8 observed idle duration
294274values and, when predicting the idle duration next time, it computes the average
295275and variance of them. If the variance is small (smaller than 400 square
296276milliseconds) or it is small relative to the average (the average is greater
297277that 6 times the standard deviation), the average is regarded as the "typical
298- 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
299280values is discarded and the computation is repeated for the remaining ones.
281+
300282Again, if the variance of them is small (in the above sense), the average is
301283taken as the "typical interval" value and so on, until either the "typical
302- interval" is determined or too many data points are disregarded, in which case
303- the "typical interval" is assumed to equal "infinity" (the maximum unsigned
304- integer value). The "typical interval" computed this way is compared with the
305- sleep length multiplied by the correction factor and the minimum of the two is
306- taken as the predicted idle duration.
307-
308- Then, the governor computes an extra latency limit to help "interactive"
309- workloads. It uses the observation that if the exit latency of the selected
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
312- entering it will be relatively small, so likely it is better to avoid the
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
315- of the extra latency limit is the predicted idle duration itself which
316- additionally is divided by a value depending on the number of tasks that
317- previously ran on the given CPU and now they are waiting for I/O operations to
318- complete. The result of that division is compared with the latency limit coming
319- from the power management quality of service, or `PM QoS <cpu-pm-qos _>`_,
320- framework and the minimum of the two is taken as the limit for the idle states'
321- exit latency.
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.
297+
298+ The ``menu `` governor maintains an array containing several correction factor
299+ values that correspond to different sleep length ranges organized so that each
300+ range represented in the array is approximately 10 times wider than the previous
301+ one.
302+
303+ The correction factor for the given sleep length range (determined before
304+ selecting the idle state for the CPU) is updated after the CPU has been woken
305+ up and the closer the sleep length is to the observed idle duration, the closer
306+ to 1 the correction factor becomes (it must fall between 0 and 1 inclusive).
307+ The sleep length is multiplied by the correction factor for the range that it
308+ falls into to obtain an approximation of the predicted idle duration that is
309+ compared to the "typical interval" determined previously and the minimum of
310+ the two is taken as the final idle duration prediction.
311+
312+ If the "typical interval" value is small, which means that the CPU is likely
313+ to be woken up soon enough, the sleep length computation is skipped as it may
314+ be costly and the idle duration is simply predicted to equal the "typical
315+ interval" value.
322316
323317Now, the governor is ready to walk the list of idle states and choose one of
324318them. For this purpose, it compares the target residency of each state with
325- the predicted idle duration and the exit latency of it with the computed latency
326- limit. It selects the state with the target residency closest to the predicted
319+ the predicted idle duration and the exit latency of it with the with the latency
320+ limit coming from the power management quality of service, or `PM QoS <cpu-pm-qos _>`_,
321+ framework. It selects the state with the target residency closest to the predicted
327322idle duration, but still below it, and exit latency that does not exceed the
328323limit.
329324
0 commit comments