Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1306589 > unrolled thread

[PATCH] rbtree: use READ_ONCE in RB_EMPTY_ROOT

Started byDavidlohr Bueso <dave@stgolabs.net>
First post2016-01-11 19:30 +0100
Last post2016-01-12 17:00 +0100
Articles 4 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] rbtree: use READ_ONCE in RB_EMPTY_ROOT Davidlohr Bueso <dave@stgolabs.net> - 2016-01-11 19:30 +0100
    Re: [PATCH] rbtree: use READ_ONCE in RB_EMPTY_ROOT Peter Zijlstra <peterz@infradead.org> - 2016-01-12 10:10 +0100
      Re: [PATCH] rbtree: use READ_ONCE in RB_EMPTY_ROOT Davidlohr Bueso <dave@stgolabs.net> - 2016-01-12 16:20 +0100
        Re: [PATCH] rbtree: use READ_ONCE in RB_EMPTY_ROOT Peter Zijlstra <peterz@infradead.org> - 2016-01-12 17:00 +0100

#1306589 — [PATCH] rbtree: use READ_ONCE in RB_EMPTY_ROOT

FromDavidlohr Bueso <dave@stgolabs.net>
Date2016-01-11 19:30 +0100
Subject[PATCH] rbtree: use READ_ONCE in RB_EMPTY_ROOT
Message-ID<qPPo6-67U-19@gated-at.bofh.it>
With d72da4a4d97 (rbtree: Make lockless searches non-fatal) our rbtrees
provide weak guarantees that allows us to do lockless (and very speculative)
reads of the tree. Such readers cannot see partial stores on nodes, ie
left/right as well as root. As such, similar to the WRITE_ONCE semantics when
doing rotations, use READ_ONCE when checking the root node in RB_EMPTY_ROOT.

Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
---
 include/linux/rbtree.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/rbtree.h b/include/linux/rbtree.h
index a5aa7ae..b690009 100644
--- a/include/linux/rbtree.h
+++ b/include/linux/rbtree.h
@@ -50,7 +50,7 @@ struct rb_root {
 #define RB_ROOT	(struct rb_root) { NULL, }
 #define	rb_entry(ptr, type, member) container_of(ptr, type, member)
 
-#define RB_EMPTY_ROOT(root)  ((root)->rb_node == NULL)
+#define RB_EMPTY_ROOT(root)  (READ_ONCE((root)->rb_node) == NULL)
 
 /* 'empty' nodes are nodes that are known not to be inserted in an rbtree */
 #define RB_EMPTY_NODE(node)  \
-- 
2.1.4

[toc] | [next] | [standalone]


#1307129

FromPeter Zijlstra <peterz@infradead.org>
Date2016-01-12 10:10 +0100
Message-ID<qQ37I-7fJ-11@gated-at.bofh.it>
In reply to#1306589
On Mon, Jan 11, 2016 at 10:22:43AM -0800, Davidlohr Bueso wrote:
> With d72da4a4d97 (rbtree: Make lockless searches non-fatal) our rbtrees
> provide weak guarantees that allows us to do lockless (and very speculative)
> reads of the tree. Such readers cannot see partial stores on nodes, ie
> left/right as well as root. As such, similar to the WRITE_ONCE semantics when
> doing rotations, use READ_ONCE when checking the root node in RB_EMPTY_ROOT.

No objection, but is this actually used anywhere?

Or is this a just-in-case completeness thing?

[toc] | [prev] | [next] | [standalone]


#1307527

FromDavidlohr Bueso <dave@stgolabs.net>
Date2016-01-12 16:20 +0100
Message-ID<qQ8TM-2LK-21@gated-at.bofh.it>
In reply to#1307129
On Tue, 12 Jan 2016, Peter Zijlstra wrote:

>On Mon, Jan 11, 2016 at 10:22:43AM -0800, Davidlohr Bueso wrote:
>> With d72da4a4d97 (rbtree: Make lockless searches non-fatal) our rbtrees
>> provide weak guarantees that allows us to do lockless (and very speculative)
>> reads of the tree. Such readers cannot see partial stores on nodes, ie
>> left/right as well as root. As such, similar to the WRITE_ONCE semantics when
>> doing rotations, use READ_ONCE when checking the root node in RB_EMPTY_ROOT.
>
>No objection, but is this actually used anywhere?

I found this because I wanted to use the waiter check in rtmutexes in a lockless
fashion (ie rt_mutex_has_waiters).

>
>Or is this a just-in-case completeness thing?

This too.

Thanks,
Davidlohr

[toc] | [prev] | [next] | [standalone]


#1307574

FromPeter Zijlstra <peterz@infradead.org>
Date2016-01-12 17:00 +0100
Message-ID<qQ9wu-2Zn-9@gated-at.bofh.it>
In reply to#1307527
On Tue, Jan 12, 2016 at 07:09:46AM -0800, Davidlohr Bueso wrote:
> On Tue, 12 Jan 2016, Peter Zijlstra wrote:
> 
> >On Mon, Jan 11, 2016 at 10:22:43AM -0800, Davidlohr Bueso wrote:
> >>With d72da4a4d97 (rbtree: Make lockless searches non-fatal) our rbtrees
> >>provide weak guarantees that allows us to do lockless (and very speculative)
> >>reads of the tree. Such readers cannot see partial stores on nodes, ie
> >>left/right as well as root. As such, similar to the WRITE_ONCE semantics when
> >>doing rotations, use READ_ONCE when checking the root node in RB_EMPTY_ROOT.
> >
> >No objection, but is this actually used anywhere?
> 
> I found this because I wanted to use the waiter check in rtmutexes in a lockless
> fashion (ie rt_mutex_has_waiters).

OK, fair enough.

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web