From patchwork Wed Jan 3 08:10:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexs@kernel.org X-Patchwork-Id: 184660 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4889227dyb; Wed, 3 Jan 2024 00:09:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IHiovARCVNdZWLBzh8HjMpcvbeXlXncc/LPyz5/2/T3EPbTHC6C8F+MK/8PszyI9oHKC3qf X-Received: by 2002:ac8:5d4e:0:b0:428:5d5:9d99 with SMTP id g14-20020ac85d4e000000b0042805d59d99mr9446634qtx.44.1704269361951; Wed, 03 Jan 2024 00:09:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704269361; cv=none; d=google.com; s=arc-20160816; b=PfUdqw6sH5728jJLlEbwzom7uAVdrQpj6BFh/momA8gKzlkIBdu0v0hncLnaa+YyT6 zvLm1+sSSrQaro12mTRh5ibC/w+YQLabORWcmnkvJG0p0arsyvOZFEZg4vIrp4ePxGRE bWO653119m+/45rP9biuHkbbL6LTtGRHIvu43tiT7SJH/O2YtumN/6FPJqBGh9HwUvqk OaVkr/qbKOyqQJOSpavdTErS9GcXq6GP0MYsYNl1bn9h39Inba2G8NTslJObpuUCfupB F+k5kxPs5EIZ1tCW96fPcNjA91ozk07j2KAcb6YlvCeFyRBE9JzUPvYuEjDBBsA7p+3T dd6Q== 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=HhxrV7MLQ/WZKFr50V+Tq2kYkQsvgih6eUUXrCqieWQ=; fh=anjk1Egm383vfZAe+uFZ4BcIo6SzVgNVjjnhXgCkdws=; b=Tys0CjTNbcHGDRQvJwzL2EEhvRAGcPCfr2wtPy5ll/Ik+vvoRmcsCWSq4mdqR2LxGX FXhF4iSzYKTjUKt25PrVO5NOR+PSKUufN2HtlUWD4NcqqtjXFj62T/x7WiJU5g5wvz77 HJ1LmTQnPUkRZBEWUyHbfjXi0dY/fwwuBr4qx4AR/RUNaaexRz5vvhpugUXKlCt+NuPx 2B58Wvg+emy+NEgPOEVV5XKGmUuJfz5owXq3ge749iRXAhzgHBvVgTGVoVYf1wEE1EBA 7jPy63TVhIaiPUWr3O+MwPjE8gB9KJfc38xQT2ye+fBfunlOxO5Z6O8TJFhP71gz+x5q /YOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=beUiVz5c; spf=pass (google.com: domain of linux-kernel+bounces-15262-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15262-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b3-20020a05622a020300b00423c167d719si28757804qtx.493.2024.01.03.00.09.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 00:09:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15262-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=beUiVz5c; spf=pass (google.com: domain of linux-kernel+bounces-15262-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15262-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id AE8EB1C23089 for ; Wed, 3 Jan 2024 08:09:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6BF618640; Wed, 3 Jan 2024 08:09:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="beUiVz5c" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E244718623 for ; Wed, 3 Jan 2024 08:09:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D8E5C433C7; Wed, 3 Jan 2024 08:09:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704269345; bh=/P93iDWx0rUgDH9n+aFD3T8XY72jOetnP/Drn34JroI=; h=From:To:Cc:Subject:Date:From; b=beUiVz5cN9puQyNHLSi1W8HtLbj0mt8+Oe8KQOvTgF5f+hxaLd8Qn3fvvWREInjEB yQrg1j/ItpNZLzHW369EOdoi8yPtgAQgl4Z3L9vD4EAincXAYH5fbcXEDr7NIEXtzg A0b+2uXr9gxA/2Bdp62YyhZfaU/07rn+iCLZonqEGZTX7FeQy5gZVA5NoIArOBYegm Tdi+UEJHpA1pOWeErT5W6JR5L7YW+rHQ0VFCouwGrNSfILL+c1OlXKLsL1pPAn8e4c qJ7kQcYry1oFaN3ppL0uT9ghFec8T2ZjgNS6qZs1zA5TT6+9gOXGSFK1UWaJmiOMj/ 15JMMtqnFU9MA== From: alexs@kernel.org To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org Cc: curuwang@tencent.com, Alex Shi Subject: [PATCH v2] sched/stat: correct the task blocking state Date: Wed, 3 Jan 2024 16:10:42 +0800 Message-ID: <20240103081042.1549189-1-alexs@kernel.org> 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787055950380674865 X-GMAIL-MSGID: 1787055950380674865 From: Alex Shi The commit 80ed87c8a9ca ("sched/wait: Introduce TASK_NOLOAD and TASK_IDLE") stopped the idle kthreads from contributing to the load average. However, the idle state time still contributes to the blocked state time instead of the sleep time. As a result, we cannot determine if a task is stopped due to some reasons or if it is idle by its own initiative. Distinguishing between these two states would make the system state clearer and provide us with an opportunity to use the 'D' state of a task as an indicator of latency issues. Originally-from: Curu Wong Signed-off-by: Alex Shi To: linux-kernel@vger.kernel.org To: Valentin Schneider To: Daniel Bristot de Oliveira To: Mel Gorman To: Ben Segall To: Steven Rostedt To: Dietmar Eggemann To: Vincent Guittot To: Juri Lelli To: Peter Zijlstra To: Ingo Molnar --- include/linux/sched.h | 6 ++++++ kernel/sched/deadline.c | 5 +++-- kernel/sched/fair.c | 5 +++-- kernel/sched/rt.c | 5 +++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 292c31697248..002f80291837 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -140,6 +140,12 @@ struct user_event_mm; #define is_special_task_state(state) \ ((state) & (__TASK_STOPPED | __TASK_TRACED | TASK_PARKED | TASK_DEAD)) +/* blocked task is UNINTERRUPTIBLE but not NOLOAD */ +#define is_blocked_state(state) \ + ((state) & TASK_UNINTERRUPTIBLE && (!((state) & TASK_NOLOAD))) + +#define is_idle_state(state) (((state) & TASK_IDLE) == TASK_IDLE) + #ifdef CONFIG_DEBUG_ATOMIC_SLEEP # define debug_normal_state_change(state_value) \ do { \ diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index b28114478b82..99d46affc2aa 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1566,11 +1566,12 @@ update_stats_dequeue_dl(struct dl_rq *dl_rq, struct sched_dl_entity *dl_se, unsigned int state; state = READ_ONCE(p->__state); - if (state & TASK_INTERRUPTIBLE) + /* idle state still accounts into sleep */ + if (state & TASK_INTERRUPTIBLE || is_idle_state(state)) __schedstat_set(p->stats.sleep_start, rq_clock(rq_of_dl_rq(dl_rq))); - if (state & TASK_UNINTERRUPTIBLE) + if (is_blocked_state(state)) __schedstat_set(p->stats.block_start, rq_clock(rq_of_dl_rq(dl_rq))); } diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d7a3c63a2171..69506253aadf 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1278,10 +1278,11 @@ update_stats_dequeue_fair(struct cfs_rq *cfs_rq, struct sched_entity *se, int fl /* XXX racy against TTWU */ state = READ_ONCE(tsk->__state); - if (state & TASK_INTERRUPTIBLE) + /* idle state still accounts into sleep */ + if (state & TASK_INTERRUPTIBLE || is_idle_state(state)) __schedstat_set(tsk->stats.sleep_start, rq_clock(rq_of(cfs_rq))); - if (state & TASK_UNINTERRUPTIBLE) + if (is_blocked_state(state)) __schedstat_set(tsk->stats.block_start, rq_clock(rq_of(cfs_rq))); } diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 6aaf0a3d6081..dd0e381689f8 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -1371,11 +1371,12 @@ update_stats_dequeue_rt(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se, unsigned int state; state = READ_ONCE(p->__state); - if (state & TASK_INTERRUPTIBLE) + /* idle state still accounts into sleep */ + if (state & TASK_INTERRUPTIBLE || is_idle_state(state)) __schedstat_set(p->stats.sleep_start, rq_clock(rq_of_rt_rq(rt_rq))); - if (state & TASK_UNINTERRUPTIBLE) + if (is_blocked_state(state)) __schedstat_set(p->stats.block_start, rq_clock(rq_of_rt_rq(rt_rq))); }