1*4882a593Smuzhiyun============= 2*4882a593SmuzhiyunAtomic bitops 3*4882a593Smuzhiyun============= 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunWhile our bitmap_{}() functions are non-atomic, we have a number of operations 6*4882a593Smuzhiyunoperating on single bits in a bitmap that are atomic. 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunAPI 10*4882a593Smuzhiyun--- 11*4882a593Smuzhiyun 12*4882a593SmuzhiyunThe single bit operations are: 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunNon-RMW ops: 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun test_bit() 17*4882a593Smuzhiyun 18*4882a593SmuzhiyunRMW atomic operations without return value: 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun {set,clear,change}_bit() 21*4882a593Smuzhiyun clear_bit_unlock() 22*4882a593Smuzhiyun 23*4882a593SmuzhiyunRMW atomic operations with return value: 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun test_and_{set,clear,change}_bit() 26*4882a593Smuzhiyun test_and_set_bit_lock() 27*4882a593Smuzhiyun 28*4882a593SmuzhiyunBarriers: 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun smp_mb__{before,after}_atomic() 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun 33*4882a593SmuzhiyunAll RMW atomic operations have a '__' prefixed variant which is non-atomic. 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun 36*4882a593SmuzhiyunSEMANTICS 37*4882a593Smuzhiyun--------- 38*4882a593Smuzhiyun 39*4882a593SmuzhiyunNon-atomic ops: 40*4882a593Smuzhiyun 41*4882a593SmuzhiyunIn particular __clear_bit_unlock() suffers the same issue as atomic_set(), 42*4882a593Smuzhiyunwhich is why the generic version maps to clear_bit_unlock(), see atomic_t.txt. 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun 45*4882a593SmuzhiyunRMW ops: 46*4882a593Smuzhiyun 47*4882a593SmuzhiyunThe test_and_{}_bit() operations return the original value of the bit. 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun 50*4882a593SmuzhiyunORDERING 51*4882a593Smuzhiyun-------- 52*4882a593Smuzhiyun 53*4882a593SmuzhiyunLike with atomic_t, the rule of thumb is: 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun - non-RMW operations are unordered; 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun - RMW operations that have no return value are unordered; 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun - RMW operations that have a return value are fully ordered. 60*4882a593Smuzhiyun 61*4882a593Smuzhiyun - RMW operations that are conditional are unordered on FAILURE, 62*4882a593Smuzhiyun otherwise the above rules apply. In the case of test_and_set_bit_lock(), 63*4882a593Smuzhiyun if the bit in memory is unchanged by the operation then it is deemed to have 64*4882a593Smuzhiyun failed. 65*4882a593Smuzhiyun 66*4882a593SmuzhiyunExcept for a successful test_and_set_bit_lock() which has ACQUIRE semantics and 67*4882a593Smuzhiyunclear_bit_unlock() which has RELEASE semantics. 68*4882a593Smuzhiyun 69*4882a593SmuzhiyunSince a platform only has a single means of achieving atomic operations 70*4882a593Smuzhiyunthe same barriers as for atomic_t are used, see atomic_t.txt. 71*4882a593Smuzhiyun 72