Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp46241imm; Tue, 21 Aug 2018 14:17:35 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxs9p7fBuurd6/WgGMJsQ8IkLv66MWdcha/1lppGtSSGkLwuuH07EN6ubrURFlBp1s6FxGk X-Received: by 2002:a17:902:e85:: with SMTP id 5-v6mr19364495plx.73.1534886255298; Tue, 21 Aug 2018 14:17:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534886255; cv=none; d=google.com; s=arc-20160816; b=DaNvnCzYX+Xtww8037awOuf4kizpipJU3JTWqdRclp96G0pfrQK7BbpoOgr8bY00uU 756YEfPa0zlzZ1RE1NuPrzIvGw2D3P0YICiFRr64/fmthRYv1uX1yrDKUddxkWisYQbY NhIGLeF3BIK5dRz45fiTH0+UUdhW5MxItklxBHJNHeDYqiSwmJ6IWF7TcM7/pZzbcHWF 58SOHeG5wx+ZRgEYAwjMZzOSg5fGsAJknsuIChvNOiIPQNIF1X1L5zaAttaHUlYHv+Or MpeMBjSMjcMW8kYT1HQ1UVRcj8DHLFchWradQLAXi3fln7qTRO7gUOPAVNO+yR93tcBZ ptYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=b2WGfRK2+UA3n6bV2KvevrdkLr5T4x/xhZPGefawB/E=; b=xKuejMHQDGR93KG4hx39n9DH077thEQuRo/AkhNkLf1Y8ufkoPwSBu8h1EWRRKr7t7 BwZD9doepdv2J5lpSga/PHASuykzEOKu1p4e8ksMoNVXL/cwYDmzCupeJqLQfAdNEuEq Y90l3IVRX+azIVw4OkMP1iAUgYRn94kiBOwsENJ63p5HCnLoSak6vZZVKHSdoHTIv5nz 10tMZai/V4srFU9C414SVDCHh9hRihFggOBWjfFBBLMJ9iz/91X9sFhcSlky784J27gA 4FD77CpZxJ/MbgfG/vFcTwV/mCJEVUKsmBPkQXyd6kVlfcy5IRghfq4PekRpeqNJumbU nLww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=o0nzq8ek; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g9-v6si13180375plo.23.2018.08.21.14.16.57; Tue, 21 Aug 2018 14:17:35 -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=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=o0nzq8ek; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727669AbeHUXcy (ORCPT + 99 others); Tue, 21 Aug 2018 19:32:54 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:33858 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726881AbeHUXcy (ORCPT ); Tue, 21 Aug 2018 19:32:54 -0400 Received: by mail-yw1-f65.google.com with SMTP id y134-v6so4773025ywg.1 for ; Tue, 21 Aug 2018 13:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=b2WGfRK2+UA3n6bV2KvevrdkLr5T4x/xhZPGefawB/E=; b=o0nzq8ek18Q1D6sMjAvusJvF2jBYjGTSBe2M/32qfESQfgfzNcAIN+mVo2f8t3Jq3z DB5HNYVH4CzZYoNm1mzGCFAcZ+XCwy7HlrU5LVlKptFjZaTjh/b68PAfpclmFX+8lMpQ rP4qadGIbCTtYXHsXXQoasipYQFo871Hl2p2bdpaLtbmVurpejhT/B4uknKeA0jLMkva +a/3kb0JzErn/7iTfRGKpY6lHO8WnCu/6HWrBnZNzcR9ZwQkAlMIybI8jIHkBtxlKtXW qk4j9o9JS1x5LEzo/sS7ZZXgE5Y1Wz+0+Ibah3A4i6kM0w48TD3tw0kbkE57ZyPJgHVG 9NDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=b2WGfRK2+UA3n6bV2KvevrdkLr5T4x/xhZPGefawB/E=; b=Caj+0NUsEa9F18PCxXxNb/c3ChVSN8iske9K6EyM1RUkCwE8GwEeJrNj18h4pWr58z QTkOiVwIk3gdQIbEgfH3czLA3PhTOlYlYLRqLia1luXww22KyE/O95m6XNELHDBNbOXO AGZnvQH4pA6Dt6YTBLi6naggamYyyvbQGK0CebJDz62lMYaiBgbo+yNsCeZ7btr4Nk5y UvnlvMqUBX6/bSo9mRutIEi3hqitdhObXXaEISnTEXMd5HQEKvh28A6bvNpwkcq8R9Zh h5O1QW9zafC0KSwRTCkGkwz3n4tIIeMYp9aHUsAS2Zpgwi1SiHk5kZvUJYD08g3vJDgr RIXA== X-Gm-Message-State: APzg51CvQ41oBReVF4GjeZ7Asn+AqvZ3YpLMd4LVlmY8oFwitaZJTsbV VvVLZi7DUzM339L0H6XWA0vvCQ== X-Received: by 2002:a81:590b:: with SMTP id n11-v6mr5137937ywb.352.1534882277857; Tue, 21 Aug 2018 13:11:17 -0700 (PDT) Received: from localhost ([2620:10d:c091:200::3:17a0]) by smtp.gmail.com with ESMTPSA id o74-v6sm1589985ywo.54.2018.08.21.13.11.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Aug 2018 13:11:16 -0700 (PDT) Date: Tue, 21 Aug 2018 16:11:15 -0400 From: Johannes Weiner To: Peter Zijlstra Cc: Ingo Molnar , Andrew Morton , Linus Torvalds , Tejun Heo , Suren Baghdasaryan , Daniel Drake , Vinayak Menon , Christopher Lameter , Mike Galbraith , Shakeel Butt , Peter Enderborg , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: Re: [PATCH 8/9] psi: pressure stall information for CPU, memory, and IO Message-ID: <20180821201115.GB24538@cmpxchg.org> References: <20180801151958.32590-1-hannes@cmpxchg.org> <20180801151958.32590-9-hannes@cmpxchg.org> <20180803172139.GE2494@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180803172139.GE2494@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 03, 2018 at 07:21:39PM +0200, Peter Zijlstra wrote: > On Wed, Aug 01, 2018 at 11:19:57AM -0400, Johannes Weiner wrote: > > + time = READ_ONCE(groupc->times[s]); > > + /* > > + * In addition to already concluded states, we > > + * also incorporate currently active states on > > + * the CPU, since states may last for many > > + * sampling periods. > > + * > > + * This way we keep our delta sampling buckets > > + * small (u32) and our reported pressure close > > + * to what's actually happening. > > + */ > > + if (test_state(groupc->tasks, cpu, s)) { > > + /* > > + * We can race with a state change and > > + * need to make sure the state_start > > + * update is ordered against the > > + * updates to the live state and the > > + * time buckets (groupc->times). > > + * > > + * 1. If we observe task state that > > + * needs to be recorded, make sure we > > + * see state_start from when that > > + * state went into effect or we'll > > + * count time from the previous state. > > + * > > + * 2. If the time delta has already > > + * been added to the bucket, make sure > > + * we don't see it in state_start or > > + * we'll count it twice. > > + * > > + * If the time delta is out of > > + * state_start but not in the time > > + * bucket yet, we'll miss it entirely > > + * and handle it in the next period. > > + */ > > + smp_rmb(); > > + time += cpu_clock(cpu) - groupc->state_start; > > + } > > As is, groupc->state_start needs a READ_ONCE() above and a WRITE_ONCE() > below. But like stated earlier, doing an update in scheduler_tick() is > probably easier. I've wrapped these in READ_ONCE/WRITE_ONCE. > > +static void psi_group_change(struct psi_group *group, int cpu, u64 now, > > + unsigned int clear, unsigned int set) > > +{ > > + struct psi_group_cpu *groupc; > > + unsigned int t, m; > > + u32 delta; > > + > > + groupc = per_cpu_ptr(group->pcpu, cpu); > > + > > + /* > > + * First we assess the aggregate resource states these CPU's > > + * tasks have been in since the last change, and account any > > + * SOME and FULL time that may have resulted in. > > + * > > + * Then we update the task counts according to the state > > + * change requested through the @clear and @set bits. > > + */ > > + > > + delta = now - groupc->state_start; > > + groupc->state_start = now; > > + > > + /* > > + * Update state_start before recording time in the sampling > > + * buckets and changing task counts, to prevent a racing > > + * aggregation from counting the delta twice or attributing it > > + * to an old state. > > + */ > > + smp_wmb(); > > + > > + if (test_state(groupc->tasks, cpu, PSI_IO_SOME)) { > > + groupc->times[PSI_IO_SOME] += delta; > > + if (test_state(groupc->tasks, cpu, PSI_IO_FULL)) > > + groupc->times[PSI_IO_FULL] += delta; > > + } > > + if (test_state(groupc->tasks, cpu, PSI_MEM_SOME)) { > > + groupc->times[PSI_MEM_SOME] += delta; > > + if (test_state(groupc->tasks, cpu, PSI_MEM_FULL)) > > + groupc->times[PSI_MEM_FULL] += delta; > > + } > > Might we worth checking the compiler does the right thing here and > optimizes this branch fest into something sensible. Yup, the results looked good. It recognizes that SOME and FULL have overlapping conditions and then lays out the branches such that it does not have to do redundant tests. It also recognizes that NONIDLE is true when any of the other states is true and collapses that. > > + if (test_state(groupc->tasks, cpu, PSI_CPU_SOME)) > > + groupc->times[PSI_CPU_SOME] += delta; > > + if (test_state(groupc->tasks, cpu, PSI_NONIDLE)) > > + groupc->times[PSI_NONIDLE] += delta;