• Vincent Guittot's avatar
    sched/cfs: Make util/load_avg more stable · 625ed2bf
    Vincent Guittot authored
    In the current implementation of load/util_avg, we assume that the
    ongoing time segment has fully elapsed, and util/load_sum is divided
    by LOAD_AVG_MAX, even if part of the time segment still remains to
    run. As a consequence, this remaining part is considered as idle time
    and generates unexpected variations of util_avg of a busy CPU in the
    range [1002..1024[ whereas util_avg should stay at 1023.
    
    In order to keep the metric stable, we should not consider the ongoing
    time segment when computing load/util_avg but only the segments that
    have already fully elapsed. But to not consider the current time
    segment adds unwanted latency in the load/util_avg responsivness
    especially when the time is scaled instead of the contribution.
    
    Instead of waiting for the current time segment to have fully elapsed
    before accounting it in load/util_avg, we can already account the
    elapsed part but change the range used to compute load/util_avg
    accordingly.
    
    At the very beginning of a new time segment, the past segments have
    been decayed and the max value is LOAD_AVG_MAX*y. At the very end of
    the current time segment, the max value becomes:
    
      LOAD_AVG_MAX*y + 1024(us)  (== LOAD_AVG_MAX)
    
    In fact, the max value is:
    
      LOAD_AVG_MAX*y + sa->period_contrib
    
    at any time in the time segment.
    
    Taking advantage of the fact that:
    
      LOAD_AVG_MAX*y == LOAD_AVG_MAX-1024
    
    the range becomes [0..LOAD_AVG_MAX-1024+sa->period_contrib].
    
    As the elapsed part is already accounted in load/util_sum, we update
    the max value according to the current position in the time segment
    instead of removing its contribution.
    Suggested-by: default avatarPeter Zijlstra <peterz@infradead.org>
    Signed-off-by: default avatarVincent Guittot <vincent.guittot@linaro.org>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Mike Galbraith <efault@gmx.de>
    Cc: Morten.Rasmussen@arm.com
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: bsegall@google.com
    Cc: dietmar.eggemann@arm.com
    Cc: pjt@google.com
    Cc: yuyang.du@intel.com
    Link: http://lkml.kernel.org/r/1493188076-2767-1-git-send-email-vincent.guittot@linaro.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
    625ed2bf
fair.c 248 KB