• Paul E. McKenney's avatar
    rcu: Eliminate read-modify-write ACCESS_ONCE() calls · a792563b
    Paul E. McKenney authored
    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: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: default avatarPaul E. McKenney <paulmck@linux.vnet.ibm.com>
    a792563b
srcu.c 22 KB