Re: [PATCH v1] sched/rt: Fix rt task's sched latency statistics in sched_stat_wait trace_point

From: Yafang Shao
Date: Tue Dec 19 2023 - 07:35:54 EST


On Mon, Dec 18, 2023 at 11:05 PM Junwen Wu <wudaemon@xxxxxxx> wrote:
>
> When enable sched_stat_wait trace_point, some rt tasks sched latency
> so long, like this:
> sched_stat_wait: comm=rcu_preempt pid=14 delay=4936139545261 [ns]
> Rt task has low latency, it must have a bug. I found the reason is
> When rt task balance off source cpu, dequeue operation not update
> the sched_statistics, so follow update_stats_wait_end_fair
> update method.

Thanks for your report!

>
> Signed-off-by: Junwen Wu <wudaemon@xxxxxxx>
> ---
> kernel/sched/rt.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
> index 6aaf0a3d6081..c75215947c20 100644
> --- a/kernel/sched/rt.c
> +++ b/kernel/sched/rt.c
> @@ -1360,12 +1360,15 @@ update_stats_dequeue_rt(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se,
> int flags)
> {
> struct task_struct *p = NULL;
> + struct rq *rq = rq_of_rt_se(rt_se);
>
> if (!schedstat_enabled())
> return;
>
> if (rt_entity_is_task(rt_se))
> p = rt_task_of(rt_se);
> + if (p != rq->curr)

This seems wrong, the rt_se might not be a task.

I think we'd better use if (!on_rt_rq(rt_se))

> + update_stats_wait_end_rt(rt_rq, rt_se);
>
> if ((flags & DEQUEUE_SLEEP) && p) {
> unsigned int state;
> --
> 2.34.1
>


--
Regards
Yafang