-
Notifications
You must be signed in to change notification settings - Fork 0
/
proof_rcu_simple.v
299 lines (234 loc) · 9.06 KB
/
proof_rcu_simple.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
From iris.base_logic.lib Require Import invariants ghost_map.
From smr.program_logic Require Import atomic.
From smr.lang Require Import proofmode notation.
From smr Require Import ebr.spec_rcu_base ebr.spec_rcu_simple helpers logic.reclamation.
From iris.prelude Require Import options.
Set Printing Projections.
Section ebr.
Context `{!heapGS Σ, !reclamationG Σ}.
Context (N : namespace).
Context (base : spec_rcu_base.rcu_base_spec Σ (mgmtN N) (ptrsN N)).
Implicit Types
(γd γb γdata γ_p : gname)
(i : positive)
(R : resource Σ).
Definition Managed γd (p : blk) (γ_p : gname) (sz : nat) R : iProp Σ :=
∃ γb γdata i,
⌜γd = encode (γb, γdata)⌝ ∗
i ↪[γdata]□ γ_p ∗
base.(BaseManaged) γb p i sz (wrap_resource γdata R γ_p).
Definition Guard γd (g : loc) (st : guard_state) : iProp Σ :=
∃ γb γdata,
⌜γd = encode (γb, γdata)⌝ ∗
match st with
| Deactivated => base.(BaseInactive) γb g
| Activated γg => ∃ Syn G Gb,
base.(BaseGuard) γb γg g Syn Gb ∗
[∗ map] p ↦ γ_p; i ∈ G; Gb,
i ↪[γdata]□ γ_p
end.
Definition RCUInv γb γdata Im Dm Rs : iProp Σ :=
ghost_map_auth γdata 1 Dm ∗
base.(RCUAuth) γb Im Rs ∗
⌜dom Im = dom Dm⌝.
Definition IsRCUDomain γd d : iProp Σ :=
∃ γb γdata,
⌜γd = encode (γb, γdata)⌝ ∗
base.(spec_rcu_base.IsRCUDomain) γb d ∗
inv ((mgmtN N).@"simpl") (∃ Im Dm Rs, RCUInv γb γdata Im Dm Rs).
Definition NodeInfo γd γg p γ_p size_i R : iProp Σ :=
∃ γb γdata i,
⌜γd = encode (γb, γdata)⌝ ∗
i ↪[γdata]□ γ_p ∗
base.(BaseGuardedNodeInfo) γb γg p i size_i (wrap_resource γdata R γ_p).
Global Instance IsRCUDomain_Persistent γd d : Persistent (IsRCUDomain γd d).
Proof. apply _. Qed.
Global Instance NodeInfo_Persistent γd γg p γ_p size_i R : Persistent (NodeInfo γd γg p γ_p size_i R).
Proof. apply _. Qed.
Lemma rcu_domain_new_spec :
rcu_domain_new_spec' N base.(rcu_domain_new) IsRCUDomain.
Proof.
intros ?.
iIntros (Φ) "_ HΦ".
iApply wp_fupd.
wp_apply (spec_rcu_base.rcu_domain_new_spec with "[//]") as (γb d) "[#BIRD BR]".
iMod (ghost_map_alloc ∅) as (γdata) "[data _]".
remember (encode (γb,γdata)) as γd eqn:Hγd.
iMod (inv_alloc ((mgmtN N).@"simpl") _ (∃ Im Dm Rs, RCUInv γb γdata Im Dm Rs) with "[data BR]") as "#?".
{ iNext. repeat iExists _. iFrame. by rewrite !dom_empty_L. }
iApply "HΦ". repeat iExists _. by iFrame (Hγd) "∗#".
Qed.
Lemma rcu_domain_register :
rcu_domain_register' N IsRCUDomain Managed.
Proof.
intros ????????.
iIntros "#IRD (p↦ & †p & R)".
iDestruct "IRD" as (γb γdata Hγd) "(BIRD & RI)".
iInv "RI" as (???) ">(data & BRA & %Hdom)".
iMod (spec_rcu_base.rcu_domain_register base (λ p lv i, i ↪[γdata]□ γ_p ∗ R p lv γ_p)%I
(dom Dm)
(λ i, ghost_map_auth γdata 1 (<[i := γ_p]> Dm) ∗ i ↪[γdata]□ γ_p)%I
with "BIRD BRA p↦ †p [data $R]") as "OUT"; [solve_ndisj..| |].
{ iIntros (i Hi).
by iMod (ghost_map_insert_persist i γ_p with "data") as "[$ #$]"; [by apply not_elem_of_dom|].
}
iDestruct "OUT" as (i Hi) "(BRA & BM & [data #i↪□])".
iModIntro. iSplitL "BRA data".
{ iNext. repeat iExists _. iFrame.
iPureIntro. rewrite !dom_insert_L. set_solver.
}
iModIntro. repeat iExists _. iFrame (Hγd) "∗#".
Qed.
Lemma guard_new_spec :
guard_new_spec' N base.(guard_new) IsRCUDomain Guard.
Proof.
intros ????.
iIntros "#IRD" (Φ) "!> _ HΦ".
iDestruct "IRD" as (γb γdata Hγd) "(BIRD & RI)".
wp_apply (spec_rcu_base.guard_new_spec with "BIRD [//]") as (g) "BG"; [solve_ndisj|].
iApply "HΦ".
repeat iExists _. iFrame (Hγd) "∗".
Qed.
Lemma guard_activate_spec :
guard_activate_spec' N base.(guard_activate) IsRCUDomain Guard.
Proof.
intros ?????.
iIntros "#IRD" (Φ) "!> G HΦ".
iDestruct "IRD" as (γb γdata Hγd) "(BIRD & RI)".
iDestruct "G" as (???) "BG". encode_agree Hγd.
wp_apply (spec_rcu_base.guard_activate_spec with "BIRD BG") as (γg Syn) "BG"; [solve_ndisj|].
iApply "HΦ".
repeat iExists _. iFrame (Hγd) "∗".
repeat iExists _. by iFrame "∗".
Qed.
Lemma guard_managed_agree :
guard_managed_agree' N Managed Guard NodeInfo.
Proof.
intros ??????????.
iIntros "#Info G M".
iDestruct "Info" as (??? Hγd) "[#i↪□' BInfo]".
iDestruct "G" as (??? Syn G Gb) "[BG #GInfo]".
iDestruct "M" as (????) "[#i↪□ BM]". do 2 encode_agree Hγd.
iDestruct (spec_rcu_base.guard_managed_agree with "BInfo BG BM") as %<-.
by iDestruct (ghost_map_elem_agree with "i↪□ i↪□'") as %?.
Qed.
Lemma guard_protect :
guard_protect' N IsRCUDomain Managed Guard NodeInfo.
Proof.
intros ??????????.
iIntros "#IRD M G".
iDestruct "IRD" as (?? Hγd) "(BIRD & RI)".
iDestruct "G" as (??? Syn G Gb) "[BG #GInfo]".
iDestruct "M" as (????) "[#i↪□ BM]". do 2 encode_agree Hγd.
iMod (spec_rcu_base.guard_protect with "BIRD BM BG") as "(BM & BG & %NotIn & %LookUp)"; [solve_ndisj|].
iDestruct (spec_rcu_base.managed_get_node_info with "BM") as "#BInfo".
iMod (spec_rcu_base.guard_protect_node_info with "BIRD BInfo BG") as "(BG & #BGInfo & _)"; [solve_ndisj|done|].
rewrite insert_insert.
iModIntro. iSplitL "BM".
{ repeat iExists _; iFrame (Hγd) "∗#". }
iDestruct (big_sepM2_dom with "GInfo") as %Hdom.
destruct (decide (is_Some (Gb !! p))) as [Hp|Hp%eq_None_not_Some]; last first.
{ assert (G !! p = None).
{ by rewrite -not_elem_of_dom Hdom not_elem_of_dom. }
iSplit; repeat iExists _; iFrame (Hγd) "∗#".
iExists (<[ p:= _ ]> G).
rewrite (big_sepM2_insert _ _ _ p); [|done..].
iFrame "#".
}
specialize (LookUp Hp) as HGbp.
rewrite insert_id //.
iDestruct (big_sepM2_lookup_r with "GInfo") as (? HGp) "#i↪□'"; [exact HGbp|].
iDestruct (ghost_map_elem_agree with "i↪□ i↪□'") as %<-.
iSplit; repeat iExists _; iFrame (Hγd) "∗#".
Qed.
Lemma guard_acc :
guard_acc' N Guard NodeInfo.
Proof.
intros ?????????.
iIntros "#Info G".
iDestruct "Info" as (??? Hγd) "[i↪□ BInfo]".
iDestruct "G" as (??? Syn G Gb) "[BG #GInfo]".
encode_agree Hγd.
iMod (spec_rcu_base.guard_acc with "BInfo BG") as (lv) "(%Hlv & p↦ & [_ R] & BG & Close1)"; [solve_ndisj|].
iApply fupd_mask_intro; [solve_ndisj|]. iIntros "Close2".
iExists lv. iFrame "∗%".
iSplit.
{ iFrame "∗#". }
iIntros (lv') "(%Hlv' & p↦ & R)".
iMod "Close2".
iMod ("Close1" with "[$p↦ R]"). { iFrame (Hlv') "∗#". }
done.
Qed.
Lemma managed_acc :
managed_acc' N Managed.
Proof.
intros ???????.
iDestruct 1 as (??? Hγd) "[#i↪ BM]".
iMod (spec_rcu_base.managed_acc with "BM") as (lv) "(% & p↦ & [_ R] & BM & Close1)"; [solve_ndisj|].
iApply fupd_mask_intro; [solve_ndisj|]. iIntros "Close2".
iExists lv. iFrame "∗%".
iSplit.
{ iFrame "#". }
iIntros (lv') "(%Hlv' & p↦ & R)".
iMod "Close2".
iMod ("Close1" with "[$p↦ R]"). { iFrame (Hlv') "∗#". }
done.
Qed.
Lemma managed_exclusive :
managed_exclusive' N Managed.
Proof.
iDestruct 1 as (??? Hγd) "[#i↪ BM1]".
iDestruct 1 as (??? ?) "[#i↪' BM2]".
encode_agree Hγd.
iApply (spec_rcu_base.managed_exclusive with "BM1 BM2").
Qed.
Lemma guard_deactivate_spec :
guard_deactivate_spec' N base.(guard_deactivate) IsRCUDomain Guard.
Proof.
intros ??????.
iIntros "#IRD" (Φ) "!> G HΦ".
iDestruct "IRD" as (γb γdata Hγd) "(BIRD & RI)".
iDestruct "G" as (??????) "[BG #GInfo]". encode_agree Hγd.
wp_apply (spec_rcu_base.guard_deactivate_spec with "BIRD BG") as "BG"; [solve_ndisj|].
iApply "HΦ".
repeat iExists _. iFrame (Hγd) "∗".
Qed.
Lemma guard_drop_spec :
guard_drop_spec' N base.(guard_drop) IsRCUDomain Guard.
Proof.
intros ??????.
iIntros "#IRD" (Φ) "!> G HΦ".
iDestruct "IRD" as (γb γdata Hγd) "(BIRD & RI)".
iDestruct "G" as (???) "BG". encode_agree Hγd.
destruct gs.
- wp_apply (spec_rcu_base.guard_drop_inactive_spec with "BIRD BG"); [solve_ndisj|]. done.
- iDestruct "BG" as (???) "[BG #GInfo]".
wp_apply (spec_rcu_base.guard_drop_spec with "BIRD BG"); [solve_ndisj|]. done.
Qed.
Lemma rcu_domain_retire_spec :
rcu_domain_retire_spec' N base.(rcu_domain_retire) IsRCUDomain Managed.
Proof.
intros ????????.
iIntros "#IRD" (Φ) "!> M HΦ".
iDestruct "IRD" as (γb γdata Hγd) "(BIRD & RI)".
iDestruct "M" as (????) "[#i↪ BM]". encode_agree Hγd.
iApply (wp_step_fupd _ E E _ (_ -∗ _)%I with "[$HΦ]"); [done..|].
awp_apply (spec_rcu_base.rcu_domain_retire_spec with "BIRD BM"); [solve_ndisj|].
iInv "RI" as (???) ">(data & BRA & %Hdom)".
iAaccIntro with "BRA".
{ iIntros. iFrame. done. }
iIntros "BRA".
iModIntro. iSplitL "BRA data".
{ iFrame. done. }
iIntros "HΦ !>". iApply "HΦ". done.
Qed.
Lemma rcu_domain_do_reclamation_spec :
rcu_domain_do_reclamation_spec' N base.(rcu_domain_do_reclamation) IsRCUDomain.
Proof.
intros ????. iIntros "#IRD" (Φ) "!> _ HΦ".
iDestruct "IRD" as (??) "(%Hγ & #BIRD & #RI)".
wp_apply (spec_rcu_base.rcu_domain_do_reclamation_spec with "BIRD [//]"); [solve_ndisj|].
iFrame "HΦ".
Qed.
End ebr.
#[export] Typeclasses Opaque IsRCUDomain Guard Managed NodeInfo.