Re: [PATCH 5/8] sched/eevdf: Reset lag when waking up on idle cpu

From: Kayra Cizmeci

Date: Tue Sep 22 2026 - 10:41:47 EST


Hello Peter,

> Right. As I mentioned during OSPM, one of the crazy ideas I had was to
> do something like the below. All of the lag stuff only makes sense while
> there is contention.

> Now, I've not actually tried this -- and at the very least the migation
> case is broken. But it should very much capture the rq->curr == rq->idle
> case and then some.


> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index dac15ec36d1e..70fe8fadafac 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -592,6 +592,7 @@ struct sched_entity {
> u64 vruntime;
> /* Approximated virtual lag: */
> s64 vlag;
> + u32 vlag_seq;
> /* 'Protected' deadline, to give out minimum quantums: */
> u64 vprot;
> u64 slice;
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 2ad46fb2eafe..3e3dde5f2117 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -898,6 +898,7 @@ bool update_entity_lag(struct cfs_rq *cfs_rq, struct sched_entity *se)
> vlag = min(vlag, 0);
> }
> se->vlag = vlag;
> + se->vlag_seq = cfs_rq->idle_seq;
>
> return avruntime - vlag != se->vruntime;
> }
> @@ -6397,6 +6398,9 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
> if (flags & ENQUEUE_QUEUED)
> nr_queued -= 1;
>
> + if (se->vlag_seq != cfs_rq->idle_seq)
> + se->vlag = 0;
> +
> /*
> * Due to how V is constructed as the weighted average of entities,
> * adding tasks with positive lag, or removing tasks with negative lag
> @@ -8374,6 +8378,9 @@ static bool __dequeue_task(struct rq *rq, struct task_struct *p, int flags)
>
> dequeue_hierarchy(p, flags);
>
> + if (!cfs_rq->h_nr_queued)
> + cfs_rq->idle_seq++;
> +
> if (sched_feat(PLACE_REL_DEADLINE) && !task_sleep) {
> se->deadline -= se->vruntime;
> se->rel_deadline = 1;
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 6c3ad70e58b8..0f0edb77e235 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -689,6 +689,7 @@ struct cfs_rq {
> u64 sum_weight;
> u64 zero_vruntime;
> unsigned int sum_shift;
> + u32 idle_seq;
>
> #ifdef CONFIG_SCHED_CORE
> unsigned int forceidle_seq;

I think we could both of these approaches.
On migration, we'll check (rq->curr == rq->idle),
On normal yours.

Or, if possible on migration before se's rq changes,
we could do this idle_seq on there too.
Tho, not really tested or proven. And IDK
if there's a place that is before se's rq changes.

Thanks,
Kayra :)