Modeling issues Book: chapters 4.12, 5.4, 8.4, 10.1.

Slides:



Advertisements
Similar presentations
1 Verification by Model Checking. 2 Part 1 : Motivation.
Advertisements

Model Checking Lecture 1.
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Model Checking Lecture 2. Three important decisions when choosing system properties: 1automata vs. logic 2branching vs. linear time 3safety vs. liveness.
Symmetric Multiprocessors: Synchronization and Sequential Consistency.
1 Reasoning with Promela Safety properties bad things do not happen can check by inspecting finite behaviours Liveness properties good things do eventually.
Completeness and Expressiveness
Modeling Software Systems Lecture 2 Book: Chapter 4.
Model Checking and Testing combined
Automatic Verification Book: Chapter 6. How can we check the model? The model is a graph. The specification should refer the the graph representation.
The SPIN System. What is SPIN? Model-checker. Based on automata theory. Allows LTL or automata specification Efficient (on-the-fly model checking, partial.
Mutual Exclusion – SW & HW By Oded Regev. Outline: Short review on the Bakery algorithm Short review on the Bakery algorithm Black & White Algorithm Black.
Problems and Their Classes
Distributed Computing 5. Snapshot Shmuel Zaks ©
CS 267: Automated Verification Lecture 2: Linear vs. Branching time. Temporal Logics: CTL, CTL*. CTL model checking algorithm. Counter-example generation.
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
Partial Order Reduction: Main Idea
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Model checking. 2 And now... the system How do we model a reactive system with an automaton ? It is convenient to model systems with Transition systems.
Automatic Verification Book: Chapter 6. What is verification? Traditionally, verification means proof of correctness automatic: model checking deductive:
ECE Synthesis & Verification - L271 ECE 697B (667) Spring 2006 Synthesis and Verification of Digital Systems Model Checking basics.
CSC321 Concurrent Programming: §3 The Mutual Exclusion Problem 1 Section 3 The Mutual Exclusion Problem.
Enforcing Concurrent Temporal Behaviors Doron Peled, Dept. of CS University of Warwick.
Program correctness The State-transition model A global state S  s 0 x s 1 x … x s m {s k = local state of process k} S0  S1  S2  … Each state transition.
PROTOCOL VERIFICATION & PROTOCOL VALIDATION. Protocol Verification Communication Protocols should be checked for correctness, robustness and performance,
1 MODULE name (parameters) “Ontology” “Program” “Properties” The NuSMV language A module can contain modules Top level: parameters less module Lower level.
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
Process Synchronization Continued 7.2 The Critical-Section Problem.
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 13.
1 Temporal Claims A temporal claim is defined in Promela by the syntax: never { … body … } never is a keyword, like proctype. The body is the same as for.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Spin Tutorial (some verification options). Assertion is always executable and has no other effect on the state of the system than to change the local.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
1 Formal Methods in SE Qaisar Javaid Assistant Professor Lecture # 11.
1 Basic abstract interpretation theory. 2 The general idea §a semantics l any definition style, from a denotational definition to a detailed interpreter.
1 Model Checking, Abstraction- Refinement, and Their Implementation Based on slides by: Orna Grumberg Presented by: Yael Meller June 2008.
Department of mathematics and computer science 1 of 21 Rob van Glabbeek (Sydney) Marc Voorhoeve (TUE) Liveness, Fairness and Impossible Futures.
Abstractions. Outline Informal intuition Why do we need abstraction? What is an abstraction and what is not an abstraction A framework for abstractions.
Modeling Software Systems Lecture 2 Book: Chapter 4.
Specification Formalisms Book: Chapter 5. Properties of formalisms Formal. Unique interpretation. Intuitive. Simple to understand (visual). Succinct.
Concurrency in Distributed Systems: Mutual exclusion.
ESE601: Hybrid Systems Introduction to verification Spring 2006.
1 Formal Engineering of Reliable Software LASER 2004 school Tutorial, Lecture1 Natasha Sharygina Carnegie Mellon University.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
Linear and Branching Time Safety, Liveness, and Fairness
Specifying and Verifying Event-based Fairness Enhanced Systems 1 ICFEM 2008 Specifying and Verifying Event-based Fairness Enhanced Systems Jun SUN, Yang.
Copyright , Doron Peled and Cesare Tinelli. These notes are based on a set of lecture notes originally developed by Doron Peled at the University.
The Complexity of Distributed Algorithms. Common measures Space complexity How much space is needed per process to run an algorithm? (measured in terms.
Program correctness The State-transition model A global states S  s 0 x s 1 x … x s m {s k = set of local states of process k} S0  S1  S2  Each state.
Defining Liveness by Bowen Alpern and Fred B. Schneider Presented by Joe Melnyk.
CIS 842: Specification and Verification of Reactive Systems Lecture INTRO-Examples: Simple BIR-Lite Examples Copyright 2004, Matt Dwyer, John Hatcliff,
Hwajung Lee. Well, you need to capture the notions of atomicity, non-determinism, fairness etc. These concepts are not built into languages like JAVA,
Hwajung Lee. Why do we need these? Don’t we already know a lot about programming? Well, you need to capture the notions of atomicity, non-determinism,
/ PSWLAB S PIN Search Optimization from “THE SPIN MODEL CHECKER” by G. Holzmann Presented by Hong,Shin 23 th Nov SPIN Search.
1 Fault tolerance in distributed systems n Motivation n robust and stabilizing algorithms n failure models n robust algorithms u decision problems u impossibility.
Quality Assurance in the Presence of Variability Kim Lauenroth, Andreas Metzger, Klaus Pohl Institute for Computer Science and Business Information Systems.
Program Correctness. The designer of a distributed system has the responsibility of certifying the correctness of the system before users start using.
Variants of LTL Query Checking Hana ChocklerArie Gurfinkel Ofer Strichman IBM Research SEI Technion Technion - Israel Institute of Technology.
Today’s Agenda  Quiz 4  Temporal Logic Formal Methods in Software Engineering1.
Complexity Relief Techniques for Model Checking METU, Aug SOFTWARE VERIFICATION WORKSHOP Hüsnü Yenigün Sabanci University Informatics Institute,
Model and complexity Many measures Space complexity Time complexity
Automatic Verification
CSEP590 – Model Checking and Automated Verification
Over-Approximating Boolean Programs with Unbounded Thread Creation
Application: Algorithms
Introduction to verification
Presentation transcript:

Modeling issues Book: chapters 4.12, 5.4, 8.4, 10.1

Fairness

Dekkers algorithm P1::while true do begin non-critical section 1 c1:=0; while c2=0 do begin if turn=2 then begin c1:=1; wait until turn=1; c1:=0; end end critical section 1 c1:=1; turn:=2 end. P2::while true do begin non-critical section 2 c2:=0; while c1=0 do begin if turn=1 then begin c2:=1; wait until turn=2; c2:=0; end end critical section 2 c2:=1; turn:=1 end. boolean c1 initially 1; boolean c2 initially 1; integer (1..2) turn initially 1;

Dekkers algorithm P1::while true do begin non-critical section 1 c1:=0; while c2=0 do begin if turn=2 then begin c1:=1; wait until turn=1; c1:=0; end end critical section 1 c1:=1; turn:=2 end. P2::while true do begin non-critical section 2 c2:=0; while c1=0 do begin if turn=1 then begin c2:=1; wait until turn=2; c2:=0; end end critical section 2 c2:=1; turn:=1 end. boolean c1 initially 1; boolean c2 initially 1; integer (1..2) turn initially 1; c1=c2=0, turn=1

Dekkers algorithm P1::while true do begin non-critical section 1 c1:=0; while c2=0 do begin if turn=2 then begin c1:=1; wait until turn=1; c1:=0; end end critical section 1 c1:=1; turn:=2 end. P2::while true do begin non-critical section 2 c2:=0; while c1=0 do begin if turn=1 then begin c2:=1; wait until turn=2; c2:=0; end end critical section 2 c2:=1; turn:=1 end. boolean c1 initially 1; boolean c2 initially 1; integer (1..2) turn initially 1; c1=c2=0, turn=1

Dekkers algorithm P1::while true do begin non-critical section 1 c1:=0; while c2=0 do begin if turn=2 then begin c1:=1; wait until turn=1; c1:=0; end end critical section 1 c1:=1; turn:=2 end. P2::while true do begin non-critical section 2 c2:=0; while c1=0 do begin if turn=1 then begin c2:=1; wait until turn=2; c2:=0; end end critical section 2 c2:=1; turn:=1 end. P1 waits for P2 to set c2 to 1 again. Since turn=1 (priority for P1), P2 is ready to do that. But never gets the chance, since P1 is constantly active checking c2 in its while loop. c1=c2=0, turn=1

0:START P1 11:c1:=1 12:true 13:end 2:c1:=0 8:c2=0? 7:turn=2? 6:c1:=0 3:c1:=1 11:turn:=2 10:c1:=1 9:critical-1 4:no-op 5:turn=2? no no no noyes yes yes yes 0:START P2 11:c2:=1 12:true 13:end 2:c2:=0 8:c1=0? 7:turn=1? 6:c2:=0 3:c2:=1 11:turn:=1 10:c2:=1 9:critical-2 4:no-op 5:turn=1? no no no noyes yes yes yes Initially: turn=1

What went wrong? The execution is unfair to P2. It is not allowed a chance to execute. Such an execution is due to the interleaving model (just picking an enabled transition). If it did, it would continue and set c2 to 0, which would allow P1 to progress. Fairness = excluding some of the executions in the interleaving model, which do not correspond to actual behavior of the system. while c1=0 do begin if turn=1 then begin c2:=1; wait until turn=2; c2:=0; end end

Recall: The interleaving model An execution is a finite or infinite sequence of states s 0, s 1, s 2, … The initial state satisfies the initial condition, I.e., I (s 0 ). Moving from one state s i to s i+1 is by executing a transition e t: e(s i ), I.e., s i satisfies e. s i+1 is obtained by applying t to s i. Now: consider only fair executions. Fairness constrains sequences that are considered to be executions. Fair executions Sequences Executions

Some fairness definitions Weak transition fairness: It cannot happen that a transition is enabled indefinitely, but is never executed. Weak process fairness: It cannot happen that a process is enabled indefinitely, but non of its transitions is ever executed Strong transition fairness: If a transition is infinitely often enabled, it will get executed. Strong process fairness: If at least one transition of a process is infinitely often enabled, a transition of this process will be executed.

How to use fairness constraints? Assume in the negative that some property (e.g., termination) does not hold, because of some transitions or processes prevented from execution. Show that such executions are impossible, as they contradict fairness assumption. We sometimes do not know in reality which fairness constraint is guaranteed.

Example P1::x=1 P2: do :: y==0 -> if :: true :: x==1 -> y=1 fi od Initially: x=0; y=0; In order for the loop to terminate (in a deadlock !) we need P1 to execute the assignment. But P1 may never execute, since P2 is in a loop executing true. Consequently, x==1 never holds, and y is never assigned a 1. pc1=l0-->(pc1,x):=(l1,1) /* x=1 */ pc2=r0/\y=0-->pc2=r1 /* y==0*/ pc2=r1-->pc2=r0 /* true */ pc2=r1/\x=1-->(pc2,y):=(r0,1) /* x==1 --> y:=1 */

Weak transition fairness P1::x=1 P2: do :: y==0 -> if :: true :: x==1 -> y=1 fi od Initially: x=0; y=0; Under weak transition fairness, P1 would assign 1 to x, but this does not guarantee that 1 is assigned to y and thus the P2 loop will terminates, since the transition for checking x==1 is not continuously enabled (program counter not always there). Weak process fairness only guarantees P1 to execute, but P2 can still choose the true guard. Strong process fairness: same.

Strong transition fairness P1::x=1P2: do :: y==0 -> if :: true :: x==1 -> y=1 fi od Initially: x=0; y=0; Under strong transition fairness, P1 would assign 1 to x. If the execution was infinite, the transition checking x==1 was infinitely often enabled. Hence it would be eventually selected. Then assigning y=1, the main loop is not enabled anymore.

Specifying fairness conditions Express properties over an alternating sequence of states and transitions: s 0 1 s 1 1 s 2 … Use transition predicates exec.

Some fairness definitions Weak transition fairness: /\ T (<>[]en -->[]<>exec ). Equivalently: /\ a T ¬<>[](en /\¬exec ) Weak process fairness: /\ Pi (<>[]en Pi -->[]<>exec Pi ) Strong transition fairness: /\ T ([]<>en -->[]<>exec ) Strong process fairness: /\ Pi ([]<>en Pi -->[]<>exec Pi ) exec is executed. exec Pi some transition of Pi is executed. en is enabled. en Pi some transition of process Pi is enabled. en Pi = \/ Pi en exec Pi = \/ Pi exec

Weaker fairness condition A is weaker than B if B -->A. (Means A has more executions than B.) Consider the executions L(A) and L(B). Then L(B) L(A). An execution is strong {process,transition} fair--> It is also weak {process,transition} fair. There are fewer strong {process,transition} fair executions. Strong transition fair execs Weak process fair execs Weak transition fair execs Strong process fair execs

Weak vs. strong fairness If a sequence is fair according to strong transition fairness and some transition is enabled from some point and forever, then it is also enabled infinitely often. Therefore, it must be executed infinitely many times. Thus, the sequence is also fair according to weak process fairness. Show other implications between fairness assumptions!

Fairness is an abstraction; no scheduler can guarantee exactly all fair executions! Initially: x=0, y=0 P1::x=1 || P2::do :: x==0 -> y=y+1 :: x==1 -> break od x=0,y=0 x=0,y=1 x=1,y=0 x=1,y=1 x=0,y=2 x=1,y=2 Under fairness assumption (any of the four defined), P1 will execute the assignment, and consequently, P2 will terminate. All executions are finite and there are infinitely many of them, and infinitely many states. Thus, an execution tree (the state space) will potentially look like the one on the left, but with infinitely many states, finite branching and only finite sequences. But according to Königs Lemma there is no such tree!

Model Checking under fairness Instead of verifying that the program satisfies, verify it satisfies fair--> Problem: may be inefficient. Also fairness formula may involves special arrangement for specifying what exec means. May specialize model checking algorithm instead.

Model Checking under Fairness Specialize model checking. For weak process fairness: search for a reachable strongly connected component, where for each process P either it contains on occurrence of a transition from P, or it contains a state where P is disabled. Weak transition fairness: similar. Strong fairness: much more difficult algorithm.

Abstractions

Problems with software analysis Many possible outcomes and interactions. Not manageable by an algorithm (undecideable, complex). Requires a lot of practice and ingenuity (e.g., finding invariants).

More problems Testing methods fail to cover potential errors. Deductive verification techniques require too much time, mathematical expertise, ingenuity. Model checking requires a lot of time/space and may introduce modeling errors.

How to alleviate the complexity? Abstraction Compositionality Partial Order Reduction Symmetry

Abstraction Represent the program using a smaller model. Pay attention to preserving the checked properties. Do not affect the flow of control.

Main idea Use smaller data objects. x:= f(m) y:=g(n) if x*y>0 then … else … x, y never used again.

How to abstract? Assign values {-1, 0, 1} to x and y. Based on the following connection: sgn(x) = 1 if x>0, 0 if x=0, and -1 if x<0. sgn(x)*sgn(y)=sgn(x*y).

Abstraction mapping S - states, I - initial states. L(s) - labeling. R(S,S) - transition relation. h(s) maps s into its abstract image. Full model --h--> Abstract model I(s) --> I(h(s)) R(s, t) --> R(h(s),h(t)) L(h(s))=L(s)

Traffic light example go stop

go stop go stop

What do we preserve? go stop go stop Every execution of the full model can be simulated by an execution of the reduced one. Every LTL property that holds in the reduced model hold in the full one. But there can be properties holding for the original model but not the abstract one.

Preserved: [](go->O stop) go stop go stop Not preserved: []<>go Counterexamples need to be checked.

Symmetry A permutation is a one-one and onto function p:A->A. For example, 1->3, 2->4, 3->1, 4->5, 5->2. One can combine permutations, e.g., p1: 1->3, 2->1, 3->2 p2: 1->2, 2->1, 3->3 1->3, 2->2, 3->1 A set of permutations is called a symmetry group.

Using symmetry in analysis Want to find some symmetry group such that for each permutation p in it, R(s,t) if and only if R(p(s), p(t)) and L(p(s))=L(s). Let K(s) be all the states that can be permuted to s. This is a set of states such that each one can be permuted to the other.

Turn=0 L0,L1 Turn=0 L0,NC1 Turn=0 NC0,L1 Turn=0 CR0,NC1 Turn=0 NC0,NC1 Turn=0 CR0,L1 Turn=1 L0,CR1 Turn=1 NC0,CR1 Turn=1 L0,NC1 Turn=1 NC0,NC1 Turn=1 NC0,L1 Turn=1 L0,L1 init

Turn=0 L0,L1 Turn=0 L0,NC1 Turn=0 NC0,L1 Turn=0 CR0,NC1 Turn=0 NC0,NC1 Turn=0 CR0,L1 init The quotient model

Homework: what is preserved in the following buffer abstraction? What is not preserved? e empty quasi full q q q f