Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp151951ybv; Tue, 18 Feb 2020 20:00:00 -0800 (PST) X-Google-Smtp-Source: APXvYqzjX2R/QQFAH9CS3PwrqjOkgcIvEl+sidkToU5xq0hY1gIyod56CURU0qxnjQNPFkbuh2jX X-Received: by 2002:a54:4f16:: with SMTP id e22mr3535224oiy.170.1582084800024; Tue, 18 Feb 2020 20:00:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582084800; cv=none; d=google.com; s=arc-20160816; b=bG3mS1vyG2zVogJrg6vEfBcfHMqYjAGWmPeSJAfcl84DOj/R/eL1LuB66phZErkyyr kXTiMitP6RCx/e+esqC4pQfwauh3+ETEyJMuaCnoD+zFli0vNaX+DfaNw+m9hk23rhu6 U9W+GnZNs1vIRxc28vCJgrDOkrFA1lfrdGj0g+imtG+4cpNDMbaSjGqHlBBZY6hG/lJH AUuI5fcGqebL1if+UfkTroBKBpP83ptDLIrh7B6dhnVS9y+KJMZ3UA+0pEKZTDMyGW9c uT++VitemFmmqhYTPLHtLnK/fu3+ZvDib7WLyvACqFUxNYK1plyPeCvMsrcs4/d8DKyG gJlg== 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=SZrnakMjGAB7TGvrK1MiBW3j/e2Dvt59mgjDnqGajPQ=; b=Dj0FJLozz0QYfSNGAttl7hgXdqeOQQ/+1ctifFJuVLsBwKf8HFv5/S9ef6DSozd84C /U2tTNHgsM6LcQCFlxMYnaIVlYHTHonPq1CzDZBe13w8O34uLDlPqYW629xXltOO8EmD i5flW4v2mAzOt9NZX2tU/rrykqqTTcCquGX2FBxjujVPelU9/GE7EYgqMj3/5DduS++T pYsNw/VuWrLR/fEDT839Fcb87+WLLf20NOO0Jc9A5gSxLpkqHR0QUCnkmoW7sptGaJf5 Fll4ZHeCnwv1n2x1tx7GBkyemwHnAouUYfXLjc/SBsFhYcjDhkJjomv/WmuifRrXNgJZ YhjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UsgF5iz6; 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 x2si8762199oie.56.2020.02.18.19.59.47; Tue, 18 Feb 2020 20:00:00 -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=UsgF5iz6; 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 S1726528AbgBSD7W (ORCPT + 99 others); Tue, 18 Feb 2020 22:59:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:46816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726464AbgBSD7W (ORCPT ); Tue, 18 Feb 2020 22:59:22 -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 2BDAD208E4; Wed, 19 Feb 2020 03:59:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582084761; bh=UlD/GgrIoO+98ilCRhTMm11ZU9cYeUcU+NIKuiRdwPM=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=UsgF5iz6/VZmX54+QmHA84ui3KIJdH/0oIaBJC6mlm9ljdykZx8mZcnyvhN9ZjoqI Jo3bo9dnj2K9gB/b2J6ZWZ1JqPyRd7uVrN1IT6bgKFVWYPPZ226X3ypA3/vdDRXtBE FOdUbeVrx/mABL9FuPe4aFjosHkBdRZ3XcX8HRs4= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id F21AF3520C69; Tue, 18 Feb 2020 19:59:20 -0800 (PST) Date: Tue, 18 Feb 2020 19:59:20 -0800 From: "Paul E. McKenney" To: Joel Fernandes Cc: Lai Jiangshan , linux-kernel@vger.kernel.org, Peter Zijlstra , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , rcu@vger.kernel.org Subject: Re: [PATCH V2 1/7] rcu: use preempt_count to test whether scheduler locks is held Message-ID: <20200219035920.GR2935@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20191102124559.1135-1-laijs@linux.alibaba.com> <20191102124559.1135-2-laijs@linux.alibaba.com> <20200219033147.GA103554@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200219033147.GA103554@google.com> 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 Tue, Feb 18, 2020 at 10:31:47PM -0500, Joel Fernandes wrote: > On Sat, Nov 02, 2019 at 12:45:53PM +0000, Lai Jiangshan wrote: > > Ever since preemption was introduced to linux kernel, > > irq disabled spinlocks are always held with preemption > > disabled. One of the reason is that sometimes we need > > to use spin_unlock() which will do preempt_enable() > > to unlock the irq disabled spinlock with keeping irq > > disabled. So preempt_count can be used to test whether > > scheduler locks is possible held. > > > > CC: Peter Zijlstra > > Signed-off-by: Lai Jiangshan > > --- > > kernel/rcu/tree_plugin.h | 8 ++++++-- > > 1 file changed, 6 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h > > index 0982e9886103..aba5896d67e3 100644 > > --- a/kernel/rcu/tree_plugin.h > > +++ b/kernel/rcu/tree_plugin.h > > @@ -603,10 +603,14 @@ static void rcu_read_unlock_special(struct task_struct *t) > > tick_nohz_full_cpu(rdp->cpu); > > // Need to defer quiescent state until everything is enabled. > > if (irqs_were_disabled && use_softirq && > > - (in_interrupt() || > > - (exp && !t->rcu_read_unlock_special.b.deferred_qs))) { > > + (in_interrupt() || (exp && !preempt_bh_were_disabled))) { > > // Using softirq, safe to awaken, and we get > > // no help from enabling irqs, unlike bh/preempt. > > + // in_interrupt(): raise_softirq_irqoff() is > > + // guaranteed not to not do wakeup > > + // !preempt_bh_were_disabled: scheduler locks cannot > > + // be held, since spinlocks are always held with > > + // preempt_disable(), so the wakeup will be safe. > > This means if preemption is disabled for any reason (other than scheduler > locks), such as acquiring an unrelated lock that is not held by the > scheduler, then the softirq would not be raised even if it was safe to > do so. From that respect, it seems a step back no? This patch was one of the things motivating me to turn tick on for nohz_full CPUs that spend too long in the kernel. Given that change, this patch can be (and recently was) made more straightforward. Prior to the nohz_full change, Lai was kind of between a rock and a hard place on this one. ;-) Thanx, Paul > thanks, > > - Joel > > > > raise_softirq_irqoff(RCU_SOFTIRQ); > > } else { > > // Enabling BH or preempt does reschedule, so... > > -- > > 2.20.1 > >