-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_rcu_traversal.v
357 lines (310 loc) · 12.8 KB
/
spec_rcu_traversal.v
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
From stdpp Require Export namespaces gmultiset.
From iris.algebra Require Import list.
From smr.program_logic Require Import atomic.
From smr.lang Require Import proofmode notation.
From smr Require Export smr_common ebr.spec_rcu_common.
From iris.prelude Require Import options.
From smr Require Import helpers.
Definition InactiveT Σ : Type :=
∀ (γd : gname) (g : loc), iProp Σ.
Definition GuardT Σ (N : namespace) : Type :=
∀ (γd : gname) (γg : gname)
(g : loc),
iProp Σ.
Definition ManagedT Σ (N : namespace) : Type :=
∀ (γd : gname)
(p : blk) (i : positive) (ty : type Σ)
(B : gmultiset positive),
iProp Σ.
Definition DeletedT Σ (N : namespace) : Type :=
∀ (γd : gname)
(p : blk) (i : positive) (ty : type Σ),
iProp Σ.
(* Logical ownership of [p +ₗ o]. If [to] is [Some], it points to a node
governed by RCU. If [None], [p +ₗ o] points to something uninteresting. *)
Definition RCUPointsToT Σ (N : namespace) : Type :=
∀ (γd : gname)
(p : blk) (i : positive) (o : nat)
(to : option (blk * positive * type Σ)),
iProp Σ.
Definition RCUNodeInfoT Σ (N : namespace) : Type :=
∀ (γd : gname) (γg : gname)
(p : blk) (i : positive)
(ty : type Σ),
iProp Σ.
Section spec.
Context {Σ} `{!heapGS Σ} (N : namespace).
Variables
(rcu_domain_new : val)
(rcu_domain_retire : val)
(rcu_domain_do_reclamation : val)
(guard_new : val)
(guard_activate : val)
(guard_deactivate : val)
(guard_drop : val).
Variables
(IsRCUDomain : DomainT Σ N)
(Inactive : InactiveT Σ)
(Guard : GuardT Σ N)
(Managed : ManagedT Σ N)
(Deleted : DeletedT Σ N)
(RCUPointsTo : RCUPointsToT Σ N)
(RCUNodeInfo : RCUNodeInfoT Σ N)
.
Definition rcu_domain_new_spec' : Prop :=
∀ E,
{{{ True }}}
rcu_domain_new #() @ E
{{{ γd d, RET #d; IsRCUDomain γd d }}}.
Implicit Types (succs : list (option (blk * positive * type Σ * gmultiset positive))).
Definition RCUNodeSuccManageds γd succs : iProp Σ :=
[∗ list] field ∈ succs,
match field with
| Some (p', i', ty', B') => Managed γd p' i' ty' B'
| _ => True
end.
Global Arguments RCUNodeSuccManageds _ !_ / : assert.
Definition succs_add_pred succs (i : positive) :=
(λ field, match field with Some (p', i', ty', B') => Some (p', i', ty', B' ⊎ {[+i+]}) | None => None end)
<$> succs.
Definition rcu_domain_register' : Prop :=
∀ (I : gset positive) ty succs (R : positive → iProp Σ) E' E (p : blk) lv γd d,
E' ## ↑(mgmtN N) →
E' ⊆ E →
↑(mgmtN N) ⊆ E →
ty.(ty_sz) = length lv →
ty.(ty_sz) = length succs →
ty.(ty_sz) > 0 →
IsRCUDomain γd d -∗
p ↦∗ lv -∗ †p…(length lv) -∗
(* NOTE: Can't let client modify the link, because that requires opening
[IsRCUDomain], which is already open in the proof of this rule. So this rule
itself should modify the links (which requires the [Managed]s of link
targets) and pass the [RCUPointsTo]s to the client. *)
RCUNodeSuccManageds γd succs -∗
( ∀ i, ⌜i ∉ I⌝ -∗
([∗ list] o ↦ field ∈ succs, RCUPointsTo γd p i o (fst <$> field)) ={E'}=∗
ty.(ty_res) p lv i ∗ R i) ={E}=∗
∃ i, ⌜i ∉ I⌝ ∗
Managed γd p i ty ∅ ∗ RCUNodeSuccManageds γd (succs_add_pred succs i) ∗ R i.
Definition guard_new_spec' : Prop :=
∀ E γd d,
↑(mgmtN N) ⊆ E →
IsRCUDomain γd d -∗
{{{ True }}}
guard_new #d @ E
{{{ g, RET #g; Inactive γd g }}}.
Definition guard_activate_spec' : Prop :=
∀ E γd d g,
↑(mgmtN N) ⊆ E →
IsRCUDomain γd d -∗
{{{ Inactive γd g }}}
guard_activate #g @ E
{{{ γg, RET #(); Guard γd γg g }}}.
Definition guard_deactivate_spec' : Prop :=
∀ E γd d γg g,
↑(mgmtN N) ⊆ E →
IsRCUDomain γd d -∗
{{{ Guard γd γg g }}}
guard_deactivate #g @ E
{{{ RET #(); Inactive γd g }}}.
Definition guard_drop_spec' : Prop :=
∀ E γd d γg g,
↑(mgmtN N) ⊆ E →
IsRCUDomain γd d -∗
{{{ Guard γd γg g }}}
guard_drop #g @ E
{{{ RET #(); True }}}.
Definition guard_drop_inactive_spec' : Prop :=
∀ E γd d g,
↑(mgmtN N) ⊆ E →
IsRCUDomain γd d -∗
{{{ Inactive γd g }}}
guard_drop #g @ E
{{{ RET #(); True }}}.
Definition guard_protect_managed' :=
∀ E γd d p i ty B γg g,
↑(mgmtN N) ⊆ E →
IsRCUDomain γd d -∗
Managed γd p i ty B -∗
Guard γd γg g ={E}=∗
Managed γd p i ty B ∗
Guard γd γg g ∗
RCUNodeInfo γd γg p i ty.
Definition guard_protect_rcu_points_to' :=
∀ E γd d p1 i1 o1 p2 i2 ty1 ty2 γg g,
↑(mgmtN N) ⊆ E →
IsRCUDomain γd d -∗
RCUNodeInfo γd γg p1 i1 ty1 -∗
RCUPointsTo γd p1 i1 o1 (Some (p2, i2, ty2)) -∗
Guard γd γg g ={E}=∗
RCUPointsTo γd p1 i1 o1 (Some (p2, i2, ty2)) ∗
Guard γd γg g ∗
RCUNodeInfo γd γg p2 i2 ty2.
Definition guard_acc' : Prop :=
∀ ty E γd γg g p i,
↑(ptrN N p) ⊆ E →
RCUNodeInfo γd γg p i ty -∗
Guard γd γg g ={E,E∖↑(ptrN N p)}=∗
∃ lv, p ↦∗ lv ∗ ▷ ty.(ty_res) p lv i ∗ Guard γd γg g ∗
(∀ lv', p ↦∗ lv' ∗ ▷ ty.(ty_res) p lv' i ={E∖↑(ptrN N p),E}=∗ True).
Definition managed_acc' : Prop :=
∀ E γd ty p i B,
↑(ptrN N p) ⊆ E →
Managed γd p i ty B ={E,E∖↑(ptrN N p)}=∗
∃ lv, p ↦∗ lv ∗ ▷ ty.(ty_res) p lv i ∗ Managed γd p i ty B ∗
(∀ lv', p ↦∗ lv' ∗ ▷ ty.(ty_res) p lv' i ={E∖↑(ptrN N p),E}=∗ True).
Definition deleted_acc' : Prop :=
∀ E γd ty p i,
↑(ptrN N p) ⊆ E →
Deleted γd p i ty ={E,E∖↑(ptrN N p)}=∗
∃ lv, p ↦∗ lv ∗ ▷ ty.(ty_res) p lv i ∗ Deleted γd p i ty ∗
(∀ lv', p ↦∗ lv' ∗ ▷ ty.(ty_res) p lv' i ={E∖↑(ptrN N p),E}=∗ True).
Definition managed_exclusive' : Prop :=
∀ γd p i i' ty ty' B B',
Managed γd p i ty B -∗ Managed γd p i' ty' B' -∗ False.
Definition guard_managed_agree' : Prop :=
∀ γd γg g p i1 i2 ty1 ty2 B,
RCUNodeInfo γd γg p i1 ty1 -∗
Guard γd γg g -∗
Managed γd p i2 ty2 B -∗
⌜i1 = i2⌝.
Definition rcu_points_to_link' : Prop :=
∀ E γd d p1 i1 o1 p2 i2 ty2 B2,
↑(mgmtN N) ⊆ E →
IsRCUDomain γd d -∗
RCUPointsTo γd p1 i1 o1 None -∗
Managed γd p2 i2 ty2 B2 ={E}=∗
RCUPointsTo γd p1 i1 o1 (Some (p2,i2,ty2)) ∗
Managed γd p2 i2 ty2 (B2 ⊎ {[+ i1 +]}).
Definition rcu_points_to_unlink' : Prop :=
∀ E γd d p1 i1 o1 p2 i2 ty2 B2,
↑(mgmtN N) ⊆ E →
IsRCUDomain γd d -∗
RCUPointsTo γd p1 i1 o1 (Some (p2,i2,ty2)) -∗
Managed γd p2 i2 ty2 B2 ={E}=∗
RCUPointsTo γd p1 i1 o1 None ∗
Managed γd p2 i2 ty2 (B2 ∖ {[+ i1 +]}).
Definition rcu_points_to_update' : Prop :=
∀ E γd d p1 i1 o1 p2 i2 ty2 B2 p3 i3 ty3 B3,
↑(mgmtN N) ⊆ E →
IsRCUDomain γd d -∗
RCUPointsTo γd p1 i1 o1 (Some (p2,i2,ty2)) -∗
Managed γd p2 i2 ty2 B2 -∗
Managed γd p3 i3 ty3 B3 ={E}=∗
RCUPointsTo γd p1 i1 o1 (Some (p3,i3,ty3)) ∗
Managed γd p2 i2 ty2 (B2 ∖ {[+ i1 +]}) ∗
Managed γd p3 i3 ty3 (B3 ⊎ {[+ i1 +]}).
(* Delayed cleanup of predecessor set using over-approximating predecessor set.
Alternative: No delayed cleanup. Require [Managed]s here. This make deletion
rule more complicated, but enables reference counting (instead of predecessor
multiset). *)
Definition managed_delete' : Prop :=
∀ E γd d p i ty,
↑(mgmtN N) ⊆ E →
IsRCUDomain γd d -∗
Managed γd p i ty ∅ ={E}=∗
Deleted γd p i ty.
Definition deleted_clean' : Prop :=
∀ E γd d p1 p2 i1 i2 ty1 ty2 B,
↑(mgmtN N) ⊆ E →
IsRCUDomain γd d -∗
Deleted γd p1 i1 ty1 -∗
Managed γd p2 i2 ty2 B ={E}=∗
Deleted γd p1 i1 ty1 ∗
Managed γd p2 i2 ty2 (B ∖ {[+ i1 +]}).
(* NOTE: variant of retire that makes guard internally. *)
Definition rcu_domain_retire_spec' : Prop :=
∀ E γd d p i ty s,
↑N ⊆ E →
s = ty.(ty_sz) →
IsRCUDomain γd d -∗
{{{ Deleted γd p i ty }}}
rcu_domain_retire #d #p #s @ E
{{{ RET #(); True }}}.
Definition rcu_domain_do_reclamation_spec' : Prop :=
∀ E γd d,
↑N ⊆ E →
IsRCUDomain γd d -∗
{{{ True }}}
rcu_domain_do_reclamation #d @ E
{{{ RET #(); True }}}.
End spec.
Record rcu_traversal_spec {Σ} `{!heapGS Σ} {N : namespace} : Type := RCUTraversalSpec {
rcu_spec_code :> rcu_code;
IsRCUDomain : DomainT Σ N;
Inactive : InactiveT Σ;
Guard : GuardT Σ N;
Managed : ManagedT Σ N;
Deleted : DeletedT Σ N;
RCUPointsTo : RCUPointsToT Σ N;
RCUNodeInfo : RCUNodeInfoT Σ N;
IsRCUDomain_Persistent : ∀ γd d, Persistent (IsRCUDomain γd d);
RCUNodeInfo_Persistent : ∀ γd γg p i ty, Persistent (RCUNodeInfo γd γg p i ty);
RCUPointsTo_Some_Contractive : ∀ γd p1 i1 o1 p2 i2 n, Proper (type_dist2 n ==> dist n) (λ ty2, RCUPointsTo γd p1 i1 o1 (Some (p2,i2,ty2)));
rcu_domain_new_spec : rcu_domain_new_spec' N rcu_spec_code.(rcu_domain_new) IsRCUDomain;
rcu_domain_register : rcu_domain_register' N IsRCUDomain Managed RCUPointsTo;
guard_new_spec : guard_new_spec' N rcu_spec_code.(guard_new) IsRCUDomain Inactive;
guard_activate_spec : guard_activate_spec' N rcu_spec_code.(guard_activate) IsRCUDomain Inactive Guard;
guard_deactivate_spec : guard_deactivate_spec' N rcu_spec_code.(guard_deactivate) IsRCUDomain Inactive Guard;
guard_drop_spec : guard_drop_spec' N rcu_spec_code.(guard_drop) IsRCUDomain Guard;
guard_drop_inactive_spec : guard_drop_inactive_spec' N rcu_spec_code.(guard_drop) IsRCUDomain Inactive;
guard_protect_managed : guard_protect_managed' N IsRCUDomain Guard Managed RCUNodeInfo;
guard_protect_rcu_points_to : guard_protect_rcu_points_to' N IsRCUDomain Guard RCUPointsTo RCUNodeInfo;
guard_acc : guard_acc' N Guard RCUNodeInfo;
managed_acc : managed_acc' N Managed;
deleted_acc : deleted_acc' N Deleted;
managed_exclusive : managed_exclusive' N Managed;
guard_managed_agree : guard_managed_agree' N Guard Managed RCUNodeInfo;
rcu_points_to_link : rcu_points_to_link' N IsRCUDomain Managed RCUPointsTo;
rcu_points_to_unlink : rcu_points_to_unlink' N IsRCUDomain Managed RCUPointsTo;
rcu_points_to_update : rcu_points_to_update' N IsRCUDomain Managed RCUPointsTo;
managed_delete : managed_delete' N IsRCUDomain Managed Deleted;
deleted_clean : deleted_clean' N IsRCUDomain Managed Deleted;
rcu_domain_retire_spec : rcu_domain_retire_spec' N rcu_spec_code.(rcu_domain_retire) IsRCUDomain Deleted;
rcu_domain_do_reclamation_spec : rcu_domain_do_reclamation_spec' N rcu_spec_code.(rcu_domain_do_reclamation) IsRCUDomain
}.
Global Arguments rcu_traversal_spec _ {_} _ : assert.
Global Existing Instances IsRCUDomain_Persistent RCUNodeInfo_Persistent RCUPointsTo_Some_Contractive.
Section helpers.
Context {Σ} `{!heapGS Σ} {N : namespace} {rcu : rcu_traversal_spec Σ N}.
Global Instance into_inv_guard γd γg p i_p ty : IntoInv (rcu.(RCUNodeInfo) γd γg p i_p ty) (ptrN N p) := {}.
Global Instance into_acc_guard E γd γg g p i_p ty :
IntoAcc (rcu.(RCUNodeInfo) γd γg p i_p ty) (↑(ptrN N p) ⊆ E) (rcu.(Guard) γd γg g)%I
(fupd E (E∖↑(ptrN N p))) (fupd (E∖↑(ptrN N p)) E)
(λ lv, p ↦∗ lv ∗ ▷ ty.(ty_res) p lv i_p ∗ rcu.(Guard) γd γg g)%I
(λ lv, ∃ lv', p ↦∗ lv' ∗ ▷ ty.(ty_res) p lv' i_p)%I (λ _, None)%I.
Proof.
rewrite /IntoAcc /accessor. iIntros (?) "#Info_p G".
iMod (rcu.(guard_acc) with "Info_p G") as (lv) "(p↦ & R & G & CloseG)"; [solve_ndisj|].
iExists lv. iFrame.
iIntros "!> (% & p↦ & R)".
by iMod ("CloseG" with "[$p↦ $R]").
Qed.
Global Instance into_inv_managed γd p i_p ty B : IntoInv (rcu.(Managed) γd p i_p ty B) (ptrN N p) := {}.
Global Instance into_acc_managed E γd p i_p ty B :
IntoAcc (rcu.(Managed) γd p i_p ty B) (↑(ptrN N p) ⊆ E) (True%I)
(fupd E (E∖↑(ptrN N p))) (fupd (E∖↑(ptrN N p)) E)
(λ lv, p ↦∗ lv ∗ ▷ ty.(ty_res) p lv i_p ∗ rcu.(Managed) γd p i_p ty B)%I
(λ lv, ∃ lv', p ↦∗ lv' ∗ ▷ ty.(ty_res) p lv' i_p)%I (λ _, None)%I.
Proof.
rewrite /IntoAcc /accessor. iIntros (?) "M _".
iMod (rcu.(managed_acc) with "M") as (lv) "(p↦ & R & M & CloseM)"; [solve_ndisj|].
iExists lv. iFrame.
iIntros "!> (% & p↦ & R)".
by iMod ("CloseM" with "[$p↦ $R]").
Qed.
Global Instance into_inv_deleted γd p i_p ty : IntoInv (rcu.(Deleted) γd p i_p ty) (ptrN N p) := {}.
Global Instance into_acc_deleted E γd p i_p ty :
IntoAcc (rcu.(Deleted) γd p i_p ty) (↑(ptrN N p) ⊆ E) (True%I)
(fupd E (E∖↑(ptrN N p))) (fupd (E∖↑(ptrN N p)) E)
(λ lv, p ↦∗ lv ∗ ▷ ty.(ty_res) p lv i_p ∗ rcu.(Deleted) γd p i_p ty)%I
(λ lv, ∃ lv', p ↦∗ lv' ∗ ▷ ty.(ty_res) p lv' i_p)%I (λ _, None)%I.
Proof.
rewrite /IntoAcc /accessor. iIntros (?) "D _".
iMod (rcu.(deleted_acc) with "D") as (lv) "(p↦ & R & D & CloseD)"; [solve_ndisj|].
iExists lv. iFrame.
iIntros "!> (% & p↦ & R)".
by iMod ("CloseD" with "[$p↦ $R]").
Qed.
End helpers.