Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp23626img; Tue, 19 Mar 2019 16:58:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFrj5pLEZWn4HPc7e77IRQz7KJV533plEMZqD1gYzuny1ik6hmIz1BS33RD5t3phammVfn X-Received: by 2002:a17:902:930b:: with SMTP id bc11mr28709578plb.101.1553039890214; Tue, 19 Mar 2019 16:58:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553039890; cv=none; d=google.com; s=arc-20160816; b=PCMnjNuteCR9cI4Jy/5P9lNhwnrv1CnXlnfdyGD4HCHdwZv931wSsRO8GRTrRbFFdP 9Hi1ppQPMnoO7ITfWgsK2dIj4SSnyeIfOFlyklxCXJVFZhxKhgKEVEM6daCr3/6GE2nj aKoiQ7hXQPM6UgcmGeCM057vqlOLJ+0q1ok149GkvNbasRvfm2CiZvVIuz+PztUAklqb FA7pTIXg4FYnUapllmOQTBm5BT/5aZDSnd9wjXkexPyuvSQxojUU/9fIrHO+RDNqvMSW wHYAF9v9z9pqCztezXuuLbwub9k2uuUx8QlvePMO3jPBEjQALup3bdxlZIeI1FzZ3qPJ Oq6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=dn6PEiCR+dScVGu5EewnvuQCwpS0GucFANxBNtI0jyg=; b=06sNTNycnAHwkggcwbz4SfW6g4SzF86gx6w1moL599Z3k4bvc5C+V7+ik5G5xU9YmT /IBzVz0w1b30JjeZgfmi3aapxRKm1znq9GWDsOOFR+5JXwbmdIP1KdsVUFpwJu/J8Y/C x9TjPq/kLkzHQ9NfIxJv4q4UE3A73YphhBPsfto04ywK1gTOT6d2Oi/WpKdNaWvoujQk fOEkScjnvW8lfgI7Ep6TaGD9PrVksxlUl9fARpe4EPdcwIXSXcaVMwgKkzokZ3/ds2Hx QkJCIEMw5BvH7U30FxYx2gvlpFmkIXWaUpRvJQJ87b5PbBiNr+ThLSep4djY0DxO3Xoo ClaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Z6b442+6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t23si226168pgv.63.2019.03.19.16.57.55; Tue, 19 Mar 2019 16:58:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Z6b442+6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727520AbfCSX4m (ORCPT + 99 others); Tue, 19 Mar 2019 19:56:42 -0400 Received: from mail-yw1-f74.google.com ([209.85.161.74]:39187 "EHLO mail-yw1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727480AbfCSX4i (ORCPT ); Tue, 19 Mar 2019 19:56:38 -0400 Received: by mail-yw1-f74.google.com with SMTP id p1so687792ywm.6 for ; Tue, 19 Mar 2019 16:56:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=dn6PEiCR+dScVGu5EewnvuQCwpS0GucFANxBNtI0jyg=; b=Z6b442+6DNI/wL3Sl+GmBfCDemyRgLchS2XX8vUdUBCLvLTr6SRAXAFrKle3CWKt83 v/Lyw5vroFag4ZNItRCs1E2AW0rTWPfFeUTPo1GonT4xq3BSGy7UAoDlpLr8wfzd4dEk cAQsQM3nDSIJoKigdyekrTeWCnEDlgdImc40cSqjYKkcrN0irpacS5iuUwz+nNKTfCj6 gN9agbjk3JafwYtdbZcJrSQ9KVE5u5RPfTsRdqFUk6odVENAIbN2URKCX146f8h3tIki tQqvJcideceDh5tkn6j7mXS/7dCIydNbwoCEy1XZmg00rksFqoQLHtmFE2PGru24T2ue Q36A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=dn6PEiCR+dScVGu5EewnvuQCwpS0GucFANxBNtI0jyg=; b=GLSchV1JvDLO2mWlH7aT3FpN1KVd2PahXDpX2+WKGl6p1fZJMxGKAaGxZQj+HsaH9D thuN6v7thh8CCTg/w2j5YDsl5xpuvSB5sSEJjO3l4+7vN9u9jsE+Z2uJJKdWWkqlOwOb V8yFXSAWAAmrVwGDfzjT5vUC0YtPjFa41h7VnDuqBQmr7XNk3qX1YXxwzQQPA9AlV9jG 0bitezsJDsnpjOPxQPO0iw1CeK2cIPY8YfxFhUKfCEmpJBLxEhSSWgAa/61TnbC2EVcr 9j/SS0tIkxIEmP6MIW4jURgM8FMp0oeQ/YZXV7UnrA5HwV+nCcR+8lzqYNm4pTNd5tqd ewcA== X-Gm-Message-State: APjAAAUL+7jteQTiqq8ps57rXMPE0FwnFEFGC2l54G2Rsw3CxfLoZGnM 6Aa8n4tJS4VbvgLb5YC3LiQnSkbppkM= X-Received: by 2002:a25:ae96:: with SMTP id b22mr1664495ybj.94.1553039797316; Tue, 19 Mar 2019 16:56:37 -0700 (PDT) Date: Tue, 19 Mar 2019 16:56:16 -0700 In-Reply-To: <20190319235619.260832-1-surenb@google.com> Message-Id: <20190319235619.260832-5-surenb@google.com> Mime-Version: 1.0 References: <20190319235619.260832-1-surenb@google.com> X-Mailer: git-send-email 2.21.0.225.g810b269d1ac-goog Subject: [PATCH v6 4/7] psi: split update_stats into parts From: Suren Baghdasaryan To: gregkh@linuxfoundation.org Cc: tj@kernel.org, lizefan@huawei.com, hannes@cmpxchg.org, axboe@kernel.dk, dennis@kernel.org, dennisszhou@gmail.com, mingo@redhat.com, peterz@infradead.org, akpm@linux-foundation.org, corbet@lwn.net, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Suren Baghdasaryan Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split update_stats into collect_percpu_times and update_averages for collect_percpu_times to be reused later inside psi monitor. Signed-off-by: Suren Baghdasaryan --- kernel/sched/psi.c | 57 +++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 4fb4d9913bc8..ace5ed97b186 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -269,17 +269,13 @@ static void calc_avgs(unsigned long avg[3], int missed_periods, avg[2] = calc_load(avg[2], EXP_300s, pct); } -static bool update_stats(struct psi_group *group) +static bool collect_percpu_times(struct psi_group *group) { u64 deltas[NR_PSI_STATES - 1] = { 0, }; - unsigned long missed_periods = 0; unsigned long nonidle_total = 0; - u64 now, expires, period; int cpu; int s; - mutex_lock(&group->avgs_lock); - /* * Collect the per-cpu time buckets and average them into a * single time sample that is normalized to wallclock time. @@ -317,11 +313,18 @@ static bool update_stats(struct psi_group *group) for (s = 0; s < NR_PSI_STATES - 1; s++) group->total[s] += div_u64(deltas[s], max(nonidle_total, 1UL)); + return nonidle_total; +} + +static u64 update_averages(struct psi_group *group, u64 now) +{ + unsigned long missed_periods = 0; + u64 expires, period; + u64 avg_next_update; + int s; + /* avgX= */ - now = sched_clock(); expires = group->avg_next_update; - if (now < expires) - goto out; if (now - expires >= psi_period) missed_periods = div_u64(now - expires, psi_period); @@ -332,7 +335,7 @@ static bool update_stats(struct psi_group *group) * But the deltas we sample out of the per-cpu buckets above * are based on the actual time elapsing between clock ticks. */ - group->avg_next_update = expires + ((1 + missed_periods) * psi_period); + avg_next_update = expires + ((1 + missed_periods) * psi_period); period = now - (group->avg_last_update + (missed_periods * psi_period)); group->avg_last_update = now; @@ -362,9 +365,8 @@ static bool update_stats(struct psi_group *group) group->avg_total[s] += sample; calc_avgs(group->avg[s], missed_periods, sample, period); } -out: - mutex_unlock(&group->avgs_lock); - return nonidle_total; + + return avg_next_update; } static void psi_avgs_work(struct work_struct *work) @@ -372,10 +374,16 @@ static void psi_avgs_work(struct work_struct *work) struct delayed_work *dwork; struct psi_group *group; bool nonidle; + u64 now; dwork = to_delayed_work(work); group = container_of(dwork, struct psi_group, avgs_work); + mutex_lock(&group->avgs_lock); + + now = sched_clock(); + + nonidle = collect_percpu_times(group); /* * If there is task activity, periodically fold the per-cpu * times and feed samples into the running averages. If things @@ -383,19 +391,15 @@ static void psi_avgs_work(struct work_struct *work) * Once restarted, we'll catch up the running averages in one * go - see calc_avgs() and missed_periods. */ - - nonidle = update_stats(group); + if (now >= group->avg_next_update) + group->avg_next_update = update_averages(group, now); if (nonidle) { - unsigned long delay = 0; - u64 now; - - now = sched_clock(); - if (group->avg_next_update > now) - delay = nsecs_to_jiffies( - group->avg_next_update - now) + 1; - schedule_delayed_work(dwork, delay); + schedule_delayed_work(dwork, nsecs_to_jiffies( + group->avg_next_update - now) + 1); } + + mutex_unlock(&group->avgs_lock); } static void record_times(struct psi_group_cpu *groupc, int cpu, @@ -707,11 +711,18 @@ void cgroup_move_task(struct task_struct *task, struct css_set *to) int psi_show(struct seq_file *m, struct psi_group *group, enum psi_res res) { int full; + u64 now; if (static_branch_likely(&psi_disabled)) return -EOPNOTSUPP; - update_stats(group); + /* Update averages before reporting them */ + mutex_lock(&group->avgs_lock); + now = sched_clock(); + collect_percpu_times(group); + if (now >= group->avg_next_update) + group->avg_next_update = update_averages(group, now); + mutex_unlock(&group->avgs_lock); for (full = 0; full < 2 - (res == PSI_CPU); full++) { unsigned long avg[3]; -- 2.21.0.225.g810b269d1ac-goog