Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp204472ybp; Thu, 3 Oct 2019 12:17:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwX3D7g1tPpCbChP86v8Bb7m6Tjc5t4Fp4Q8DQvHAnhRbQqCwm2Fd+wjE53jauRc5Oc9vNM X-Received: by 2002:a17:906:81c6:: with SMTP id e6mr9063392ejx.284.1570130254968; Thu, 03 Oct 2019 12:17:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570130254; cv=none; d=google.com; s=arc-20160816; b=Msjykxiv/0A+iPRsR6Olfm1u0Dnx3s3HzUqUTb9OC9+vkO7NBT0O/USg75JeQKQatp 4S6t+cmwMFy8IciPqNm4c8mm3InqN6qhWlXLm17G9PNyeqW5oIq/sTnI2joFLANoFiNu lTIdxqSXVmr+QXCyeIz34/rc36KUSJtceLtoC3lGyecbTfMnOVrhQl+x4gxip1Clzws0 piNPvgJN6G6E1Z6hkn51Jzf8pjjgq/aCtlCQnWZYsYLq6Zqlg5sLYxjcBxJ4vhA+lTAu ij7kTQs3fsAssV/wfz/b4elUqODg4zneb5YdNpX1c/WxTSXHwi8KUG8BNyiVh+M/mxs8 c6Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=7io7uSdeeE/pgtuBYIIMb2OgPbrbl38vwPbZaO6HFvw=; b=ExV918kqWLTwDOQiaQO2dXzCx2enDzcbHQjXgs8puMwIPatEw3dqyhnSej0L7mD3K2 SV5fgAN/8MtodQWZpyE2W4GgC/CVKF8xvTB0wFF9sQxXkkEWhuqgIOY7mTRI4PKkC6QY pu01x+7XfVn/jER/ppCjBQgUG95Ri8TaOYmDF2P3vQCA+0Vb4dgIIfc9y9+hyJERIqor JQsEGq/EP/VAyhkK05EXukQVhLfwLaPgc+8louy2cV8qFdaShKymCCCDTllqVil/v0wV 6b5igXN3gFMzGCwn5As6ugbS71n2vsryAsVAm61A6jZ3ji2nGl1OPfX+IeXIS32JfM0R aoDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=beEbyjRH; 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=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g22si2105787eda.27.2019.10.03.12.17.10; Thu, 03 Oct 2019 12:17:34 -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=@efficios.com header.s=default header.b=beEbyjRH; 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=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730640AbfJCTOP (ORCPT + 99 others); Thu, 3 Oct 2019 15:14:15 -0400 Received: from mail.efficios.com ([167.114.142.138]:60432 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726677AbfJCTOO (ORCPT ); Thu, 3 Oct 2019 15:14:14 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id A458233B6C7; Thu, 3 Oct 2019 15:14:12 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id 2VPmRjdUR16r; Thu, 3 Oct 2019 15:14:12 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id EFB6B33B6C0; Thu, 3 Oct 2019 15:14:11 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com EFB6B33B6C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1570130052; bh=7io7uSdeeE/pgtuBYIIMb2OgPbrbl38vwPbZaO6HFvw=; h=Date:From:To:Message-ID:MIME-Version; b=beEbyjRH8RDU1ayL22FADOwMgSZr7sHigxFMjXI2qgq8/UCvEKQUz0BAu0ma4VSvH ElPhCIJKfqloIbzwqUaoYvSl+CEHYWIryWQIgbiSFMZpkJ5+OS0shtOszfU4hrmLBY jYqCOd7595Fh6TTom8wsBPKfTS3G9e2H2NNipLmsUaxy25yvbX0GC0tN02TLH+bxZJ ShGjKH2aMkcnnvYeFhHRCrhYpqir8/Kl9yvc40l/H9QyVN1Rl9fWVdWN6u1DcuNw7A 091bRHxp6Ou1eohY9EJy7NTbFvVu2hFX17GjUDpbGzGcO/Z1Q1oiLEbz3v6ak39k3I XSWRvWk/KNzvg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id pJzSuz6dVofd; Thu, 3 Oct 2019 15:14:11 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id D0F9B33B6B3; Thu, 3 Oct 2019 15:14:11 -0400 (EDT) Date: Thu, 3 Oct 2019 15:14:11 -0400 (EDT) From: Mathieu Desnoyers To: paulmck Cc: rcu , linux-kernel , Ingo Molnar , Lai Jiangshan , dipankar , Andrew Morton , Josh Triplett , Thomas Gleixner , Peter Zijlstra , rostedt , David Howells , Eric Dumazet , fweisbec , Oleg Nesterov , "Joel Fernandes, Google" , Bart Van Assche , Christoph Hellwig , Hannes Reinecke , Johannes Thumshirn , Shane M Seymour , Martin Message-ID: <996944932.1292.1570130051686.JavaMail.zimbra@efficios.com> In-Reply-To: <20191003190919.GA2689@paulmck-ThinkPad-P72> References: <20191003014153.GA13156@paulmck-ThinkPad-P72> <20191003014310.13262-1-paulmck@kernel.org> <644598334.955.1570120530976.JavaMail.zimbra@efficios.com> <20191003165220.GZ2689@paulmck-ThinkPad-P72> <618064891.1049.1570123274780.JavaMail.zimbra@efficios.com> <20191003190919.GA2689@paulmck-ThinkPad-P72> Subject: Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.15_GA_3847 (ZimbraWebClient - FF69 (Linux)/8.8.15_GA_3847) Thread-Topic: Upgrade rcu_swap_protected() to rcu_replace() Thread-Index: ag42kyaxnP9eCqmhEy53O9DecrsO8A== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Oct 3, 2019, at 3:09 PM, paulmck paulmck@kernel.org wrote: > On Thu, Oct 03, 2019 at 01:21:14PM -0400, Mathieu Desnoyers wrote: >> ----- On Oct 3, 2019, at 12:52 PM, paulmck paulmck@kernel.org wrote: >> >> > On Thu, Oct 03, 2019 at 12:35:30PM -0400, Mathieu Desnoyers wrote: >> >> ----- On Oct 2, 2019, at 9:43 PM, paulmck paulmck@kernel.org wrote: >> >> >> >> > From: "Paul E. McKenney" >> >> > >> >> > Although the rcu_swap_protected() macro follows the example of swap(), >> >> > the interactions with RCU make its update of its argument somewhat >> >> > counter-intuitive. This commit therefore introduces an rcu_replace() >> >> > that returns the old value of the RCU pointer instead of doing the >> >> > argument update. Once all the uses of rcu_swap_protected() are updated >> >> > to instead use rcu_replace(), rcu_swap_protected() will be removed. >> >> >> >> We expose the rcu_xchg_pointer() API in liburcu (Userspace RCU) project. >> >> Any reason for not going that way and keep the kernel and user-space RCU >> >> APIs alike ? >> >> >> >> It's of course fine if they diverge, but we might want to at least consider >> >> if using the same API name would be OK. >> > >> > Different semantics. An rcu_xchg_pointer() allows concurrent updates, >> > and rcu_replace() does not. >> > >> > But yes, if someone needs the concurrent updates, rcu_xchg_pointer() >> > would certainly be my choice for the name. >> >> Then considering that its assignment counterpart is "rcu_assign_pointer()" >> (and not "rcu_assign()"), would "rcu_replace_pointer()" be less ambiguous >> about its intended use ? > > The sequence was rcu_swap_protected() -> rcu_swap() -> rcu_replace(). > Because that rcu_replace(), unlike rcu_swap_protected(), returns a > value, the shorter name is valuable. > > Maybe we should have used rcu_assign() instead of rcu_assign_pointer(), > but there is no point in that sort of change at this late date! I agree that having both the "rcu_" prefix and the "_pointer" suffix is somewhat redundant. Indeed it's not a worthwhile change for a pre-existing API, but it is welcome for a new API. Thanks! Mathieu > > Thanx, Paul > >> Thanks, >> >> Mathieu >> >> >> > >> > Thanx, Paul >> > >> >> Thanks, >> >> >> >> Mathieu >> >> >> >> >> >> > >> >> > Link: >> >> > https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/ >> >> > Reported-by: Linus Torvalds >> >> > Signed-off-by: Paul E. McKenney >> >> > Cc: Bart Van Assche >> >> > Cc: Christoph Hellwig >> >> > Cc: Hannes Reinecke >> >> > Cc: Johannes Thumshirn >> >> > Cc: Shane M Seymour >> >> > Cc: Martin K. Petersen >> >> > --- >> >> > include/linux/rcupdate.h | 18 ++++++++++++++++++ >> >> > 1 file changed, 18 insertions(+) >> >> > >> >> > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h >> >> > index 75a2ede..3b73287 100644 >> >> > --- a/include/linux/rcupdate.h >> >> > +++ b/include/linux/rcupdate.h >> >> > @@ -383,6 +383,24 @@ do { \ >> >> > } while (0) >> >> > >> >> > /** >> >> > + * rcu_replace() - replace an RCU pointer, returning its old value >> >> > + * @rcu_ptr: RCU pointer, whose old value is returned >> >> > + * @ptr: regular pointer >> >> > + * @c: the lockdep conditions under which the dereference will take place >> >> > + * >> >> > + * Perform a replacement, where @rcu_ptr is an RCU-annotated >> >> > + * pointer and @c is the lockdep argument that is passed to the >> >> > + * rcu_dereference_protected() call used to read that pointer. The old >> >> > + * value of @rcu_ptr is returned, and @rcu_ptr is set to @ptr. >> >> > + */ >> >> > +#define rcu_replace(rcu_ptr, ptr, c) \ >> >> > +({ \ >> >> > + typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c)); \ >> >> > + rcu_assign_pointer((rcu_ptr), (ptr)); \ >> >> > + __tmp; \ >> >> > +}) >> >> > + >> >> > +/** >> >> > * rcu_swap_protected() - swap an RCU and a regular pointer >> >> > * @rcu_ptr: RCU pointer >> >> > * @ptr: regular pointer >> >> > -- >> >> > 2.9.5 >> >> >> >> -- >> >> Mathieu Desnoyers >> >> EfficiOS Inc. >> > > http://www.efficios.com >> >> -- >> Mathieu Desnoyers >> EfficiOS Inc. > > http://www.efficios.com -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com