Skip to content

Commit e30d023

Browse files
fbqpaulmckrcu
authored andcommitted
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 <[email protected]> Acked-by: Andrea Parri <[email protected]> Signed-off-by: Boqun Feng <[email protected]> Reviewed-by: Joel Fernandes (Google) <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 4dcd4d3 commit e30d023

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

Documentation/atomic_t.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,34 +233,34 @@ as well. Similarly, something like:
233233
is an ACQUIRE pattern (though very much not typical), but again the barrier is
234234
strictly stronger than ACQUIRE. As illustrated:
235235

236-
C strong-acquire
236+
C Atomic-RMW+mb__after_atomic-is-stronger-than-acquire
237237

238238
{
239239
}
240240

241-
P1(int *x, atomic_t *y)
241+
P0(int *x, atomic_t *y)
242242
{
243243
r0 = READ_ONCE(*x);
244244
smp_rmb();
245245
r1 = atomic_read(y);
246246
}
247247

248-
P2(int *x, atomic_t *y)
248+
P1(int *x, atomic_t *y)
249249
{
250250
atomic_inc(y);
251251
smp_mb__after_atomic();
252252
WRITE_ONCE(*x, 1);
253253
}
254254

255255
exists
256-
(r0=1 /\ r1=0)
256+
(0:r0=1 /\ 0:r1=0)
257257

258258
This should not happen; but a hypothetical atomic_inc_acquire() --
259259
(void)atomic_fetch_inc_acquire() for instance -- would allow the outcome,
260260
because it would not order the W part of the RMW against the following
261261
WRITE_ONCE. Thus:
262262

263-
P1 P2
263+
P0 P1
264264

265265
t = LL.acq *y (0)
266266
t++;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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)

Documentation/litmus-tests/atomic/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@ tools/memory-model/README.
77
LITMUS TESTS
88
============
99

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+
1015
Atomic-RMW-ops-are-atomic-WRT-atomic_set.litmus
1116
Test that atomic_set() cannot break the atomicity of atomic RMWs.

0 commit comments

Comments
 (0)