Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2812170ybx; Fri, 8 Nov 2019 09:38:28 -0800 (PST) X-Google-Smtp-Source: APXvYqzac59M+HrA7wcJHKavvNJ+u/nrLan/TO5/X4N/3wkhElMWS9HJ3dwkPTcfesrJQl5F0Lcp X-Received: by 2002:a05:6402:1146:: with SMTP id g6mr11704309edw.215.1573234708383; Fri, 08 Nov 2019 09:38:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573234708; cv=none; d=google.com; s=arc-20160816; b=adkHgFlELitepOqXdW1bzDan/Y1MyWTz2m3Z17r4sQV0syQf2m7bUCWigfJhZbZhqc ieNwGhM7FE7J6/v6DgWydMt1PQ4yNrIdt0/RBfuXFAedmYcQ5f3nWLyfEp2eaTs8COWB 5IEM5QyiE7bDilar3xKpugy4B/t8i+JCOUwK9BuL3EV0do+O9srHTtx3M2tTg7gaAELA T5FHXRwhPb18Ngu0g39b/Ml8OWyXC3G/guJnE7qOw0Oxcjl4KBa19PmT0ODaFMqaq8Zt ZTXMqVZpAxZBF4aTgUrlzFePUCi/H/r05tMGkpJsPj2QBdFdgSn53NRz/1AYd1UHHigX 6uVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=cPLUavt2+18JPUOXrhPbURoYnAFRHZBbfEdJHEBm5qQ=; b=r01mO3LdzZkoa6BKYKriyazndh7+WTLWxJWWCffjYj5uIWxHcckwdrEVOVEcgULwxc Xku1XvKGA92C/ckaZaK9+86ok+rTMqUnuMGZL1u4NVOiBInA1cj7GffFQksSqSYZPs2+ 7JVRggvzJEF/1Bq9Hrm+5M3Y5NXp/qik7t6TR9LZkmU1asPvy6iDJpDEysiiHe/Pef+t D5W0gDePSm/81XBEzKhJGAL2QwfxutTeY7KzvBYrQI1w8wBJwF6Oah2GOsJgJMbga36M psaIq7ZgFaqPksGEFhzC1U5y/ZyR/hp12K8wFWXAebgNArZcyMnJoGTX/DFsb8SqhLOG iiIw== ARC-Authentication-Results: i=1; mx.google.com; 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 gw3si3941032ejb.385.2019.11.08.09.38.04; Fri, 08 Nov 2019 09:38:28 -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; 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 S1727296AbfKHRf5 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 8 Nov 2019 12:35:57 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:52303 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726121AbfKHRf4 (ORCPT ); Fri, 8 Nov 2019 12:35:56 -0500 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1iT8Ar-000888-G8; Fri, 08 Nov 2019 18:35:53 +0100 Date: Fri, 8 Nov 2019 18:35:53 +0100 From: Sebastian Andrzej Siewior To: Dennis Zhou Cc: linux-kernel@vger.kernel.org, Tejun Heo , Christoph Lameter , Thomas Gleixner , Peter Zijlstra , "Paul E. McKenney" Subject: [PATCH v2] percpu-refcount: Use normal instead of RCU-sched" Message-ID: <20191108173553.lxsdic6wa4y3ifsr@linutronix.de> References: <20191002112252.ro7wpdylqlrsbamc@linutronix.de> <20191107091319.6zf5tmdi54amtann@linutronix.de> <20191107161749.GA93945@dennisz-mbp> <20191107162842.2qgd3db2cjmmsxeh@linutronix.de> <20191107165519.GA99408@dennisz-mbp> <20191107172434.ylz4hyxw4rbmhre2@linutronix.de> <20191107173653.GA1242@dennisz-mbp> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: <20191107173653.GA1242@dennisz-mbp> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a revert of commit a4244454df129 ("percpu-refcount: use RCU-sched insted of normal RCU") which claims the only reason for using RCU-sched is "rcu_read_[un]lock() … are slightly more expensive than preempt_disable/enable()" and "As the RCU critical sections are extremely short, using sched-RCU shouldn't have any latency implications." The problem with using RCU-sched here is that it disables preemption and the release callback (called from percpu_ref_put_many()) must not acquire any sleeping locks like spinlock_t. This breaks PREEMPT_RT because some of the users acquire spinlock_t locks in their callbacks. Using rcu_read_lock() on PREEMPTION=n kernels is not any different compared to rcu_read_lock_sched(). On PREEMPTION=y kernels there are already performance issues due to additional preemption points. Looking at the code, the rcu_read_lock() is just an increment and unlock is almost just a decrement unless there is something special to do. Both are functions while disabling preemption is inlined. Doing a small benchmark, the minimal amount of time required was mostly the same. The average time required was higher due to the higher MAX value (which could be preemption). With DEBUG_PREEMPT=y it is rcu_read_lock_sched() that takes a little longer due to the additional debug code. Convert back to normal RCU. Signed-off-by: Sebastian Andrzej Siewior --- On 2019-11-07 12:36:53 [-0500], Dennis Zhou wrote: > > some RCU section here invoke callbacks which acquire spinlock_t locks. > > This does not work on RT with disabled preemption. > > > > Yeah, so adding a bit in the commit message about why it's an issue for > RT kernels with disabled preemption as I don't believe this is an issue > for non-RT kernels. I realized that I had partly in the commit message so I rewrote the second chapter hopefully covering it all now more explicit. v1…v2: Slightly rewriting the second paragraph regarding RT implications. include/linux/percpu-refcount.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h index 7aef0abc194a2..390031e816dcd 100644 --- a/include/linux/percpu-refcount.h +++ b/include/linux/percpu-refcount.h @@ -186,14 +186,14 @@ static inline void percpu_ref_get_many(struct percpu_ref *ref, unsigned long nr) { unsigned long __percpu *percpu_count; - rcu_read_lock_sched(); + rcu_read_lock(); if (__ref_is_percpu(ref, &percpu_count)) this_cpu_add(*percpu_count, nr); else atomic_long_add(nr, &ref->count); - rcu_read_unlock_sched(); + rcu_read_unlock(); } /** @@ -223,7 +223,7 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref) unsigned long __percpu *percpu_count; bool ret; - rcu_read_lock_sched(); + rcu_read_lock(); if (__ref_is_percpu(ref, &percpu_count)) { this_cpu_inc(*percpu_count); @@ -232,7 +232,7 @@ static inline bool percpu_ref_tryget(struct percpu_ref *ref) ret = atomic_long_inc_not_zero(&ref->count); } - rcu_read_unlock_sched(); + rcu_read_unlock(); return ret; } @@ -257,7 +257,7 @@ static inline bool percpu_ref_tryget_live(struct percpu_ref *ref) unsigned long __percpu *percpu_count; bool ret = false; - rcu_read_lock_sched(); + rcu_read_lock(); if (__ref_is_percpu(ref, &percpu_count)) { this_cpu_inc(*percpu_count); @@ -266,7 +266,7 @@ static inline bool percpu_ref_tryget_live(struct percpu_ref *ref) ret = atomic_long_inc_not_zero(&ref->count); } - rcu_read_unlock_sched(); + rcu_read_unlock(); return ret; } @@ -285,14 +285,14 @@ static inline void percpu_ref_put_many(struct percpu_ref *ref, unsigned long nr) { unsigned long __percpu *percpu_count; - rcu_read_lock_sched(); + rcu_read_lock(); if (__ref_is_percpu(ref, &percpu_count)) this_cpu_sub(*percpu_count, nr); else if (unlikely(atomic_long_sub_and_test(nr, &ref->count))) ref->release(ref); - rcu_read_unlock_sched(); + rcu_read_unlock(); } /** -- 2.24.0