From nobody Sat Apr 11 19:44:41 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C940C00140 for ; Mon, 8 Aug 2022 06:20:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232511AbiHHGUf (ORCPT ); Mon, 8 Aug 2022 02:20:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbiHHGUa (ORCPT ); Mon, 8 Aug 2022 02:20:30 -0400 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34C74272A for ; Sun, 7 Aug 2022 23:20:27 -0700 (PDT) Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTPS id 2786DVQ5076732 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Mon, 8 Aug 2022 14:13:31 +0800 (CST) (envelope-from zhaoyang.huang@unisoc.com) Received: from bj03382pcu.spreadtrum.com (10.0.74.65) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 8 Aug 2022 14:13:31 +0800 From: "zhaoyang.huang" To: Johannes Weiner , Suren Baghdasaryan , Zhaoyang Huang , , , Subject: [RFC PATCH] psi: introduce PSI UNINTERRUPTIBLE Date: Mon, 8 Aug 2022 14:13:28 +0800 Message-ID: <1659939208-22454-1-git-send-email-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.0.74.65] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 2786DVQ5076732 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 grou= p, while get nothing high for none of the pressures, which could be the processes wi= thin are stock in some given resources and turn to be UN status. Introduce PSI_U= N as a sub-type among PSI system here. 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 =3D 5, + NR_PSI_TASK_COUNTS =3D 6, }; =20 /* 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) =20 /* Resources that workloads could be stalled on */ enum psi_res { PSI_IO, PSI_MEM, PSI_CPU, - NR_PSI_RESOURCES =3D 3, + PSI_UN, + NR_PSI_RESOURCES =3D 4, }; =20 /* @@ -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 =3D 7, + NR_PSI_STATES =3D 9, }; =20 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_s= tates 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] +=3D delta; } =20 + if (groupc->state_mask & (1 << PSI_UN_SOME)) { + groupc->times[PSI_UN_SOME] +=3D delta; + if (groupc->state_mask & (1 << PSI_UN_FULL)) + groupc->times[PSI_UN_FULL] +=3D delta; + } + if (groupc->state_mask & (1 << PSI_NONIDLE)) groupc->times[PSI_NONIDLE] +=3D 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, b= ool wakeup) if (p->in_iowait) clear |=3D TSK_IOWAIT; } + clear |=3D TSK_UNINTERRUPTIBLE; =20 psi_task_change(p, clear, set); } @@ -139,6 +140,7 @@ static inline void psi_enqueue(struct task_struct *p, b= ool wakeup) static inline void psi_dequeue(struct task_struct *p, bool sleep) { int clear =3D TSK_RUNNING; + int set =3D 0; =20 if (static_branch_likely(&psi_disabled)) return; @@ -154,8 +156,10 @@ static inline void psi_dequeue(struct task_struct *p, = bool sleep) =20 if (p->in_memstall) clear |=3D (TSK_MEMSTALL | TSK_MEMSTALL_RUNNING); + if (READ_ONCE(p->__state) & TASK_UNINTERRUPTIBLE) + set =3D TSK_UNINTERRUPTIBLE; =20 - psi_task_change(p, clear, 0); + psi_task_change(p, clear, set); } =20 static inline void psi_ttwu_dequeue(struct task_struct *p) --=20 1.9.1