[PATCH] sched/rt: Update wait_time when doing migration.
From: LiuJie Xie
Date: Mon Apr 14 2025 - 07:49:45 EST
From: LiuJie Xie <xieliujie@xxxxxxxxxx>
With __update_stats_wait_start() and __update_stats_wait_end(), we track
task's latency and the info can be seen in proc node '/proc/pid/sched'.
But it seems that we loss updating wait_time when rt task doing migration.
In update_stats_dequeue_fair() by calling update_stats_wait_end_fair(), the
fair sched class make this update work.
When a rt doing migration, we can see:
step1: wait_start=1503718063442 C:(__update_stats_wait_start<-ttwu_do_activate<-try_to_wake_up)
step2: wait_start=124844 C:(__update_stats_wait_start<-activate_task<-push_rt_task<-push_rt_tasks<-finish_task_switch)
step3: wait_start=124844 delta=1503718120473 C:(__update_stats_wait_end<-__schedule<-schedule)
In step2, the wait_start become very small after doing the below logic
and we will get a very big delta in step3.
void __update_stats_wait_start()
{
prev_wait_start = schedstat_val(stats->wait_start);
if (p && likely(wait_start > prev_wait_start))
wait_start -= prev_wait_start;
__schedstat_set(stats->wait_start, wait_start);
}
So, update_stats_dequeue_rt() should also update wait_time just like
fair to get the correct delta.
Signed-off-by: LiuJie Xie <xieliujie@xxxxxxxxxx>
---
kernel/sched/rt.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index fa03ec3ed56a..a93d23b839ad 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1346,6 +1346,13 @@ update_stats_dequeue_rt(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se,
if (rt_entity_is_task(rt_se))
p = rt_task_of(rt_se);
+ /*
+ * Mark the end of the wait period if dequeueing a
+ * waiting task:
+ */
+ if (p && !task_on_cpu(task_rq(p), p))
+ update_stats_wait_end_rt(rt_rq, rt_se);
+
if ((flags & DEQUEUE_SLEEP) && p) {
unsigned int state;
--
2.43.0