290 likes | 310 Views
Analyzing the Intel Itanium Memory Ordering Rules using Logic Programming and SAT. Yue Yang Ganesh Gopalakrishnan Gary Lindstrom Konrad Slind School of Computing University of Utah Work supported in part by NSF Awards CCR-0081406 and 0219805, and SRC Contract 1031.001.
E N D
Analyzing the Intel Itanium Memory Ordering Rulesusing Logic Programming and SAT Yue Yang Ganesh Gopalakrishnan Gary Lindstrom Konrad Slind School of Computing University of Utah Work supported in part by NSF Awards CCR-0081406 and 0219805, and SRC Contract 1031.001
What are Memory Ordering Rules? The effects of aggressive hardware optimizations… ‘Bypassing’ (read back own store before others) Aggressive load/store reorderings Strong orderings only at acquires/releases …. cpu cpu cpu mem ...that are visible as out-of-order executions to a programmer ld.acq d,2; ld c,1; ld b,2; ld a,0; st c,1 ; st.rel d,2; “out of order” usually means “with respect to SC” st a,1 ; st b,2; …. cpu cpu cpu cpu mem
Why Relaxed Ordering Rules? • All modern high-end processors employ relaxed ordering rules • Modern multi-threaded languages also follow suit WHY? • Aggressive updates are too expensive • CPU / Memory speed mismatch getting progressively worse • Enables performance enhancing optimizations at the bus / interconnect level • Simplifies directory protocols (less waiting, avoid deadlocks by relaxing message traffic rules, ...)
Contrast between `strict’ and `relaxed’ orderings Strict (e.g., Sequential Consistency) Relaxed (e.g., PRAM) Each processor’s instructions come according to program order They execute as if connected to a single serial memory thru a non-deterministic switch One memory per processor in effect (details omitted) No write-atomicity - only program order obeyed memory
Contrast between Relaxed Academic and Industrial Models Relaxed + Strict + Hybrid + ... (e.g., Itanium) Relaxed (e.g., PRAM) • See our ICCD’99 • paper for a very • approximate operational • model • Lamport et.al. have one • in TLA, too...
Who depends on Memory Orderings? • Compiler / OS developers • many of the proposed high-performance kernels exploit weakness to a high degree • People who port existing code-bases • code-bases must port between platforms • Implementers of thread-based systems, JVMs, .... • it has to mesh with the language-level memory model as well • It is a central issue even in “uniprocessors” in which multiple threads share memory
A taxonomy of methods to specify industrial Relaxed Memory Models • Informal • “A Store Release flushes out earlier pended operations. • All Store Releases appear to commit in a global total order. • They allow Read Bypassing, except for non-Cacheable addresses • Full Intel spec available by searching `251429’ under google • A dozen or so litmus tests also given as a supplement P1 P2 st.rel A,1; st.rel B,1; ld.acq r1,A; [1] ld.acq r3,B; [1] ld r2,B; [0] ld r4,A; [0] • Formal • Operational • Axiomatic
A taxonomy of Formal methods to specify industrial Relaxed Memory Models • Operational • Operational models of industrial memory models are complex • Running them inside a standard model-checker is too slow! • Utility for verification is limited • Provides limited insight • Axiomatic • Much more precise • Orderings must ideally be expressed thru an ORTHOGONAL set of rules • No such prior axiomatic specs of industrial memory models
How to Organize AxiomaticMemory Ordering Specs? • Ad-hoc • Visibility Order Based
Visibility Order Specs A memory model (spec of Memory Ordering Rules) is a mapping from executions to a set of allowed total orders called visibility orders; it is a 1-to-many mapping: Strict Ordering Allowed st(A,1) st(B,2) ld(B,v1) ld(A,v2) ld B [v1] ld A [v2] st A,1 ; st B,2; ld(A,v2) ld(B,v1) st(B,2) st(A,1) Relaxed Ordering allowed too For “complex” instructions, we generate more visibility events seen in P1 seen in P2 ld.acq B [v1] ld A [v2] st.rel A,1 ; st B,2; { st.rel(A,1), st(B,2), st.rel(A,1), st(B,2), ld.acq(B,v1), ld(A,v2) } After specifying all allowed Visibility Orders, the Load-Value Rule specifies how Loads return their values ..... see below initial memory ld(A,?)st(A,1) st(A,1)st(B,2)st(B,2);ld(B,?) 0 2
Our first contribution • Developed Axiomatic, Visibility Order based Spec for most of Itanium Orderings (semaphores will be added in next version) • Orderings implicit in their document made explicit • 3-pages of HOL as opposed to 24 pages of prose + tables • Also developed an executable constraint-Prolog version • Can reason using a theorem prover • will attempt claim found in Intel’s manual about causality • Written in a generic style - several other memory models specified in the same framework • pre-requisite to formally comparing memory models • Comprised of orthogonal sub-rules
legalItanium Style of specification legalItanium(ops) = Existsorder. ( constraint1 ops order /\ constraint2 ops order /\ ... ) • Can selectively disable constraints and compare results • Since the constraints are orthogonal, we can localize errors Visibility Order described by order : visevent -> visevent -> bool We use the “id” of each visevent which is an int; so order : int -> int -> bool
legalItanium legalItanium(ops) = Existsorder. ( requireLinearOrder ops order /\ requireWriteOperationOrder ops order /\ requireProgramOrder ops order /\ requireMemoryDataDependence ops order /\ requireDataFlowDependence ops order /\ requireCoherence ops order /\ requireReadValue ops order /\ requireAtomicWBRelease ops order /\ requireSequentialUC ops order /\ requireNoUCBypass ops order )
requireProgramOrder requireProgramOrder ops order = Forall i,j : ops ( orderedByAcquire i j \/ orderedByRelease i j \/ orderedByFence i j ) ==> order i j
Where do we use our Formal Spec of Memory Orderings? • To help solve one of the nastiest problems encountered during Post-Silicon Validation • An MP system has just been built (boards, fan, ...) • How do we certify that it obeys the memory ordering rules? WHY IS POST-SILICON VERIFICATION HARD? Limited observability (forced to observe via “final effects” on programs) Unverified inter-module assumptions examined for the first time at GHz speeds!
Typical Post-Si Memory Ordering Verification Approach • Manual reasoning of executions generated by random tests • Highly labor intensive • designers have to think through ALL ordering rules at EACH step • No systematic methods to write the tests • Ad-hoc tools employed for behavior matching • No Formal Guarantees even on small executions • No insights provided upon failure • Cannot pinpoint onset of divergence from allowed behaviors
Our Idealized Approach to a solution (currently under development) An Arbitrary Specification of Memory Ordering Rules in HOL ILLEGAL! explanation script... BUILDTHIS BOX !! LEGAL! Explanation script + ALL bindings to V2 and V3 st.rel a,1; st.rel b,1; ld.acq r1,a; [V2] ld.acq r3,b;[V3] ld r2,b;[0] ld r4,a;[0] An Arbitrary Litmus Test, e.g. ...
The first approach presented here ILLEGAL! Spec of Memory Ordering Rules Coded-up Nicely as a Constraint Logic Program LEGAL! explanation script... st.rel a,1; st.rel b,1; ld.acq r1,a; [1] ld.acq r3,b;[1] ld r2,b;[0] ld r4,a;[0] An Arbitrary Ground Litmus Test, e.g. ... only ground values allowed
The second approach presented here Spec of Memory Ordering Rules Coded-up Nicely as a Constraint Logic Program UNSAT! implies ILLEGAL! A SAT checker An Arbitrary Ground Litmus Test SAT! implies LEGAL!
How does Approach #1 work ? • Need to know a little bit about Constraint Logic Programs (e.g., • GnuProlog, Sicstus Prolog, Mozart, ... support constraints directly • Available as “free-standing” packages callable from C, Java, Ocaml, ... called with Y = W, X unbound evens_below_Y( X,Y) :- X is in (0..10), X < Y, (X mod 2) = 0 Allocates constraint-store entry for X with some user-chosen initial range Imposes X=W-1 Imposes constraint (W-1) mod 2 = 0 into constraint store backtracking triggered if W is later found = 6
How to model requireProgramOrder(e.g.)as a Constraint Logic Program? requireProgramOrder ops order = Forall i,j : ops ( orderedByAcquire i j \/ orderedByRelease i j \/ orderedByFence i j ) ==> order i j i • Allocate 2D constraint-var array • Interpret Litmus test, adding • constraint to 2D array • When Interpretation Finishes, all • “x” reveals latitude in weak order • When an “x” changes to a 1, an attempt • to set it 0 later triggers backtracking x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x j = 1 means i is ordered before j
Our Prolog Code is VERY close to the HOL spec! requireProgramOrder ops order = Forall i,j : ops ( orderedByAcquire i j \/ orderedByRelease i j \/ orderedByFence i j ) ==> order i j
Our Prolog Code is VERY close to the HOL spec! requireProgramOrder ops order = Forall i,j : ops ( orderedByAcquire i j \/ orderedByRelease i j \/ orderedByFence i j ) ==> order i j ( % Rule (ACQ): ACQ>>I ..... #\/ % Rule (REL): Op_j #= StRel #/\ ( IsWr_i #==> (WrType_i #= Local #/\ WrType_j #= Local #\/ WrType_i #= Remote #/\ WrType_j #= Remote #/\ WrProc_i #= WrProc_j) ) .... #==> Oij. IMPOSES CONSTRAINT ON MATRIX ENTRY Oij
Idea behind the SAT approach ( % Rule (ACQ): ACQ>>I ..... #\/ % Rule (REL): Op_j #= StRel #/\ ( IsWr_i #==> (WrType_i #= Local #/\ WrType_j #= Local #\/ WrType_i #= Remote #/\ WrType_j #= Remote #/\ WrProc_i #= WrProc_j) ) .... #==> Emit Boolean Expression here(as opposed to imposing constraint on constraint-store)
What did we learn? • A really elegant approach to study Memory Ordering • Many bugs in spec caught through finite executions • Formal `paper-and-pencil’ memory ordering specs are very unreliable! • Prolog Code may not scale • Prolog Quirks (memory resources scattered in stack, trail-stack, constraint-store, ... - execution halts if one exhausted) • Prolog’s search may not be “as smart” as SAT’s (?) • SAT generation time dominates • Pretty naive coding and CNF generation • Could scale considerably; for example: FD-solvingSAT-genSAT-varsSAT-clausesSAT-solving 22 s 200s 576 15k 0.01s • Best long-term approach is the `ideal’ one mentioned earlier • (explain details if there is time)
Summary of Key Contributions • We provide a formal specification of the entire Itanium memory ordering specification in Higher Order Logic(barring semaphores that change the ‘data structures’ we need) • Our Spec (3 pages of hol) replaces 24 pages of Intel spec • Our Spec is EASIER to understand (said the Charme reviewers!) • We can now prove theorems to increase confidence • We present TWO ways to use this hol spec to check executions obtained from the post-silicon environment • Encode as a Constraint-Logic programthat interprets assembly executions and checks conformance with the rules • Constraint-Logic program that interprets assembly executions, and generates a SAT instance embodying conformance • Our tool was given to engineers in Intel’s post-Si validation group • highly encouraging feedback obtained
Some of the Related Work • Classical approaches • Mostly paper-and-pencil specs • Executable specs (Murphi) used to verify critical section codes • Spec of the Alpha memory ordering rules in FOL/HOL • Yuan Yu (personal communication) - unpublished • VCs generated for assembly programs and given to ESC prover • Our work is for a modern system (Itanium) and uses SAT • TLA+ spec of the Itanium ordering rules • Details are not published • Not amenable to execution (very slow execution speeds) • Impractical for use in checking assembly program executions
Work in progress An Arbitrary Specification of Memory Ordering Rules in HOL Generate a QBF formula for the size of the Litmus test ILLEGAL! explanation script... QBF Solver LEGAL! Explanation script + ALL bindings to V2 and V3 Generate “compact” CNF An Arbitrary Litmus Test (non-ground values allowed) DNF representation of Litmus test (“ROM”) QBF is natural for memory ordering rules