sched/fair: don't assign runtime for throttled cfs_rq
PATCH v2 1/1 sched/fair: don't assign runtime for throttled cfs_rq
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.
This will cause other cfs_rq 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; }.
This cast will cause that runtime will be a large number and cfs_b->runtime will be subtracted to be zero at last. 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 to avoid the above incorrect type cast.
--- kernel/sched/fair.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/sched/fair.c +5 -0
@@ -4470,6 +4470,8 @@ static void __account_cfs_rq_runtime(struct cfs_rq *cfs_rq, u64 delta_exec)if (likely (cfs_rq->runtime_remaining >0 ))return ; +if (cfs_rq->throttled) +return ;/* * if we're unable to extend our runtime we resched so that the active * hierarchy can be throttled
@@ -4673,6 +4675,9 @@ static u64 distribute_cfs_runtime(struct cfs_bandwidth *cfs_b,if (!cfs_rq_throttled (cfs_rq)) goto next; +/* By the above check, this should never be true */ +WARN_ON (cfs_rq->runtime_remaining >0 ); + runtime = -cfs_rq->runtime_remaining +1 ;if (runtime > remaining) runtime = remaining;
Signature · 1 line
2.14.4.44.g2045bb6
Peter Zijlstra
maintainerQuoted 6 lines · Liangyan
do_sched_cfs_period_timer()will refillcfs_bruntime and calldistribute_cfs_runtime()to unthrottlecfs_rq, sometimescfs_b->runtimewill allocate all quota to onecfs_rqincorrectly.
This will cause othercfs_rqcan't get runtime and will be throttled. We find that one throttledcfs_rqhas non-negativecfs_rq->runtime_remainingand cause an unexpetced cast from s64 to u64
Quoted 8 lines
in snippet:
distribute_cfs_runtime(){
runtime = -cfs_rq->runtime_remaining + 1; }.
This cast will cause that runtime will be a large number andcfs_b->runtimewill be subtracted to be zero at last. According to Ben Segall, the throttledcfs_rqcan haveaccount_cfs_rq_runtimecalled on it because it is throttled beforeidle_balance, and theidle_balancecallsupdate_rq_clockto add time that is accounted to the task.
That is distinctly unreadable. Please try again with a little bit of whitespace added.
Quoted 6 lines
This commit prevents
cfs_rqto be assgined new runtime if it has been throttled to avoid the above incorrect type cast.Signed-off-by Liangyan <[email protected]>Reviewed-by Ben Segall <[email protected]>Reviewed-by Valentin Schneider <[email protected]>