• Liangyan's avatar
    sched/fair: Don't assign runtime for throttled cfs_rq · 5e2d2cc2
    Liangyan authored
    
    
    do_sched_cfs_period_timer() will refill cfs_b runtime and call
    distribute_cfs_runtime to unthrottle cfs_rq, sometimes cfs_b->runtime
    will allocate all quota to one cfs_rq incorrectly, then other cfs_rqs
    attached to this cfs_b can't get runtime and will be throttled.
    
    We find that one throttled cfs_rq has non-negative
    cfs_rq->runtime_remaining and cause an unexpetced cast from s64 to u64
    in snippet:
    
      distribute_cfs_runtime() {
        runtime = -cfs_rq->runtime_remaining + 1;
      }
    
    The runtime here will change to a large number and consume all
    cfs_b->runtime in this cfs_b period.
    
    According to Ben Segall, the throttled cfs_rq can have
    account_cfs_rq_runtime called on it because it is throttled before
    idle_balance, and the idle_balance calls update_rq_clock to add time
    that is accounted to the task.
    
    This commit prevents cfs_rq to be assgined new runtime if it has been
    throttled until that distribute_cfs_runtime is called.
    
    Signed-off-by: default avatarLiangyan <liangyan.peng@linux.alibaba.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: default avatarValentin Schneider <valentin.schneider@arm.com>
    Reviewed-by: default avatarBen Segall <bsegall@google.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: shanpeic@linux.alibaba.com
    Cc: stable@vger.kernel.org
    Cc: xlpang@linux.alibaba.com
    Fixes: d3d9dc33 ("sched: Throttle entities exceeding their allowed bandwidth")
    Link: https://lkml.kernel.org/r/20190826121633.6538-1-liangyan.peng@linux.alibaba.com
    
    
    Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
    5e2d2cc2