CS 5/6110, Software Correctness Analysis, Spring 2023
Ganesh Gopalakrishnan
School of Computing
University of Utah
Salt Lake City, UT 84112
Outline
What is memory coherence?
An example demonstrating the diff starkly
P0 P1 (“P” = processes or shared-memory threads)
Initially a==b==0
Store(a,1); Store(b,2);
Load(b,0);//returns 0 Load(a,0);//returns 0
If you wear a pair of goggles that just sees black or just sees brown
There is an “SC explanation” -- try it
But if you see both colors together, then no SC explanation
Hence coherent (one address has always the latest value, since the real-time order of local operations is irrelevant at the global level)
Complexity of trace-verification for coherence
Suppose someone gives you a trace
Px:S(a,0); Py:L(a,1); Pz:S(a,33); Pz: (a,44); Px: S(a,3); ….
Where the P are processes (or threads) that share the SINGLE address a
And each Px: …. ; …. ; Px: … is listed in program order per Px
With the other Py , y ~= x listed according to some interleaving
Then what is the complexity of checking that such a trace and declaring whether it is coherent or not?
Complexity of trace-verification for coherence
NP-Complete!
Where is a good (accessible) proof? – ANS : Cantin’s paper
Where is a good (accessible) proof? – ANS : Cantin’s paper
Given four processes (or hardware threads) and reads/writes
Per location (“a_u” in this case) explain read-value outcomes.
Here we explain as if this interleaving took place.
The inability find such an explanation means the system is incoherent
Cool piece of encoding by Cantin: Given a 3SAT formula, he generates a shared memory execution such that the formula is SAT iff the execution is coherent!
Cantin’s reduction from SAT (general SAT which is = 3SAT wrt complexity)
Recall or know
That
2-sat
Is P-time
(= 2-coloring)
Recap / Summary
Implementing coherence
Coherence Verification
Basics about Transition Systems
Almost all specs for safety property checking look like this
Rule1: g1 ==> a1
Rule2: g2 ==> a2
…
RuleN: gN ==> aN
Invariant P
14
Let us understand how we may safely transform such rule-based specifications (this is what we have to do in the parametric verification approach to be presented). The method is called the CMP method named after its inventors at Intel.
15
The name of the game – “invariants” !!
Invariants, Inductive Invariants
Invariants, Inductive Invariants
Invariants, Inductive Invariants
Tools to interactively discover invariants
Let us understand how we may safely transform such rule-based specifications. The first few will be warmups. Then the real thing!
Rule1: g1 \/ Cond1 ==> a1
Rule2: g2 ==> a2
Invariant P
21
But… Guard Strengthening is, by itself, Unsound
Rule1: g1 /\ Cond1 ==> a1
Rule2: g2 ==> a2
Invariant P
22
Guard Strengthening can be made sound, if the conjunct is implied by the guard
Rule1: g1 /\ Cond1 ==> a1
Rule2: g2 ==> a2
Invariant P /\ (g1 ==> Cond1)
23
Summary of Transformations so far (checkmark shows what’s safe)
24
✔
✔
X
The CMP Approach
25
Weaken to the Extreme sounds crazy at first!
Rule1: g1 \/ True ==> a1
Rule2: g2 ==> a2
Invariant P
26
The transition system above
can be transformed to the one below without any issues
(except the proof of P being an invariant might not go through) – but that will be fixed momentarily
Rule1: True ==> a1
Rule2: g2 ==> a2
Invariant P
Strengthen Back Some
27
Rule1: True /\ C1 ==> a1
Rule2: g2 ==> a2
Invariant P /\ (g1 => C1)
“Not Enough!” may be
the outcome of strengthening.
That is, while we added C1 back,
it may not be strong-enough.
How to pick C1 will be discussed soon.
Strengthen Back More…
28
Rule1: True /\ C1 /\ C2 ==> a1
Rule2: g2 ==> a2
Invariant P /\ (g1 => C1) /\ (g1 => C2)
“OK, just right!”
Rule1: True /\ C1 ==> a1
Rule2: g2 ==> a2
Invariant P /\ g1 => C1
“Not Enough!”
A Variation of Guard Strengthening Supported by Lemma: �Doing it in a meta-circular manner (i.e., the temporal induction I alluded to earlier…)
29
✔
This is the approach in our work
Now the secret: in the CMP method, the designer decouples all nodes beyond k (typically 2) explicitly modeled nodes. Then, brings back the N-k nodes, but in ‘spirit’ – i.e., in terms of the non-interference conditions they must obey (note that “N” is a free parameter). ��The Ci are thus the non-interference lemmas. Each is discovered upon seeing a counterexample, and then added back into the system! If the coherence invariant is proved (usually this happens), then you ended up having used a model-checker to prove a parametric theorem – which is a big deal!
30
✔
This is the approach in our work
This method has been perfected at Intel and in production use!
We will now present highlights of the German Protocol to tell you how coherence protocols look like (but this is like a “hello world” of cache protocols)
CMP highlights from paper of C-T Chou
CMP highlights from paper of C-T Chou
CMP highlights from paper of C-T Chou
CMP highlights from paper of C-T Chou
The top-left rule is changed to the bottom-right rule in the CMP method, by introducing non-interference lemmas to strengthen the guards. These lemmas are proven in the same model being refined.
German protocol
German protocol
German protocol
German protocol
German protocol
German protocol
German protocol
German protocol
German protocol
German protocol
German protocol
German protocol
German protocol
German protocol
German protocol
Invariants of the German protocol
Locking protocols, Scalar Sets, etc
How to initialize the dist locking protocol w/o breaking symmetry required by scalar sets!
Code from dist termination… how initialization is done + how invariants are done (need to generalize)
Code from dist termination… how initialization is done + how invariants are done (need to generalize)
Code from dist termination… how initialization is done + how invariants are done (need to generalize)
Code from dist termination… how initialization is done + how invariants are done (need to generalize)
Code from dist termination… how initialization is done + how invariants are done (need to generalize)
Code from dist termination… how initialization is done + how invariants are done (need to generalize)
Snippets from Peterson’s protocol with programmable bug-depth
Snippets from Peterson’s protocol with programmable bug-depth
Snippets from Peterson’s protocol with programmable bug-depth
Snippets from Peterson’s protocol with programmable bug-depth
Snippets from Peterson’s protocol with programmable bug-depth
Snippets from Peterson’s protocol with programmable bug-depth
Snippets from Peterson’s protocol with programmable bug-depth