Re: [PATCH sched_ext/for-6.12] sched_ext: Handle cases where pick_task_scx() is called without preceding balance_scx()

Tejun Heo
2024-09-05T16:41:43Z

Hello,

On Thu, Sep 05, 2024 at 05:00:12PM +0200, Peter Zijlstra wrote:
...
> > Oh cute. Which class in particular did you see this do?

The easiest repro was fair.

> > Looking at balance_fair() / sched_balance_newidle() I suppose we could
> > verify we actually have a runnable task once we've re-acquired the
> > rq-lock and have pulled_task > 0.
> >
> >
> > Tightening all that up would probably be better than trying to deal with
> > the fallout like this, hmm?

Oh, yeah, that would be better and we probably want to add a sanity check so
that we know if balance() and pick_task() disagree.

> Something like so. Haven't yet looked at the rt/dl classes.
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 11e890486c1b..7db42735d504 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -12716,6 +12716,12 @@ static int sched_balance_newidle(struct rq *this_rq, struct rq_flags *rf)
> if (this_rq->cfs.h_nr_running && !pulled_task)
> pulled_task = 1;
>
> + /*
> + * We pulled a task, but it got stolen before we re-acquired rq->lock.
> + */
> + if (!this_rq->cfs.h_nr_running && pulled_task)
> + pulled_task = 0;
> +

Lemme test that.

Thanks.

--
tejun