From nobody Sat Feb 7 10:15:49 2026 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (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 3B8B73ECBDE for ; Wed, 4 Feb 2026 12:00:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770206423; cv=none; b=jR63ixLUwQLMgYosY8Qn69ycIGxfdZjt/5csKV7tFPjjB1sYXnU6bDYkUbBuiP6DzR5EDnkZfibGzfJ4zrmpBU08+0mzsF/hUdBXxI1nsig+djirNlDGgSip+sbnq3jjGjVe68o+IDRRfxc2MGcWh6EwKJYPTZrZJMxAcDbEA+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770206423; c=relaxed/simple; bh=/DU+wehPne0dKg1asq9VyfPpEVNhbsgnDjXC615SpQA=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Nx/iuIkbK/X1VKGiE1hzftdrVjA+wpssuv1iyJwDd5PM9spayvuvmTgFo3bHT9OU8Wl3e9W1M2M4lP+umbpo6uxrMb5NPmp7c8BZgX0VItyP8JUc52WWNxryvd+nYNKo/DcYTu3OF19UDnBs6cCIXrE2eHLiMfWwHE45aS5YV1g= 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=OU6ZtDEK; arc=none smtp.client-ip=60.244.123.138 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="OU6ZtDEK" X-UUID: 11b6062201c111f185319dbc3099e8fb-20260204 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=OU6ZtDEKYYAo7KV4BW5z4hplCHYaTL24iCpf9Cc9TJAxDsiZTb6j8jc6i3XQCvB6bp5nqxpPCRB7vwMT9r7sS7ady7MvIw2rllaU7LHjggfFXdcIP+AHYOobfY0ktDmNRP1QpYx1ESa0b8425uBfF5ti/P5h4NwPxApxrvP1idU=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.11,REQID:48309b92-eb94-429d-b759-a8980fb24467,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:1,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:1 X-CID-META: VersionHash:89c9d04,CLOUDID:e93eec5a-a957-4259-bcca-d3af718d7034,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:-1,COL:0,OSI:0,OSA :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: 11b6062201c111f185319dbc3099e8fb-20260204 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 316070306; Wed, 04 Feb 2026 20:00:16 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.29; Wed, 4 Feb 2026 20:00:14 +0800 Received: from gcnsap21.gcn.mediatek.inc (10.17.81.22) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.2562.29 via Frontend Transport; Wed, 4 Feb 2026 20:00:14 +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 RESEND] sched: fix incorrect schedstats for rt and dl thread Date: Wed, 4 Feb 2026 19:59:29 +0800 Message-ID: <20260204115959.3183567-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