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


Groups > linux.kernel > #1349751

Re: [PATCH] futex: replace bare barrier() with more lightweight READ_ONCE()

From Jianyu Zhan <nasa4836@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH] futex: replace bare barrier() with more lightweight READ_ONCE()
Date 2016-03-04 02:20 +0100
Message-ID <r8Mzo-7ld-11@gated-at.bofh.it> (permalink)
References <r8Dw6-Di-21@gated-at.bofh.it> <r8EVd-1Ta-21@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Fri, Mar 4, 2016 at 1:05 AM, Darren Hart <dvhart@infradead.org> wrote:
> I thought I provided a corrected comment block.... maybe I didn't. We have been
> working on improving the futex documentation, so we're paying close attention to
> terminology as well as grammar. This one needs a couple minor tweaks. I suggest:
>
> /*
>  * Use READ_ONCE to forbid the compiler from reloading q->lock_ptr and
>  * optimizing lock_ptr out of the logic below.
>  */
>
> The bit about q->lock_ptr possibly changing is already covered by the large
> comment block below the spin_lock(lock_ptr) call.

The large comment block is explaining the why the retry logic is required.
To achieve this semantic requirement,  the READ_ONCE is needed to prevent
compiler optimizing it by doing double loads.

So I think the comment above should explain this tricky part.

> /* Use READ_ONCE to forbid the compiler from reloading q->lock_ptr  in spin_lock()  */

And as for preventing from optimizing the lock_ptr out of the retry
code block,  I have consult
Paul Mckenney,  he suggests one more  READ_ONCE should be added here:

if (unlikely(lock_ptr != READ_ONCE(q->lock_ptr))) {
<------------------------------
                  spin_unlock(lock_ptr);
                  goto retry;
 }

And I think this are two problem, and should be separated into two patches?



Regards,
Jianyu Zhan

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] futex: replace bare barrier() with more lightweight READ_ONCE() Jianyu Zhan <nasa4836@gmail.com> - 2016-03-03 16:40 +0100
  Re: [PATCH] futex: replace bare barrier() with more lightweight  READ_ONCE() Darren Hart <dvhart@infradead.org> - 2016-03-03 18:10 +0100
    Re: [PATCH] futex: replace bare barrier() with more lightweight READ_ONCE() Jianyu Zhan <nasa4836@gmail.com> - 2016-03-04 02:20 +0100
      Re: [PATCH] futex: replace bare barrier() with more lightweight  READ_ONCE() Darren Hart <dvhart@infradead.org> - 2016-03-04 22:10 +0100
        Re: [PATCH] futex: replace bare barrier() with more lightweight  READ_ONCE() "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-03-04 23:10 +0100
          Re: [PATCH] futex: replace bare barrier() with more lightweight  READ_ONCE() Darren Hart <dvhart@infradead.org> - 2016-03-04 23:40 +0100
            Re: [PATCH] futex: replace bare barrier() with more lightweight  READ_ONCE() "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-03-04 23:50 +0100
              Re: [PATCH] futex: replace bare barrier() with more lightweight  READ_ONCE() Darren Hart <dvhart@infradead.org> - 2016-03-05 00:00 +0100
        [PATCH v3] futex: replace bare barrier() with more lightweight READ_ONCE() Jianyu Zhan <nasa4836@gmail.com> - 2016-03-07 02:40 +0100
          Re: [PATCH v3] futex: replace bare barrier() with more lightweight  READ_ONCE() Darren Hart <dvhart@infradead.org> - 2016-03-08 12:30 +0100
          [tip:locking/core] futex: Replace barrier() in unqueue_me() with  READ_ONCE() tip-bot for Jianyu Zhan <tipbot@zytor.com> - 2016-03-08 17:20 +0100

csiph-web