From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E0A524A07C for ; Mon, 12 Jan 2026 16:38:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768235910; cv=none; b=RXfkoNYG7iaoKBtUQQm4+3mrUraM6w71+415KrDfhQ5HNVPhsziyyz7nOXKW2Qw3fSBbIyNXStwXmo33w+7Lx1uijJ3zciyYwtD8p+V6f4lv1vDdAmQgbxB5339NGTqwue8cmeOMW1w5uDnPrYDouLiD0L05O3aZ8zx+GdHdvWw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768235910; c=relaxed/simple; bh=uwj0e0mlD+/Ry0Qwa2iV4rlG1wN4MRxzm6HfImGhhuQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LDFC1jaDfeNoaVCYAlca3SFsom56z79yBCzZbbKa1o1SBhwJVKHt4UGQL9KZSR+iCsnjq1/1WNrBaxJTwPTPB+Mhj+AqT55XiM0a6hJ+kquiTVmoaN382JVORvE6Plhcfs97Vasi5d5fOBG2wismNh6uoEFiBMIB4GK/B07G8RI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=BWzg0ci9; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BWzg0ci9" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=y6frWGL3mv0azutt360p+irVL7NLCTrHz31j8urvnMs=; b=BWzg0ci9lRV6kM6SAg7C7W64ZR hxsgs65EQUWzH+vLcV0xGzP7mlKYEi1ZGOzd2wQCIYUh2Gj/MHYmMlXCrpPrdb4QvQ7LKCcsVKZs1 2znQv+OE26br4sYs33mIe/b08YuM3ySyQVlV30Ou13MV5v+dT7N6HX5f1Psj26bR5j2Puu6qXM+Nu Sudk3bDWLysMVCVz60/H7OO0En3GnyDUBqB9s1rqQho9v4U5RPwyzG4ChLkZFoSaB2s+2PnrFMlbD cyGjFT5t4S5Bycf03Vddc7iqgHF2d7lEVn9AsWB2lzmOk0tJn5PaNZAVLHc4jc/rCgZ4j/Cg1esgb aIGUEPlw==; Received: from 2001-1c00-8d85-5700-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:5700:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vfKvn-00000001BSA-3TpF; Mon, 12 Jan 2026 16:38:16 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id C66AC302D3E; Mon, 12 Jan 2026 17:38:14 +0100 (CET) Date: Mon, 12 Jan 2026 17:38:14 +0100 From: Peter Zijlstra To: Dengjun Su 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 Message-ID: <20260112163814.GP830755@noisy.programming.kicks-ass.net> References: <20260108111632.GH272712@noisy.programming.kicks-ass.net> <20260109072451.2843331-1-dengjun.su@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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); }