Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp723847imm; Fri, 3 Aug 2018 10:23:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf/PJ78zQmle0aOLurO5JIhjFW4OCyDi5wXx9AKQY2g2Uxbts40SUoYe4dStCwfHsZziflJ X-Received: by 2002:a63:6ecf:: with SMTP id j198-v6mr4736923pgc.213.1533316980387; Fri, 03 Aug 2018 10:23:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533316980; cv=none; d=google.com; s=arc-20160816; b=Ui6JYGhNvgfeEVE2rm9AlcztAnD+Xyx4szapAkU7e964mqJpstzr0wQEgvvNiO7cqa oRut3LTkU8Do8Hrz5g5MjNopCt8Qc5FfxJZBuhyw75LZSEZefb8q7xC5ELaInjdiX3jf nMdupOzcfMOWhWk2AiwPFmZ0v99cjE5rgmb+5xL4xqm/qTsoO6apP2O4gYrY5Ow5FNDc A5P2phKFYeiJQcQudMgE1Aai5Q46tQMpeGwVJ4mxC+Yg1pdYBWo6GZJUeJHZzsS00fnn Rh5FTNsquDQqOwGQBGVxxQedxN8YfDe4GsywTuolWszLYJDDefjOQ7iJvjrOJ8Igt/wt aVWQ== 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=/7zcp47e6Ydd4cZN9LQW18xrO4SGF+ktz9zrchZXPTw=; b=VN2xF9mNGdYP0E9+5gCUt8zM+4OBGs+uzAXmSbCGWKLTpK7zbcGmuiY0odhRMswQNR kt02lhCG3DX17MKgT5slk3N0qDI6I14v/Azldm8Riyae2p0AVLsVqCgprbz45OnzJQAp jfKzSa5DKJ8SyTULmpVMqLw4ZBx+jyBaoXLV9HAuJUB6lco2xzHtnSn7VoQciEq0HbYR ALgNPHxTS1rFzTakJBStIR6dqSaRQkJGLVMnT5mTTsxEeVmFbXAnj1TTuAYZdh9Qcmu1 U+wyfUxVD6C1EMH8MJ2tpgx/47AXYQ1HdYutnJ8JLurb+J+L/YSyXGKCKkp0t4YkI49t E3Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=IC0ceDxa; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a74-v6si5897974pfe.301.2018.08.03.10.22.45; Fri, 03 Aug 2018 10:23:00 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=IC0ceDxa; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728477AbeHCTTA (ORCPT + 99 others); Fri, 3 Aug 2018 15:19:00 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:38286 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727841AbeHCTTA (ORCPT ); Fri, 3 Aug 2018 15:19:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/7zcp47e6Ydd4cZN9LQW18xrO4SGF+ktz9zrchZXPTw=; b=IC0ceDxaj3PSNtMTXsAaOk1M9 QEtga76/juR42zvAw8YxOerG0K+uYK2ow40CGzi1YhW5SewN0LagB8Dfwz2LWm9Btlztd4040Zpl6 u0/ODDUHaxsv2ONZgj7/zbIBDGXO1qRD5kDu5ruoTk/wjutwUf0TfDR3kxkYUjYrrFVGfQObFkuFs WSVr6hJyDuwr3bq6lDxduvs9KjgJq2oX76ZRgr8aiwsQg75b2NvkOHRn30bcFRwPnZQCUh1tkPUs0 MdNVE0Edk8oQuZyCVZHkWoqr7+K1hAYuXDzvw1kTkP2wUeiYZve62Gb2b7CUiY31wKu+X/8iGWQKM JtR6kOARA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fldll-0008BK-El; Fri, 03 Aug 2018 17:21:41 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E8E7A20267E51; Fri, 3 Aug 2018 19:21:39 +0200 (CEST) Date: Fri, 3 Aug 2018 19:21:39 +0200 From: Peter Zijlstra To: Johannes Weiner 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: <20180803172139.GE2494@hirez.programming.kicks-ass.net> References: <20180801151958.32590-1-hannes@cmpxchg.org> <20180801151958.32590-9-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180801151958.32590-9-hannes@cmpxchg.org> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > +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. > + 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;