Skip to contentSkip to conversation

sched/rt: Fix rt task's sched latency statistics in sched_stat_wait trace_point

PATCH Superseded Junwen Wu 2 participants 8 messages Dec 18, 2023 – Dec 21, 2023 Scheduler

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Junwen Wu

author
#0 lore raw

PATCH 1/1 sched/rt: Fix rt task's sched latency statistics in sched_stat_wait trace_point

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.

---
 kernel/sched/rt.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/sched/rt.c +3 -0
index 6aaf0a3d6081..c75215947c20 100644
@@ -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)
+		update_stats_wait_end_rt(rt_rq, rt_se);
 
 	if ((flags & DEQUEUE_SLEEP) && p) {
 		unsigned int state;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 8 lines · Junwen Wu

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!

Quoted 12 lines
---
 kernel/sched/rt.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/sched/rt.c +0 -0
index 6aaf0a3d6081..c75215947c20 100644
@@ -1360,12 +1360,15 @@ update_stats_dequeue_rt(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se,
                        int flags)

kernel/sched/rt.c update_stats_dequeue_rt(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se, · line 1370

Quoted 10 lines
kernel/sched/rt.c +2 -0
 {
        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))

Quoted 7 lines
kernel/sched/rt.c +1 -1
+               update_stats_wait_end_rt(rt_rq, rt_se);
 
        if ((flags & DEQUEUE_SLEEP) && p) {
                unsigned int state;
--

2.34.1

--
Regards
Yafang

author
#2 lore raw

ok, I will take your advise, and test my platform.

--
Regards
Junwen

author
#4 lore raw

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

Quoted 4 lines
Quoted 4 lines

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

+ update_stats_wait_end_rt(rt_rq, rt_se);

hi, Yafang.when execute update_stats_dequeue_rt, rt_se->on_rq is still 0, util dequeue_rt_stack, the method is not effect.
I this we can use if (p && p != rq->curr) /*Mark the end of the wait period if dequeueing task*/ because schedstats is not supported for rt group,we only need to update rt_se that is realy task. --
Best regards

author
#5 lore raw

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

sorry, type error. rt_se->on_rq is still 1
--
Best regards

#6 lore raw

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

In reply to Junwen Wu
Quoted 7 lines · Junwen Wu
Quoted 5 lines
Quoted 5 lines

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

+ update_stats_wait_end_rt(rt_rq, rt_se);

hi, Yafang.when execute update_stats_dequeue_rt, rt_se->on_rq is still 0, util dequeue_rt_stack, the method is not effect.

Ah, you are right.

Quoted 1 line

I this we can use if (p && p != rq->curr) /*Mark the end of the wait period if dequeueing task*/

Agreed.

Quoted 4 lines

because schedstats is not supported for rt group,we only need to update rt_se that is realy task. --
Best regards

Signature · 2 lines
Regards
Yafang
author
#7 lore raw

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

Quoted 10 lines

Ah, you are right.

Quoted 1 line

I this we can use if (p && p != rq->curr) /*Mark the end of the wait period if dequeueing task*/

Agreed.

Quoted 4 lines

because schedstats is not supported for rt group,we only need to update rt_se that is realy task. --
Best regards

ok, I send PATCH v2 later
--
Best regards