sched/fair: Make balance_fair() test sched_fair_runnable() instead of rq->nr_running
authorTejun Heo <tj@kernel.org>
Mon, 5 Aug 2024 22:39:10 +0000 (12:39 -1000)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 7 Aug 2024 10:44:16 +0000 (12:44 +0200)
commit924e2904da9b5edec61611918b98ab1f7fccc461
treedd3efc7fa0f9ee8f44b1289cad1988f3f1f599d2
parentcea5a3472ac43f18590e1bd6b842f808347a810c
sched/fair: Make balance_fair() test sched_fair_runnable() instead of rq->nr_running

balance_fair() skips newidle balancing if rq->nr_running - there are already
tasks on the rq, so no need to try to pull tasks. This tests the total
number of queued tasks on the CPU instead of only the fair class, but is
still correct as the rq can currently only have fair class tasks while
balance_fair() is running.

However, with the addition of sched_ext below the fair class, this will not
hold anymore and make put_prev_task_balance() skip sched_ext's balance()
incorrectly as, when a CPU has only lower priority class tasks,
rq->nr_running would still be positive and balance_fair() would return 1
even when fair doesn't have any tasks to run.

Update balance_fair() to use sched_fair_runnable() which tests
rq->cfs.nr_running which is updated by bandwidth throttling. Note that
pick_next_task_fair() already uses sched_fair_runnable() in its optimized
path for the same purpose.

Reported-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Chengming Zhou <chengming.zhou@linux.dev>
Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
Link: https://lore.kernel.org/r/ZrFUjlCf7x3TNXB8@slm.duckdns.org
kernel/sched/fair.c