Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Documentation/litmus-tests/atomic: Add a test for smp_mb__after_atomic()

We already use a litmus test in atomic_t.txt to describe atomic RMW +
smp_mb__after_atomic() is stronger than acquire (both the read and the
write parts are ordered). So make it a litmus test in atomic-tests
directory, so that people can access the litmus easily.

Additionally, change the processor numbers "P1, P2" to "P0, P1" in
atomic_t.txt for the consistency with the processor numbers in the
litmus test, which herd can handle.

Acked-by: Alan Stern <stern@rowland.harvard.edu>
Acked-by: Andrea Parri <parri.andrea@gmail.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>

authored by

Boqun Feng and committed by
Paul E. McKenney
e30d0235 4dcd4d36

+42 -5
+5 -5
Documentation/atomic_t.txt
··· 233 233 is an ACQUIRE pattern (though very much not typical), but again the barrier is 234 234 strictly stronger than ACQUIRE. As illustrated: 235 235 236 - C strong-acquire 236 + C Atomic-RMW+mb__after_atomic-is-stronger-than-acquire 237 237 238 238 { 239 239 } 240 240 241 - P1(int *x, atomic_t *y) 241 + P0(int *x, atomic_t *y) 242 242 { 243 243 r0 = READ_ONCE(*x); 244 244 smp_rmb(); 245 245 r1 = atomic_read(y); 246 246 } 247 247 248 - P2(int *x, atomic_t *y) 248 + P1(int *x, atomic_t *y) 249 249 { 250 250 atomic_inc(y); 251 251 smp_mb__after_atomic(); ··· 253 253 } 254 254 255 255 exists 256 - (r0=1 /\ r1=0) 256 + (0:r0=1 /\ 0:r1=0) 257 257 258 258 This should not happen; but a hypothetical atomic_inc_acquire() -- 259 259 (void)atomic_fetch_inc_acquire() for instance -- would allow the outcome, 260 260 because it would not order the W part of the RMW against the following 261 261 WRITE_ONCE. Thus: 262 262 263 - P1 P2 263 + P0 P1 264 264 265 265 t = LL.acq *y (0) 266 266 t++;
+32
Documentation/litmus-tests/atomic/Atomic-RMW+mb__after_atomic-is-stronger-than-acquire.litmus
··· 1 + C Atomic-RMW+mb__after_atomic-is-stronger-than-acquire 2 + 3 + (* 4 + * Result: Never 5 + * 6 + * Test that an atomic RMW followed by a smp_mb__after_atomic() is 7 + * stronger than a normal acquire: both the read and write parts of 8 + * the RMW are ordered before the subsequential memory accesses. 9 + *) 10 + 11 + { 12 + } 13 + 14 + P0(int *x, atomic_t *y) 15 + { 16 + int r0; 17 + int r1; 18 + 19 + r0 = READ_ONCE(*x); 20 + smp_rmb(); 21 + r1 = atomic_read(y); 22 + } 23 + 24 + P1(int *x, atomic_t *y) 25 + { 26 + atomic_inc(y); 27 + smp_mb__after_atomic(); 28 + WRITE_ONCE(*x, 1); 29 + } 30 + 31 + exists 32 + (0:r0=1 /\ 0:r1=0)
+5
Documentation/litmus-tests/atomic/README
··· 7 7 LITMUS TESTS 8 8 ============ 9 9 10 + Atomic-RMW+mb__after_atomic-is-stronger-than-acquire 11 + Test that an atomic RMW followed by a smp_mb__after_atomic() is 12 + stronger than a normal acquire: both the read and write parts of 13 + the RMW are ordered before the subsequential memory accesses. 14 + 10 15 Atomic-RMW-ops-are-atomic-WRT-atomic_set.litmus 11 16 Test that atomic_set() cannot break the atomicity of atomic RMWs.