Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1571272imu; Wed, 16 Jan 2019 23:05:07 -0800 (PST) X-Google-Smtp-Source: ALg8bN7Spok7is5UnUigfS55EayzyQiJjjIz5SmTHa0x8l2Hb6sZu/V/HYYtjbw0xgOKhDVzaJtF X-Received: by 2002:a17:902:8306:: with SMTP id bd6mr13873001plb.217.1547708707110; Wed, 16 Jan 2019 23:05:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547708707; cv=none; d=google.com; s=arc-20160816; b=LX9EWY7bcDcZLbbLeyYuGjJvaEpYC9ejWmtSFTToFc3rLlWnRFbaIzw268tMDrmG2q Fhkm6yTmcHs5ahiqTB1iHJObqnR4M59RJwJMOGU5SyOZn04yAATTeFv/1AzbP62/aKCe MJ3OUtu4023Igu1RbxDnaWCBla7lNNOk4c/Df4Y7DUlPGY4fW14F7YS16cPN2vmM9prC Do8mNE6kmBnra004Rnp/2GCpa99tYU3T8YNGyO0sc7/RR9DvroReYAL/YWb3H0CaRz47 N6HpK8Gs4+HJNpHNZUo4dD9gCdR/nAkA0LEE9HsuFt0KgUKlSwhv+gTBS6xxOrdu2ZLF Shaw== 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=kIFFLkmq7d3xFpRMLDb08Mw1HpNVbvYZHc+n3mgNoj8=; b=jnjd3y3L//2ZVIA78EYhq5eHpaBTUk1TGhg+Xb+vkeD1AdwDk9cGNGjc1V6dhHWSnY nZxKnkQTFkpHNtOxzgvucGW3+6d9I8d1wluc7WVYaFEHrW3gRfDhwscZgtpb9xNYZIKk xptnQCF0USldF+Yn2PlI/Ouu6w+61FoNxTPyuKxYDAjoamYT1PCr0wqEraQ/q1D53Nz5 7AouqYU6tUoTtBgOKP1O45erdkEnmnRY2U2wv0AiWQypU4iTMscQpn6y1Wj3MfcFUMfC iRsZw0aNieyDdKGe2h4ZXWDItO4i8v6rpiYO6BboELm0fjCU0NadkTGlja6pnaRbwu4h M7Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b="NNSL/Bd3"; 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 t19si810826pgk.163.2019.01.16.23.04.50; Wed, 16 Jan 2019 23:05:07 -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="NNSL/Bd3"; 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 S1730572AbfAPTRc (ORCPT + 99 others); Wed, 16 Jan 2019 14:17:32 -0500 Received: from mail-yw1-f66.google.com ([209.85.161.66]:42847 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730517AbfAPTRc (ORCPT ); Wed, 16 Jan 2019 14:17:32 -0500 Received: by mail-yw1-f66.google.com with SMTP id x2so2834032ywc.9 for ; Wed, 16 Jan 2019 11:17:31 -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=kIFFLkmq7d3xFpRMLDb08Mw1HpNVbvYZHc+n3mgNoj8=; b=NNSL/Bd3aNrBfSndV2o1hvQ3nbYDQ3op0STM0igBEdRn8QAeAmSSbGIugQi43fcd5V b8FNwOkSMLltBhPH6uzFCikvhmh/KuhWnRObaUw2AkhiHXf7S4hKCiSq61zp4r9PIaA+ BL2xSSnZJVsoP1r5qg9HlTN1zRpYiRkI5PZEo/ynNddY0l83FBP8pCEgNKFoeeSvY/fD 5VT6G1MQkskyoTaGsiqJ7pD8/XsObcLDBFxJSMW7RhXnc9ekhDPGw9CSQF0iGSemOPuK Bmf9gGjHDicM8qG90ire2HSUPXzunPANhQ8gD90oyUxt+2yv2Oxr+0fVV1ULNUOQ7oyP fgpg== 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=kIFFLkmq7d3xFpRMLDb08Mw1HpNVbvYZHc+n3mgNoj8=; b=JHGvm8IM9Smialle1SWHzWJVra/8dRoYhQSk+08HQ9Eg7HLmwGbGq+fIuokj+LoXPO BaHF6DUvwJRL1BRrUmB+LqrVhsSbNhZ6hPN6qEurSiDs2fxd9/RmhzfUZw9MVt7ylM8C IhFZ9cIK+zBpCFh22NQCUo0azmajqyXpP+LehIGsO3momQpQBXXClbfJ0G+FYfpKOnkh fblAWCMFd3ntE7N9peXlV6qhGQ/aGrr0t+breDbtCOnn2amoq9UGl8rSlYq4+SuoICn4 dQ+U3MsboK38ySRzjk6jStXk660tkWQ8ikYgzboO1J+stUVC1ejrsHpRzY7Ilr3900pf 5ISQ== X-Gm-Message-State: AJcUukfeeQ8pHGczlHOCEZLohSmOBY8KvmH4nZuoBIQgUMscSp+TqLc1 AyQoHqdyQrXnyKitWcza6RWLiQ== X-Received: by 2002:a81:c144:: with SMTP id e4mr9203726ywl.409.1547666250524; Wed, 16 Jan 2019 11:17:30 -0800 (PST) Received: from localhost ([2620:10d:c091:200::5:ddb4]) by smtp.gmail.com with ESMTPSA id d85sm3073760ywd.22.2019.01.16.11.17.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Jan 2019 11:17:29 -0800 (PST) Date: Wed, 16 Jan 2019 14:17:28 -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: <20190116191728.GA1380@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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() or something to make the ordering a bit more visible. And also add a comment to the actual cmpxchg() in the code directly that says that we rely on the implied ordering and that it pairs with the smp_mb() in the slowpath; add a similar comment to the 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'. > > Oh, I see. Will do. Thanks! Yikes, that's news to me too. Good to know.