From: Vincent Guittot <vincent.guittot@linaro.org> stable inclusion from stable-v6.6.114 commit 66c29d9fc1dce37b92b41d39b897ec25fcebccf5 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ID7OBU Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=... -------------------------------- [ Upstream commit 17e3e88ed0b6318fde0d1c14df1a804711cab1b5 ] The check for some lost idle pelt time should be always done when pick_next_task_fair() fails to pick a task and not only when we call it from the fair fast-path. The case happens when the last running task on rq is a RT or DL task. When the latter goes to sleep and the /Sum of util_sum of the rq is at the max value, we don't account the lost of idle time whereas we should. Fixes: 67692435c411 ("sched: Rework pick_next_task() slow-path") Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Conflicts: kernel/sched/fair.c [Context conflicts.] Signed-off-by: Chen Jinghuang<chenjinghuang2@huawei.com> --- kernel/sched/fair.c | 70 ++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index e7d05661bafb..0dd23a637ecf 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -10625,52 +10625,52 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rf return p; idle: - if (!rf) - return NULL; - - time = schedstat_start_time(); + if (rf) { + time = schedstat_start_time(); - /* - * We must set idle_stamp _before_ calling try_steal() or - * idle_balance(), such that we measure the duration as idle time. - */ - rq_idle_stamp_update(rq); + /* + * We must set idle_stamp _before_ calling try_steal() or + * idle_balance(), such that we measure the duration as idle time. + */ + rq_idle_stamp_update(rq); - if (steal_fail_ni_enabled()) { - new_tasks = try_steal(rq, rf); - if (new_tasks == 0) - new_tasks = newidle_balance(rq, rf); - } else { - new_tasks = newidle_balance(rq, rf); - if (new_tasks == 0) + if (steal_fail_ni_enabled()) { new_tasks = try_steal(rq, rf); - } - schedstat_end_time(rq, time); + if (new_tasks == 0) + new_tasks = newidle_balance(rq, rf); + } else { + new_tasks = newidle_balance(rq, rf); + if (new_tasks == 0) + new_tasks = try_steal(rq, rf); + } + schedstat_end_time(rq, time); - if (new_tasks) - rq_idle_stamp_clear(rq); + if (new_tasks) + rq_idle_stamp_clear(rq); - /* - * Because try_steal() and idle_balance() release (and re-acquire) - * rq->lock, it is possible for any higher priority task to appear. - * In that case we must re-start the pick_next_entity() loop. - */ - if (new_tasks < 0) - return RETRY_TASK; + /* + * Because try_steal() and idle_balance() release (and re-acquire) + * rq->lock, it is possible for any higher priority task to appear. + * In that case we must re-start the pick_next_entity() loop. + */ + if (new_tasks < 0) + return RETRY_TASK; - if (new_tasks > 0) - goto again; + if (new_tasks > 0) + goto again; #ifdef CONFIG_QOS_SCHED - if (unthrottle_qos_cfs_rqs(cpu_of(rq))) { - rq->idle_stamp = 0; - goto again; - } + if (unthrottle_qos_cfs_rqs(cpu_of(rq))) { + rq->idle_stamp = 0; + goto again; + } - if (!qos_smt_expelled(cpu_of(rq))) - __this_cpu_write(qos_cpu_overload, 0); + if (!qos_smt_expelled(cpu_of(rq))) + __this_cpu_write(qos_cpu_overload, 0); #endif + } + /* * rq is about to be idle, check if we need to update the * lost_idle_time of clock_pelt -- 2.34.1