]> git.baikalelectronics.ru Git - kernel.git/commit
sched/fair: Fix corner case in __accumulate_sum()
authorPeter Zijlstra <peterz@infradead.org>
Fri, 31 Mar 2017 08:51:41 +0000 (10:51 +0200)
committerIngo Molnar <mingo@kernel.org>
Fri, 14 Apr 2017 08:26:34 +0000 (10:26 +0200)
commit04a0e01596054fa60de2fdf5ed250ce74c39b83b
tree3951cb0ee80c3307bd60740099034ec6c4ec5269
parent8c0b6c2e04783e363def3bc72ced5d5114dd3e4a
sched/fair: Fix corner case in __accumulate_sum()

Paul noticed that in the (periods >= LOAD_AVG_MAX_N) case in
__accumulate_sum(), the returned contribution value (LOAD_AVG_MAX) is
incorrect.

This is because at this point, the decay_load() on the old state --
the first step in accumulate_sum() -- will not have resulted in 0, and
will therefore result in a sum larger than the maximum value of our
series. Obviously broken.

Note that:

decay_load(LOAD_AVG_MAX, LOAD_AVG_MAX_N) =

                1   (345 / 32)
47742 * - ^            = ~27
                2

Not to mention that any further contribution from the d3 segment (our
new period) would also push it over the maximum.

Solve this by noting that we can write our c2 term:

    p
c2 = 1024 \Sum y^n
   n=1

In terms of our maximum value:

    inf       inf   p
max = 1024 \Sum y^n = 1024 ( \Sum y^n + \Sum y^n + y^0 )
    n=0       n=p+1  n=1

Further note that:

           inf              inf            inf
        ( \Sum y^n ) y^p = \Sum y^(n+p) = \Sum y^n
           n=0              n=0            n=p

Combined that gives us:

    p
c2 = 1024 \Sum y^n
   n=1

     inf        inf
   = 1024 ( \Sum y^n - \Sum y^n - y^0 )
     n=0        n=p+1

   = max - (max y^(p+1)) - 1024

Further simplify things by dealing with p=0 early on.

Reported-by: Paul Turner <pjt@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Yuyang Du <yuyang.du@intel.com>
Cc: linux-kernel@vger.kernel.org
Fixes: 10369914a209 ("sched/fair: Optimize ___update_sched_avg()")
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/sched/fair.c