Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5176281ybv; Mon, 17 Feb 2020 14:04:44 -0800 (PST) X-Google-Smtp-Source: APXvYqy747JaKw8t+rX1LIZh+EijiFgh/Q7Hmff4blw+JwCnnROrzrfsZIb8A3kLoPX/tWZ/9pnI X-Received: by 2002:a05:6808:50:: with SMTP id v16mr666696oic.133.1581977084704; Mon, 17 Feb 2020 14:04:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581977084; cv=none; d=google.com; s=arc-20160816; b=AeFKqXo/vnwdQXQIQ8XXqDk4tHPPAF9cjBLLEHy8kDynzkZFfv4ALQXpBGSOYfblxP iigRueOdMZxsPcVlNpAmsodbhIz/mSb3SDk/qWY/GssTEwQJLaoFpdi84gdyZq/wuch8 Yp/jHJKsTsT0OCOJp95MwzvWr/junhZOa1VgmkfurJssBT3e5WzT/vJ3ZsYbspd5guVV DMFOqbTpdh25tiOwRpiG/4nBi8zyGrYjMZSxppA+ZU0zzq0yQG4bd3wdZKTGT1UW7bau V/Tg+H3MXE1XFtJy2Uarg9Ya1+QMcZinKB9puezbLxmF09IHG2IttGN/gZFGGKhsT4+N WF5w== 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:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=jgMkF2d0p0QOy5SbTQ7r+45Pdu/DQLra6QEtiK1bios=; b=ZFwIePz1nCLCgOPLahOSR7hyqxEJwciqBdp8cwODL+oOlHguBdXOnaq1bTQGLG6CL6 MXkh5RDwYORvZ0pWE0NWzh/IOVmx4Unm82SKYaNGgkg7kLf1ndWyPIJesaX0nupjKMe5 mhaU7cqBa6DzCn2RBfdJCudZp26a2g0WRjxfjSebkSPqIAJTpUOyMeYrjRkgeYOsNDHu owKG7d14kq1ocRnyORXI7sI0RSlaRg6fELkTF4lbJGTkMd8xqRsvh3LSanYRmcG1TBml 4EPQIBl1BHGRxHRM4b1CrkibRwDfZiBprvGihRs976WYdexBui5n1dI10bsvYTAujgPZ uZtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b9DX063i; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si775261oth.247.2020.02.17.14.04.32; Mon, 17 Feb 2020 14:04:44 -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=@kernel.org header.s=default header.b=b9DX063i; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726641AbgBQWEB (ORCPT + 99 others); Mon, 17 Feb 2020 17:04:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:44556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726594AbgBQWD5 (ORCPT ); Mon, 17 Feb 2020 17:03:57 -0500 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 93435208C4; Mon, 17 Feb 2020 22:03:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581977036; bh=fSgLQbgUCTGkFGI9WEMvi0TtroVvcTTgS22HXIR6a7k=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=b9DX063ihLe8boQQIDSLrb/Nn0+M/UnjrMRElgbLFwD44aVWfM7Mmy4cGk5W0fiDZ s246+RbKFjhhWHReSeVGym6ua1YzTqmtgx3vqzU+QfDyvP69hfN2d4wgWHhBEA+aC6 KiTqiIjGLO8JQXRr8aTPxSjZYfhgmVLWADh0h7VQ= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 5FDB235227A8; Mon, 17 Feb 2020 14:03:56 -0800 (PST) Date: Mon, 17 Feb 2020 14:03:56 -0800 From: "Paul E. McKenney" To: Steven Rostedt Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, mingo@kernel.org, jiangshanlai@gmail.com, dipankar@in.ibm.com, akpm@linux-foundation.org, mathieu.desnoyers@efficios.com, josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org, dhowells@redhat.com, edumazet@google.com, fweisbec@gmail.com, oleg@redhat.com, joel@joelfernandes.org, Linus Torvalds Subject: Re: [PATCH tip/core/rcu 22/30] rcu: Don't flag non-starting GPs before GP kthread is running Message-ID: <20200217220356.GY2935@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200214235536.GA13364@paulmck-ThinkPad-P72> <20200214235607.13749-22-paulmck@kernel.org> <20200214225305.48550d6a@oasis.local.home> <20200215110111.GZ2935@paulmck-ThinkPad-P72> <20200215134208.GA9879@paulmck-ThinkPad-P72> <20200217152517.26cc11ea@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200217152517.26cc11ea@gandalf.local.home> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 17, 2020 at 03:25:17PM -0500, Steven Rostedt wrote: > On Sat, 15 Feb 2020 05:42:08 -0800 > "Paul E. McKenney" wrote: > > > > > And does the following V2 look better? > > > > For the issue I brought up, yes. But now I have to ask... > > > @@ -1252,10 +1253,10 @@ static bool rcu_future_gp_cleanup(struct rcu_node *rnp) > > */ > > static void rcu_gp_kthread_wake(void) > > { > > - if ((current == rcu_state.gp_kthread && > > - !in_irq() && !in_serving_softirq()) || > > - !READ_ONCE(rcu_state.gp_flags) || > > - !rcu_state.gp_kthread) > > + struct task_struct *t = READ_ONCE(rcu_state.gp_kthread); > > + > > + if ((current == t && !in_irq() && !in_serving_softirq()) || > > + !READ_ONCE(rcu_state.gp_flags) || !t) > > Why not test !t first? As that is the fastest operation in the if > statement, and will shortcut all the other operations if it is true. > > As I like to micro-optimize ;-), for or (||) statements, I like to add > the fastest operations first. To me, that would be: > > if (!t || READ_ONCE(rcu_state.gp_flags) || > (current == t && !in_irq() && !in_serving_softirq())) > return; > > Note, in_irq() reads preempt_count which is not always a fast operation. And what is a day without micro-optimization of a slowpath? :-) OK, let's see... Grace-period kthread wakeups are normally mediated by rcu_start_this_gp(), which uses a funnel lock to consolidate concurrent requests to start a grace period. If a grace period is already in progress, it refrains from doing a wakeup because that means that the grace-period kthread will check for another grace period being needed at the end of the current grace period. Exceptions include: o The wakeup reporting the last quiescent state of the current grace period. o Emergency situations such as callback overloads and RCU CPU stalls. So on a busy system that is not overloaded, the common case is that rcu_gp_kthread_wake() is invoked only once per grace period because there is no emergency and there is a grace period in progress. If this system has short idle periods and a fair number of quiescent states, a reasonable amount of idle time, then the last quiescent state will not normally be detected by the grace-period kthread. But workloads can of course vary. The "!t" holds only during early boot. So we could put a likely() around the "t". But more to the point, at runtime, "!t" would always be false, so it really should be last in the list of "||" clauses. This isn't enough of a fastpath for a static branch to make sense. The "!READ_ONCE(rcu_state.gp_flags)" will normally hold, though it is false often enough to pay for itself. Or has been in the past, anyway. I suspect that access to the global variable rcu_state.gp_flags is not always fast either. So I am having difficulty talking myself into modifying this one given the frequency of operations. Thanx, Paul