Skip to content

Commit fafa180

Browse files
Jonas Oberhauserpaulmckrcu
authored andcommitted
tools/memory-model: Switch to softcoded herd7 tags
A new version of herd7 provides a -lkmmv2 switch which overrides the old herd7 behavior of simply ignoring any softcoded tags in the .def and .bell files. We port LKMM to this version of herd7 by providing the switch in linux-kernel.cfg and reporting an error if the LKMM is used without this switch. To preserve the semantics of LKMM, we also softcode the Noreturn tag on atomic RMW which do not return a value and define atomic_add_unless with an Mb tag in linux-kernel.def. We update the herd-representation.txt accordingly and clarify some of the resulting combinations. Co-developed-by: Hernan Ponce de Leon <[email protected]> Signed-off-by: Hernan Ponce de Leon <[email protected]> Signed-off-by: Jonas Oberhauser <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]> Reviewed-by: Boqun Feng <[email protected]> Tested-by: Boqun Feng <[email protected]> Tested-by: Akira Yokosawa <[email protected]> # herdtools7.7.58
1 parent 2927934 commit fafa180

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

tools/memory-model/Documentation/herd-representation.txt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
#
1919
# By convention, a blank line in a cell means "same as the preceding line".
2020
#
21+
# Note that the syntactic representation does not always match the sets and
22+
# relations in linux-kernel.cat, due to redefinitions in linux-kernel.bell and
23+
# lock.cat. For example, the po link between LKR and LKW is upgraded to an rmw
24+
# link, and W[acquire] are not included in the Acquire set.
25+
#
2126
# Disclaimer. The table includes representations of "add" and "and" operations;
2227
# corresponding/identical representations of "sub", "inc", "dec" and "or", "xor",
2328
# "andnot" operations are omitted.
@@ -60,14 +65,13 @@
6065
------------------------------------------------------------------------------
6166
| RMW ops w/o return value | |
6267
------------------------------------------------------------------------------
63-
| atomic_add | R*[noreturn] ->rmw W*[once] |
68+
| atomic_add | R*[noreturn] ->rmw W*[noreturn] |
6469
| atomic_and | |
6570
| spin_lock | LKR ->po LKW |
6671
------------------------------------------------------------------------------
6772
| RMW ops w/ return value | |
6873
------------------------------------------------------------------------------
69-
| atomic_add_return | F[mb] ->po R*[once] |
70-
| | ->rmw W*[once] ->po F[mb] |
74+
| atomic_add_return | R*[mb] ->rmw W*[mb] |
7175
| atomic_fetch_add | |
7276
| atomic_fetch_and | |
7377
| atomic_xchg | |
@@ -79,13 +83,13 @@
7983
| atomic_xchg_relaxed | |
8084
| xchg_relaxed | |
8185
| atomic_add_negative_relaxed | |
82-
| atomic_add_return_acquire | R*[acquire] ->rmw W*[once] |
86+
| atomic_add_return_acquire | R*[acquire] ->rmw W*[acquire] |
8387
| atomic_fetch_add_acquire | |
8488
| atomic_fetch_and_acquire | |
8589
| atomic_xchg_acquire | |
8690
| xchg_acquire | |
8791
| atomic_add_negative_acquire | |
88-
| atomic_add_return_release | R*[once] ->rmw W*[release] |
92+
| atomic_add_return_release | R*[release] ->rmw W*[release] |
8993
| atomic_fetch_add_release | |
9094
| atomic_fetch_and_release | |
9195
| atomic_xchg_release | |
@@ -94,17 +98,16 @@
9498
------------------------------------------------------------------------------
9599
| Conditional RMW ops | |
96100
------------------------------------------------------------------------------
97-
| atomic_cmpxchg | On success: F[mb] ->po R*[once] |
98-
| | ->rmw W*[once] ->po F[mb] |
99-
| | On failure: R*[once] |
101+
| atomic_cmpxchg | On success: R*[mb] ->rmw W*[mb] |
102+
| | On failure: R*[mb] |
100103
| cmpxchg | |
101104
| atomic_add_unless | |
102105
| atomic_cmpxchg_relaxed | On success: R*[once] ->rmw W*[once] |
103106
| | On failure: R*[once] |
104-
| atomic_cmpxchg_acquire | On success: R*[acquire] ->rmw W*[once] |
105-
| | On failure: R*[once] |
106-
| atomic_cmpxchg_release | On success: R*[once] ->rmw W*[release] |
107-
| | On failure: R*[once] |
107+
| atomic_cmpxchg_acquire | On success: R*[acquire] ->rmw W*[acquire] |
108+
| | On failure: R*[acquire] |
109+
| atomic_cmpxchg_release | On success: R*[release] ->rmw W*[release] |
110+
| | On failure: R*[release] |
108111
| spin_trylock | On success: LKR ->po LKW |
109112
| | On failure: LF |
110113
------------------------------------------------------------------------------

tools/memory-model/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ that litmus test to be exercised within the Linux kernel.
2020
REQUIREMENTS
2121
============
2222

23-
Version 7.52 or higher of the "herd7" and "klitmus7" tools must be
23+
Version 7.58 or higher of the "herd7" and "klitmus7" tools must be
2424
downloaded separately:
2525

2626
https://github.com/herd/herdtools7

tools/memory-model/linux-kernel.bell

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,6 @@ let carry-dep = (data ; [~ Srcu-unlock] ; rfi)*
9494
let addr = carry-dep ; addr
9595
let ctrl = carry-dep ; ctrl
9696
let data = carry-dep ; data
97+
98+
flag ~empty (if "lkmmv2" then 0 else _)
99+
as this-model-requires-variant-higher-than-lkmmv1

tools/memory-model/linux-kernel.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
macros linux-kernel.def
22
bell linux-kernel.bell
33
model linux-kernel.cat
4+
variant lkmmv2
45
graph columns
56
squished true
67
showevents noregs

tools/memory-model/linux-kernel.def

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ atomic_set(X,V) { WRITE_ONCE(*X,V); }
6363
atomic_read_acquire(X) smp_load_acquire(X)
6464
atomic_set_release(X,V) { smp_store_release(X,V); }
6565

66-
atomic_add(V,X) { __atomic_op(X,+,V); }
67-
atomic_sub(V,X) { __atomic_op(X,-,V); }
68-
atomic_and(V,X) { __atomic_op(X,&,V); }
69-
atomic_or(V,X) { __atomic_op(X,|,V); }
70-
atomic_xor(V,X) { __atomic_op(X,^,V); }
71-
atomic_inc(X) { __atomic_op(X,+,1); }
72-
atomic_dec(X) { __atomic_op(X,-,1); }
73-
atomic_andnot(V,X) { __atomic_op(X,&~,V); }
66+
atomic_add(V,X) { __atomic_op{noreturn}(X,+,V); }
67+
atomic_sub(V,X) { __atomic_op{noreturn}(X,-,V); }
68+
atomic_and(V,X) { __atomic_op{noreturn}(X,&,V); }
69+
atomic_or(V,X) { __atomic_op{noreturn}(X,|,V); }
70+
atomic_xor(V,X) { __atomic_op{noreturn}(X,^,V); }
71+
atomic_inc(X) { __atomic_op{noreturn}(X,+,1); }
72+
atomic_dec(X) { __atomic_op{noreturn}(X,-,1); }
73+
atomic_andnot(V,X) { __atomic_op{noreturn}(X,&~,V); }
7474

7575
atomic_add_return(V,X) __atomic_op_return{mb}(X,+,V)
7676
atomic_add_return_relaxed(V,X) __atomic_op_return{once}(X,+,V)
@@ -144,3 +144,5 @@ atomic_fetch_andnot(V,X) __atomic_fetch_op{mb}(X,&~,V)
144144
atomic_fetch_andnot_acquire(V,X) __atomic_fetch_op{acquire}(X,&~,V)
145145
atomic_fetch_andnot_release(V,X) __atomic_fetch_op{release}(X,&~,V)
146146
atomic_fetch_andnot_relaxed(V,X) __atomic_fetch_op{once}(X,&~,V)
147+
148+
atomic_add_unless(X,V,W) __atomic_add_unless{mb}(X,V,W)

0 commit comments

Comments
 (0)