-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'lkmm.2024.05.10a' of git://git.kernel.org/pub/scm/linux/ke…
…rnel/git/paulmck/linux-rcu Pull LKMM documentation updates from Paul McKenney: "This upgrades LKMM documentation, perhaps most notably adding a number of litmus tests illustrating cmpxchg() ordering properties. TL;DR: Failing cmpxchg() operations provide no ordering" * tag 'lkmm.2024.05.10a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu: Documentation/litmus-tests: Make cmpxchg() tests safe for klitmus Documentation/atomic_t: Emphasize that failed atomic operations give no ordering Documentation/litmus-tests: Demonstrate unordered failing cmpxchg Documentation/litmus-tests: Add locking tests to README
- Loading branch information
Showing
6 changed files
with
176 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-1.litmus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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; | ||
int r1; | ||
|
||
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) |
30 changes: 30 additions & 0 deletions
30
Documentation/litmus-tests/atomic/cmpxchg-fail-ordered-2.litmus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
C cmpxchg-fail-ordered-2 | ||
|
||
(* | ||
* Result: Never | ||
* | ||
* Demonstrate use of smp_mb__after_atomic() to make a failing cmpxchg | ||
* operation have acquire ordering. | ||
*) | ||
|
||
{} | ||
|
||
P0(int *x, int *y) | ||
{ | ||
int r1; | ||
|
||
WRITE_ONCE(*x, 1); | ||
r1 = cmpxchg(y, 0, 1); | ||
} | ||
|
||
P1(int *x, int *y) | ||
{ | ||
int r1; | ||
int r2; | ||
|
||
r1 = cmpxchg(y, 0, 1); | ||
smp_mb__after_atomic(); | ||
r2 = READ_ONCE(*x); | ||
} | ||
|
||
exists (0:r1=0 /\ 1:r1=1 /\ 1:r2=0) |
34 changes: 34 additions & 0 deletions
34
Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-1.litmus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
C cmpxchg-fail-unordered-1 | ||
|
||
(* | ||
* Result: Sometimes | ||
* | ||
* Demonstrate that a failing cmpxchg() operation does not act as a | ||
* full barrier. (In contrast, a successful cmpxchg() does act as a | ||
* full barrier.) | ||
*) | ||
|
||
{} | ||
|
||
P0(int *x, int *y, int *z) | ||
{ | ||
int r0; | ||
int r1; | ||
|
||
WRITE_ONCE(*x, 1); | ||
r1 = cmpxchg(z, 1, 0); | ||
r0 = READ_ONCE(*y); | ||
} | ||
|
||
P1(int *x, int *y, int *z) | ||
{ | ||
int r0; | ||
int r1; | ||
|
||
WRITE_ONCE(*y, 1); | ||
r1 = cmpxchg(z, 1, 0); | ||
r0 = READ_ONCE(*x); | ||
} | ||
|
||
locations[0:r1;1:r1] | ||
exists (0:r0=0 /\ 1:r0=0) |
30 changes: 30 additions & 0 deletions
30
Documentation/litmus-tests/atomic/cmpxchg-fail-unordered-2.litmus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
C cmpxchg-fail-unordered-2 | ||
|
||
(* | ||
* Result: Sometimes | ||
* | ||
* Demonstrate that a failing cmpxchg() operation does not act as either | ||
* an acquire release operation. (In contrast, a successful cmpxchg() | ||
* does act as both an acquire and a release operation.) | ||
*) | ||
|
||
{} | ||
|
||
P0(int *x, int *y) | ||
{ | ||
int r1; | ||
|
||
WRITE_ONCE(*x, 1); | ||
r1 = cmpxchg(y, 0, 1); | ||
} | ||
|
||
P1(int *x, int *y) | ||
{ | ||
int r1; | ||
int r2; | ||
|
||
r1 = cmpxchg(y, 0, 1); | ||
r2 = READ_ONCE(*x); | ||
} | ||
|
||
exists (0:r1=0 /\ 1:r1=1 /\ 1:r2=0) |