Re: [PATCH 3/4] sched/fair: Limit run to parity to the min slice of enqueued entities

From: dhaval
Date: Fri Jun 13 2025 - 18:54:13 EST







On Friday, June 13th, 2025 at 7:16 AM, Vincent Guittot <vincent.guittot@xxxxxxxxxx> wrote:

>
>
> Run to parity ensures that current will get a chance to run its full
> slice in one go but this can create large latency for entity with shorter
> slice that has alreasy exausted its slice and wait to run the next one.

"already exhausted"

>
> Clamp the run to parity duration to the shortest slice of all enqueued
> entities.
>
> Signed-off-by: Vincent Guittot vincent.guittot@xxxxxxxxxx
>
> ---
> kernel/sched/fair.c | 19 ++++++++++++++-----
> 1 file changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 479b38dc307a..d8345219dfd4 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -917,23 +917,32 @@ struct sched_entity *__pick_first_entity(struct cfs_rq cfs_rq)
> }
>
> /
> - * HACK, stash a copy of deadline at the point of pick in vlag,
> - * which isn't used until dequeue.
> + * HACK, Set the vruntime, up to which the entity can run before picking
> + * another one, in vlag, which isn't used until dequeue.
> + * In case of run to parity, we use the shortest slice of the enqueued
> + * entities.
> */

I am going to admit - I don't have a good intuitive sense on how this will affect the functionality. Maybe you can help me think of a test case to explicitly write out this assumption in behavior?

Dhaval

> static inline void set_protect_slice(struct sched_entity *se)
> {
> - se->vlag = se->deadline;
>
> + u64 min_slice;
> +
> + min_slice = cfs_rq_min_slice(cfs_rq_of(se));
> +
> + if (min_slice != se->slice)
>
> + se->vlag = min(se->deadline, se->vruntime + calc_delta_fair(min_slice, se));
>
> + else
> + se->vlag = se->deadline;
>
> }
>
> static inline bool protect_slice(struct sched_entity *se)
> {
> - return se->vlag == se->deadline;
>
> + return ((s64)(se->vlag - se->vruntime) > 0);
>
> }
>
> static inline void cancel_protect_slice(struct sched_entity *se)
> {
> if (protect_slice(se))
> - se->vlag = se->deadline + 1;
>
> + se->vlag = se->vruntime;
>
> }
>
> /*
> --
> 2.43.0