mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Peter Hurley <peter@hurleysoftware.com>
Cc: paulmck@linux.vnet.ibm.com, Waiman Long <Waiman.Long@hpe.com>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org, Davidlohr Bueso <dave@stgolabs.net>,
	Jason Low <jason.low2@hp.com>, Dave Chinner <david@fromorbit.com>,
	Scott J Norton <scott.norton@hpe.com>,
	Douglas Hatch <doug.hatch@hpe.com>,
	kcc@google.com, dvyukov@google.com
Subject: Re: [PATCH v2] locking/rwsem: Add reader-owned state to the owner field
Date: Mon, 16 May 2016 19:50:41 +0200	[thread overview]
Message-ID: <20160516175041.GR3193@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <5739D686.302@hurleysoftware.com>

On Mon, May 16, 2016 at 07:17:42AM -0700, Peter Hurley wrote:

> >> Correct; which is why we should always use {READ,WRITE}_ONCE() for
> >> anything that is used locklessly.
> > 
> > Completely agreed.  Improve readability of code by flagging lockless
> > shared-memory accesses, help checkers better find bugs, and prevent the
> > occasional compiler mischief!
> 
> I think this would be a mistake for 3 reasons:
> 
> 1. If READ_ONCE()/WRITE_ONCE() is necessary to prevent load/store tearing
>    of any normally-atomic type (char/int/long/void*), then _every_ access
>    would require READ_ONCE()/WRITE_ONCE(), thus eliminating any possibility
>    of compiler optimization (eg. eliding redundant loads) where it would
>    otherwise be possible.

Should not really be a problem I think; you already have to be very
careful when doing lockless stuff.

> 2. Makes a mess of otherwise readable code.

We have to disagree here; I think code with {READ,WRITE}_ONCE() is more
readable, as their presence is a clear indication something special is
up.

> 3. Error-prone; ie., easy to overlook in review.

lockless stuff is error prone by nature; what's your point?

> There is no practical difference between _always_ using READ_ONCE()/WRITE_ONCE()
> (to prevent tearing) and declaring the field volatile.

There is, declaring the field volatile doesn't make it stand out in the
code while reading at all; it also doesn't allow you to omit the
volatile qualifier in places where it doesn't matter.

The whole; variables aren't volatile, accesses are, thing is still very
much in effect.

> So we've come full-circle from volatile-considered-harmful.

I don't think so; the cases that document talks about are still very
much relevant and volatile should not be used for that.

But yes, our understanding of both the memory model and the
language/compiler has come a long way since then.

  parent reply	other threads:[~2016-05-16 17:50 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-07  0:20 Waiman Long
2016-05-07  4:56 ` Ingo Molnar
2016-05-08  3:04   ` Waiman Long
2016-05-09  8:27 ` Peter Zijlstra
2016-05-10  2:24   ` Waiman Long
2016-05-10  7:02     ` Peter Zijlstra
2016-05-09 18:44 ` Jason Low
2016-05-10 13:03 ` Davidlohr Bueso
2016-05-11 22:04 ` Peter Hurley
2016-05-12 20:15   ` Waiman Long
2016-05-12 21:27     ` Peter Hurley
2016-05-12 23:13       ` Waiman Long
2016-05-13 15:07   ` Peter Zijlstra
2016-05-13 17:58     ` Peter Hurley
2016-05-15 14:47       ` Waiman Long
2016-05-16 11:09       ` Peter Zijlstra
2016-05-16 12:17         ` Paul E. McKenney
2016-05-16 14:17           ` Peter Hurley
2016-05-16 17:22             ` Paul E. McKenney
2016-05-17 19:46               ` Peter Hurley
2016-05-17 19:53                 ` Peter Hurley
2016-05-16 17:50             ` Peter Zijlstra [this message]
2016-05-17 19:15               ` Peter Hurley
2016-05-17 19:46                 ` Paul E. McKenney
2016-05-18 11:05                   ` Peter Zijlstra
2016-05-18 15:56                     ` Waiman Long
2016-05-18 17:28                       ` Paul E. McKenney
2016-05-18 17:26                     ` Paul E. McKenney
2016-05-19  9:00                       ` Peter Zijlstra
2016-05-19 13:43                         ` Paul E. McKenney
2016-05-19  1:37 ` Dave Chinner
2016-05-19  8:32   ` Peter Zijlstra
2016-05-20 22:56   ` Waiman Long

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=20160516175041.GR3193@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=Waiman.Long@hpe.com \
    --cc=dave@stgolabs.net \
    --cc=david@fromorbit.com \
    --cc=doug.hatch@hpe.com \
    --cc=dvyukov@google.com \
    --cc=jason.low2@hp.com \
    --cc=kcc@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peter@hurleysoftware.com \
    --cc=scott.norton@hpe.com \
    /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

Powered by JetHome