From: Vincent Guittot <vincent.guittot@linaro.org> stable inclusion from stable-v6.6.130 commit 8c1befea57db435d7dc032487a942cb22c40c5d0 category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9037 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=... -------------------------------- [ Upstream commit 98c88dc8a1ace642d9021b103b28cba7b51e3abc ] Samuel and Alex reported regressions of the util_avg of RT rq with commit 17e3e88ed0b6 ("sched/fair: Fix pelt lost idle time detection"). It happens that fair is updating and syncing the pelt clock with task one when pick_next_task_fair() fails to pick a task but before the prev scheduling class got a chance to update its pelt signals. Move update_idle_rq_clock_pelt() in set_next_task_idle() which is called after prev class has been called. Fixes: 17e3e88ed0b6 ("sched/fair: Fix pelt lost idle time detection") Reported-by: Samuel Wu <wusamuel@google.com> Closes: https://lore.kernel.org/all/CAG2KctpO6VKS6GN4QWDji0t92_gNBJ7HjjXrE+6H+RwRXt=... Reported-by: Alex Hoh <Alex.Hoh@mediatek.com> Closes: https://lore.kernel.org/all/8cf19bf0e0054dcfed70e9935029201694f1bb5a.camel@m... Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Samuel Wu <wusamuel@google.com> Tested-by: Alex Hoh <Alex.Hoh@mediatek.com> Link: https://patch.msgid.link/20260121163317.505635-1-vincent.guittot@linaro.org (cherry picked from commit 98c88dc8a1ace642d9021b103b28cba7b51e3abc) [ wusamuel: Did not include line 'exec_start = rq_clock_task()', which is not present in 6.6.y but found in mainline ] Signed-off-by: Samuel Wu <wusamuel@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Conflicts: kernel/sched/fair.c kernel/sched/idle.c [Context difference due to 766362823084("sched_ext: idle: Refresh idle masks during idle-to-idle transitions") and CONFIG_QOS_SCHED.] Signed-off-by: Chen Jinghuang<chenjinghuang2@huawei.com> --- kernel/sched/fair.c | 6 ------ kernel/sched/idle.c | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 0dd23a637ecf..26530bafcb35 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10671,12 +10671,6 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf #endif } - /* - * rq is about to be idle, check if we need to update the - * lost_idle_time of clock_pelt - */ - update_idle_rq_clock_pelt(rq); - #ifdef CONFIG_QOS_SCHED_SMT_EXPELLER qos_smt_expel(this_cpu, NULL); #endif diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index f8a87a84248f..2f4e866dccd7 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -477,6 +477,12 @@ static void set_next_task_idle(struct rq *rq, struct task_struct *next, bool fir update_idle_core(rq); scx_update_idle(rq, true, true); schedstat_inc(rq->sched_goidle); + + /* + * rq is about to be idle, check if we need to update the + * lost_idle_time of clock_pelt + */ + update_idle_rq_clock_pelt(rq); } struct task_struct *pick_task_idle(struct rq *rq) -- 2.34.1