[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <18117.7611.660070.879392@cargo.ozlabs.ibm.com>
Date: Fri, 17 Aug 2007 14:02:03 +1000
From: Paul Mackerras <paulus@...ba.org>
To: Nick Piggin <nickpiggin@...oo.com.au>
Cc: paulmck@...ux.vnet.ibm.com,
Herbert Xu <herbert@...dor.apana.org.au>,
Stefan Richter <stefanr@...6.in-berlin.de>,
Satyam Sharma <satyam@...radead.org>,
Christoph Lameter <clameter@....com>,
Chris Snook <csnook@...hat.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
linux-arch@...r.kernel.org,
Linus Torvalds <torvalds@...ux-foundation.org>,
netdev@...r.kernel.org, Andrew Morton <akpm@...ux-foundation.org>,
ak@...e.de, heiko.carstens@...ibm.com, davem@...emloft.net,
schwidefsky@...ibm.com, wensong@...ux-vs.org, horms@...ge.net.au,
wjiang@...ilience.com, cfriesen@...tel.com, zlynx@....org,
rpjday@...dspring.com, jesper.juhl@...il.com,
segher@...nel.crashing.org
Subject: Re: [PATCH 0/24] make atomic_read() behave consistently across all
architectures
Nick Piggin writes:
> Why are people making these undocumented and just plain false
> assumptions about atomic_t?
Well, it has only been false since December 2006. Prior to that
atomics *were* volatile on all platforms.
> If they're using lockless code (ie.
> which they must be if using atomics), then they actually need to be
> thinking much harder about memory ordering issues.
Indeed. I believe that most uses of atomic_read other than in polling
loops or debug printk statements are actually racy. In some cases the
race doesn't seem to matter, but I'm sure there are cases where it
does.
> If that is too
> much for them, then they can just use locks.
Why use locks when you can just sprinkle magic fix-the-races dust (aka
atomic_t) over your code? :) :)
> > Precisely. And volatility is a key property of "atomic". Let's please
> > not throw it away.
>
> It isn't, though (at least not since i386 and x86-64 don't have it).
Conceptually it is, because atomic_t is specifically for variables
which are liable to be modified by other CPUs, and volatile _means_
"liable to be changed by mechanisms outside the knowledge of the
compiler".
> _Adding_ it is trivial, and can be done any time. Throwing it away
> (ie. making the API weaker) is _hard_. So let's not add it without
Well, in one sense it's not that hard - Linus did it just 8 months ago
in commit f9e9dcb3. :)
> really good reasons. It most definitely results in worse code
> generation in practice.
0.0008% increase in kernel text size on powerpc according to my
measurement. :)
> I don't know why people would assume volatile of atomics. AFAIK, most
By making something an atomic_t you're saying "other CPUs are going to
be modifying this, so treat it specially". It's reasonable to assume
that special treatment extends to reading and setting it.
> of the documentation is pretty clear that all the atomic stuff can be
> reordered etc. except for those that modify and return a value.
Volatility isn't primarily about reordering (though as Linus says it
does restrict reordering to some extent).
Paul.
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists