linux-yocto/Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-1.litmus
Paul E. McKenney 293f5bc271 Documentation/litmus-tests: Demonstrate unordered failing cmpxchg
This commit adds four litmus tests showing that a failing cmpxchg()
operation is unordered unless followed by an smp_mb__after_atomic()
operation.

Suggested-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Will Deacon <will@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Jade Alglave <j.alglave@ucl.ac.uk>
Cc: Luc Maranget <luc.maranget@inria.fr>
Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Akira Yokosawa <akiyks@gmail.com>
Cc: Daniel Lustig <dlustig@nvidia.com>
Cc: Joel Fernandes <joel@joelfernandes.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: <linux-arch@vger.kernel.org>
Cc: <linux-doc@vger.kernel.org>
Acked-by: Andrea Parri <parri.andrea@gmail.com>
2024-05-06 14:28:54 -07:00

35 lines
499 B
Plaintext

C cmpxchg-fail-ordered-1
(*
* Result: Never
*
* Demonstrate that a failing cmpxchg() operation will act as a full
* barrier when followed by smp_mb__after_atomic().
*)
{}
P0(int *x, int *y, int *z)
{
int r0;
int r1;
WRITE_ONCE(*x, 1);
r1 = cmpxchg(z, 1, 0);
smp_mb__after_atomic();
r0 = READ_ONCE(*y);
}
P1(int *x, int *y, int *z)
{
int r0;
WRITE_ONCE(*y, 1);
r1 = cmpxchg(z, 1, 0);
smp_mb__after_atomic();
r0 = READ_ONCE(*x);
}
locations[0:r1;1:r1]
exists (0:r0=0 /\ 1:r0=0)