Skip to content

Commit

Permalink
locking/atomic/bitops: Document and clarify ordering semantics for fa…
Browse files Browse the repository at this point in the history
…iled test_and_{}_bit()

A test_and_{}_bit() operation fails if the value of the bit is such that
the modification does not take place. For example, if test_and_set_bit()
returns 1. In these cases, follow the behaviour of cmpxchg and allow the
operation to be unordered. This also applies to test_and_set_bit_lock()
if the lock is found to be be taken already.

Signed-off-by: Will Deacon <[email protected]>
Acked-by: Peter Zijlstra (Intel) <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Paul E. McKenney <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
wildea01 authored and Ingo Molnar committed Feb 13, 2018
1 parent 11dc132 commit 61e0239
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Documentation/atomic_bitops.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ Like with atomic_t, the rule of thumb is:

- RMW operations that have a return value are fully ordered.

Except for test_and_set_bit_lock() which has ACQUIRE semantics and
- RMW operations that are conditional are unordered on FAILURE,
otherwise the above rules apply. In the case of test_and_{}_bit() operations,
if the bit in memory is unchanged by the operation then it is deemed to have
failed.

Except for a successful test_and_set_bit_lock() which has ACQUIRE semantics and
clear_bit_unlock() which has RELEASE semantics.

Since a platform only has a single means of achieving atomic operations
Expand Down
3 changes: 2 additions & 1 deletion include/asm-generic/bitops/lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* @nr: Bit to set
* @addr: Address to count from
*
* This operation is atomic and provides acquire barrier semantics.
* This operation is atomic and provides acquire barrier semantics if
* the returned value is 0.
* It can be used to implement bit locks.
*/
#define test_and_set_bit_lock(nr, addr) test_and_set_bit(nr, addr)
Expand Down

0 comments on commit 61e0239

Please sign in to comment.