[PATCH] sched/rt: fix the error in rt task wait time calculation

From: Vincent Zhou
Date: Mon Dec 09 2024 - 04:05:07 EST


From: vincentzhou <vincentzhou@xxxxxxxxxxxxx>

update_stats_wait_end_rt needs to be called in dequeue_task_rt
to update the wait_start variable, otherwise calling
update_stats_wait_start_rt again will casue a wrong small value
of wait_start because the following codes logic:
if (p && likely(wait_start > prev_wait_start))
wait_start -= prev_wait_start;
After that, update_stats_wait_end_rt is called again, it will
calculate wait time by using current rq_clock subtracting
wait_start which will cause a very big wait time.

Signed-off-by: vincentzhou <vincentzhou@xxxxxxxxxxxxx>
---
kernel/sched/rt.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index bd66a46b06ac..544dd55447df 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1488,6 +1488,10 @@ static bool dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags)
struct sched_rt_entity *rt_se = &p->rt;

update_curr_rt(rq);
+
+ if (!task_current(rq, p))
+ update_stats_wait_end_rt(rt_rq_of_se(rt_se), rt_se);
+
dequeue_rt_entity(rt_se, flags);

dequeue_pushable_task(rq, p);
--
2.25.1