From: Peter Zijlstra <peterz@infradead.org> mainline inclusion from mainline-v6.12-rc1 commit 82e9d0456e06cebe2c89f3c73cdbc9e3805e9437 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICDF44 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i... -------------------------------- During OSPM24 Youssef noted that migrations are re-setting the virtual deadline. Notably everything that does a dequeue-enqueue, like setting nice, changing preferred numa-node, and a myriad of other random crap, will cause this to happen. This shouldn't be. Preserve the relative virtual deadline across such dequeue/enqueue cycles. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Valentin Schneider <vschneid@redhat.com> Tested-by: Valentin Schneider <vschneid@redhat.com> Link: https://lkml.kernel.org/r/20240727105030.625119246@infradead.org Conflicts: include/linux/sched.h kernel/sched/fair.c kernel/sched/features.h [features.h: context different due to comment, so ignore the comment. sched.h: There is no sched_delayed feature, so ingore this attr. fair.c: There is no sched_delayed feature, so ingore the logic and only pick the necessary code 'rel_deadline'.] Signed-off-by: Zicheng Qu <quzicheng@huawei.com> --- include/linux/sched.h | 4 +++- kernel/sched/fair.c | 13 +++++++++++++ kernel/sched/features.h | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index bb23790fd2d3..17647b1c35d3 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -584,7 +584,9 @@ struct sched_entity { u64 min_vruntime; struct list_head group_node; - unsigned int on_rq; + unsigned char on_rq; + unsigned char rel_deadline; + /* hole */ u64 exec_start; u64 sum_exec_runtime; diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 49b883b7b94b..daa08c92d345 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5449,6 +5449,12 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) se->vruntime = vruntime - lag; + if (sched_feat(PLACE_REL_DEADLINE) && se->rel_deadline) { + se->deadline += se->vruntime; + se->rel_deadline = 0; + return; + } + /* * When joining the competition; the exisiting tasks will be, * on average, halfway through their slice, as such start tasks @@ -5564,6 +5570,7 @@ static __always_inline void return_cfs_rq_runtime(struct cfs_rq *cfs_rq); static void dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) { + bool sleep = flags & DEQUEUE_SLEEP; int action = UPDATE_TG; if (entity_is_task(se) && task_on_rq_migrating(task_of(se))) @@ -5591,6 +5598,12 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) clear_buddies(cfs_rq, se); update_entity_lag(cfs_rq, se); + + if (sched_feat(PLACE_REL_DEADLINE) && !sleep) { + se->deadline -= se->vruntime; + se->rel_deadline = 1; + } + if (se != cfs_rq->curr) __dequeue_entity(cfs_rq, se); se->on_rq = 0; diff --git a/kernel/sched/features.h b/kernel/sched/features.h index b95797360dd6..1f665fbf0137 100644 --- a/kernel/sched/features.h +++ b/kernel/sched/features.h @@ -6,6 +6,10 @@ */ SCHED_FEAT(PLACE_LAG, true) SCHED_FEAT(PLACE_DEADLINE_INITIAL, true) +/* + * Preserve relative virtual deadline on 'migration'. + */ +SCHED_FEAT(PLACE_REL_DEADLINE, true) SCHED_FEAT(RUN_TO_PARITY, true) SCHED_FEAT(RUN_TO_PARITY_WAKEUP, true) -- 2.34.1