Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1284021imu; Wed, 16 Jan 2019 16:22:53 -0800 (PST) X-Google-Smtp-Source: ALg8bN4qn4vrn5YAuJbyYcdwWzg8b+aPbW7M0ZuCXEpGStQgiJv66Lv53xObhZzN1XRK+spNoU6W X-Received: by 2002:a62:fc8a:: with SMTP id e132mr12501422pfh.176.1547684573691; Wed, 16 Jan 2019 16:22:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547684573; cv=none; d=google.com; s=arc-20160816; b=M6so58yQHLLYRAyrFc3WSWBeGHlq9sWK/nBwulR4c4IWRjoM0dBtieP3vKbL5LAedJ coiomW7YEFlAqNbk8o9lg8laiwqDXjyerKG4TeIXOk/h7X5mi/nhazEA+XS/+MgFRfQN XLAgTbHUOH05nBRaTH7nQxV6eH0wblcQMlY4NTkaH1XGSQ2eF5Tzo2DgeDHOsBcHSGzi SxMihs8MoA7jB973ez0zGmuo6N9F8Auc05eMDt8L5qbhj/hqe7qb2BDbbY1rvQpAV4Wy 9Tgj1gcPCGdDgATi5HPxp62mX+ejO4tY2lYnTgWZ0cnnWbDvFuk/VxW99WbKbN0zU9vf FtFw== 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=WiVtpIOuEwH4DhBlsSM5aJC00b41A66MDpCmjW42bSs=; b=iXNlmQhh5+P5g05zyHMsYQaDTxcyz7+71TKNGZ7bFi06VPGnlDAVzOVMcBCGCv33xK A8UIEs4rlYD13Mj2rT3EyeejAtd4ZZxBlVuy0nprGobjpptagBUjewQfMbV6h3NviHvs yEWMYLhxLinTyTIbgwAkhSqJ47iHs2eguef2RsEwOPmP52zXBqxHnoaaV5qgrX/3of57 KJvywyhDAm5L+DRZ34/iozyg8ACwULqtKyd/NPZl6GqxCajTHErHjivYS7coqkhPW/Cg 1qhAegTuxUDiMD+JbBxjAYonYiCTQhAzgHGJs54ZjgiR2n0FkOqBEinKMtqpHQc4hexh Vq4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=cuMu4RiA; 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 f17si7013023pgj.208.2019.01.16.16.22.28; Wed, 16 Jan 2019 16:22:53 -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=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=cuMu4RiA; 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 S1730868AbfAPT1s (ORCPT + 99 others); Wed, 16 Jan 2019 14:27:48 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:37718 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730511AbfAPT1r (ORCPT ); Wed, 16 Jan 2019 14:27:47 -0500 Received: by mail-yw1-f68.google.com with SMTP id h193so2865896ywc.4 for ; Wed, 16 Jan 2019 11:27:46 -0800 (PST) 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=WiVtpIOuEwH4DhBlsSM5aJC00b41A66MDpCmjW42bSs=; b=cuMu4RiAnGXx2I+SUKExjCnU+aFOY/M6XwCvtAb5DrpByPtxk2pa4v5MavdkB+jxr5 vIFRDzdZVnLY62BzGNnvFt8620kZQA7tU36sJCp3WdWGSkpe9urA+idxSp6llrqwX6IK 385vnuqHJMXf5xvzdhZh70oiei31K9tsZ2USDFYJriBloD1IQNqjSx57DlElEfMeDi37 BhVLkctMRe/eiNKD5P92BvaziOx0fYopaziptyNkL64zKIds37UablJmBAK+YyZ5AeOk 4fj9W71/L5V9Vtoa3ea6i4/PydI+RaQG6mJqL9NFlzyh2y0HEx9b9s5DbFh2tG3I5wgE Rtfg== 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=WiVtpIOuEwH4DhBlsSM5aJC00b41A66MDpCmjW42bSs=; b=SXwcTLGjZuqmzZtKVtA+pMECdxhHYX9WivvefqiMS9xCH0P97CQGX0pKy3Va/Bjq4H ORC+ExS/eOpFDEkGts8GlogeOLJOEFho7ixLaES7VN15foOAWDX8FwUAmPx9yM5FaD7S zo5W6A3UCMltV0T6xLYbZECYxmUr5CPzvjNXP/sqr7zIAZZOxuojNhM7qjDLcT5FIOsV JLWRAFKdGFjgwHouLHNrAbO8wDEbKgqRqHPFxP0KEtTQJ0bCtvkZEfJINsPrFwrUKnbi 9tRJyf0JLx9OLvWPy4/U+z/3WeDADAtWmgW0OnAQZQaUbn7cYGJ6WRO/htnd7kfhxmew UtVg== X-Gm-Message-State: AJcUukc2ZUkljPK4F6Yxh4oQZdfMI0qlfOFqxdNHm7RY0hfpFPCaAJz4 uwzBop6KGnFPJxHG0zDBl2bVMA== X-Received: by 2002:a0d:d54e:: with SMTP id x75mr6638846ywd.308.1547666866398; Wed, 16 Jan 2019 11:27:46 -0800 (PST) Received: from localhost ([2620:10d:c091:200::5:ddb4]) by smtp.gmail.com with ESMTPSA id f10sm5419601ywb.26.2019.01.16.11.27.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Jan 2019 11:27:45 -0800 (PST) Date: Wed, 16 Jan 2019 14:27:44 -0500 From: Johannes Weiner To: Suren Baghdasaryan Cc: Peter Zijlstra , Greg Kroah-Hartman , Tejun Heo , lizefan@huawei.com, 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: <20190116192744.GA1576@cmpxchg.org> References: <20190110220718.261134-1-surenb@google.com> <20190110220718.261134-6-surenb@google.com> <20190114102137.GB14054@worktop.programming.kicks-ass.net> <20190116132446.GF10803@hirez.programming.kicks-ass.net> <20190116191728.GA1380@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190116191728.GA1380@cmpxchg.org> User-Agent: Mutt/1.11.2 (2019-01-07) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 16, 2019 at 02:17:28PM -0500, Johannes Weiner wrote: > On Wed, Jan 16, 2019 at 09:39:13AM -0800, Suren Baghdasaryan wrote: > > On Wed, Jan 16, 2019 at 5:24 AM Peter Zijlstra wrote: > > > > > > 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. > > > > Should I keep it in the comments to make it obvious and add a note > > about implicit barriers being the reason we don't call smp_mb() in the > > code explicitly? > > I'd keep 'em out if they aren't actually in the code. But I'd switch > > delta = times[*] > > in this comment to to > > get_recent_times() // implies smp_mb() Actually, I might have been mistaken about this. The seqcount locking does an smp_rmb() and an smp_wmb(), and that orders reads and writes respectively, but doesn't necessarily order reads against writes. So I think we need an explicit smp_mb() after all.