From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: paulmck <paulmck@kernel.org>
Cc: rcu <rcu@vger.kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@kernel.org>,
Lai Jiangshan <jiangshanlai@gmail.com>,
dipankar <dipankar@in.ibm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Josh Triplett <josh@joshtriplett.org>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
rostedt <rostedt@goodmis.org>,
David Howells <dhowells@redhat.com>,
Eric Dumazet <edumazet@google.com>, fweisbec <fweisbec@gmail.com>,
Oleg Nesterov <oleg@redhat.com>,
"Joel Fernandes, Google" <joel@joelfernandes.org>,
Bart Van Assche <bart.vanassche@wdc.com>,
Christoph Hellwig <hch@lst.de>, Hannes Reinecke <hare@suse.de>,
Johannes Thumshirn <jthumshirn@suse.de>,
Shane M Seymour <shane.seymour@hpe.com>,
Martin <martin.petersen@oracle.com>
Subject: Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
Date: Thu, 3 Oct 2019 15:14:11 -0400 (EDT) [thread overview]
Message-ID: <996944932.1292.1570130051686.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <20191003190919.GA2689@paulmck-ThinkPad-P72>
----- 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" <paulmck@kernel.org>
>> >> >
>> >> > 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 <torvalds@linux-foundation.org>
>> >> > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
>> >> > Cc: Bart Van Assche <bart.vanassche@wdc.com>
>> >> > Cc: Christoph Hellwig <hch@lst.de>
>> >> > Cc: Hannes Reinecke <hare@suse.de>
>> >> > Cc: Johannes Thumshirn <jthumshirn@suse.de>
>> >> > Cc: Shane M Seymour <shane.seymour@hpe.com>
>> >> > Cc: Martin K. Petersen <martin.petersen@oracle.com>
>> >> > ---
>> >> > 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
next prev parent reply other threads:[~2019-10-03 19:14 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-03 1:41 [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
2019-10-03 1:43 ` [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace() paulmck
2019-10-03 16:35 ` Mathieu Desnoyers
2019-10-03 16:52 ` Paul E. McKenney
2019-10-03 17:21 ` Mathieu Desnoyers
2019-10-03 19:09 ` Paul E. McKenney
2019-10-03 19:14 ` Mathieu Desnoyers [this message]
2019-10-03 1:43 ` [PATCH tip/core/rcu 2/9] x86/kvm/pmu: Replace rcu_swap_protected() with rcu_replace() paulmck
2019-10-03 10:14 ` Paolo Bonzini
2019-10-05 16:11 ` Paul E. McKenney
2019-10-03 1:43 ` [PATCH tip/core/rcu 3/9] drivers/gpu: " paulmck
2019-10-03 1:43 ` [PATCH tip/core/rcu 4/9] drivers/scsi: " paulmck
2019-10-04 2:09 ` Martin K. Petersen
2019-10-05 16:06 ` Paul E. McKenney
2019-10-10 2:36 ` Martin K. Petersen
2019-10-03 1:43 ` [PATCH tip/core/rcu 5/9] fs/afs: " paulmck
2019-10-03 1:43 ` [PATCH tip/core/rcu 6/9] bpf/cgroup: " paulmck
2019-10-03 17:21 ` Andrii Nakryiko
2019-10-03 20:58 ` Song Liu
2019-10-05 16:11 ` Paul E. McKenney
2019-10-03 1:43 ` [PATCH tip/core/rcu 7/9] net/core: " paulmck
2019-10-03 1:43 ` [PATCH tip/core/rcu 8/9] net/netfilter: " paulmck
2019-10-08 14:16 ` Pablo Neira Ayuso
2019-10-09 15:36 ` Paul E. McKenney
2019-10-03 1:43 ` [PATCH tip/core/rcu 9/9] net/sched: " paulmck
2019-10-03 8:38 ` [PATCH tip/core/rcu 5/9] fs/afs: " David Howells
2019-10-05 16:10 ` Paul E. McKenney
2019-10-03 8:39 ` [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace() David Howells
2019-10-03 13:08 ` Steven Rostedt
2019-10-03 13:33 ` Paul E. McKenney
2019-10-03 13:41 ` Peter Zijlstra
2019-10-03 13:58 ` Paul E. McKenney
2019-10-03 14:01 ` Joel Fernandes
2019-10-03 16:31 ` Mathieu Desnoyers
2019-10-03 18:05 ` Peter Zijlstra
2019-10-22 19:11 ` [PATCH v2 tip/core/rcu 0/10] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
2019-10-22 19:12 ` [PATCH tip/core/rcu 01/10] rcu: Upgrade rcu_swap_protected() to rcu_replace() paulmck
2019-10-22 19:12 ` [PATCH tip/core/rcu 02/10] x86/kvm/pmu: Replace rcu_swap_protected() with rcu_replace() paulmck
2019-10-22 19:12 ` [PATCH tip/core/rcu 03/10] drivers/gpu: " paulmck
2019-10-28 12:57 ` Joonas Lahtinen
2019-10-28 13:40 ` Paul E. McKenney
2019-10-22 19:12 ` [PATCH tip/core/rcu 04/10] drivers/scsi: " paulmck
2019-10-22 19:12 ` [PATCH tip/core/rcu 05/10] fs/afs: " paulmck
2019-10-22 19:12 ` [PATCH tip/core/rcu 06/10] bpf/cgroup: " paulmck
2019-10-22 19:12 ` [PATCH tip/core/rcu 07/10] net/core: " paulmck
2019-10-22 19:12 ` [PATCH tip/core/rcu 08/10] net/netfilter: " paulmck
2019-10-22 19:12 ` [PATCH tip/core/rcu 09/10] net/sched: " paulmck
2019-10-22 19:12 ` [PATCH tip/core/rcu 10/10] security/safesetid: " paulmck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=996944932.1292.1570130051686.JavaMail.zimbra@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=akpm@linux-foundation.org \
--cc=bart.vanassche@wdc.com \
--cc=dhowells@redhat.com \
--cc=dipankar@in.ibm.com \
--cc=edumazet@google.com \
--cc=fweisbec@gmail.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=jthumshirn@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=shane.seymour@hpe.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).