1 Written By: Adi Omari (Revised and corrected in 2012 by others) Memory Models CDP 236370.

Slides:



Advertisements
Similar presentations
Implementation and Verification of a Cache Coherence protocol using Spin Steven Farago.
Advertisements

Theory of Computer Science - Algorithms
Virtual Time Virtual Time and Global States of Distributed Systems Friedmann Mattern, 1989 The Model: An asynchronous distributed system = a set of processes.
TRANSACTION PROCESSING SYSTEM ROHIT KHOKHER. TRANSACTION RECOVERY TRANSACTION RECOVERY TRANSACTION STATES SERIALIZABILITY CONFLICT SERIALIZABILITY VIEW.
1 Written By: Adi Omari (Revised and corrected in 2012 by others) Memory models CDP Tutorial 7.
Relaxed Consistency Models. Outline Lazy Release Consistency TreadMarks DSM system.
Virtual Time “Virtual Time and Global States of Distributed Systems” Friedmann Mattern, 1989 The Model: An asynchronous distributed system = a set of processes.
D u k e S y s t e m s Time, clocks, and consistency and the JMM Jeff Chase Duke University.
Consistency and Replication Chapter Introduction: replication and scalability 6.2 Data-Centric Consistency Models 6.3 Client-Centric Consistency.
Shared Memory – Consistency of Shared Variables The ideal picture of shared memory: CPU0CPU1CPU2CPU3 Shared Memory Read/ Write The actual architecture.
Tree Locking Protocol Silberchatz and Kedem, JACM, January1980.
Replication and Consistency Chapter 6. Data-Centric Consistency Models The general organization of a logical data store, physically distributed and replicated.
Consistency Models Based on Tanenbaum/van Steen’s “Distributed Systems”, Ch. 6, section 6.2.
Section 2.3 Gauss-Jordan Method for General Systems of Equations
Slides 8d-1 Programming with Shared Memory Specifying parallelism Performance issues ITCS4145/5145, Parallel Programming B. Wilkinson Fall 2010.
Concurrent Transactions Even when there is no “failure,” several transactions can interact to turn a consistent state into an inconsistent state.
© Katz, 2003 Formal Specifications of Complex Systems-- Real-time 1 Adding Real-time to Formal Specifications Formal Specifications of Complex Systems.
Computer Science Lecture 14, page 1 CS677: Distributed OS Consistency and Replication Today: –Introduction –Consistency models Data-centric consistency.
Ordering and Consistent Cuts Presented By Biswanath Panda.
CPSC 668Set 16: Distributed Shared Memory1 CPSC 668 Distributed Algorithms and Systems Fall 2006 Prof. Jennifer Welch.
Computer Architecture 2011 – coherency & consistency (lec 7) 1 Computer Architecture Memory Coherency & Consistency By Dan Tsafrir, 11/4/2011 Presentation.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
Concurrency. Busy, busy, busy... In production environments, it is unlikely that we can limit our system to just one user at a time. – Consequently, it.
© Katz, 2007 Formal Specifications of Complex Systems-- Real-time 1 Adding Real-time to Formal Specifications Formal Specifications of Complex Systems.
Computer Architecture II 1 Computer architecture II Lecture 9.
Transactions or Concurrency Control. Introduction A program which operates on a DB performs 2 kinds of operations: –Access to the Database (Read/Write)
Concurrency. Correctness Principle A transaction is atomic -- all or none property. If it executes partly, an invalid state is likely to result. A transaction,
Shared Memory – Consistency of Shared Variables The ideal picture of shared memory: CPU0CPU1CPU2CPU3 Shared Memory Read/ Write The actual architecture.
Processor Consistency [Goodman 1989]* Processor Consistency is a memory model in which the result of any execution is the same as if the operations of.
Time, Clocks, and the Ordering of Events in a Distributed System Leslie Lamport (1978) Presented by: Yoav Kantor.
Memory Consistency Models Some material borrowed from Sarita Adve’s (UIUC) tutorial on memory consistency models.
Shared Memory – Consistency of Shared Variables The ideal picture of shared memory: CPU0CPU1CPU2CPU3 Shared Memory Read/ Write The actual architecture.
Lazy Release Consistency for Software Distributed Shared Memory Pete Keleher Alan L. Cox Willy Z.
Computer Architecture 2015 – Cache Coherency & Consistency 1 Computer Architecture Memory Coherency & Consistency By Yoav Etsion and Dan Tsafrir Presentation.
CDP 2012 Based on “C++ Concurrency In Action” by Anthony Williams and The C++11 Memory Model and GCC WikiThe C++11 Memory Model and GCC Created by Eran.
CDP 2013 Based on “C++ Concurrency In Action” by Anthony Williams, The C++11 Memory Model and GCCThe C++11 Memory Model and GCC Wiki and Herb Sutter’s.
Work Replication with Parallel Region #pragma omp parallel { for ( j=0; j
Assignment 3 -- Solution 1. Problem 1 H 1 : r 1 [y] r 1 [x] r 2 [x] w 1 [y] c 1 w 2 [y] c 2 H 1 is normally-strict two-phase locked: rl 1 [y] r 1 [y]
Memory Consistency Models Alistair Rendell See “Shared Memory Consistency Models: A Tutorial”, S.V. Adve and K. Gharachorloo Chapter 8 pp of Wilkinson.
Synchronization. Why we need synchronization? It is important that multiple processes do not access shared resources simultaneously. Synchronization in.
“Virtual Time and Global States of Distributed Systems”
Memory Consistency Models. Outline Review of multi-threaded program execution on uniprocessor Need for memory consistency models Sequential consistency.
Consider the program fragment below left. Assume that the program containing this fragment executes t1() and t2() on separate threads running on separate.
Java Thread and Memory Model
Time, Clocks, and the Ordering of Events in a Distributed System Leslie Lamport Massachusetts Computer Associates,Inc. Presented by Xiaofeng Xiao.
Memory Consistency Models 1. Uniform Consistency Models Only have read and write operations Sequential Consistency Pipelined-RAM Causal Consistency Coherence.
Fundamentals of Parallel Computer Architecture - Chapter 71 Chapter 7 Introduction to Shared Memory Multiprocessors Yan Solihin Copyright.
D u k e S y s t e m s Asynchronous Replicated State Machines (Causal Multicast and All That) Jeff Chase Duke University.
Consistency and Replication. Outline Introduction (what’s it all about) Data-centric consistency Client-centric consistency Replica management Consistency.
Consider the Java code snippet below. Is it a legal use of Java synchronization? What happens if two threads A and B call get() on an object supporting.
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS Fall 2011 Prof. Jennifer Welch CSCE 668 Set 16: Distributed Shared Memory 1.
Event Ordering. CS 5204 – Operating Systems2 Time and Ordering The two critical differences between centralized and distributed systems are: absence of.
Specifying Multithreaded Java semantics for Program Verification Abhik Roychoudhury National University of Singapore (Joint work with Tulika Mitra)
Week 9, Class 3: Java’s Happens-Before Memory Model (Slides used and skipped in class) SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
The C++11 Memory Model CDP Based on “C++ Concurrency In Action” by Anthony Williams, The C++11 Memory Model and GCCThe C++11 Memory Model and GCC Wiki.
Tutorial 3: Homework 2 and Project 2
1 Programming with Shared Memory - 3 Recognizing parallelism Performance issues ITCS4145/5145, Parallel Programming B. Wilkinson Jan 22, 2016.
Concurrency 2 CS 2110 – Spring 2016.
Transaction Management
Memory Consistency Models
Memory Consistency Models
Specifying Multithreaded Java semantics for Program Verification
Threads and Memory Models Hal Perkins Autumn 2011
COP 4600 Operating Systems Fall 2010
Threads and Memory Models Hal Perkins Autumn 2009
Memory Consistency Models
Programming with Shared Memory - 3 Recognizing parallelism
Programming with Shared Memory Specifying parallelism
Consistency and Replication
Ch 3.
Presentation transcript:

1 Written By: Adi Omari (Revised and corrected in 2012 by others) Memory Models CDP

Tutorial Outline Coherence Sequential consistency Causal consistency Release consistency (if time allows) 2

The Happened Before Relation in Shared Memory We say that event e happened before event e’ (and denote it by e  e’ or e < e’) if one of the following properties holds: 1)Processor Order: e precedes e’ in the same process 2)Write-Read: e is a write and e’ is the corresponding read (reading the same value) 3)Transitivity: exists e’’ s.t. e < e’’ and e’’< e’ Two events e, e’ are said to be independent or concurrent (denoted by e || e’) if not e < e’ and not e’ < e. 3

The Happened Before Relation in Shared Memory - Example 4 (1) Processor Order: e precedes e’ in the same process (2) Write-Read: e is a write and e’ is the corresponding read (reading the same value) (3) Transitivity: exists e’’ s.t. e < e’’ and e’’< e’ P1 P2 P3 R x,0 W x,1 W z,3 R x,1 R z,0 global time R y,2 W y, 2 R z,4 W z,4 Program order: R y,2 < W z,4 Write-Read: W y,2 < R y,2 Write-Read: W z,4 < R z,4 Transitivity: W y,2 < R z,4 Concurrent: W z,3 || R x,0

Coherence – Reminder A program P is coherent if for every variable x, there exists an order of read(x)/write(x) which is consistent with program order in all the processes. 5 (1) Processor Order: e precedes e’ in the same process (2) Write-Read: e is a write and e’ is the corresponding read (reading the same value) (3) Transitivity: exists e’’ s.t. e < e’’ and e’’< e’

Coherence – Example 1 A program P is coherent if for every variable x, there exists an order of read(x)/write(x) which is consistent with program order in all the processes. 6 (3) => R x,1 < W x,1 (1) R x,1 < W x,2 (2) < R x,2 (1) < W x,1 (2) W x,1 < R x,1 (1) Processor Order: e precedes e’ in the same process (2) Write-Read: e is a write and e’ is the corresponding read (reading the same value) (3) Transitivity: exists e’’ s.t. e < e’’ and e’’< e’ The execution is not coherent. There is no order of read(x)/write(x) that is consistent with both process 1 and 2.

Coherence – Example 2 A program P is coherent if for every variable x, there exists an order of read(x)/write(x) which is consistent with program order in all the processes. 7 This execution is coherent. We found an order of read(x)/write(x) and read(y)/write(y) that is consistent with both process 1 and 2. For variable x we have: W x,2 < R x,2 For variable y we have: W y,1 < R y,1

Exam Question 1 (1) Given the following execution of a program with 4 threads: Is the execution coherent? If no explain, if yes give an execution order for X and Y writes. 8 P1: R X,7; R Y,17; R X,13; R Y,11 P2: W X,7; W Y,11; R X,7; R Y,11 P3: W X,13; W Y,17 P4: R Y,11; R X,13

Exam Question 1 (2) For commands relating to X we suggest the following order: 9 Then we can order the writes to X in the following order: W X,7; W X,13;

Exam Question 1 (3) For commands relating to Y we suggest the following order: 10 Then we can order the writes to Y as the following: W Y,17; W Y,11; For each one of the variables X and Y we found a working commands order; therefore the execution is coherent.

Sequential Consistency - Reminder A program P is sequentially consistent if there exists an order of reads/writes (of all the variables) which is consistent with program order in all the processes. 11

Sequential Consistency – Example A program P is sequentially consistent if there exists an order of reads/writes (of all the variables) which is consistent with program order in all the processes. 12 We already verified that this execution is coherent The execution is not sequentially consistent. There is no order of read(x)/write(x) that is consistent with both process 1 and 2. (the same as the first coherent example)

Exam Question 2 (1) Given the following execution of a program with 4 threads: Is the execution sequentially consistent? If no explain, if yes give an execution order for X and Y writes. 13 P1: R X,7; R Y,17; R X,13; R Y,11 P2: W X,7; W Y,11; R X,7; R Y,11 P3: W X,13; W Y,17 P4: R Y,11; R X,13

Exam Question 2 (2) 14 P1: R X,7; R Y,17; R X,13; R Y,11 P2: W X,7; W Y,11; R X,7; R Y,11 P3: W X,13; W Y,17 P4: R Y,11; R X,13 (P3) W X,13 < W Y,17 (1) < W Y,11 (P2) < R X,7 (2) < W X,13 (1) According to P1: R Y,17 < R Y,11 (P1 Order) (2) According to P1: R X,7 < R X,13 (P1 Order) => W Y,17 < W Y,11 => W X,7 < W X,13 => W X,7 < R X,7 < W X,13 (no other writes)

Causal Consistency If event B is caused or influenced by an earlier event A (A happened before B), Causal Consistency requires that all the processes first see A, then see B Causally related events: Events A and B are causally related if A causes or influences B (A happened before B) Concurrent events: Events A and B are concurrent/independent if they are not causally related Formally: Casual Consistency: An execution is said to be legal under causal consistency if writes that are casually related are seen by all processes in the same order. Concurrent writes may be seen/read in a different order on different machines. 15

Example – Causally Consistent P1P1 W 1 (x),1W 1 (x),3 P2P2 R 2 (x),1W 2 (x),2 P3P3 R 3 (x),1R 3 (x),3R 3 (x),2 P4P4 R 4 (x),1R 4 (x),2R 4 (x),3 16 W 2 (x),2 and W 1 (x),3 are concurrent events (so it is not required that all processes see them in the same order). W 1 (x),1  W 2 (x),2 and W 1 (x),1  W 1 (x),3 are the only writes that are causally related. The above sequence of events is Causally Consistent but not Sequentially Consistent (conflicting readings of x in P3 and P4).

Example – Causally Inconsistent P1P1 W 1 (x),1 P2P2 R 2 (x),1W 2 (x),2 P3P3 R 3 (x),2R 3 (x),1 P4P4 R 4 (x),1R 4 (x),2 17 Since the two writes are causally related all processes must see them in the same order as they relate each-other, however, P3 sees them in a different order. W 2 (x),2 is causally related to W 1 (x),1 (because the writing of 2 may result from the value read by R 2 (x),1).

Example – Causally Consistent P1P1 W 1 (x),1 P2P2 W 2 (x),2 P3P3 R 3 (x),2R 3 (x),1 P4P4 R 4 (x),1R 4 (x),2 18 W 2 (x),2 and W 1 (x),1 are concurrent events (the read R 2 (x),1 from previous example was removed). Since the two writes are concurrent they may be seen in a different order by different processes.

Exam Question 3 (1) Given the following execution of a program with 4 threads: Is the execution causally consistent ? If no explain, if yes give an execution order for X and Y writes. 19 P1: R X,7; R Y,17; R X,13; R Y,11 P2: W X,7; W Y,11; R X,7; R Y,11 P3: W X,13; W Y,17 P4: R Y,11; R X,13

Exam Question 3 (2) 20 We can order the causally related command such that reads come after the write they related to There is no other causal relations in this program This defines a partial order, but that is what causally consistent requires in our case For every group of related commands, the order must be seen the same for all the processes P1: R X,7; R Y,17; R X,13; R Y,11; P2: W X,7; W Y,11; R X,7; R Y,11; P3: W X,13; W Y,17; P4: R Y,11; R X,13; R X,7;

Exam Question 4 (1) 21

Exam Question 4 (2) 22

Exam Question 4 (3) 23 P1: R Y,1; W Y,2; R Y,2; W X,1; P2: R X,1; W Y,1; R Y,2;

Exam Question 4 (4) 24

Exam Question 5 (1) Given that Java's lock-free memory model obeys Coherence, what values of a,b are possible after the following execution: Initialization: int a = 1, b = 2; After the initializations, both threads are running in parallel Note: in this question there can be more than one right answer (mark them all). A. a = 1; b = 2; B. a = 2; b = 1; C. a = 1; b = 1; 25 Thread A: a = b; Thread B: b = a;

Exam Question 5 (2) Option A: a = 1; b = 2; Initialization: int a = 1, b = 2; 26 Thread B: b = a; Thread A: a = b; R a, 2R b, 1 W b, 2W a, 1 W b,1 does not exist!

Exam Question 5 (3) Option B: a = 2; b = 1; Initialization: int a = 1, b = 2; 27 Thread B: b = a; Thread A: a = b; R a, 1R b, 2 W b, 1W a, 2 Full order of reads and writes = > Sequential Consistency

Exam Question 5 (4) Option C: a = 1; b = 1; Initialization: int a = 1, b = 2; 28 Thread B: b = a; Thread A: a = b; R a, 1R b, 1 W b, 1W a, 1 Full order of reads and writes = > Sequential Consistency

Release Consistency - Reminder Before issuing a write to a memory object or a read from it, the process must acquire the needed lock, and later release it. Before a read or write access is allowed to perform, all previous acquire accesses must be performed, and Before a release access is allowed to perform, all previous read or write accesses must be performed, and Acquire and release accesses are sequentially consistent. 29

Exam Question 6 Event e considered happened before event e’ according to Release consistency. Write the 3 cases that defines this formally: Answer: 1) Processor Order: e precedes e’ in the same process (thread). 2) Release-Acquire: e is a release and e’ is the following acquire of the same lock. 3) Transitivity: exists e’’ s.t. e < e’’ and e’’< e’ 30