Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp23284img; Tue, 19 Mar 2019 16:57:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqyl6QxFYlIFku9b6CqNy79zuybkscvve7JjueMQuC1AxzDmgHo3x7rsEpfaeNNHqN0Epe64 X-Received: by 2002:a17:902:127:: with SMTP id 36mr4825179plb.268.1553039852496; Tue, 19 Mar 2019 16:57:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553039852; cv=none; d=google.com; s=arc-20160816; b=Q8S3J/l+WjnieSt/OyDMfQgoweYzR/tSZYaVb2MPmiESkLIntUwQ1R0ZCEopxMUqSW eiEq2rp87QxDBJAjw3F1jggCyNLDdhkhIke88eY77omGw4GgfjHocXhK/0leQlnGEiyD QNmsMzSZJah+qxum3k7JF38TxEGhGf7NWqqZiwivdm9/ldEKX5+NdWU70I3/UNx05fEi c0GEd/1IUaqF8cBj0ABtIwwPQzC+sm+MXublNdRAjFCTUdlLQBbK2gVQqBkHXLjwADzg ZAn0opvXtRMAcQwiI29/oHqsz3O1uX1ZkzccWc2gh3/1ZmZd5T4XfStkHrMN0r26/hmE oTlQ== 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=BhrmowS2eMjbffJ9OB92bQfOOAToNjJ94P17cQjPdo8=; b=dWii9p2c279m1oqZK/X88FHURfIQevJfbqABywV4cAYr0BcTytde7/vtgaF0PmfZJI bcrCMJX6pYXhm9Q7zI2uyN2ZP9qDI8BPZX6060A5m1g8Yw6iyWGg49myB55pxoZBRq4f j7lSISQCk4+SFUL/u6dD+l6qtkAjinqvMbjMR81WWUXEAwEeEMx9ZLq0HuWwtGqOnZl5 Kl5kFH30zn7N+bsylYq4CbXcDfRRi0xR8/hIj0nrnW7B01xf9iVAYhJbXsCiGborXozT /fgi8t/WBU2X2UEm3dfRSR9JhOxOot7hgLqaLGbCo3o798AZbeXLHWw2qWX/d0NuxU8c qM9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=s39qkpCi; 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 o3si230590pgh.189.2019.03.19.16.57.17; Tue, 19 Mar 2019 16:57:32 -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=s39qkpCi; 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 S1727415AbfCSX4c (ORCPT + 99 others); Tue, 19 Mar 2019 19:56:32 -0400 Received: from mail-it1-f201.google.com ([209.85.166.201]:50541 "EHLO mail-it1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726686AbfCSX4a (ORCPT ); Tue, 19 Mar 2019 19:56:30 -0400 Received: by mail-it1-f201.google.com with SMTP id i63so637661itb.0 for ; Tue, 19 Mar 2019 16:56:30 -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=BhrmowS2eMjbffJ9OB92bQfOOAToNjJ94P17cQjPdo8=; b=s39qkpCiLoow4b9/kgH0brUOsB6xmuRjJsD/eb1HqzNYh9jtmiyICnlIREYYOCKL88 kXqqEiT1p592C2CJ41x570vo4IJQ+qIpXP1mS4NZTtgimX1bxdcuhLtuhXWjoT7rB8Dn cCHD7VVysNVpuZas/uyx34+spsa3iuS9UElEGU+wOJpvGuxLM1+50lBJdu72gwMh/7wj CCzhl3Pdf2CzqMNOj5pObXsCmj1nUNiS+EioFVGTxI0M1+2nuPhekgCPfSV6zecvX9yc rPXVPjJj0/fg2QH1UnaNfhmCPCuO7XIQEvbgcqFXz50DTetnIuZxNs6cQ/pmXD0+ZpAY nC8Q== 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=BhrmowS2eMjbffJ9OB92bQfOOAToNjJ94P17cQjPdo8=; b=dHHKZnSVApS9pls8/kXp0swk2VzA5wEQmaJ0tgbqWzFD4pWTeNd5hL2mVhSH8/rnjX Dpv1WF5J+Rqz1CXbfNl2Zd8b76nD5SzA2ZZ8EjDQ21ajacx/ZlMTmo0+1UK6oamAgpWi pq3UCYDVVf7yI5fU5nZ/13y1xs4V7B6NlQoLjxk2mYnu/uT6AE+VN9xcjzQK5izJ26Va //vBwS8wVJtcxOW33Dmd1qrYrGSAz2dajuUfFDnGl+iV3Tkh+fj2X3wkFkye/OJiunb1 supemDdh8REldyBAAeYvKPTe9YsDr17nyj/cpRaimietaSIqDJZNLXueWRGDjdXiWUEP Gppg== X-Gm-Message-State: APjAAAUqO8USsDIO46d/l/iCyen2y9hZTQTNinagv9V34XmMyBrJE2c5 h3gsGHLS3KnSsXzFc1Wdy8tz2oPAIpY= X-Received: by 2002:a24:6545:: with SMTP id u66mr3145504itb.36.1553039789710; Tue, 19 Mar 2019 16:56:29 -0700 (PDT) Date: Tue, 19 Mar 2019 16:56:13 -0700 In-Reply-To: <20190319235619.260832-1-surenb@google.com> Message-Id: <20190319235619.260832-2-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 1/7] psi: introduce state_mask to represent stalled psi states 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 , Stephen Rothwell 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 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. This adds 4-byte state_mask member into psi_group_cpu struct which results in its first cacheline-aligned part becoming 52 bytes long. Add explicit values to enumeration element counters that affect psi_group_cpu struct size. Link: http://lkml.kernel.org/r/20190124211518.244221-4-surenb@google.com Signed-off-by: Suren Baghdasaryan Acked-by: Johannes Weiner Cc: Dennis Zhou Cc: Ingo Molnar Cc: Jens Axboe Cc: Li Zefan Cc: Peter Zijlstra Cc: Tejun Heo Signed-off-by: Andrew Morton Signed-off-by: Stephen Rothwell --- include/linux/psi_types.h | 9 ++++++--- kernel/sched/psi.c | 29 +++++++++++++++++++---------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/include/linux/psi_types.h b/include/linux/psi_types.h index 2cf422db5d18..762c6bb16f3c 100644 --- a/include/linux/psi_types.h +++ b/include/linux/psi_types.h @@ -11,7 +11,7 @@ enum psi_task_count { NR_IOWAIT, NR_MEMSTALL, NR_RUNNING, - NR_PSI_TASK_COUNTS, + NR_PSI_TASK_COUNTS = 3, }; /* Task state bitmasks */ @@ -24,7 +24,7 @@ enum psi_res { PSI_IO, PSI_MEM, PSI_CPU, - NR_PSI_RESOURCES, + NR_PSI_RESOURCES = 3, }; /* @@ -41,7 +41,7 @@ enum psi_states { PSI_CPU_SOME, /* Only per-CPU, to weigh the CPU in the global average: */ PSI_NONIDLE, - NR_PSI_STATES, + NR_PSI_STATES = 6, }; struct psi_group_cpu { @@ -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 0e97ca9306ef..22c1505ad290 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -213,17 +213,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)); @@ -239,7 +239,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]; @@ -407,15 +407,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; @@ -436,10 +436,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; } @@ -448,6 +448,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); @@ -480,6 +482,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); } -- 2.21.0.225.g810b269d1ac-goog