Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1440957ybl; Wed, 28 Aug 2019 14:58:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyMr+HQN6ZjjD7ru3PXj7fF/yVrCX08TDohjr9PW4EbpOcBLYCOduxDm8bMr8lak4mXdKjo X-Received: by 2002:a65:4243:: with SMTP id d3mr5481074pgq.119.1567029481386; Wed, 28 Aug 2019 14:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567029481; cv=none; d=google.com; s=arc-20160816; b=yBX5mbtS8qFpfl428GLopnLLUQOLWDJcx1/fuWVqdScPQzke7vg47qeNaS0mv4reI2 Vg4mo9uHOw8ZK4G7yU0HhLHtegMwK4X2TYRCw/DyytfLeQTC5HYeppWsEL9+Pdg1UguD iV9ZaQF9etK242IM+keIkOssyPO1ty/MTZ3JHLOgDV/oZZ5xQlDl3MPgSszv17NmZ4wo 6UdRGTF3QoSLVy3//cB5ifG8+h0y78D8Q0NUz9AFePp63nMQVqacW911toj/80lU/Xwz dw6rVEFPBnL6m7I9iZno1eln4XpoSDbGU2m1SlETW/lW2LDuY6g9im9SsD8tEY8Cnsxn 3uvw== 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=Nd+bPWlCXNocXiigb90jYgWHpu3MGjlLHt1H4GIPKsk=; b=ALp+zTvhzNvzX/FmgdBIp9LBkU1hA8GuUqpaXWS2Fj/qMIiiOmugOztSDvJR+AxEc/ 3mPCygbkiAiSKBd71vwGAQ4lF8XgnGU1YiBZg6lGUFYbBJWCk1MwxzVpQSXrP2TsR/Be 00e4VCVRY0yEgAPfYvEatgqTR5vot3yAma5UTJy05AkTO20YQ6vAXcM9yv6hyrdY6t2M fw0ba05llmTG57RarHj+3CiEuC7b/ULdgVkINZdvDaF1A8/YzJG5cJTovrf0UQev2WCE SR/cJI9SBpG0bX4TwRy6c2OA0OWPKbGCZaI2bLTZHd4+yNn3isPnwZg4sQh1MVyM9S7c ldCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=n+Iz3RNK; 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 f185si468516pfg.47.2019.08.28.14.57.46; Wed, 28 Aug 2019 14:58:01 -0700 (PDT) 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=@joelfernandes.org header.s=google header.b=n+Iz3RNK; 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 S1726658AbfH1V5A (ORCPT + 99 others); Wed, 28 Aug 2019 17:57:00 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43669 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726875AbfH1V47 (ORCPT ); Wed, 28 Aug 2019 17:56:59 -0400 Received: by mail-pg1-f195.google.com with SMTP id k3so411201pgb.10 for ; Wed, 28 Aug 2019 14:56:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Nd+bPWlCXNocXiigb90jYgWHpu3MGjlLHt1H4GIPKsk=; b=n+Iz3RNKIv2G78ZVZ1TXSEKF9j9dLXkEdNpnMNVoicyXdstnIuPLFqkCjqyGSH9iJY o8gawdyeaRKIA7HYM9GwBrmZEUjqEqoQzGDPL6Qjj+hPvALZQLVeqdqiODiTzfmDwDgB jXgqJyq703XAb4M2dMxq/L+kBPkok4Gcf/Gco= 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=Nd+bPWlCXNocXiigb90jYgWHpu3MGjlLHt1H4GIPKsk=; b=EGDFOQ+4RMfRM2DTdS0tHZ3m78c3nNYEAgD8dkdnGd6AHF+ESP1KuT8odN9rTDj+m6 BP2AJlDgWHM1pTNZsCNZXcO/2C2R9nJOeqa+bKSVnMIJMIldsNnaLqIEkoK08p0T7tNK s6bLKp+/+Zl2hibLh4wLq5RHSKdHDf+aeyc/upr1zRCFOJwJ1HhTbrD7XnxRsmOrTRLD CeZREA1GBw1c18Vhk5uFAISNJeggr5ssYFPzUWhi2VV/z2y1dUWrfF6v4YgpLAwJ3vMD fpCCpF4pFBOxV9h7L5qAA695FTulIhlMVwMPXMZcNmx+EjGoCF9VJyoOVFP0akwb2zcF 2EkA== X-Gm-Message-State: APjAAAVhw2RP8vjCMxxNJsQKUW1QZVEnjwNJY+IwZPnF1lRcjhdn0ghm XuT92FF2UWgRc66FguT1aosrFQ== X-Received: by 2002:a17:90a:bb91:: with SMTP id v17mr6143826pjr.84.1567029418977; Wed, 28 Aug 2019 14:56:58 -0700 (PDT) Received: from localhost ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id p20sm144125pgj.47.2019.08.28.14.56.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2019 14:56:58 -0700 (PDT) Date: Wed, 28 Aug 2019 17:56:57 -0400 From: Joel Fernandes To: "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Frederic Weisbecker , Jonathan Corbet , Josh Triplett , kernel-team@android.com, Lai Jiangshan , linux-doc@vger.kernel.org, Mathieu Desnoyers , Mauro Carvalho Chehab , rcu@vger.kernel.org, Steven Rostedt Subject: Re: [RFC v1 1/2] rcu/tree: Clean up dynticks counter usage Message-ID: <20190828215657.GA71365@google.com> References: <5d648895.1c69fb81.5e60a.fc6f@mx.google.com> <20190828201344.GR26530@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190828201344.GR26530@linux.ibm.com> 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 Wed, Aug 28, 2019 at 01:13:44PM -0700, Paul E. McKenney wrote: > On Mon, Aug 26, 2019 at 09:33:53PM -0400, Joel Fernandes (Google) wrote: > > The dynticks counter are confusing due to crowbar writes of > > DYNTICK_IRQ_NONIDLE whose purpose is to detect half-interrupts (i.e. we > > see rcu_irq_enter() but not rcu_irq_exit() due to a usermode upcall) and > > if so then do a reset of the dyntick_nmi_nesting counters. This patch > > tries to get rid of DYNTICK_IRQ_NONIDLE while still keeping the code > > working, fully functional, and less confusing. The confusion recently > > has even led to patches forgetting that DYNTICK_IRQ_NONIDLE was written > > to which wasted lots of time. > > > > The patch has the following changes: [snip] > > /* > > * Grace-period counter management. > > */ > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > index 68ebf0eb64c8..255cd6835526 100644 > > --- a/kernel/rcu/tree.c > > +++ b/kernel/rcu/tree.c > > @@ -81,7 +81,7 @@ > > > > static DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_data, rcu_data) = { > > .dynticks_nesting = 1, > > - .dynticks_nmi_nesting = DYNTICK_IRQ_NONIDLE, > > + .dynticks_nmi_nesting = 0, > > C initializes to zero by default, so this can simply be deleted. Fixed. > > .dynticks = ATOMIC_INIT(RCU_DYNTICK_CTRL_CTR), > > }; > > struct rcu_state rcu_state = { > > @@ -558,17 +558,18 @@ EXPORT_SYMBOL_GPL(rcutorture_get_gp_data); > > /* > > * Enter an RCU extended quiescent state, which can be either the > > * idle loop or adaptive-tickless usermode execution. > > - * > > - * We crowbar the ->dynticks_nmi_nesting field to zero to allow for > > - * the possibility of usermode upcalls having messed up our count > > - * of interrupt nesting level during the prior busy period. > > */ > > static void rcu_eqs_enter(bool user) > > { > > struct rcu_data *rdp = this_cpu_ptr(&rcu_data); > > > > - WARN_ON_ONCE(rdp->dynticks_nmi_nesting != DYNTICK_IRQ_NONIDLE); > > - WRITE_ONCE(rdp->dynticks_nmi_nesting, 0); > > + /* Entering usermode/idle from interrupt is not handled. These would > > + * mean usermode upcalls or idle entry happened from interrupts. But, > > + * reset the counter if we warn. > > + */ > > Please either put the "/*" on its own line or use "//"-style comments. I'll put "/*" on its own line. > > WARN_ON_ONCE(rdp->dynticks_nmi_nesting <= 0); > > WARN_ON_ONCE(rcu_dynticks_curr_cpu_in_eqs()); > > > > + WRITE_ONCE(rdp->dynticks_nmi_nesting, /* No store tearing. */ > > + rdp->dynticks_nmi_nesting - 1); > > This is problematic. The +/-1 and +/-2 dance is specifically for NMIs, so... This counter is deleted in the following patch so I hope its Ok to leave it here for this one. I just kept it split into different patch to make testing/review/development easier. > > if (irq) > > rcu_prepare_for_idle(); > > @@ -723,10 +728,6 @@ void rcu_irq_exit_irqson(void) > > /* > > * Exit an RCU extended quiescent state, which can be either the > > * idle loop or adaptive-tickless usermode execution. > > - * > > - * We crowbar the ->dynticks_nmi_nesting field to DYNTICK_IRQ_NONIDLE to > > - * allow for the possibility of usermode upcalls messing up our count of > > - * interrupt nesting level during the busy period that is just now starting. > > */ > > static void rcu_eqs_exit(bool user) > > { > > @@ -747,8 +748,13 @@ static void rcu_eqs_exit(bool user) > > trace_rcu_dyntick(TPS("End"), rdp->dynticks_nesting, 1, rdp->dynticks); > > WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current)); > > WRITE_ONCE(rdp->dynticks_nesting, 1); > > - WARN_ON_ONCE(rdp->dynticks_nmi_nesting); > > - WRITE_ONCE(rdp->dynticks_nmi_nesting, DYNTICK_IRQ_NONIDLE); > > + > > + /* Exiting usermode/idle from interrupt is not handled. These would > > + * mean usermode upcalls or idle exit happened from interrupts. But, > > + * reset the counter if we warn. > > + */ > > + if (WARN_ON_ONCE(rdp->dynticks_nmi_nesting != 0)) > > + WRITE_ONCE(rdp->dynticks_nmi_nesting, 0); > > And here. Plus this is adding a test and branch in the common case. > Given that the location being written to should be hot in the cache, > it is not clear that this is a win. The next patch removes the branch itself and just has the warning. > > WARN_ON_ONCE(rdp->dynticks_nmi_nesting < 0); > > > > /* > > @@ -826,16 +833,21 @@ static __always_inline void rcu_nmi_enter_common(bool irq) > > > > incby = 1; > > } else if (tick_nohz_full_cpu(rdp->cpu) && > > - rdp->dynticks_nmi_nesting == DYNTICK_IRQ_NONIDLE && > > - rdp->rcu_urgent_qs && !rdp->rcu_forced_tick) { > > + !rdp->dynticks_nmi_nesting && rdp->rcu_urgent_qs && > > + !rdp->rcu_forced_tick) { > > OK. Though you should be able to save a line by pulling the > "rdp->rcu_urgent_qs &&" onto the first line. Fixed. > > rdp->rcu_forced_tick = true; > > tick_dep_set_cpu(rdp->cpu, TICK_DEP_BIT_RCU); > > } > > + > > Not clear that the added blank line is a win, here or below. Fixed, thanks! - Joel [snip]