Re: [PATCH] sched/fair: Reschedule the cfs_rq when current is ineligible

From: Chen Yu
Date: Sat May 25 2024 - 07:58:08 EST


On 2024-05-25 at 08:41:28 +0200, Mike Galbraith wrote:
> On Fri, 2024-05-24 at 21:40 +0800, Chunxin Zang wrote:
> > I found that some tasks have been running for a long enough time and
> > have become illegal, but they are still not releasing the CPU. This
> > will increase the scheduling delay of other processes. Therefore, I
> > tried checking the current process in wakeup_preempt and entity_tick,
> > and if it is illegal, reschedule that cfs queue.
>
> My box gave making the XXX below reality a two thumbs up when fiddling
> with the original unfettered and a bit harsh RUN_TO_PARITY.
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 8a5b1ae0aa55..922834f172b0 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -8413,12 +8413,13 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
> update_curr(cfs_rq);
>
> /*
> - * XXX pick_eevdf(cfs_rq) != se ?
> + * Run @curr until it is no longer our best option. Basing the preempt
> + * decision on @curr reselection puts any previous decisions back on the
> + * table in context "now", including granularity preservation decisions
> + * by RUN_TO_PARITY.
> */
> - if (pick_eevdf(cfs_rq) == pse)
> - goto preempt;
> -
> - return;
> + if (pick_eevdf(cfs_rq) == se)
> + return;
>

I suppose this change benefits the overloaded scenario:
neither current nor the wakee is the best one.

before: current continues to run.
after: best se in the tree preempts current.

hackbench -g 12 -l 1000000000 & (480 tasks, 2x of the CPUs)

cyclictest --mlockall -D 1m -q
before:
T: 0 (15983) P: 0 I:1000 C: 43054 Min: 11 Act: 144 Avg: 627 Max: 11446

after:
T: 0 (16473) P: 0 I:1000 C: 49822 Min: 7 Act: 160 Avg: 388 Max: 10190

Min, Avg, Max latency all decreased.

thanks,
Chenyu