mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] sched/rt: Fix rt task's sched latency statistics error in sched_stat_wait trace_point
@ 2023-12-21 15:02 Junwen Wu
  2023-12-22  8:16 ` Yafang Shao
  0 siblings, 1 reply; 4+ messages in thread
From: Junwen Wu @ 2023-12-21 15:02 UTC (permalink / raw)
  To: mingo, laoar.shao, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall
  Cc: mgorman, bristot, vschneid, linux-kernel, 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. When rt task balance off
source cpu, dequeue operation not update the sched_statistics, so follow
update_stats_wait_end_fair update method.

Signed-off-by: Junwen Wu <wudaemon@163.com>
---
Changes since v1:
https://lore.kernel.org/all/20231218150322.788382-1-wudaemon@163.com/

 kernel/sched/rt.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 6aaf0a3d6081..6a2600213991 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1360,12 +1360,19 @@ 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);
+	 /*
+	  * Mark the end of the wait period
+	  * if dequeueing a waiting task.
+	  */
+	if (p && (p != rq->curr))
+		update_stats_wait_end_rt(rt_rq, rt_se);
 
 	if ((flags & DEQUEUE_SLEEP) && p) {
 		unsigned int state;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] sched/rt: Fix rt task's sched latency statistics error in sched_stat_wait trace_point
  2023-12-21 15:02 [PATCH v2] sched/rt: Fix rt task's sched latency statistics error in sched_stat_wait trace_point Junwen Wu
@ 2023-12-22  8:16 ` Yafang Shao
  2023-12-23  5:36   ` Junwen Wu
  0 siblings, 1 reply; 4+ messages in thread
From: Yafang Shao @ 2023-12-22  8:16 UTC (permalink / raw)
  To: Junwen Wu
  Cc: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid, linux-kernel

On Thu, Dec 21, 2023 at 11:03 PM Junwen Wu <wudaemon@163.com> 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. When rt task balance off
> source cpu, dequeue operation not update the sched_statistics, so follow
> update_stats_wait_end_fair update method.
>
> Signed-off-by: Junwen Wu <wudaemon@163.com>
> ---
> Changes since v1:
> https://lore.kernel.org/all/20231218150322.788382-1-wudaemon@163.com/
>
>  kernel/sched/rt.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
> index 6aaf0a3d6081..6a2600213991 100644
> --- a/kernel/sched/rt.c
> +++ b/kernel/sched/rt.c
> @@ -1360,12 +1360,19 @@ 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);
> +        /*
> +         * Mark the end of the wait period
> +         * if dequeueing a waiting task.
> +         */
> +       if (p && (p != rq->curr))
> +               update_stats_wait_end_rt(rt_rq, rt_se);

It seems DL has the same issue. Pls. also fix it in update_stats_dequeue_dl().
And add the Fixes tag in the commit log:
Fixes: 57a5c2dafca8 ("sched/rt: Support schedstats for RT sched class")
Fixes: b5eb4a5f6521 ("sched/dl: Support schedstats for deadline sched class")

>
>         if ((flags & DEQUEUE_SLEEP) && p) {
>                 unsigned int state;
> --
> 2.34.1
>


-- 
Regards
Yafang

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] sched/rt: Fix rt task's sched latency statistics error in sched_stat_wait trace_point
  2023-12-22  8:16 ` Yafang Shao
@ 2023-12-23  5:36   ` Junwen Wu
  2023-12-24 11:38     ` Yafang Shao
  0 siblings, 1 reply; 4+ messages in thread
From: Junwen Wu @ 2023-12-23  5:36 UTC (permalink / raw)
  To: laoar.shao
  Cc: bristot, bsegall, dietmar.eggemann, juri.lelli, linux-kernel,
	mgorman, mingo, peterz, rostedt, vincent.guittot, vschneid,
	wudaemon

>It seems DL has the same issue. Pls. also fix it in update_stats_dequeue_dl().
>And add the Fixes tag in the commit log:
>Fixes: 57a5c2dafca8 ("sched/rt: Support schedstats for RT sched class")
>Fixes: b5eb4a5f6521 ("sched/dl: Support schedstats for deadline sched class")

ok, the PATCH v3 below is ok?

Subject: [PATCH v3] sched/stats: Fix rt/dl task's sched latency statistics
 error 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. When rt task balance off source cpu,
dequeue operation not update the sched_statistics, so follow update_stats_wait_end_fair
update method, so do dl tasks.

Fixes: 57a5c2dafca8 ("sched/rt: Support schedstats for RT sched class")
Fixes: b5eb4a5f6521 ("sched/dl: Support schedstats for deadline sched class")
Signed-off-by: Junwen Wu <wudaemon@163.com>
---
 kernel/sched/deadline.c | 8 +++++++-
 kernel/sched/rt.c       | 7 +++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index b28114478b82..29223163ee22 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1558,10 +1558,16 @@ update_stats_dequeue_dl(struct dl_rq *dl_rq, struct sched_dl_entity *dl_se,
                        int flags)
 {
        struct task_struct *p = dl_task_of(dl_se);
+       struct rq *rq = rq_of_dl_rq(dl_rq);

        if (!schedstat_enabled())
                return;
-
+       /*
+        * Mark the end of the wait period
+        * if dequeueing a waiting task.
+        */
+       if (p && (p != rq->curr))
+                update_stats_wait_end_dl(dl_rq, dl_se);
        if ((flags & DEQUEUE_SLEEP)) {
                unsigned int state;

diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 6aaf0a3d6081..6a2600213991 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1360,12 +1360,19 @@ 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);
+        /*
+         * Mark the end of the wait period
+         * if dequeueing a waiting task.
+         */
+       if (p && (p != rq->curr))
+               update_stats_wait_end_rt(rt_rq, rt_se);

        if ((flags & DEQUEUE_SLEEP) && p) {
                unsigned int state;

--
Best regards


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] sched/rt: Fix rt task's sched latency statistics error in sched_stat_wait trace_point
  2023-12-23  5:36   ` Junwen Wu
@ 2023-12-24 11:38     ` Yafang Shao
  0 siblings, 0 replies; 4+ messages in thread
From: Yafang Shao @ 2023-12-24 11:38 UTC (permalink / raw)
  To: Junwen Wu
  Cc: bristot, bsegall, dietmar.eggemann, juri.lelli, linux-kernel,
	mgorman, mingo, peterz, rostedt, vincent.guittot, vschneid

On Sat, Dec 23, 2023 at 1:38 PM Junwen Wu <wudaemon@163.com> wrote:
>
> >It seems DL has the same issue. Pls. also fix it in update_stats_dequeue_dl().
> >And add the Fixes tag in the commit log:
> >Fixes: 57a5c2dafca8 ("sched/rt: Support schedstats for RT sched class")
> >Fixes: b5eb4a5f6521 ("sched/dl: Support schedstats for deadline sched class")
>
> ok, the PATCH v3 below is ok?
>
> Subject: [PATCH v3] sched/stats: Fix rt/dl task's sched latency statistics
>  error 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. When rt task balance off source cpu,
> dequeue operation not update the sched_statistics, so follow update_stats_wait_end_fair
> update method, so do dl tasks.
>
> Fixes: 57a5c2dafca8 ("sched/rt: Support schedstats for RT sched class")
> Fixes: b5eb4a5f6521 ("sched/dl: Support schedstats for deadline sched class")
> Signed-off-by: Junwen Wu <wudaemon@163.com>

Acked-by: Yafang Shao <laoar.shao@gmail.com>

> ---
>  kernel/sched/deadline.c | 8 +++++++-
>  kernel/sched/rt.c       | 7 +++++++
>  2 files changed, 14 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index b28114478b82..29223163ee22 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -1558,10 +1558,16 @@ update_stats_dequeue_dl(struct dl_rq *dl_rq, struct sched_dl_entity *dl_se,
>                         int flags)
>  {
>         struct task_struct *p = dl_task_of(dl_se);
> +       struct rq *rq = rq_of_dl_rq(dl_rq);
>
>         if (!schedstat_enabled())
>                 return;
> -
> +       /*
> +        * Mark the end of the wait period
> +        * if dequeueing a waiting task.
> +        */
> +       if (p && (p != rq->curr))
> +                update_stats_wait_end_dl(dl_rq, dl_se);
>         if ((flags & DEQUEUE_SLEEP)) {
>                 unsigned int state;
>
> diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
> index 6aaf0a3d6081..6a2600213991 100644
> --- a/kernel/sched/rt.c
> +++ b/kernel/sched/rt.c
> @@ -1360,12 +1360,19 @@ 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);
> +        /*
> +         * Mark the end of the wait period
> +         * if dequeueing a waiting task.
> +         */
> +       if (p && (p != rq->curr))
> +               update_stats_wait_end_rt(rt_rq, rt_se);
>
>         if ((flags & DEQUEUE_SLEEP) && p) {
>                 unsigned int state;
>
> --
> Best regards
>


-- 
Regards
Yafang

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-24 11:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-21 15:02 [PATCH v2] sched/rt: Fix rt task's sched latency statistics error in sched_stat_wait trace_point Junwen Wu
2023-12-22  8:16 ` Yafang Shao
2023-12-23  5:36   ` Junwen Wu
2023-12-24 11:38     ` Yafang Shao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®