Skip to content

Commit ea6ee1b

Browse files
AlanSternpaulmckrcu
authored andcommitted
tools/memory-model: Code reorganization in lock.cat
Code reorganization for the lock.cat file in tools/memory-model: Improve the efficiency by ruling out right at the start RU events (spin_is_locked() calls that return False) inside a critical section for the same lock. Improve the organization of the code for handling LF and RU events by pulling the definitions of the pair-to-relation macro out from two different complicated compound expressions, using a single standalone definition instead. Rewrite the calculations of the rf relation for LF and RU events, for greater clarity. Signed-off-by: Alan Stern <[email protected]> Tested-by: Andrea Parri <[email protected]> Acked-by: Andrea Parri <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 4c830ee commit ea6ee1b

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

tools/memory-model/lock.cat

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ flag ~empty LKR \ domain(lk-rmw) as unpaired-LKR
5454
*)
5555
empty ([LKW] ; po-loc ; [LKR]) \ (po-loc ; [UL] ; po-loc) as lock-nest
5656

57+
(*
58+
* In the same way, spin_is_locked() inside a critical section must always
59+
* return True (no RU events can be in a critical section for the same lock).
60+
*)
61+
empty ([LKW] ; po-loc ; [RU]) \ (po-loc ; [UL] ; po-loc) as nested-is-locked
62+
5763
(* The final value of a spinlock should not be tested *)
5864
flag ~empty [FW] ; loc ; [ALL-LOCKS] as lock-final
5965

@@ -79,39 +85,47 @@ empty ([UNMATCHED-LKW] ; loc ; [UNMATCHED-LKW]) \ id as unmatched-locks
7985
(* rfi for LF events: link each LKW to the LF events in its critical section *)
8086
let rfi-lf = ([LKW] ; po-loc ; [LF]) \ ([LKW] ; po-loc ; [UL] ; po-loc)
8187

82-
(* rfe for LF events *)
88+
(* Utility macro to convert a single pair to a single-edge relation *)
89+
let pair-to-relation p = p ++ 0
90+
91+
(*
92+
* If a given LF event e is outside a critical section, it cannot read
93+
* internally but it may read from an LKW event in another thread.
94+
* Compute the relation containing these possible edges.
95+
*)
96+
let possible-rfe-noncrit-lf e = (LKW * {e}) & loc & ext
97+
98+
(* Compute set of sets of possible rfe edges for LF events *)
8399
let all-possible-rfe-lf =
84100
(*
85-
* Given an LF event r, compute the possible rfe edges for that event
86-
* (all those starting from LKW events in other threads),
87-
* and then convert that relation to a set of single-edge relations.
101+
* Convert the possible-rfe-noncrit-lf relation for e
102+
* to a set of single edges
88103
*)
89-
let possible-rfe-lf r =
90-
let pair-to-relation p = p ++ 0
91-
in map pair-to-relation ((LKW * {r}) & loc & ext)
92-
(* Do this for each LF event r that isn't in rfi-lf *)
93-
in map possible-rfe-lf (LF \ range(rfi-lf))
104+
let set-of-singleton-rfe-lf e =
105+
map pair-to-relation (possible-rfe-noncrit-lf e)
106+
(* Do this for each LF event e that isn't in rfi-lf *)
107+
in map set-of-singleton-rfe-lf (LF \ range(rfi-lf))
94108

95109
(* Generate all rf relations for LF events *)
96110
with rfe-lf from cross(all-possible-rfe-lf)
97111
let rf-lf = rfe-lf | rfi-lf
98112

99113
(*
100-
* RU, i.e., spin_is_locked() returning False, is slightly different.
101-
* We rely on the memory model to rule out cases where spin_is_locked()
102-
* within one of the lock's critical sections returns False.
114+
* A given RU event e may read internally from the last po-previous UL,
115+
* or it may read from a UL event in another thread or the initial write.
116+
* Compute the relation containing these possible edges.
103117
*)
118+
let possible-rf-ru e = (((UL * {e}) & po-loc) \
119+
([UL] ; po-loc ; [UL] ; po-loc)) |
120+
(((UL | IW) * {e}) & loc & ext)
104121

105-
(*
106-
* rf for RU events: an RU may read from an external UL or the initial write,
107-
* or from the last po-previous UL
108-
*)
122+
(* Compute set of sets of possible rf edges for RU events *)
109123
let all-possible-rf-ru =
110-
let possible-rf-ru r =
111-
let pair-to-relation p = p ++ 0
112-
in map pair-to-relation ((((UL | IW) * {r}) & loc & ext) |
113-
(((UL * {r}) & po-loc) \ ([UL] ; po-loc ; [LKW] ; po-loc)))
114-
in map possible-rf-ru RU
124+
(* Convert the possible-rf-ru relation for e to a set of single edges *)
125+
let set-of-singleton-rf-ru e =
126+
map pair-to-relation (possible-rf-ru e)
127+
(* Do this for each RU event e *)
128+
in map set-of-singleton-rf-ru RU
115129

116130
(* Generate all rf relations for RU events *)
117131
with rf-ru from cross(all-possible-rf-ru)

0 commit comments

Comments
 (0)