atomic_bitops.txt 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. =============
  2. Atomic bitops
  3. =============
  4. While our bitmap_{}() functions are non-atomic, we have a number of operations
  5. operating on single bits in a bitmap that are atomic.
  6. API
  7. ---
  8. The single bit operations are:
  9. Non-RMW ops:
  10. test_bit()
  11. RMW atomic operations without return value:
  12. {set,clear,change}_bit()
  13. clear_bit_unlock()
  14. RMW atomic operations with return value:
  15. test_and_{set,clear,change}_bit()
  16. test_and_set_bit_lock()
  17. Barriers:
  18. smp_mb__{before,after}_atomic()
  19. All RMW atomic operations have a '__' prefixed variant which is non-atomic.
  20. SEMANTICS
  21. ---------
  22. Non-atomic ops:
  23. In particular __clear_bit_unlock() suffers the same issue as atomic_set(),
  24. which is why the generic version maps to clear_bit_unlock(), see atomic_t.txt.
  25. RMW ops:
  26. The test_and_{}_bit() operations return the original value of the bit.
  27. ORDERING
  28. --------
  29. Like with atomic_t, the rule of thumb is:
  30. - non-RMW operations are unordered;
  31. - RMW operations that have no return value are unordered;
  32. - RMW operations that have a return value are fully ordered.
  33. - RMW operations that are conditional are unordered on FAILURE,
  34. otherwise the above rules apply. In the case of test_and_{}_bit() operations,
  35. if the bit in memory is unchanged by the operation then it is deemed to have
  36. failed.
  37. Except for a successful test_and_set_bit_lock() which has ACQUIRE semantics and
  38. clear_bit_unlock() which has RELEASE semantics.
  39. Since a platform only has a single means of achieving atomic operations
  40. the same barriers as for atomic_t are used, see atomic_t.txt.