]> git.karo-electronics.de Git - linux-beck.git/commit
rcu: Eliminate read-modify-write ACCESS_ONCE() calls
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Mon, 2 Jun 2014 21:54:34 +0000 (14:54 -0700)
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Wed, 9 Jul 2014 16:14:49 +0000 (09:14 -0700)
commita792563bd47632d85158c72e2acf4484eed0ec32
treebbe0ccd1e3966c92f978347e9e32cbe9cd8a86bd
parent4da117cfa72e6cde3d9e8f5ed932381863cdeec9
rcu: Eliminate read-modify-write ACCESS_ONCE() calls

RCU contains code of the following forms:

ACCESS_ONCE(x)++;
ACCESS_ONCE(x) += y;
ACCESS_ONCE(x) -= y;

Now these constructs do operate correctly, but they really result in a
pair of volatile accesses, one to do the load and another to do the store.
This can be confusing, as the casual reader might well assume that (for
example) gcc might generate a memory-to-memory add instruction for each
of these three cases.  In fact, gcc will do no such thing.  Also, there
is a good chance that the kernel will move to separate load and store
variants of ACCESS_ONCE(), and constructs like the above could easily
confuse both people and scripts attempting to make that sort of change.
Finally, most of RCU's read-modify-write uses of ACCESS_ONCE() really
only need the store to be volatile, so that the read-modify-write form
might be misleading.

This commit therefore changes the above forms in RCU so that each instance
of ACCESS_ONCE() either does a load or a store, but not both.  In a few
cases, ACCESS_ONCE() was not critical, for example, for maintaining
statisitics.  In these cases, ACCESS_ONCE() has been dispensed with
entirely.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
kernel/rcu/srcu.c
kernel/rcu/tree.c