From: Linus Torvalds <torvalds@linux-foundation.org>
To: Nick Piggin <npiggin@suse.de>
Cc: Anton Blanchard <anton@samba.org>,
akpm@linux-foundation.org, willy@linux.intel.com,
benh@kernel.crashing.org, paulus@samba.org,
linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [PATCH 2/2]: atomic_t: Remove volatile from atomic_t definition
Date: Wed, 19 May 2010 07:55:19 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.2.00.1005190740390.23538@i5.linux-foundation.org> (raw)
In-Reply-To: <20100519130327.GW2516@laptop>
On Wed, 19 May 2010, Nick Piggin wrote:
>
> I wonder, Linus, is there a good reason to use volatile for these at
> all?
>
> I asked you about it quite a while back, and IIRC you said it might
> be OK to remove volatile from bitops, provided that callers were audited
> (ie. that nobody used bitops on volatile variables).
The bitops volatiles are different. They are there to allow for the C type
system (ie "const volatile *" just means that it accepts any kind of
pointer without complaining about implicit casting of const -> non-const
or volatile -> non-volatile).
For atomic_read(), and for the test_bit(), the _internal_ volatiles are
there just to get that ACCESS_ONCE() behavior, so that you can do things
like
while (test_bit(..)) {
..
}
and know that the compiler doesn't think it can do things like move the
atomic or bit read outside the loop or whatever.
Now, I do agree that _normally_ we should have memory barriers or similar
that guarantee that the compiler won't do odd things, but atomics and the
bitops are basically designed to work in the _absense_ of any other
serialization, so that's why it makes sense to have ACCESS_ONCE()
semantics for them.
> For atomic_read it shouldn't matter unless gcc is *really* bad at it.
> Ah, for atomic_read, the required semantic is surely ACCESS_ONCE, so
> that's where the volatile is needed? (maybe it would be clearer to
> explicitly use ACCESS_ONCE?)
Exactly. The volatile access on read inside those macros/functions (as
opposed to the "volatiles" that are there for C type reasons) is basically
the same as ACCESS_ONCE(). We could replace it with ACCESS_ONCE, although
I don't think it makes much difference as long as you always just think of
volatile as ACCESS_ONCE and just always put it in code (rather than on the
data structures)).
And replacing it with ACCESS_ONCE always has the header file dependency
issues, so..
> The case I was thinking about for bitops was for multiple non-atomic
> bitops, which would be nice to combine. In reality a lot of performance
> critical code (like page allocator) bites the bullet and does the
> open-coded bitwise ops. But it would be nice if that just worked for
> __set_bit / __clear_bit too.
__set_bit / __clear_bit should probably just be done as regular C code.
And yeah, we should remove the volatile from them. They aren't even valid
on anything that isn't locked anyway, so if somebody uses them on
something they have marked volatile, it's a bug.
Linus
next prev parent reply other threads:[~2010-05-19 14:57 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-17 4:33 [PATCH 1/2]: atomic_t: Cast to volatile when accessing atomic variables Anton Blanchard
2010-05-17 4:34 ` [PATCH 2/2]: atomic_t: Remove volatile from atomic_t definition Anton Blanchard
2010-05-17 8:58 ` Heiko Carstens
2010-05-17 15:01 ` Linus Torvalds
2010-05-17 20:13 ` Jamie Lokier
2010-05-17 20:20 ` Linus Torvalds
2010-05-19 13:03 ` Nick Piggin
2010-05-19 14:55 ` Linus Torvalds [this message]
2010-05-19 15:01 ` Paul E. McKenney
2010-05-19 19:54 ` David Miller
2010-05-19 22:50 ` Paul E. McKenney
2010-05-21 5:27 ` Nick Piggin
2010-05-21 5:54 ` David Miller
2010-05-21 6:06 ` Nick Piggin
2010-05-21 6:10 ` David Miller
2010-05-21 6:44 ` Eric Dumazet
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=alpine.LFD.2.00.1005190740390.23538@i5.linux-foundation.org \
--to=torvalds@linux-foundation.org \
--cc=akpm@linux-foundation.org \
--cc=anton@samba.org \
--cc=benh@kernel.crashing.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=npiggin@suse.de \
--cc=paulmck@linux.vnet.ibm.com \
--cc=paulus@samba.org \
--cc=willy@linux.intel.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;
as well as URLs for NNTP newsgroup(s).