18c2ecf20Sopenharmony_ci============= 28c2ecf20Sopenharmony_ciAtomic bitops 38c2ecf20Sopenharmony_ci============= 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ciWhile our bitmap_{}() functions are non-atomic, we have a number of operations 68c2ecf20Sopenharmony_cioperating on single bits in a bitmap that are atomic. 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciAPI 108c2ecf20Sopenharmony_ci--- 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ciThe single bit operations are: 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ciNon-RMW ops: 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci test_bit() 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ciRMW atomic operations without return value: 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci {set,clear,change}_bit() 218c2ecf20Sopenharmony_ci clear_bit_unlock() 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ciRMW atomic operations with return value: 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci test_and_{set,clear,change}_bit() 268c2ecf20Sopenharmony_ci test_and_set_bit_lock() 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ciBarriers: 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci smp_mb__{before,after}_atomic() 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ciAll RMW atomic operations have a '__' prefixed variant which is non-atomic. 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ciSEMANTICS 378c2ecf20Sopenharmony_ci--------- 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ciNon-atomic ops: 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ciIn particular __clear_bit_unlock() suffers the same issue as atomic_set(), 428c2ecf20Sopenharmony_ciwhich is why the generic version maps to clear_bit_unlock(), see atomic_t.txt. 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ciRMW ops: 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciThe test_and_{}_bit() operations return the original value of the bit. 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ciORDERING 518c2ecf20Sopenharmony_ci-------- 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ciLike with atomic_t, the rule of thumb is: 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci - non-RMW operations are unordered; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci - RMW operations that have no return value are unordered; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci - RMW operations that have a return value are fully ordered. 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci - RMW operations that are conditional are unordered on FAILURE, 628c2ecf20Sopenharmony_ci otherwise the above rules apply. In the case of test_and_set_bit_lock(), 638c2ecf20Sopenharmony_ci if the bit in memory is unchanged by the operation then it is deemed to have 648c2ecf20Sopenharmony_ci failed. 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciExcept for a successful test_and_set_bit_lock() which has ACQUIRE semantics and 678c2ecf20Sopenharmony_ciclear_bit_unlock() which has RELEASE semantics. 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ciSince a platform only has a single means of achieving atomic operations 708c2ecf20Sopenharmony_cithe same barriers as for atomic_t are used, see atomic_t.txt. 718c2ecf20Sopenharmony_ci 72