Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1705177rdd; Thu, 11 Jan 2024 07:04:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IHafc9ryIF5ZY+tScg6OeYEJCC3AzAYvSFTo0RhYq3Q4jtAsol2zucnbgmH2T8RBNAJFtIF X-Received: by 2002:a05:6808:3014:b0:3bd:45cd:2891 with SMTP id ay20-20020a056808301400b003bd45cd2891mr1450341oib.109.1704985480267; Thu, 11 Jan 2024 07:04:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704985480; cv=none; d=google.com; s=arc-20160816; b=da/dyTPZKPC27z1y6FrhFqwUkTinumS4a5cS9KDFb1uFEJDP5b7tLCHI2ywVioJpX5 CAxCvhfxXvP7GQY+TYjHfR4jgo+ZgJna8lLGfuIlAxtQEMjcGGPdfm6BcjYP+5l7hINt IscYrPHuImH+kE9zJkQ6640SDUGz7W7p6WtxKDnQu46GGAz1SaPOmVBhZ7J4AC+gejH2 /79tpTBsEIIkLsUEz3TYPaeqWIbu1RAgDbo6Dpeqw5Gz62Xz3+6D8GauJiA/9U02iL9K gE85ZxIPtwZOlWwrKdj/Y0nQbC8MbOIsSG/STWstJMjWoEPpimBGfa6OprIy3sMmGCSf YG1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=m/pqEXf08c+vliWE8lSPeFsP2w2ISvMh2c2RA9T/8Vk=; fh=7iwxoLOSnHAIXpDDGEeI3eELn1Xp2inR5lwNZjnZMqk=; b=gK6SRaZyoC6R9PRFs9vqX8zjc0e6vxjq4VgsBFGQoTMnhbJqr4m1pEX2XhnGlN57yJ SOttn98/cja7GGNgbxipa8bGSGMds6FFy1ELtFQDN1z+Q3LkLcnUYni/4K/EHJJUaTAO h1ImfAP0L3tEfsgH/SZIPRAL3zWwNgNnI+3rThTclC/XQRtELCCgejtyPO1x8/twrg+N B/lcxMRAZbPoNaafRmAQOXmUyLKKK42UvLPdLb1x/RJAX2a73EpQ7zqZ6SeU5SFfxJbv pgVpIDpeKUJQy8lSjSiCq3EQ/J6AWiYYDIItrDTVfZt+oOdA61AJAeuc/03TPLJF3vlf JEig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=jiGy7jUj; spf=pass (google.com: domain of linux-kernel+bounces-23757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23757-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q10-20020a056808200a00b003bbc2200cdcsi461886oiw.38.2024.01.11.07.04.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 07:04:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=jiGy7jUj; spf=pass (google.com: domain of linux-kernel+bounces-23757-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23757-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C3E392889E6 for ; Thu, 11 Jan 2024 15:04:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1718A4B5DD; Thu, 11 Jan 2024 15:04:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="jiGy7jUj" Received: from m16.mail.163.com (m15.mail.163.com [45.254.50.219]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 261ED4B5A9 for ; Thu, 11 Jan 2024 15:04:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=m/pqE Xf08c+vliWE8lSPeFsP2w2ISvMh2c2RA9T/8Vk=; b=jiGy7jUjzM8eqr0WaiGnV g96UwcNwS19UoxjDFFnojFRyVX9m0UqsW1YiEGCCNj/3W94Wk5XbWbgXauZgHkPL a53T4UY/faYyT5XcqzWBRgA+fUxGnoQ4B9osqB2thRZTmjGLCVcAS4NNSy/UAwYg DegEtlbmH58qcSJEPTOpqA= Received: from localhost.localdomain (unknown [120.229.70.38]) by gzga-smtp-mta-g0-1 (Coremail) with SMTP id _____wD3H_LlAqBlABYnAA--.8189S2; Thu, 11 Jan 2024 23:02:00 +0800 (CST) From: Junwen Wu To: bristot@redhat.com, mingo@redhat.com, laoar.shao@gmail.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com Cc: mgorman@suse.de, vschneid@redhat.com, linux-kernel@vger.kernel.org, Junwen Wu Subject: [PATCH v5] sched/stats: Fix rt/dl task's sched latency statistics error in sched_stat_wait tracepoint Date: Thu, 11 Jan 2024 15:01:47 +0000 Message-Id: <20240111150147.182937-1-wudaemon@163.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wD3H_LlAqBlABYnAA--.8189S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7CF15CF4fWw1UKFW8AFW8WFg_yoW8ur1Up3 yDWay8Jw4qg3yjgw4xZr4DWrW5Wwn3J342gFnrGayftF4Ykr1Yq3WSqFW3XFZ09r9YkF17 tr40939rKw4v9F7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piX4S7UUUUU= X-CM-SenderInfo: 5zxgtvxprqqiywtou0bp/1tbisQtibWVOBBV09gAAsN The sched_stat_wait tracepoint is showing unreasonably long latencies for real-time tasks. For example: sched_stat_wait: comm=rcu_preempt pid=14 delay=4936139545261 [ns] This error happens when the rt task balances off the source CPU because the dequeue operation is not updating the sched_statistics. So, follow update_stats_wait_end_fair() and update the stats. Do the same for SCHED_DEADLINE. Fixes: 57a5c2dafca8 ("sched/rt: Support schedstats for RT sched class") Fixes: b5eb4a5f6521 ("sched/dl: Support schedstats for deadline sched class") Acked-by: Yafang Shao Signed-off-by: Junwen Wu --- kernel/sched/deadline.c | 5 ++++- kernel/sched/rt.c | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index b28114478b82..4a9aad291fb9 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1558,10 +1558,13 @@ 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..5cb3a54d6b13 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1360,12 +1360,16 @@ 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