Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4715133ybc; Fri, 15 Nov 2019 08:57:46 -0800 (PST) X-Google-Smtp-Source: APXvYqw87vmLlgChYR/rFPgy5rVru2nUkhaTQ5rfyr0k6G6j6K9f53PBTbYoy1tdQpoTRmyIw1kn X-Received: by 2002:a17:906:d0c8:: with SMTP id bq8mr2181091ejb.263.1573837065889; Fri, 15 Nov 2019 08:57:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573837065; cv=none; d=google.com; s=arc-20160816; b=vcDAjI6q4Wbj9blWqMZlre8pnobSqg8I4ePsbDG/zJlD1Q5AJC4pe9l0KwVO+rzGgi 4tv5zT38uttNRIqX9PYhAlTLlpfqviIeOb3poRU4WMm52ILQg3g2X8N1tksBvBFNjZMR SWrp6BsSO6YcuaqYFYPpMca3M3MIaWWigm4/ERPZZwqDGBBSWuKwHKpEpXxzpjU2O+a3 hYp/N+J2zu1b8bpH1AcpJCrZuOnDRODbOYtoOQdK80UjzMTtFfJ4vwdSrI+KUjQyfPvv Qwt1FBMF95yGRuv/XwYH5pJPApIJO0ehCpY7fWXwR/cK+ZOhSagr33ZFZyX1McPoxmwH pPjQ== 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=qV1x1a3lTrigApUp9/Llmm7X7a54P/g1Tz4PQPiIyBA=; b=yHuBYXWqaaYw3c7LB+1wvpj8aPmOT67mEFYMEpNoJ7pL1TTZAU3fA+U/FE/prG0jyJ ZJRQUfyQAWkL8SSG9+utPAKPIllA2LVAWSVXlQQ1iJJyoI5IQIj8Fq1hLyQLfv7PllF4 zYbyQKLUgm62GnPrCcWjq1BmOI2IowCJAMkxvhJdnbolb1OysKjD7ESjBLNRFTx5Jkm3 9SMiPxbHbljrxuQOnN8rRsCVIlRPxcZxKBPf6rsW5BJxvr1lPENJSM4fPkG7J20o7vqJ MyucYL1Rn3053bMjecJ6AnM+PTYkwPbJd7rI3+7Bxm19YfDqhosYUuIcuTwSj4qLZMEW oCZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GQkkwKer; 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 b3si7492322edn.202.2019.11.15.08.57.20; Fri, 15 Nov 2019 08:57:45 -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=GQkkwKer; 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 S1727721AbfKOQxw (ORCPT + 99 others); Fri, 15 Nov 2019 11:53:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:59008 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727528AbfKOQxv (ORCPT ); Fri, 15 Nov 2019 11:53:51 -0500 Received: from paulmck-ThinkPad-P72.home (unknown [199.201.64.141]) (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 EC5332072A; Fri, 15 Nov 2019 16:53:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573836831; bh=iqa2VgMhrt2aB+p1sb2tJk0Xa1Bpa8AmODLk3wv8qjo=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=GQkkwKerfikMRcMW73319WJPScvBJwOJ7xz2tGoYpCSVwAKeDl3ssWmn6bDsG8UnD rOkTc3CdBLY4LTOMTGAFhS6hNy1UafxPrnXsqntB96AeH1CN/wAJy/jMQkxhXy3brH LSOEEAVQ4UAjeJwJqNdaSehbl6DjknEZHC41YBXs= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 51DA735207BD; Fri, 15 Nov 2019 08:53:50 -0800 (PST) Date: Fri, 15 Nov 2019 08:53:50 -0800 From: "Paul E. McKenney" To: Lai Jiangshan Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , rcu@vger.kernel.org Subject: Re: [PATCH V2 1/7] rcu: use preempt_count to test whether scheduler locks is held Message-ID: <20191115165350.GV2865@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20191102124559.1135-1-laijs@linux.alibaba.com> <20191102124559.1135-2-laijs@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191102124559.1135-2-laijs@linux.alibaba.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 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 Again, your point that RCU flavor consolidation allows some simplifications is an excellent one, so thank you again. And sorry to be slow, but the interaction with the rest of RCU must be taken into account. Therefore, doing this patch series justice does require some time. > --- > 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))) { My concern here is that this relies on a side-effect of the _irq locking primitives. What if someone similar to you comes along and is able to show significant performance benefits from making raw_spin_lock_irqsave() and friends leave preempt_count alone? After all, these primitives disable interrupts, so the bits in preempt_count can be argued to have no effect. But this patch is not central to simplifying __rcu_read_unlock(). Plus RCU now re-enables the scheduler clock tick on nohz_full CPUs that are blocking normal grace periods, which gives additional flexibility on this code path -- one of the big concerns when this was written was that in a PREEMPT=y kernel, a nohz_full CPU spinning in kernel code might never pass through a quiescent state. And expedited grace periods need to be fast on average, not worst case. So another approach might be to: 1. Simplfy the above expression to only do raise_softirq_irqoff() if we are actually in an interrupt handler. 2. Make expedited grace periods re-enable the scheduler-clock interrupt on CPUs that are slow to pass through quiescent states. (Taking care to disable them again, which might require coordination with the similar logic in normal grace periods.) As a second step, it might still be possible to continue using raise_softirq_irqoff() in some of the non-interrupt-handler cases involving __rcu_read_unlock() with interrupts disabled. Thoughts? Thanx, Paul > // 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. > raise_softirq_irqoff(RCU_SOFTIRQ); > } else { > // Enabling BH or preempt does reschedule, so... > -- > 2.20.1 >