-
Notifications
You must be signed in to change notification settings - Fork 1
/
OneUpdate.tla
379 lines (318 loc) · 10.1 KB
/
OneUpdate.tla
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
--------------------------- MODULE OneUpdate ---------------------------
EXTENDS OneUpdateMeta
-------------------------------------------------------------------------------------
\* Helpers
dir_has_action_pending == dReqPending = 1
dir_set_action_pending == dReqPending' = 1
dir_rst_action_pending == dReqPending' = 0
upd_dir_state(s) == dState' = s
upd_state(n, s) == cState' = [cState EXCEPT![n] = s]
\*
rmv_sharer(s) == dSharers' = dSharers \ {s}
add_sharer(s) == dSharers' = dSharers \union {s}
upd_owner(o) ==
/\ dOwner' = o
/\ dSharers' = {o}
rmv_owner(o) ==
/\ rmv_sharer(o)
/\ dOwner' = EMPTY_OWNER
rst_acks(n) ==
cRcvAcks' = [cRcvAcks EXCEPT![n] = {}]
add_ack(n, m) ==
cRcvAcks' = [cRcvAcks EXCEPT![n] = cRcvAcks[n] \union {m.sender}]
rst_dir_acks ==
dRcvAcks' = {}
add_dir_ack(m) ==
dRcvAcks' = dRcvAcks \union {m.sender}
rcv_upd_ack_msg(n, m) ==
/\ m.receiver = n
/\ m.type = "UAck"
rcv_ack_msg(n, m) ==
/\ m.receiver = n
/\ \/ m.type = "SAck"
\/ m.type = "SDataAck"
_is_last_Ack_from_set(n, m, set) ==
set \subseteq (cRcvAcks[n] \union {m.sender})
is_last_Ack(n, m) ==
/\ rcv_ack_msg(n, m)
/\ _is_last_Ack_from_set(n, m, dSharers \ {n})
is_last_upd_Ack(n, m) ==
/\ rcv_upd_ack_msg(n, m)
/\ _is_last_Ack_from_set(n, m, CORES \ {n})
is_last_dir_Ack(m) ==
/\ m.type = "UAck"
/\ dSharers \subseteq (dRcvAcks \union {m.sender})
owner_or_min_sharer ==
IF dOwner # EMPTY_OWNER
THEN dOwner
ELSE Min(dSharers)
sharers_no_fwd == dSharers \ {owner_or_min_sharer}
-------------------------------------------------------------------------------------
\**********************************
\* Requests involving only Directory
\**********************************
\* Local write hit
EtoM(n) == \* E to M
/\ cState[n] = "E"
/\ upd_owner(n)
/\ upd_state(n, "M")
/\ upd_dir_state("M")
/\ unchanged_gmMsgs
/\ UNCHANGED <<dReqPending, cData, cRcvAcks, dRcvAcks>>
\* Eviction
PutE(n) == \* E to I
/\ cState[n] = "E"
/\ rmv_owner(n)
/\ upd_state(n, "I")
/\ upd_dir_state("I")
/\ unchanged_gmMsgs
/\ UNCHANGED <<dReqPending, cData, cRcvAcks, dRcvAcks>>
PutM(n) == \* M to I
/\ cState[n] = "M"
/\ rmv_owner(n)
/\ upd_mem_data(n)
/\ upd_state(n, "I")
/\ upd_dir_state("I")
/\ unchanged_gMsgs
/\ UNCHANGED <<dReqPending, cData, cRcvAcks, dRcvAcks>>
PutS(n) == \* S to I/S
/\ cState[n] = "S"
/\ rmv_sharer(n)
/\ upd_state(n, "I")
/\ IF Cardinality(dSharers) = 1
THEN upd_dir_state("I")
ELSE UNCHANGED <<dState>>
/\ unchanged_gmMsgs
/\ UNCHANGED <<dOwner, dReqPending, cData, cRcvAcks, dRcvAcks>>
PutO(n) == \* O to I/S
/\ cState[n] = "O"
/\ rmv_owner(n)
/\ upd_mem_data(n)
/\ upd_state(n, "I")
/\ IF Cardinality(dSharers) = 1
THEN upd_dir_state("I")
ELSE upd_dir_state("S")
/\ unchanged_gMsgs
/\ UNCHANGED <<dReqPending, cData, cRcvAcks, dRcvAcks>>
\* Cache miss (fetching from memory)
GetS_dI(n) == \* I to E
/\ dState = "I"
/\ cState[n] = "I"
/\ add_sharer(n)
/\ rd_mem_data(n)
/\ upd_state(n, "E")
/\ upd_dir_state("E")
/\ unchanged_gmMsgs
/\ UNCHANGED <<dOwner, dReqPending, cRcvAcks, dRcvAcks>>
GetM_dI(n) == \* I to M
/\ dState = "I"
/\ cState[n] = "I"
/\ upd_owner(n)
/\ rd_mem_data(n)
/\ upd_state(n, "M")
/\ upd_dir_state("M")
/\ unchanged_gmMsgs
/\ UNCHANGED <<dReqPending, cRcvAcks, dRcvAcks>>
-------------------------------------------------------------------------------------
\* Dir
GetS_Fwd(n) ==
/\ dState # "I"
/\ cState[n] = "I"
/\ dir_set_action_pending
/\ ucst_FwdGetS(n, owner_or_min_sharer)
/\ IF (dState = "E" \/ dState = "S")
THEN /\ upd_dir_state("S")
ELSE upd_dir_state("O")
/\ unchanged_gmc
/\ UNCHANGED <<dOwner, dSharers, dRcvAcks>>
GetS(n) ==
\/ GetS_dI(n)
\/ GetS_Fwd(n)
\* Sharers
RcvFwdGetS(n, m) ==
/\ rcv_FwdGetS(m, n)
/\ resp_SData(m)
/\ IF (cState[n] = "E" \/ cState[n] = "S")
THEN upd_state(n, "S")
ELSE upd_state(n, "O")
/\ unchanged_gmd
/\ UNCHANGED <<cData, cRcvAcks, dRcvAcks>>
\* Requester
RcvData(n, m) ==
/\ rcv_SData(m, n)
/\ deliver_Msg(m)
/\ add_sharer(n)
/\ upd_state(n, "S")
/\ upd_core_data(n, m.data)
/\ dir_rst_action_pending
/\ unchanged_gm
/\ UNCHANGED <<dOwner, dState, cRcvAcks, dRcvAcks>>
-------------------------------------------------------------------------------------
\* Dir
GetM_Invs(n) ==
/\ dState # "I"
/\ cState[n] # "M"
/\ cState[n] # "E"
/\ Cardinality(dSharers \ {n}) > 0
/\ rst_acks(n)
/\ dir_set_action_pending
/\ upd_dir_state("M")
/\ unchanged_m
/\ UNCHANGED <<dOwner, dSharers, cState, cData, dRcvAcks>>
/\ IF (dState = "E" \/ dState = "M")
THEN /\ ucst_FwdGetM(n, owner_or_min_sharer) \* single remote owner case
/\ unchanged_g
ELSE IF (cState[n] = "S" \/ dOwner = n)
THEN /\ bcst_DInv(n, dSharers \ {n}) \* is owner but w/ sharers
/\ unchanged_Msgs
ELSE /\ ucst_FwdGetM(n, owner_or_min_sharer) \* (remote) owner and sharers
/\ IF Cardinality(dSharers \ {owner_or_min_sharer, n}) > 0
THEN bcst_DInv(n, dSharers \ {owner_or_min_sharer, n})
ELSE unchanged_g
GetM(n) ==
\/ EtoM(n)
\/ GetM_dI(n)
\/ GetM_Invs(n)
\* Sharers -> rcvInv or FwdGetM
RcvInv(n, m) ==
/\ (rcv_DInv(m, n) \/ rcv_FwdGetM(m, n))
/\ upd_state(n, "I")
/\ IF rcv_DInv(m, n)
THEN resp_SAck(m)
ELSE resp_SDataAck(m)
/\ unchanged_gmd
/\ UNCHANGED <<cData, cRcvAcks, dRcvAcks>>
\* Requester -> normal Ack or DataAck
RcvAck(n, m) ==
/\ rcv_ack_msg(n, m)
/\ deliver_Msg(m)
/\ unchanged_gm
/\ UNCHANGED <<dState, dRcvAcks>>
/\ IF rcv_SDataAck(m, n)
THEN upd_core_data(n, m.data)
ELSE UNCHANGED <<cData>>
/\ IF ~is_last_Ack(n, m)
THEN /\ add_ack(n, m)
/\ unchanged_d
/\ UNCHANGED <<cState>>
ELSE /\ rst_acks(n)
/\ upd_owner(n)
/\ upd_state(n, "M")
/\ dir_rst_action_pending
-------------------------------------------------------------------------------------
\* Dir
\*SharedUpdate
\*predicate
\* For simplicity now we always make every core a sharer here
MtoO(n) ==
/\ dir_set_action_pending
/\ bcst_Upd(n, CORES \ {n}, cData[n])
/\ unchanged_mMsgs
/\ IF ENABLE_DIR_ACKS
THEN /\ upd_state(n, "O") \* update eagerly to O state if dir collects ACKs
/\ dRcvAcks = {n} \* add the requester to rcved acks for easier check of all acks predicate
ELSE /\ rst_acks(n)
/\ UNCHANGED <<cState, dRcvAcks>>
/\ UNCHANGED <<cData, dOwner, dSharers, dState>>
RcvUpd(n, m) ==
/\ rcv_Upd(m, n)
/\ resp_UAck(m)
/\ upd_state(n, "S")
/\ upd_core_data(n, m.data)
/\ unchanged_gmd
/\ UNCHANGED <<cRcvAcks, dRcvAcks>>
RcvUpdAck(n, m) ==
/\ ~ENABLE_DIR_ACKS
/\ cState[n] = "M"
/\ rcv_upd_ack_msg(n, m)
/\ deliver_Msg(m)
/\ unchanged_gm
/\ UNCHANGED <<cData, dRcvAcks>>
/\ IF ~is_last_upd_Ack(n, m)
THEN /\ add_ack(n, m)
/\ unchanged_d
/\ UNCHANGED <<cState>>
ELSE /\ rst_acks(n)
/\ upd_state(n, "O")
/\ dState' = "O"
/\ dOwner' = n
/\ dSharers' = CORES
/\ dir_rst_action_pending
DirRcvUpdAck(m) ==
/\ ENABLE_DIR_ACKS
/\ dir_has_action_pending
/\ dState = "M"
/\ m.type = "UAck"
/\ deliver_Msg(m)
/\ unchanged_gmc
/\ UNCHANGED <<dOwner>>
/\ IF ~is_last_dir_Ack(m)
THEN /\ add_dir_ack(m)
/\ UNCHANGED <<dSharers, dReqPending, dState>>
ELSE /\ rst_dir_acks
/\ dState' = "O"
/\ dSharers' = CORES
/\ dir_rst_action_pending
-------------------------------------------------------------------------------------
must_update(n) ==
/\ cState[n] = "M"
/\ cData[n] = WRITE_TO_UPDATE
Requests(n) ==
/\ ~dir_has_action_pending
/\ IF must_update(n)
THEN MtoO(n)
ELSE \/ GetM(n)
\/ GetS(n)
\/ PutE(n)
\/ PutM(n)
\/ PutS(n)
\/ PutO(n)
SharerActions(n, m) ==
\/ RcvUpd(n, m)
\/ RcvInv(n, m)
\/ RcvFwdGetS(n, m)
RequesterActions(n, m) ==
\/ RcvAck(n, m)
\/ RcvData(n, m)
\/ RcvUpdAck(n, m)
DirActions(m) == DirRcvUpdAck(m)
MessageActions(n) ==
\E m \in Msgs:
\/ DirActions(m)
\/ SharerActions(n, m)
\/ RequesterActions(n, m)
PerformBcast ==
/\ gBcstMsg # {}
/\ \E m \in gBcstMsg:
/\ _send_Msg(m)
/\ unchanged_mcd
/\ UNCHANGED <<dRcvAcks>>
/\ IF gBcstMsgRcvers = {}
THEN /\ gBcstMsg' = {}
/\ UNCHANGED <<gBcstMsgRcvers>>
ELSE LET rcver == CHOOSE x \in gBcstMsgRcvers : TRUE IN
/\ gBcstMsg' = {[m EXCEPT!.receiver = rcver]}
/\ gBcstMsgRcvers' = gBcstMsgRcvers \ {rcver}
-------------------------------------------------------------------------------------
WriteData(n) ==
/\ cState[n] = "M"
/\ cData[n] < MAX_WRITES
/\ ~must_update(n)
/\ cData' = [cData EXCEPT![n] = cData[n] + 1]
/\ unchanged_gdmMsgs
/\ UNCHANGED <<cState, cRcvAcks, dRcvAcks>>
\* Modeling 1-Update protocol (Directory, memory and core/cache actions)
ANext ==
IF gBcstMsg # {}
THEN PerformBcast
ELSE \E n \in CORES:
\/ Requests(n)
\/ WriteData(n)
\/ MessageActions(n)
(***************************************************************************)
(* The complete definition of the algorithm *)
(***************************************************************************)
Spec == AInit /\ [][ANext]_vars
Invariants == /\ ([]ATypeOK) /\ ([]INVARIANTS)
THEOREM Spec => Invariants
=============================================================================