From patchwork Fri Dec 14 17:15:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 10731489 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C744F746 for ; Fri, 14 Dec 2018 17:16:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2335A2C807 for ; Fri, 14 Dec 2018 17:16:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1754F2D8F5; Fri, 14 Dec 2018 17:16:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 826032C807 for ; Fri, 14 Dec 2018 17:16:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E34E8E01F8; Fri, 14 Dec 2018 12:16:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5BA248E01DC; Fri, 14 Dec 2018 12:16:25 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D2178E01F8; Fri, 14 Dec 2018 12:16:25 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id 0F35F8E01DC for ; Fri, 14 Dec 2018 12:16:25 -0500 (EST) Received: by mail-pf1-f198.google.com with SMTP id 82so4851036pfs.20 for ; Fri, 14 Dec 2018 09:16:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=YwSYAI43KM10GrnM4hZ3Qtd3y6BkTcR7ZHO9M+skX2s=; b=B26J0xHp3RAjTbQCtXuTyVUZILuMq1e58iwiTnKk6YFhk9BS752ej1FaPQ/pmUPn+X JLgGJeEmbFbRhGIxsih8cqUpLT5i+6ai8GZCTnamcysPPTYT+GAkP9DeBD3M7FxIYppU 0PVZEfi30tG5+5zw5qLKZAVceFZNhXvl4GFNgwpdlxSzCC+3XAmaLjsZGv6G5dPim0LN DPKEFcUBxvpfOH/wxB0UHLkAuSXCGS5iFIp0YM/Z73EHBEFBLa9P071sZQZhuHC7LJtt zJqfXPNB+UHbiPmi09OtRWTmCx9BmupLAsUf2fLFVqA/tH1ZRwhdOhu6fsKLFNVhId9E f/Nw== X-Gm-Message-State: AA+aEWYTIM/ZCEmomc++0WfVXSGXNCkD7ppOtSF90ZapKNJaGvd6X3As nDuce8aajMzpMcciiN1u/Lr6kzTly3PVJsk9EON5LkIbfAFmla6Hg3+P2rQQPyoDv58zCIEXrtl EUwadBbC0Zr5LrGgB4ko19MyjfRrWzpRae0akPfCBNn5jCqMA+CzW8c6ZmNDrEQubnNRofmRGHx OrhKbIPiOvrvsxPEe0CidGwFJB5u//zIRdUNCD0K/SttaTtYPZ0NyVAG5RUxLVXpFyzkX6dU6Jt GbAEfNWuDEM97IpHfnyKCGNHdqg5kbPQMJQQ/MLpnpXTu6zKvjiHcyf3qkADTyc/QIbsmng6+kc YBa1t/WbU7VAleci1NuUt10DpEOfgH6M0z4VOPInZ3B5nyliYjYjgKM8HbNrnJYe3MpeKNJygn2 E X-Received: by 2002:a63:85c6:: with SMTP id u189mr3303831pgd.156.1544807784730; Fri, 14 Dec 2018 09:16:24 -0800 (PST) X-Received: by 2002:a63:85c6:: with SMTP id u189mr3303771pgd.156.1544807783877; Fri, 14 Dec 2018 09:16:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544807783; cv=none; d=google.com; s=arc-20160816; b=OR3T4mZVsB3Pa5RrFP43CY9HefVV6SH4ysHrvXXoKyyBbUhQuB9vAsQGF1X0yNbT0h mkP/UQlBqsSay0Tn1sDKMftYJjSuQ2PYH5qBG78RYQeY2oLpsnU6KMooLR2ocXBG597X P29CN7d+wlvPoRaREbVXFmV5wR7bWDDJ+mnOB2i5sCNtJDRyMkWyNYGfS0rvx+T+GFzb qK+xocTrVNiJV2H71ujm6wmxPB5O5XFAPQrlY88USziJAPoWSzN9xhHUVqyGZUqV0OvB DTiZ3Y2Y5d8lDHLa6ZR3VrsImm9WCR1sSeW9ZNYV21cunllpVUrqwuKmjWJnqsZBdALp 36Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=YwSYAI43KM10GrnM4hZ3Qtd3y6BkTcR7ZHO9M+skX2s=; b=ZfgF34L9/xveIVOQwUxh3HBHq+62m0K259Ju5KfI3EMIis2GYm9znqpW4VT/D8hntJ ztYqjURqgc2fGmRq6QkLQ5/mC6Rif7pTY+bEpQoJtWaMs671BakGPWQDCwHl737ZSMel 7sLmDaY/y7IJnQYAcQTP5GvXn9cMkV8hYarbXdtAqMjVsv3pyfSa/yjBOcW0Srsi1Gr7 xJEpMBkaYypA/3Zu3nJ/Kl05wF357l/iBLdo9f1FLsy1Jg5eihURz0by51YS9x4Ssx1U xtciLxc8amyoYu2j21egZr3YfV3Q+gle9yppg/oRpz2IcPm97CxJ3lcS85gdFMRPOj+P OpOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=akXIWndi; spf=pass (google.com: domain of surenb@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id w11sor8347559ply.14.2018.12.14.09.16.23 for (Google Transport Security); Fri, 14 Dec 2018 09:16:23 -0800 (PST) Received-SPF: pass (google.com: domain of surenb@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=akXIWndi; spf=pass (google.com: domain of surenb@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YwSYAI43KM10GrnM4hZ3Qtd3y6BkTcR7ZHO9M+skX2s=; b=akXIWndiUHaos9TbyNLP3xeaC0ZtOOtr3cSf/ilsoUM7WywehoLoqyXEZzuFIORB9M OvxzyeHc32Q4lx447L/4jMQROuD8Tpifnb+eTjanco+ff7o+IwZScCVw5XFu71NXZHQx h65SJNlG1uCZ+LcxQFWTzPj27rLKDsz7X5nBwYOPjf33icL9nUeUcN8H4DxeA2dJ2CoJ u04GoPkgs3B2NaoDOzsMLnvT61RyHEVW0r29CnBfMfhJUd+xuXxPuur/lVVYkfCIPun7 /axdZ+sXYAdccL5hZ+AL8HqqFeX7QG3R9jGqHbyBu5W6pW9dZ01ISpGwMqGQkIolMen/ 1COA== X-Google-Smtp-Source: AFSGD/UnqpC986vJpvC7OunDuj94mE83rlw4ebocm39rs/p+lo9QYqHHDyqOGddBMnR+LPZQxbTwJQ== X-Received: by 2002:a17:902:b20e:: with SMTP id t14mr3653918plr.128.1544807783288; Fri, 14 Dec 2018 09:16:23 -0800 (PST) Received: from surenb0.mtv.corp.google.com ([2620:0:1000:1612:3320:4357:47df:276b]) by smtp.googlemail.com with ESMTPSA id g185sm7605761pfc.174.2018.12.14.09.16.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Dec 2018 09:16:21 -0800 (PST) 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 Subject: [PATCH 4/6] psi: introduce state_mask to represent stalled psi states Date: Fri, 14 Dec 2018 09:15:06 -0800 Message-Id: <20181214171508.7791-5-surenb@google.com> X-Mailer: git-send-email 2.20.0.405.gbc1bbc6f85-goog In-Reply-To: <20181214171508.7791-1-surenb@google.com> References: <20181214171508.7791-1-surenb@google.com> MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP The psi monitoring patches will need to determine the same states as record_times(). To avoid calculating them twice, maintain a state mask that can be consulted cheaply. Do this in a separate patch to keep the churn in the main feature patch at a minimum. Signed-off-by: Suren Baghdasaryan --- include/linux/psi_types.h | 3 +++ kernel/sched/psi.c | 29 +++++++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h index 2cf422db5d18..2c6e9b67b7eb 100644 --- a/include/linux/psi_types.h +++ b/include/linux/psi_types.h @@ -53,6 +53,9 @@ struct psi_group_cpu { /* States of the tasks belonging to this group */ unsigned int tasks[NR_PSI_TASK_COUNTS]; + /* Aggregate pressure state derived from the tasks */ + u32 state_mask; + /* Period time sampling buckets for each state of interest (ns) */ u32 times[NR_PSI_STATES]; diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index d2b9c9a1a62f..153c0624976b 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -212,17 +212,17 @@ static bool test_state(unsigned int *tasks, enum psi_states state) static void get_recent_times(struct psi_group *group, int cpu, u32 *times) { struct psi_group_cpu *groupc = per_cpu_ptr(group->pcpu, cpu); - unsigned int tasks[NR_PSI_TASK_COUNTS]; u64 now, state_start; + enum psi_states s; unsigned int seq; - int s; + u32 state_mask; /* Snapshot a coherent view of the CPU state */ do { seq = read_seqcount_begin(&groupc->seq); now = cpu_clock(cpu); memcpy(times, groupc->times, sizeof(groupc->times)); - memcpy(tasks, groupc->tasks, sizeof(groupc->tasks)); + state_mask = groupc->state_mask; state_start = groupc->state_start; } while (read_seqcount_retry(&groupc->seq, seq)); @@ -238,7 +238,7 @@ static void get_recent_times(struct psi_group *group, int cpu, u32 *times) * (u32) and our reported pressure close to what's * actually happening. */ - if (test_state(tasks, s)) + if (state_mask & (1 << s)) times[s] += now - state_start; delta = times[s] - groupc->times_prev[s]; @@ -390,15 +390,15 @@ static void record_times(struct psi_group_cpu *groupc, int cpu, delta = now - groupc->state_start; groupc->state_start = now; - if (test_state(groupc->tasks, PSI_IO_SOME)) { + if (groupc->state_mask & (1 << PSI_IO_SOME)) { groupc->times[PSI_IO_SOME] += delta; - if (test_state(groupc->tasks, PSI_IO_FULL)) + if (groupc->state_mask & (1 << PSI_IO_FULL)) groupc->times[PSI_IO_FULL] += delta; } - if (test_state(groupc->tasks, PSI_MEM_SOME)) { + if (groupc->state_mask & (1 << PSI_MEM_SOME)) { groupc->times[PSI_MEM_SOME] += delta; - if (test_state(groupc->tasks, PSI_MEM_FULL)) + if (groupc->state_mask & (1 << PSI_MEM_FULL)) groupc->times[PSI_MEM_FULL] += delta; else if (memstall_tick) { u32 sample; @@ -419,10 +419,10 @@ static void record_times(struct psi_group_cpu *groupc, int cpu, } } - if (test_state(groupc->tasks, PSI_CPU_SOME)) + if (groupc->state_mask & (1 << PSI_CPU_SOME)) groupc->times[PSI_CPU_SOME] += delta; - if (test_state(groupc->tasks, PSI_NONIDLE)) + if (groupc->state_mask & (1 << PSI_NONIDLE)) groupc->times[PSI_NONIDLE] += delta; } @@ -431,6 +431,8 @@ static void psi_group_change(struct psi_group *group, int cpu, { struct psi_group_cpu *groupc; unsigned int t, m; + enum psi_states s; + u32 state_mask = 0; groupc = per_cpu_ptr(group->pcpu, cpu); @@ -463,6 +465,13 @@ static void psi_group_change(struct psi_group *group, int cpu, if (set & (1 << t)) groupc->tasks[t]++; + /* Calculate state mask representing active states */ + for (s = 0; s < NR_PSI_STATES; s++) { + if (test_state(groupc->tasks, s)) + state_mask |= (1 << s); + } + groupc->state_mask = state_mask; + write_seqcount_end(&groupc->seq); }