From patchwork Fri Sep 10 07:54:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaoyang Huang X-Patchwork-Id: 12484537 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,USER_AGENT_GIT autolearn=unavailable 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 CC18BC433F5 for ; Fri, 10 Sep 2021 07:55:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 67993611C0 for ; Fri, 10 Sep 2021 07:55:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 67993611C0 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 02D426B0071; Fri, 10 Sep 2021 03:55:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF7C06B0072; Fri, 10 Sep 2021 03:55:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D98BD900002; Fri, 10 Sep 2021 03:55:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id C37776B0071 for ; Fri, 10 Sep 2021 03:55:07 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7AE7427709 for ; Fri, 10 Sep 2021 07:55:07 +0000 (UTC) X-FDA: 78570903054.17.74CD219 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf24.hostedemail.com (Postfix) with ESMTP id 44954B00009F for ; Fri, 10 Sep 2021 07:55:07 +0000 (UTC) Received: by mail-pf1-f175.google.com with SMTP id q22so1201350pfu.0 for ; Fri, 10 Sep 2021 00:55:07 -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=ud5nsy3x4vqodFGp3SJ1jgpGgfjSxfFrO/uXGKOTbO8=; b=H7Qdh1t61VM/XfXYYNmKrQCNhpOCzsrJJyDL6qjqXx2xRIrLnfrSgiGkuDnZ9DHuz3 g/z2YGwsmkROS4UVwIG4JIE1DuDmzrTGiL18EyLzPHermX1BjBxo9vGmoHyw2QE0je1k 8BqfVyBDb7NxEPl6x+5D1Smvb11+46A7al4Y2EaIQqSe0WCq8p23AnYgxJEFSqBX6cG3 mQtzLWZpMzsOurjbs1z+KRtpnbzObNdkyE5V/tfbuTgH00V7bshTVU08aN9BSzY01vRo f93ksIOFJ+t6NkGvYZHXi3BdRDbN7C72NBFTaxPb3Yj4pil8GRSjmD5tdmBoPkTW7eIY Ahvw== 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=ud5nsy3x4vqodFGp3SJ1jgpGgfjSxfFrO/uXGKOTbO8=; b=b5c/xNTFH79i7WFINBn7MvHuaxRSmDswDgPEL8WRONcQl4mOgBtZocZADevDLYTK72 PRnl1LYbsY6dLNYq0NvEWowaEbl02y5ocxUAr92AO18oJad/OxBTnagdpzFkLcIv9peB nffbKjUzyctO+ETpanR2qGXnU2LpkmiiJMdabg5erQtbV/CXPGVTYftcZYT7lyAbGh+H hCp99970HtcANrK4VBrAqqNb4jUeSTjzU3rqrIzMmDYrXzKx+6O86dOg6JMCiH3wonyF XuQ/FbNWZrcdgdS1eOurWXJCuPzJO6BAcnjuCj3v7k9AtdIhSF7vvljVJBBWYQ0Wku4J CNIQ== X-Gm-Message-State: AOAM533YC5rncMUui4CT8GFQ/OMcnOPEibXCDM5+zXtVqhxipAlofUr4 GgliHuMjLuuOaKIezK/OgHg= X-Google-Smtp-Source: ABdhPJyZwLFdg34fD6CkmHFOd9FXUuEp+2y9uaeg5ptzP3xaY8Nqq93emkw4qAmSySPpa3BGIPOZ0Q== X-Received: by 2002:a63:4b60:: with SMTP id k32mr6257498pgl.198.1631260506172; Fri, 10 Sep 2021 00:55:06 -0700 (PDT) Received: from bj03382pcu.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id i10sm4367098pfk.87.2021.09.10.00.55.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Sep 2021 00:55:05 -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: [PATCH] psi : calc cfs task memstall time more precisely Date: Fri, 10 Sep 2021 15:54:46 +0800 Message-Id: <1631260486-6735-1-git-send-email-huangzhaoyang@gmail.com> X-Mailer: git-send-email 1.7.9.5 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 44954B00009F X-Stat-Signature: 8fitatj47anwtyqx7xwfqmck8tnief6o Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=H7Qdh1t6; spf=pass (imf24.hostedemail.com: domain of huangzhaoyang@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=huangzhaoyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1631260507-195201 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Zhaoyang Huang cfs task's memstall time is counted as simple as exit - entry so far, which ignore the preempted time by rt, dl and irq time. Eliminating them by calc the time growth via the proportion of cfs_rq's utilization on the whole rq. eg. Here is the scenario which this commit want to fix, that is the rt and irq consume some utilization of the whole rq. This scenario could be typical in a core which is assigned to deal with all irqs. Furthermore, the rt task used to run on little core under EAS. Binder:305_3-314 [002] d..1 257.880195: psi_memtime_fixup: original:30616,adjusted:25951,se:89,cfs:353,rt:139,dl:0,irq:18 droid.phone-1525 [001] d..1 265.145492: psi_memtime_fixup: original:61616,adjusted:53492,se:55,cfs:225,rt:121,dl:0,irq:15 Signed-off-by: Zhaoyang Huang --- kernel/sched/psi.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index cc25a3c..754a836 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,21 @@ 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) + growth_fixed = div64_ul((1024 - rq->avg_rt.util_avg - rq->avg_dl.util_avg + - rq->avg_irq.util_avg + 1) * growth, 1024); + + return growth_fixed; +} + static void init_triggers(struct psi_group *group, u64 now) { struct psi_trigger *t; @@ -658,6 +675,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 +946,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); }