600 likes | 726 Views
Verification of architectural memory models by model checking. Shaz Qadeer Compaq Systems Research Center Shaz.Qadeer@compaq.com. Outline. Introduction to shared-memory systems and models Model checking method for verifying models on systems. Multithreaded program. Language memory model
E N D
Verification of architectural memory models by model checking Shaz Qadeer Compaq Systems Research Center Shaz.Qadeer@compaq.com
Outline • Introduction to shared-memory systems and models • Model checking method for verifying models on systems
Multithreaded program Language memory model (Java, Modula-3, C with threads) Compiler Executable code Multiprocessor
Multiprocessor P P P INTERCONNECT NETWORK P P P
Multiprocessor Architectural memory model (SC, Alpha, Sun)
Multithreaded program Language memory model (Java, Modula-3, C with threads) Compiler Executable code Multiprocessor
Multithreaded program Language memory model (Java, Modula-3, C with threads) Compiler Executable code Architectural memory model (SC, Alpha, Sun)
Multiprocessor Verification Problem ? Architectural memory model (SC, Alpha, Sun)
Uniprocessor Initially A = B = 0 P A := 1; if (B = 0) { ... } Memory
Shared-memory multiprocessor Initially A = B = 0 P P A := 1; if (B = 0) { ... } B := 1; if (A = 0) { ... } Memory
Shared-memory model Initially A = B = 0 P P W(A, 1) R(B, ?) W(B, 1) R(A, ?) Memory
Sequential consistency Initially A = B = 0 P P W(A, 1) R(B, 1) W(B, 1) R(A, 1) Memory
Sequential consistency Initially A = B = 0 P P W(A, 1) R(B, 0) W(B, 1) R(A, 1) Memory
Sequential consistency Initially A = B = 0 P P W(A, 1) R(B, 1) W(B, 1) R(A, 0) Memory
Initially A = B = 0 P P W(A, 1) R(B, 0) W(B, 1) R(A, 0) Memory Sequential consistency
Dekker’s algorithm Initially A = B = 0 P P A := 1; if (B = 0) { CS } B := 1; if (A = 0) { CS } Memory
RDEX(A) FWD_RDEX(A, P1) state[A] = INV state[A] = EXC P1 P2 WR_REQ(A) C1 C2 Interconnect network Memory + Directory
RDEX(A) FWD_RDEX(A, P1) state[A] = INV state[A] = INV P1 P2 RDEX_ACK(A) WR_REQ(A) C1 C2 Interconnect network Memory + Directory
RDEX(A) FWD_RDEX(A, P1) state[A] = EXC state[A] = INV P1 P2 RDEX_ACK(A) WR_REQ(A) WR_ACK(A) C1 C2 Interconnect network Memory + Directory
Programmers program according to a memory model • System must satisfy memory model for software correctness • Shared-memory systems are very complex
Parameterized shared-memory systems Parameters: processors n, addresses m Memory actions: {R,W} {1,..,n} {1,..,m} Val Internal actions: I {1,..,n} {1,..,m} State transition system: State variables Initial predicate Guarded command for each action
State transition system cache: array [1..n] of array [1..m] of {s: State, d: Val} queue: array [1..n] of Queue[m: Msg, a: [1..m]] … (R,i,j,v) [] cache[i][j].s INV cache[i][j].d = v (W,i,j,v) [] cache[i][j].s = EXC cache[i][j].d := v (RRQ,i,j) [] cache[i][j].s = INV queue[i].enqueue(RD_REQ, j) …
(EventId, Proc, Addr, Data) (WRQ, 2, 1) (WRP, 2, 1) (W, 2, 1, 1) (R, 1, 1, 0) (R, 2, 1, 1) (WRQ, 1, 1) (WRP, 1, 1) (R, 1, 1, 1) (W, 1, 1, 2) (RRQ, 2, 1) (RRP, 2, 1) (R, 2, 1, 2) Run: finite action sequence executable from initial state
Verification problem Impl: state transition system with actions Spec: 1. Invariants, e.g., 1 i, j n. cache[i].s = EXC i j cache[j].s = INV 2. Memory models, e.g., sequential consistency, Alpha memory model Does Impl satisfy Spec?
(EventId, Proc, Addr, Data) (WRQ, 2, 1) (WRP, 2, 1) (W, 2, 1, 1) (R, 1, 1, 0) (R, 2, 1, 1) (WRQ, 1, 1) (WRP, 1, 1) (R, 1, 1, 1) (W, 1, 1, 2) (RRQ, 2, 1) (RRP, 2, 1) (R, 2, 1, 2) Run: finite action sequence executable from initial state
Memory model (EventId, Proc, Addr, Data) Processor 1 Processor 2 (R,1,1,0) (R,1,1,1) (W,1,1,2) (W,2,1,1) (R,2,1,1) (R,2,1,2) • n partial orders, one for each processor • i th partial order on memory actions at processor i
Sequential consistency (EventId, Proc, Addr, Data) Processor 1 Processor 2 (R,1,1,0) (R,1,1,1) (W,1,1,2) (W,2,1,1) (R,2,1,1) (R,2,1,2)
(W,2,1,1) (R,1,1,0) (R,2,1,1) (R,1,1,1) (W,1,1,2) (R,2,1,2) swap! Sequential consistency (EventId, Proc, Addr, Data) Addr 1 0 1 1 1 2 2 (R,1,1,0) (W,2,1,1) (R,2,1,1) (R,1,1,1) (W,1,1,2) (R,2,1,2)
Sequential consistency (EventId, Proc, Addr, Data) Witness order (R,1,1,0) (W,2,1,1) (R,2,1,1) (R,1,1,1) (W,1,1,2) (R,2,1,2) System S satisfies Model M iff there is a witness order for every run
Impl needed in practice Fixed parameters Arbitrary parameters Spec Invariants Memory models Debugging vs. Verification McMillan, Schwalbe 91 Clarke et al. 93 Eiriksson, McMillan 95 Ip, Dill 96 Loewenstein, Dill 92 Pong, Dubois 95 Park, Dill 96 Delzanno 00 Graf 94 Henzinger et al. 99 TLA Plakal et al. 98 • Katz, Peled 92 • Alur et al. 96 • Nalumasu et al. 98 • Henzinger et al. 99
Verifying Memory Models is Hard Alur, McMillan, Peled 96 : Checking sequential consistency for finite parameter values is undecidable.
Contribution Model checking algorithm to verify a number of shared-memory models on a useful class of shared-memory systems for finite number of processors and addresses by reduction to invariant verification.
Outline • Introduction to shared-memory systems and models • Model checking method for verifying models on systems
State transition system cache: array [1..n] of array [1..m] of {s: State, d: Val} queue: array [1..n] of Queue[m: Msg, a: [1..m]] … (R,i,j,v) [] cache[i][j].s INV cache[i][j].d = v (W,i,j,v) [] cache[i][j].s = EXC cache[i][j].d := v (RRQ,i,j) [] cache[i][j].s = INV queue[i].enqueue(RD_REQ, j) …
(EventId, Proc, Addr, Data) (WRQ, 2, 1) (WRP, 2, 1) (W, 2, 1, 1) (R, 1, 1, 0) (R, 2, 1, 1) (WRQ, 1, 1) (WRP, 1, 1) (R, 1, 1, 1) (W, 1, 1, 2) (RRQ, 2, 1) (RRP, 2, 1) (R, 2, 1, 2) Run: finite action sequence executable from initial state
Data independence • Memory systems do not conjure up data values • Data values copied but not examined by actions (except for read and write actions) • Every run can be generated from an unambiguous run by suitably renaming data values. Unambiguous run: (EventId, Proc, Addr, Data) (R,1,1,0) (R,1,1,1) (W,1,1,2) (W,2,1,1) (R,2,1,1) (R,2,1,2) Suffices to analyze unambiguous runs!
Unambiguous run: (R,1,1,0) (R,1,1,1) (W,1,1,2) (W,2,1,1) (R,2,1,1) (R,2,1,2) acyclic graph witness order Witness write order for address 1 (W,2,1,1) (W,1,1,2) (EventId, Proc, Addr, Data) System S satisfies Model M iff for every run there are witness write orders for all addresses
Recipe for verification For every unambiguous run, 1. guess write order for each address 2. generate graph and check for cycles
RDEX(A) FWD_RDEX(A, P1) state[A] = EXC state[A] = INV P1 P2 RDEX_ACK(A) WR_REQ(A) WR_ACK(A) C1 C2 Interconnect network Memory + Directory
Simple write order For each location, order write events according to actual occurrence order !!
Examples • Piranha chip multiprocessor (Compaq) • Wildfire challenge problem (Compaq) • DASH multiprocessor (Stanford)
Recipe for verification • For every unambiguous run, • 1. guess write order for each address • simple write order • 2. generate graph and check for cycles
Nice cycles • 3-nice cycle: • 3 processors i, j, k • 3 addresses x, y, z (EventId, Proc, Addr, Data) . . . . . . . . . . . . . . . . . . (*,i,z,*) . . . (*,i,x,*) . . . . . . (*,j,x,*) . . . (*,j,y,*) . . . . . . (*,k,y,*) . . . (*,k,z,*) . . . . . . . . . . . . . . . . . . k-nice cycle involves k processors and k addresses
Nice cycles S: memory system with n processors, m addresses Lemma: S has a cycle iff S has a k-nice cycle for 1 k min(n,m)
Recipe for verification • For every unambiguous run, • 1. guess write orders for each address • simple write order • 2. generate graph and check for cycles • reduce to nice cycles • detecting nice cycles by model checking
Detecting nice cycles S: memory system with n processors, m addresses Lemma: S has a cycle iff S has a k-nice cycle for 1 k min(n,m) min(n,m) model checking lemmas: kth lemma checks for k-nice cycles
Property = i. Moni@err Model checker Detecting nice cycles • Supj supplies write values for address j. • Moni monitors memory events at processor i. 1-nice cycle Sup1 Mon1 Memory system
Property = i. Moni@err Model checker Detecting nice cycles • Supj supplies write values for address j. • Moni monitors memory events at processor i. 2-nice cycle Sup1 Mon1 Memory system Sup2 Mon2
Property = i. Moni@err Sup1 Mon1 Memory system Sup2 Mon2 Model checker Sup3 Mon3 Detecting nice cycles • Supj supplies write values for address j. • Moni monitors memory events at processor i. 3-nice cycle