Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1235928imu; Wed, 16 Jan 2019 15:22:50 -0800 (PST) X-Google-Smtp-Source: ALg8bN59C8HIngMMrKioL7PIByerqO/qalTVf5WpxA1CG9u04QwSubgPHAmZj9XXk0a9ROfQEqZz X-Received: by 2002:a62:5e41:: with SMTP id s62mr12274031pfb.232.1547680970451; Wed, 16 Jan 2019 15:22:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547680970; cv=none; d=google.com; s=arc-20160816; b=s7pJDlBMjd13ivvtSy1lBzj/gIemIxZCDYA+AKiT54iQp0Hs/PsFe+yTJ0ukHSQDKV GpkLSi/3GriAQJ5pFcJOg7fIhkJ/CgiImlo5H+tpSHaOT2ntVgEgwqpubVpQpU39iqrG 0I0DzfSrO/jI+w6D4XKNHUUckGebHjPo1fbR5OMHXA9IVE5gwA/lga4+RRwdaNBjQueI 2/NuMVfPae0NFxVXvI8QmTELOS/6Dr2Ew9ZvTZ8KUkacMI/0ns/89xCe6KnbOh9Nbh50 HJ1J5SlrZqxePXQj6o9laRL/UllV8k8lSJymv8XSlYqL66HN7WF+4RNoNUvf0q0b9SZk 4eMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=SkHnhOOsLYZDGsqCGEnCW12gFbGohE4xp9i6QhoRkNQ=; b=HAAwtIb4KP5dpP5zAUoN66EOH/UlH0DCtRKY3f3fHcK2oRabWUk5tobY6UfezdXLqx kVCUPF3nEnp+0z9JFMiyRYFa4J6vwB6KQcdAL9OidTfV8H9hL8Ps6+BbkblMFQliEgbl eRQdozF8GFDNO/cihYhpZQc+RpA1EGRl5Bi9wKuaZaAQ1sowEHJkKN6iir/YdjgtHBG3 lVM8f2KcY916pNNJ8xHrHCmWBtdUU9/Nk+iZUJPDP42yB42SwgoCzTmhNyp+NcF5d1J8 wDGqKTgzdCVJjDw+iAfeYT59n0MPM7NEftml4SOFpddmjsRSCRiBpXLVToBel8Jjl6j9 dE+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NtAmxsdF; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d37si7730672plb.140.2019.01.16.15.22.32; Wed, 16 Jan 2019 15:22:50 -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=@google.com header.s=20161025 header.b=NtAmxsdF; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727425AbfAPRj2 (ORCPT + 99 others); Wed, 16 Jan 2019 12:39:28 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:35302 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726077AbfAPRj1 (ORCPT ); Wed, 16 Jan 2019 12:39:27 -0500 Received: by mail-wm1-f66.google.com with SMTP id t200so2944938wmt.0 for ; Wed, 16 Jan 2019 09:39:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SkHnhOOsLYZDGsqCGEnCW12gFbGohE4xp9i6QhoRkNQ=; b=NtAmxsdF4VzGKlpT0lmtbvYJiLYQMDar/xlqxYhw6D/UuTkJBzDMdyd/hiLxRfJO2Y 284bfW00aWxNO3W84K1wxGC6FdOVJi3yht8vSyaV9LVwNt1yWJnscmHq3scQVZtP4Yuk NwdR8JXXdSFdSAmlvuSToZrQ/1bb8/noYvzuqfdtVX0xUUnPV6bQrcw9L3LKLovGVP+a uzrTmr2uyUgJHhZg3HRVoqkKn3znCcQjf4OTkB+imsQXGBrkBA+FnOyjvMOOQYf8jqSX D9JFbu4kXY2Fw56nyWXDxhFO9QXWJjEvtIXpBlx30XSDmtk+M8rtFEcrG+bEWE3SSi5R hSuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SkHnhOOsLYZDGsqCGEnCW12gFbGohE4xp9i6QhoRkNQ=; b=D4Zrul8ZbGQn0of1p2azVh3ZRoyJWqzFasa2Xets6S0b6yxoJpYfQ6gv0lan/f2NjN dK1HBUzbcVuyXBubMPFuRlANAowsLEs3PEwUzBix0q40pgJlBZBhpYXFKFffkPqGSY1W cjxaRm18k4FVaIRSp6b5biwBQkShwC4nkQbvO7toCLH5mzQgaX+s+w/kW0uJ2xY0YxNa o0dATtdiASyeYXLgRo05EccaB7/I8SwNLtHPnfKIPscFJogUzM4qLCeqB/qTsndjKrUE FLlixx/Le6HGeM071IrnQHAdVyDebsy/kT55K4iXoi2hgr0CqaNHFn7X/hUT3f7hCC5f D2lw== X-Gm-Message-State: AJcUukcoL2Z+wFArS5ifgutjGJ+FXtfGd9KHY13YjJk77u0P6MLaQDrw ih1bSM6rDx5isHwzqM+L6ffGODnmryRejHbIfZemUA== X-Received: by 2002:a7b:c951:: with SMTP id i17mr8931903wml.70.1547660365119; Wed, 16 Jan 2019 09:39:25 -0800 (PST) MIME-Version: 1.0 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> In-Reply-To: <20190116132446.GF10803@hirez.programming.kicks-ass.net> From: Suren Baghdasaryan Date: Wed, 16 Jan 2019 09:39:13 -0800 Message-ID: Subject: Re: [PATCH v2 5/5] psi: introduce psi monitor To: Peter Zijlstra 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 Content-Type: text/plain; charset="UTF-8" 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 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? > 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(). Just to clarify, smp_mb() is needed only in the comments or do you want an explicit smp_mb() in the code as well? As Johannes noted get_recent_times() which is part of "delta = times[*]" operation involves read_seqcount section that should act as implicit memory barrier in the slowpath. > 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! > -- > You received this message because you are subscribed to the Google Groups "kernel-team" group. > To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com. >