Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4535344rwb; Mon, 8 Aug 2022 02:47:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR48gVv0fORe2OjGRdfOQb+8mEBr+hVstbhEC/pS0+il8As1fczaCF4dgUVFS0qQrJ4tbKTN X-Received: by 2002:a17:90a:de13:b0:1f7:4bd3:36ec with SMTP id m19-20020a17090ade1300b001f74bd336ecmr4798366pjv.179.1659952058348; Mon, 08 Aug 2022 02:47:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659952058; cv=none; d=google.com; s=arc-20160816; b=DJJerEmh9Fzha/4cNEjjwudjzm2jMCFfpCdABxXRB4Kv8oMMIxanyI8L9u5iiHe9H+ GyPP3GznvMNHQtq1vYQHXaL00Mo+kEOTJII4hAwflPrgX53rtRVmqR+CoGDb5qCo4Ft3 u61wOro5bSvur3mMjy3Ywak7qKJ36RCf8u8PHbF17AoICWBOJR+CBPgR52gQ8FW7k66G 3tzjabpraYWQUunxSp7zTAqNImGd8c31lfaIm4dlpA4D1wiyrwQMNBzYNf6MouryR48D 2KO6JvqH773JS9D+MDsp+n96jrOugty0RNLNrXwDpuiBb6hOX1AEBE3K7gJ+Vh7eJn2S vZlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=4wW9IqhKPya86Ne3kZ8W5Px3+wqvxjBbUcrSQT3T4dg=; b=yY3JxaX2ffb/H4CVCGDgLS7JJYKl+SJTspeX3VfaqdsY0l60iWJjMCCdcw6jyOz50M sUeWKlzsh9tvlTf3hLSGPJrRudbh16yPvo5gW0j5ouh+FstcAvBikACj0nCNdR+lUJpY gjrryuSCfjlQZb09Cb/7Nbtt96t1IxP1Bh2jyNL1VDSY8QoG0fQXLQv2qnS8lyV7aiDK k2UUYYSrScHazF+PyPOPqivZWMZ7edhF/gKu3qZGghgZk/bscGhpLBjPq2LUwEpc7wPh vYB9Xb4zbfjGN5v19U+5nJtS9gFvrT7kSmmzcgg5zS8jNaj4mcODx78cqK/GOzVAK9eA 0g+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=a5yopIAy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 26-20020a17090a035a00b001ecba51171dsi14565905pjf.143.2022.08.08.02.47.24; Mon, 08 Aug 2022 02:47:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=a5yopIAy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242460AbiHHJj4 (ORCPT + 99 others); Mon, 8 Aug 2022 05:39:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232190AbiHHJjy (ORCPT ); Mon, 8 Aug 2022 05:39:54 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41AE613D5B for ; Mon, 8 Aug 2022 02:39:53 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id c17so11851445lfb.3 for ; Mon, 08 Aug 2022 02:39:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4wW9IqhKPya86Ne3kZ8W5Px3+wqvxjBbUcrSQT3T4dg=; b=a5yopIAy9kR8vRJlLjjVB/b3JFrdKEiOl1LXNHsZWQEZQ7CtXgLbcICnqWkKujmAHq 05o71oKxa2k5A8j4aprmUr1Hn8fDaXrN17Fg1uQqkR0t9B5BTvqn+NDqrBBNwrRoryT5 QKxsu+DhijXkvc7zcjvSo3DRYx55VKV0GjEuj+WN/zhy4DUmJ1fugfy76JOBIqLhLXDf eefrS1NRbOkn+/n89qggUJgaoM2l+J8eW7LSxfBlftFachh1Q2Bex4+atnGJzY2VBr/6 7DWMADSq7fqayAs/E0ugrAQzMoUwXfSdyhbVBu6VFlYbM7XCXqQgaM38nSzDaIFX5uop DBPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4wW9IqhKPya86Ne3kZ8W5Px3+wqvxjBbUcrSQT3T4dg=; b=KdgNwrn3w3tWtd1TI6zsqQsbyJZDnheoDj1mx72gaWz1I6WjI+uB62QXvJVyjOIuMQ liH9lRipRVCJZN7g3yROA0GL0vjGm5hxX++PpCFhwvMaASKsJA7q5NheWRqZEe244Kse t71CVI/TdEGRGezy/27RNhAlNlaX737VQ/rgETOI7j/72DbmDyBYHRnGzmRNrfZx8o0G TE6PyCx/JpWFvWXHy+nT3Noih6O54bgiJB5VSHfnbO1B0wsM1xNbputlVKMSVGrwh3Jc /EcjaUriT0jLXfNJKiyPl76feJgQT5ovAlGZP4l9RlqtTVDZwJbxHvmN/W4gUy2RhanV yGlA== X-Gm-Message-State: ACgBeo1PUW++Tl0f6QfRi9wQVg6VRrAGCgjMQnkumSeskSfrnTjfyXoW Z3+F2Kf+BWgagjHZLuMDdc5L83Xw4LiTkGVyWSi7pLfZBjA= X-Received: by 2002:ac2:4e4f:0:b0:48c:e6b6:9d7e with SMTP id f15-20020ac24e4f000000b0048ce6b69d7emr1509155lfr.128.1659951591486; Mon, 08 Aug 2022 02:39:51 -0700 (PDT) MIME-Version: 1.0 References: <1659939208-22454-1-git-send-email-zhaoyang.huang@unisoc.com> In-Reply-To: From: Zhaoyang Huang Date: Mon, 8 Aug 2022 17:39:39 +0800 Message-ID: Subject: Re: [RFC PATCH] psi: introduce PSI UNINTERRUPTIBLE To: Chengming Zhou Cc: "zhaoyang.huang" , Johannes Weiner , Suren Baghdasaryan , LKML , Ke Wang , xuewen.yan@unisoc.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 8, 2022 at 5:12 PM Chengming Zhou wrote: > > On 2022/8/8 14:13, zhaoyang.huang wrote: > > From: Zhaoyang Huang > > > > Uninterruptible sleep has not been monitored as an important system status yet. > > Imagin that a set of psi triggers are created for monitoring a special group, while > > get nothing high for none of the pressures, which could be the processes within > > are stock in some given resources and turn to be UN status. Introduce PSI_UN as > > a sub-type among PSI system here. > > Hello, > > The problem is that not all TASK_UNINTERRUPTIBLE task means stalled on some > shared resource, like many schedule_timeout() paths. Thanks for heads up. The aim is to distinguish where the processes go (on or off cpu? waiting for anything?). It could be deemed as PSI_MEM like property which is not a precise running time for memory things. Furthermore, we do have method to make it be precise. > > Thanks. > > > > > Signed-off-by: Zhaoyang Huang > > --- > > include/linux/psi_types.h | 11 ++++++++--- > > kernel/sched/psi.c | 10 ++++++++++ > > kernel/sched/stats.h | 6 +++++- > > 3 files changed, 23 insertions(+), 4 deletions(-) > > > > diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h > > index c7fe7c0..8cc1979 100644 > > --- a/include/linux/psi_types.h > > +++ b/include/linux/psi_types.h > > @@ -15,6 +15,7 @@ enum psi_task_count { > > NR_IOWAIT, > > NR_MEMSTALL, > > NR_RUNNING, > > + NR_UNINTERRUPTIBLE, > > /* > > * This can't have values other than 0 or 1 and could be > > * implemented as a bit flag. But for now we still have room > > @@ -32,7 +33,7 @@ enum psi_task_count { > > * threads and memstall ones. > > */ > > NR_MEMSTALL_RUNNING, > > - NR_PSI_TASK_COUNTS = 5, > > + NR_PSI_TASK_COUNTS = 6, > > }; > > > > /* Task state bitmasks */ > > @@ -41,13 +42,15 @@ enum psi_task_count { > > #define TSK_RUNNING (1 << NR_RUNNING) > > #define TSK_ONCPU (1 << NR_ONCPU) > > #define TSK_MEMSTALL_RUNNING (1 << NR_MEMSTALL_RUNNING) > > +#define TSK_UNINTERRUPTIBLE (1 << NR_UNINTERRUPTIBLE) > > > > /* Resources that workloads could be stalled on */ > > enum psi_res { > > PSI_IO, > > PSI_MEM, > > PSI_CPU, > > - NR_PSI_RESOURCES = 3, > > + PSI_UN, > > + NR_PSI_RESOURCES = 4, > > }; > > > > /* > > @@ -63,9 +66,11 @@ enum psi_states { > > PSI_MEM_FULL, > > PSI_CPU_SOME, > > PSI_CPU_FULL, > > + PSI_UN_SOME, > > + PSI_UN_FULL, > > /* Only per-CPU, to weigh the CPU in the global average: */ > > PSI_NONIDLE, > > - NR_PSI_STATES = 7, > > + NR_PSI_STATES = 9, > > }; > > > > enum psi_aggregators { > > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c > > index a337f3e..a37b4a4 100644 > > --- a/kernel/sched/psi.c > > +++ b/kernel/sched/psi.c > > @@ -231,6 +231,10 @@ static bool test_state(unsigned int *tasks, enum psi_states state) > > return unlikely(tasks[NR_RUNNING] > tasks[NR_ONCPU]); > > case PSI_CPU_FULL: > > return unlikely(tasks[NR_RUNNING] && !tasks[NR_ONCPU]); > > + case PSI_UN_SOME: > > + return unlikely(tasks[NR_UNINTERRUPTIBLE]); > > + case PSI_UN_FULL: > > + return unlikely(tasks[NR_UNINTERRUPTIBLE] && !tasks[NR_RUNNING]); > > case PSI_NONIDLE: > > return tasks[NR_IOWAIT] || tasks[NR_MEMSTALL] || > > tasks[NR_RUNNING]; > > @@ -683,6 +687,12 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) > > groupc->times[PSI_CPU_FULL] += delta; > > } > > > > + if (groupc->state_mask & (1 << PSI_UN_SOME)) { > > + groupc->times[PSI_UN_SOME] += delta; > > + if (groupc->state_mask & (1 << PSI_UN_FULL)) > > + groupc->times[PSI_UN_FULL] += delta; > > + } > > + > > if (groupc->state_mask & (1 << PSI_NONIDLE)) > > groupc->times[PSI_NONIDLE] += delta; > > } > > diff --git a/kernel/sched/stats.h b/kernel/sched/stats.h > > index baa839c..bf98829 100644 > > --- a/kernel/sched/stats.h > > +++ b/kernel/sched/stats.h > > @@ -132,6 +132,7 @@ static inline void psi_enqueue(struct task_struct *p, bool wakeup) > > if (p->in_iowait) > > clear |= TSK_IOWAIT; > > } > > + clear |= TSK_UNINTERRUPTIBLE; > > > > psi_task_change(p, clear, set); > > } > > @@ -139,6 +140,7 @@ static inline void psi_enqueue(struct task_struct *p, bool wakeup) > > static inline void psi_dequeue(struct task_struct *p, bool sleep) > > { > > int clear = TSK_RUNNING; > > + int set = 0; > > > > if (static_branch_likely(&psi_disabled)) > > return; > > @@ -154,8 +156,10 @@ static inline void psi_dequeue(struct task_struct *p, bool sleep) > > > > if (p->in_memstall) > > clear |= (TSK_MEMSTALL | TSK_MEMSTALL_RUNNING); > > + if (READ_ONCE(p->__state) & TASK_UNINTERRUPTIBLE) > > + set = TSK_UNINTERRUPTIBLE; > > > > - psi_task_change(p, clear, 0); > > + psi_task_change(p, clear, set); > > } > > > > static inline void psi_ttwu_dequeue(struct task_struct *p)