From nobody Sun Feb 8 02:21:46 2026 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (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 1892928642D for ; Fri, 9 Jan 2026 07:35:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767944132; cv=none; b=MF8tW53wCx2pptOM8w5oLRY6dN/kYBIJTDpZo5veDJ+gzm6yFeibvOuTqpc4QAWOca/8Kb4ilOGhhvTAhTmPByJdAcCxe/e88GKGodCNTf70gMr9OtQsZDbymVIstnK08jsxnayA+gjlpXHWB7FhISLkf9aWz9AQxPgCnJpyLX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767944132; c=relaxed/simple; bh=/DU+wehPne0dKg1asq9VyfPpEVNhbsgnDjXC615SpQA=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=LsLmIv6oIQThb/IukT5Ft+6QQIXH/5EJmL3Uf140a93QpdCvcDVV9rax+3xf7RwqV/5VodCdnyeyCm5zJ673KrFLgdlw2YXUprQZFdpZ6xlj4gvn2d2wfe3t8ARxf246K0KTjou2UCOo8Cg6F2psZTR7qynWR52Qx0UmmmUsowI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=OCnY8Zj8; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="OCnY8Zj8" X-UUID: c1fb0b20ed2d11f0bb3cf39eaa2364eb-20260109 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=aqNMzU1Qw+T1MRI2oqS9RMu5Na9ZwPrUfIxVrukiy8k=; b=OCnY8Zj8KGmECg9R7H9DUmD7KYc9lBsFoQEOlvfct+ZL7yl3ZfqZC1fIxmhpXbCbPkCYnrkhRkk24Q4F2M85jz2xNSSvgVlwEXfkNAMk4OjBEY4kDkTrV5h3yQk9LW6VXWhnSPISeqE0xcE5o/6NZe5Ux6wfqlX1lq2SvYNBN7o=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.9,REQID:dba73309-f488-43b8-963d-e52d717c19c8,IP:0,UR L:0,TC:0,Content:0,EDM:0,RT:1,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION:r elease,TS:1 X-CID-META: VersionHash:5047765,CLOUDID:90139879-8c8a-4fc4-88c0-3556e7711556,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102|836|888|898,TC:-5,Content:0|15|5 0,EDM:-3,IP:nil,URL:0,File:130,RT:0,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OS A:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: c1fb0b20ed2d11f0bb3cf39eaa2364eb-20260109 Received: from mtkmbs14n2.mediatek.inc [(172.21.101.76)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 744317155; Fri, 09 Jan 2026 15:35:23 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by MTKMBS14N2.mediatek.inc (172.21.101.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.29; Fri, 9 Jan 2026 15:35:22 +0800 Received: from gcnsap21.gcn.mediatek.inc (10.17.81.22) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.2562.29 via Frontend Transport; Fri, 9 Jan 2026 15:35:21 +0800 From: Dengjun Su To: , Peter Zijlstra CC: , , , , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Matthias Brugger , AngeloGioacchino Del Regno , , Subject: [PATCH v2] sched: fix incorrect schedstats for rt and dl thread Date: Fri, 9 Jan 2026 15:35:16 +0800 Message-ID: <20260109073518.2843689-1-dengjun.su@mediatek.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Content-Type: text/plain; charset="utf-8" For RT and DL thread, only 'set_next_task_(rt/dl)' will call 'update_stats_wait_end_(rt/dl)' to update schedstats information. However, during the migration process, 'update_stats_wait_start_(rt/dl)' will be called twice, which will cause the values of wait_max and wait_sum to be incorrect. The specific output as follows: $ cat /proc/6046/task/6046/sched | grep wait wait_start : 0.000000 wait_max : 496717.080029 wait_sum : 7921540.776553 A complete schedstats information update flow of migrate should be __update_stats_wait_start() [enter queue A, stage 1] -> __update_stats_wait_end() [leave queue A, stage 2] -> __update_stats_wait_start() [enter queue B, stage 3] -> __update_stats_wait_end() [start running on queue B, stage 4] Stage 1: prev_wait_start is 0, and in the end, wait_start records the time of entering the queue. Stage 2: task_on_rq_migrating(p) is true, and wait_start is updated to the waiting time on queue A. Stage 3: prev_wait_start is the waiting time on queue A, wait_start is the time of entering queue B, and wait_start is expected to be greater than prev_wait_start. Under this condition, wait_start is updated to (the moment of entering queue B) - (the waiting time on queue A). Stage 4: the final wait time =3D (time when starting to run on queue B) - (time of entering queue B) + (waiting time on queue A) =3D waiting time on queue B + waiting time on queue A. The current problem is that stage 2 does not call __update_stats_wait_end to update wait_start, which causes the final computed wait time =3D waiting time on queue B + the moment of entering queue A, leading to incorrect wait_max and wait_sum. Add 'update_stats_wait_end_(rt/dl)' in 'update_stats_dequeue_(rt/dl)' to update schedstats information when dequeue_task. Signed-off-by: Dengjun Su --- v2: changes according to Peter's suggestions 1. add fix for dl class; 2. add more commit message to explain the reasons for the modifications. --- kernel/sched/deadline.c | 4 ++++ kernel/sched/rt.c | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 319439fe1870..610243a56bf8 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -2115,10 +2115,14 @@ update_stats_dequeue_dl(struct dl_rq *dl_rq, struct= sched_dl_entity *dl_se, int flags) { struct task_struct *p =3D dl_task_of(dl_se); + struct rq *rq =3D rq_of_dl_rq(dl_rq); =20 if (!schedstat_enabled()) return; =20 + if (p !=3D rq->curr) + update_stats_wait_end_dl(dl_rq, dl_se); + if ((flags & DEQUEUE_SLEEP)) { unsigned int state; =20 diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index f1867fe8e5c5..12f2efddca9f 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1302,13 +1302,18 @@ update_stats_dequeue_rt(struct rt_rq *rt_rq, struct= sched_rt_entity *rt_se, int flags) { struct task_struct *p =3D NULL; + struct rq *rq =3D rq_of_rt_rq(rt_rq); =20 if (!schedstat_enabled()) return; =20 - if (rt_entity_is_task(rt_se)) + if (rt_entity_is_task(rt_se)) { p =3D rt_task_of(rt_se); =20 + if (p !=3D rq->curr) + update_stats_wait_end_rt(rt_rq, rt_se); + } + if ((flags & DEQUEUE_SLEEP) && p) { unsigned int state; =20 --=20 2.43.0