From patchwork Thu Sep 9 12:00:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaoyang Huang X-Patchwork-Id: 12482989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7AD2C4332F for ; Thu, 9 Sep 2021 12:01:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 87ACB632D8 for ; Thu, 9 Sep 2021 12:01:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 87ACB632D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id A9B496B0071; Thu, 9 Sep 2021 08:01:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A48B86B0072; Thu, 9 Sep 2021 08:01:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 910E66B0073; Thu, 9 Sep 2021 08:01:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0154.hostedemail.com [216.40.44.154]) by kanga.kvack.org (Postfix) with ESMTP id 7E23F6B0071 for ; Thu, 9 Sep 2021 08:01:43 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1832E18454A45 for ; Thu, 9 Sep 2021 12:01:43 +0000 (UTC) X-FDA: 78567895686.11.B7E4544 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf21.hostedemail.com (Postfix) with ESMTP id C6EC7D02A4C2 for ; Thu, 9 Sep 2021 12:00:42 +0000 (UTC) Received: by mail-pj1-f48.google.com with SMTP id k23-20020a17090a591700b001976d2db364so1249427pji.2 for ; Thu, 09 Sep 2021 05:00:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id; bh=ZyboCNpRKmt5JAGuC0MIfoTudI4GGu+5XsEDI/iZI/k=; b=heUheBnqCJS87W1YfFuV3bopChXvsZsJyAslanU5R2faeilg2Y2QfyPeSgQXo2nCcR r1t2MnJDEUBWM8yiYsD6zqF5vVuM4Tnyuvh3nX0xk64YWJomDzDas3M/eZNOV/9EDb9Z 7RzD+8XVelmSNGrGwWu2c4f4WjqMYjxGzZzEx8fGXikL9rTLw+t4mXI2jSkCYdIWL1xV 7iFX5Bc36oaEJbDLwaTALZm3DRJV6RacT+gba+z2y7kPKdFTTpeLJzMhm9CqwIpncCEk Y/iRNR8QPp5dme85wCCbTWN0rJExoJhUyOIvImZPwByI1/ffHp3YF2wZn5NqXvGrkv0M kLkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id; bh=ZyboCNpRKmt5JAGuC0MIfoTudI4GGu+5XsEDI/iZI/k=; b=QXVNlOxXDc2baP/HJb/G5hGbVKGtKkQPUnceWw963bzi7g5NmbCPQeEB+poah1DXv1 XHCojqzkkxoQRGnDO7hEbi282fdMdiggukhkFNKcHyljFBR6l6NTH1ZyJC3JsR2ZaXdf +Ky/TzAHarvDquQLxYzYeeSRmPldn3yIS8FKXQk2w6bddeJmcmk2MgIV6TmJXLZ08GTK GlL+gSMfvy+UxxNqM/NlmiU/+wuSj1f1lIoHGo8DZCJW67fCt+uzJKMtEkZb7OvT0OcR /p81txKx3x5Eyidc1dh3en3lq/hfJm7WdA5TxfDiJJ8Yfju5AfuLckqe/FqgS1DRrHf8 XS4Q== X-Gm-Message-State: AOAM530xT931yvpG4uvLaRi1NGJ5mOD9Fs9jebMyCy289iHgVD9wbUHI aVw/gSGepLhrNaZWjClRPwk= X-Google-Smtp-Source: ABdhPJxbKK2BNr2HMUEo+ueZywAbPmd5BYIETKPzzMZ6FI1d+MKB+9k3K2jFd6Ak8DLepc5aKG9BsA== X-Received: by 2002:a17:902:a3c1:b0:13a:47a:1c5a with SMTP id q1-20020a170902a3c100b0013a047a1c5amr2412858plb.13.1631188841846; Thu, 09 Sep 2021 05:00:41 -0700 (PDT) Received: from bj03382pcu.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id c9sm2370123pgq.58.2021.09.09.05.00.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Sep 2021 05:00:41 -0700 (PDT) From: Huangzhaoyang To: Johannes Weiner , Zhaoyang Huang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, xuewen.yan@unisoc.com, ke.wang@unisoc.com Subject: [RFC PATCH] psi : calc psi memstall time more precisely Date: Thu, 9 Sep 2021 20:00:24 +0800 Message-Id: <1631188824-25623-1-git-send-email-huangzhaoyang@gmail.com> X-Mailer: git-send-email 1.7.9.5 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C6EC7D02A4C2 X-Stat-Signature: ar7wxkobzgnnzr1ycboguhp7b4jefhjt Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=heUheBnq; spf=pass (imf21.hostedemail.com: domain of huangzhaoyang@gmail.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=huangzhaoyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1631188842-41692 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Zhaoyang Huang psi's memstall time is counted as simple as exit - entry so far, which ignore the task's off cpu time. Fix it by calc the percentage of off time via task and rq's util and runq load. Signed-off-by: Zhaoyang Huang --- kernel/sched/psi.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index cc25a3c..6812c7e 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -182,6 +182,8 @@ struct psi_group psi_system = { static void psi_avgs_work(struct work_struct *work); +static unsigned long psi_memtime_fixup(u32 growth); + static void group_init(struct psi_group *group) { int cpu; @@ -492,6 +494,23 @@ static u64 window_update(struct psi_window *win, u64 now, u64 value) return growth; } +static unsigned long psi_memtime_fixup(u32 growth) +{ + struct rq *rq = task_rq(current); + unsigned long growth_fixed = (unsigned long)growth; + + if !(current->policy == SCHED_NORMAL || current->policy == SCHED_BATCH) + return growth_fixed; + + if ((current->in_memstall) + && (current->se.avg.util_avg <= rq->cfs.avg.util_avg) + && current->se.avg.util_avg != 0) + growth_fixed = div64_ul((current->se.avg.util_avg + 1) * growth, + rq->cfs.avg.util_avg + rq->avg_rt.util_avg + 1); + + return growth_fixed; +} + static void init_triggers(struct psi_group *group, u64 now) { struct psi_trigger *t; @@ -658,6 +677,7 @@ static void record_times(struct psi_group_cpu *groupc, u64 now) } if (groupc->state_mask & (1 << PSI_MEM_SOME)) { + delta = psi_memtime_fixup(delta); groupc->times[PSI_MEM_SOME] += delta; if (groupc->state_mask & (1 << PSI_MEM_FULL)) groupc->times[PSI_MEM_FULL] += delta; @@ -928,8 +948,8 @@ void psi_memstall_leave(unsigned long *flags) */ rq = this_rq_lock_irq(&rf); - current->in_memstall = 0; psi_task_change(current, TSK_MEMSTALL, 0); + current->in_memstall = 0; rq_unlock_irq(rq, &rf); }