Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1166704imu; Wed, 16 Jan 2019 14:01:37 -0800 (PST) X-Google-Smtp-Source: ALg8bN463LPJCt7UNAymBeF2E+tOUCcSGDcxVscZ57Q3HYt/FWIYc4f23JMlgrtvX5LvDrge2CxX X-Received: by 2002:a63:2d46:: with SMTP id t67mr11115748pgt.140.1547676097805; Wed, 16 Jan 2019 14:01:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547676097; cv=none; d=google.com; s=arc-20160816; b=WwNs+bgwNQsDRvkfwiZNE/+YIMzruVbV487OcLOYNJIXFAmAGx8ASweiRphG0fw4QB 0mEcRPIunHrQ08knJgS9LayZ7LxYUYTjvODlJ+Do8C6guYiMu8D1U6vbMGe3+G8tfPEH H70gPq02QH8OFip/pcW+BW7ghuu0agF6gtBd8AgVHkWbTrquvCe20VKRl+kc/0ipejHS 7HYJjMSdbdpKSo1gV4VnHYb8pKGkjY+TpPlqcaIQh0txKpMwTuQNaH2RGFhhhfguSA2v mR7RP211xP6KWtfBZvIDMXefiLX/CEU0Ot9g2g65FI3Qcg8KCPauqfoHi2q8uiEtxlOf XwAg== 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; bh=ZhArKsuY/tKhYOpp7E5c4gvQHpi9b44Cpojgm9W2al4=; b=ElxQPXdj+pFR6zrq/R4aKPT5aXoVE6fh7LSWTA4B9Ka8kzsxeQEt3fKs+PYvvLjoWe vgSa+Ug0NP8QtrhsqSnhTKIG1yq4XMQLVpVg/BefwS71CL2VaeW8eTr7aInQ2pdIuOTp Wy/o/YLtue0Yqes+Vy72vtKM1hqBFEqhYAc/9a8xXpKdg16eC5btWJLlyTzMnAbor2fH CjW3UZwZI/UUHEgF9wyREIwwbYoAK7aBf5ppdr6X7HGB7ZO7+xZ9oMq+cuZvgmr7fh8q bogUJsNorfNLRNQJb/VKInNkCLPjZMClSI+Wjtrxyv2e3L+He3QddRF+bYsReDkFNoFb CzZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=G2kfkJGQ; 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 d90si7691322pld.148.2019.01.16.14.01.21; Wed, 16 Jan 2019 14:01:37 -0800 (PST) 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=G2kfkJGQ; 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 S2404279AbfAPNY7 (ORCPT + 99 others); Wed, 16 Jan 2019 08:24:59 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:48174 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732880AbfAPNY6 (ORCPT ); Wed, 16 Jan 2019 08:24:58 -0500 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=ZhArKsuY/tKhYOpp7E5c4gvQHpi9b44Cpojgm9W2al4=; b=G2kfkJGQ6exaAg21qUWzW8RFv FQ9l92BqSsJceUcSKG4R1VM3c0MyYQN/3rHjb8KoLZjvjogEHb+B8sA1izOLaN0JrUSkC4gv9bOyX icZDBTwptY2OyEIWsWVlPwCX5Xroc0vphIyCUqPorrD0YdZFixmMfvbefX4A0l6Wjcwtw7gMDbvxB mmD3c6C2zLiXtrfR3iH4SBwwQLUtTlWjVdsVoh18NIgjrYPkQoyDrSeyuGsVBIVXutUt3+nA8OU3O 94EbKtLSMupZBFbaw1PpR1tkRk8/kriLcBrvzQj9xIpF5wfI2Mssy5gSGWOMXY19zGqNFGOKnnmvO +W2q5+B4Q==; 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 1gjlBZ-0000sA-4U; Wed, 16 Jan 2019 13:24:49 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 76814207C0189; Wed, 16 Jan 2019 14:24:46 +0100 (CET) Date: Wed, 16 Jan 2019 14:24:46 +0100 From: Peter Zijlstra To: Suren Baghdasaryan Cc: Greg Kroah-Hartman , Tejun Heo , lizefan@huawei.com, Johannes Weiner , axboe@kernel.dk, dennis@kernel.org, Dennis Zhou , Ingo Molnar , Andrew Morton , Jonathan Corbet , cgroups@vger.kernel.org, linux-mm , linux-doc@vger.kernel.org, LKML , kernel-team@android.com Subject: Re: [PATCH v2 5/5] psi: introduce psi monitor Message-ID: <20190116132446.GF10803@hirez.programming.kicks-ass.net> References: <20190110220718.261134-1-surenb@google.com> <20190110220718.261134-6-surenb@google.com> <20190114102137.GB14054@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Mon, Jan 14, 2019 at 11:30:12AM -0800, Suren Baghdasaryan wrote: > For memory ordering (which Johannes also pointed out) the critical point is: > > times[cpu] += delta | if g->polling: > smp_wmb() | g->polling = polling = 0 > cmpxchg(g->polling, 0, 1) | smp_rmb() > | delta = times[*] (through goto SLOWPATH) > > So that hotpath writes to times[] then g->polling and slowpath reads > g->polling then times[]. cmpxchg() implies a full barrier, so we can > drop smp_wmb(). Something like this: > > times[cpu] += delta | if g->polling: > cmpxchg(g->polling, 0, 1) | g->polling = polling = 0 > | smp_rmb() > | delta = times[*] (through goto SLOWPATH) > > Would that address your concern about ordering? cmpxchg() implies smp_mb() before and after, so the smp_wmb() on the left column is superfluous. The right hand column is actively wrong; because that reads like it wants to order a store (g->polling = 0) and a load (d = times[]), and therefore requires smp_mb(). Also, you probably want to use atomic_t for g->polling, because we (sadly) have architectures where regular stores and atomic ops don't work 'right'.