public inbox for linux-mediatek@lists.infradead.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Dengjun Su <dengjun.su@mediatek.com>
Cc: angelogioacchino.delregno@collabora.com, bsegall@google.com,
	dietmar.eggemann@arm.com, haiqiang.gong@mediatek.com,
	juri.lelli@redhat.com, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
	matthias.bgg@gmail.com, mgorman@suse.de, mike.zhang@mediatek.com,
	mingo@redhat.com, peijun.huang@mediatek.com, rostedt@goodmis.org,
	vincent.guittot@linaro.org, vschneid@redhat.com
Subject: Re: [PATCH] sched/rt: fix incorrect schedstats for rt thread
Date: Mon, 12 Jan 2026 17:38:14 +0100	[thread overview]
Message-ID: <20260112163814.GP830755@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20260109072451.2843331-1-dengjun.su@mediatek.com>

On Fri, Jan 09, 2026 at 03:24:47PM +0800, Dengjun Su wrote:

> For __update_stats_wait_end(), task_on_rq_migrating(p) is needed to
> distinguish between stage 2 and stage 4 because they involve different
> processing flows, but for __update_stats_wait_start(), it is not necessary
> to distinguish between stage 1 and stage 3.
> 
> As for adding the condition wait_start > prev_wait_start, I think it is
> more like a mechanism to prevent statistical deviations caused by time
> inconsistencies.

It looks like nonsense to me.. since you have a test-case, could you see
what this does for you?

Specifically:

 - it ensures that when not in a migration, prev_wait_start must be 0

 - it unconditionally subtracts; unsigned types are defined to wrap
   nicely (2s complement) and it all should work just fine.

---

diff --git a/kernel/sched/stats.c b/kernel/sched/stats.c
index d1c9429a4ac5..144b23029327 100644
--- a/kernel/sched/stats.c
+++ b/kernel/sched/stats.c
@@ -12,8 +12,10 @@ void __update_stats_wait_start(struct rq *rq, struct task_struct *p,
 	wait_start = rq_clock(rq);
 	prev_wait_start = schedstat_val(stats->wait_start);
 
-	if (p && likely(wait_start > prev_wait_start))
+	if (p) {
+		WARN_ON_ONCE(!task_on_rq_migrating(p) && prev_wait_start);
 		wait_start -= prev_wait_start;
+	}
 
 	__schedstat_set(stats->wait_start, wait_start);
 }


  reply	other threads:[~2026-01-12 16:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08  3:13 [PATCH] sched/rt: fix incorrect schedstats for rt thread Dengjun Su
2026-01-08 11:16 ` Peter Zijlstra
2026-01-09  7:24   ` Dengjun Su
2026-01-12 16:38     ` Peter Zijlstra [this message]
2026-01-14 11:55       ` Dengjun Su

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260112163814.GP830755@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=bsegall@google.com \
    --cc=dengjun.su@mediatek.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=haiqiang.gong@mediatek.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=mgorman@suse.de \
    --cc=mike.zhang@mediatek.com \
    --cc=mingo@redhat.com \
    --cc=peijun.huang@mediatek.com \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox