Memory Models (1) Xinyu Feng University of Science and Technology of China.

Slides:



Advertisements
Similar presentations
Dataflow Analysis for Datarace-Free Programs (ESOP 11) Arnab De Joint work with Deepak DSouza and Rupesh Nasre Indian Institute of Science, Bangalore.
Advertisements

© 2005 P. Kouznetsov Computing with Reads and Writes in the Absence of Step Contention Hagit Attiya Rachid Guerraoui Petr Kouznetsov School of Computer.
Memory Consistency Models Kevin Boos. Two Papers Shared Memory Consistency Models: A Tutorial – Sarita V. Adve & Kourosh Gharachorloo – September 1995.
Multiprocessor Architectures for Speculative Multithreading Josep Torrellas, University of Illinois The Bulk Multicore Architecture for Programmability.
Java PathRelaxer: Extending JPF for JMM-Aware Model Checking Huafeng Jin, Tuba Yavuz-Kahveci, and Beverly Sanders Computer and Information Science and.
A Rely-Guarantee-Based Simulation for Verifying Concurrent Program Transformations Hongjin Liang, Xinyu Feng & Ming Fu Univ. of Science and Technology.
D u k e S y s t e m s Time, clocks, and consistency and the JMM Jeff Chase Duke University.
Memory Models: A Case for Rethinking Parallel Languages and Hardware † Sarita Adve University of Illinois Acks: Mark Hill, Kourosh Gharachorloo,
DRF x A Simple and Efficient Memory Model for Concurrent Programming Languages Dan Marino Abhay Singh Todd Millstein Madan Musuvathi Satish Narayanasamy.
PARTIAL-COHERENCE ABSTRACTIONS FOR RELAXED MEMORY MODELS Presented by Michael Kuperstein, Technion Joint work with Martin Vechev, IBM Research and Eran.
Memory Models: The Case for Rethinking Parallel Languages and Hardware Sarita Adve University of Illinois at Urbana-Champaign
ADVERSARIAL MEMORY FOR DETECTING DESTRUCTIVE RACES Cormac Flanagan & Stephen Freund UC Santa Cruz Williams College PLDI 2010 Slides by Michelle Goodstein.
PARALLEL PROGRAMMING with TRANSACTIONAL MEMORY Pratibha Kona.
Threading Part 2 CS221 – 4/22/09. Where We Left Off Simple Threads Program: – Start a worker thread from the Main thread – Worker thread prints messages.
“THREADS CANNOT BE IMPLEMENTED AS A LIBRARY” HANS-J. BOEHM, HP LABS Presented by Seema Saijpaul CS-510.
By Sarita Adve & Kourosh Gharachorloo Review by Jim Larson Shared Memory Consistency Models: A Tutorial.
Formalisms and Verification for Transactional Memories Vasu Singh EPFL Switzerland.
On the Relationship Between Concurrent Separation Logic and Assume-Guarantee Reasoning Xinyu Feng Yale University Joint work with Rodrigo Ferreira and.
Specifying Java Thread Semantics Using a Uniform Memory Model Jason Yue Yang Ganesh Gopalakrishnan Gary Lindstrom School of Computing University of Utah.
Computer Architecture II 1 Computer architecture II Lecture 9.
1 Ivan Lanese Computer Science Department University of Bologna Italy Concurrent and located synchronizations in π-calculus.
The Java Memory Model. JMM: SC intuition may fail Application programmer supposes sequential consistent memory model The trace proves that the memory.
Semantics of Multithreaded Java Jeremy Manson and William Pugh Background Material Jack Newton University of Alberta
Java Race Finder Checking Java Programs for Sequential Consistency Tuba Yavuz-Kahveci Fall 2013.
Memory Consistency Models Some material borrowed from Sarita Adve’s (UIUC) tutorial on memory consistency models.
A Behavioral Memory Model for the UPC Language Kathy Yelick Joint work with: Dan Bonachea, Jason Duell, Chuck Wallace.
Exceptions and Mistakes CSE788 John Eisenlohr. Big Question How can we improve the quality of concurrent software?
Compositional Verification of Termination-Preserving Refinement of Concurrent Programs Hongjin Liang Univ. of Science and Technology of China (USTC) Joint.
Shared Memory Consistency Models: A Tutorial Sarita V. Adve Kouroush Ghrachorloo Western Research Laboratory September 1995.
Yang Liu, Jun Sun and Jin Song Dong School of Computing National University of Singapore.
Foundations of the C++ Concurrency Memory Model Hans-J. Boehm Sarita V. Adve HP Laboratories UIUC.
Rethinking Hardware and Software for Disciplined Parallelism Sarita V. Adve University of Illinois
Aritra Sengupta, Swarnendu Biswas, Minjia Zhang, Michael D. Bond and Milind Kulkarni ASPLOS 2015, ISTANBUL, TURKEY Hybrid Static-Dynamic Analysis for Statically.
By Sarita Adve & Kourosh Gharachorloo Slides by Jim Larson Shared Memory Consistency Models: A Tutorial.
Shared Memory Consistency Models. SMP systems support shared memory abstraction: all processors see the whole memory and can perform memory operations.
Memory Consistency Models. Outline Review of multi-threaded program execution on uniprocessor Need for memory consistency models Sequential consistency.
Pattern-based Synthesis of Synchronization for the C++ Memory Model Yuri Meshman, Noam Rinetzky, Eran Yahav 1.
Data races, informally [More formal definition to follow] “race condition” means two different things Data race: Two threads read/write, write/read, or.
Threads Cannot be Implemented as a Library Hans-J. Boehm.
Memory Consistency Models 1. Uniform Consistency Models Only have read and write operations Sequential Consistency Pipelined-RAM Causal Consistency Coherence.
Threads cannot be implemented as a library Hans-J. Boehm (presented by Max W Schwarz)
Memory Consistency Zhonghai Lu Outline Introduction What is a memory consistency model? Who should care? Memory consistency models Strict.
Weak Ordering: A New Definition (presenting: Matthew Moskewicz) CS258, UCB, ( )
ICFEM 2002, Shanghai Reasoning about Hardware and Software Memory Models Abhik Roychoudhury School of Computing National University of Singapore.
A Safety-First Approach to Memory Models Madan Musuvathi Microsoft Research ISMM ‘13 Keynote 1.
CS533 Concepts of Operating Systems Jonathan Walpole.
Aritra Sengupta, Man Cao, Michael D. Bond and Milind Kulkarni PPPJ 2015, Melbourne, Florida, USA Toward Efficient Strong Memory Model Support for the Java.
Specifying Multithreaded Java semantics for Program Verification Abhik Roychoudhury National University of Singapore (Joint work with Tulika Mitra)
Fundamentals of Memory Consistency Smruti R. Sarangi Prereq: Slides for Chapter 11 (Multiprocessor Systems), Computer Organisation and Architecture, Smruti.
Prescient Memory: Exposing Weak Memory Model Behavior by Looking into the Future MAN CAO JAKE ROEMER ARITRA SENGUPTA MICHAEL D. BOND 1.
An Operational Approach to Relaxed Memory Models
CS5102 High Performance Computer Systems Memory Consistency
Memory Consistency Models
Threads Cannot Be Implemented As a Library
Memory Consistency Models
Specifying Multithreaded Java semantics for Program Verification
Hongjin Liang, Xinyu Feng & Ming Fu
Threads and Memory Models Hal Perkins Autumn 2011
Shared Memory Consistency Models: A Tutorial
Threads and Memory Models Hal Perkins Autumn 2009
Background for Debate on Memory Consistency Models
Shared Memory Consistency Models: A Tutorial
Store Atomicity What does atomicity really require?
Memory Consistency Models
Xinyu Feng University of Science and Technology of China
Relaxed Consistency Part 2
Relaxed Consistency Finale
Tools for the development of parallel applications
Compilers, Languages, and Memory Models
CS 152 Computer Architecture and Engineering CS252 Graduate Computer Architecture Lecture 19 Memory Consistency Models Krste Asanovic Electrical Engineering.
Presentation transcript:

Memory Models (1) Xinyu Feng University of Science and Technology of China

Why Memory Models C1 || C2Compiler Memory Result

Why Memory Models C1 || C2Compiler Memory Result Which reads see which write?

Sequential Consistent (SC) Model... Memory Interleaving semantics: P1 P2P3Pn [Lamport 1979]

The need of weak memory models SC model prohibits many optimization: x = 1; r1 = y; y = 1; r2 = x; r1 = r2 = 0? Initially: x = y = 0 Impossible in SC model, but allowed in x86 or Java. r1 = y; x = 1 y = 1; r2 = x; Weak memory model allow more behaviors.

Usability: DRF guarantee – DRF programs have the same behaviors as in SC model Not too strong – Allow common optimization techniques – In some sense hijacked by the mainstream compiler Preserve type-safety and security guarantee – Cannot be too weak Design Criteria Very challenging to satisfy all the requirements!

Compiler Optimization Can Be Smart r1 = x; r2 = x; if (r1 == r2) y = 2; r3 = y; x = r3; Initially: x = 0, y = 1 r1 = r2 = r3 = 2? Must be allowed! y = 2; r1 = x; r2 = r1; if (true) Redundant read elim.

Efforts for Java Memory Model (JMM) First edition in Java Language Spec – Fatally flawed, not support key optimizations [Pough 2000] Current JMM [Manson et al. 2005] – Based on 5-year discussion and many failed proposals – “very complex” [Adve & Boehm 2010] – Surprising behaviors and bugs [Aspinall & Sevcik 2007] Next generation: JEP 188, Dec. 2013

Happens-Before Order Program execution: a set of events, and some orders between them. po: Time T1 T2 rel acqrel acq sw: Happens-before order (hb): transitive closure of po  sw [Lamport 1978]

Happens-Before Order Time T1 T2 po: rel acqrel acq sw: Happens-before order (hb): transitive closure of po  sw w1 w2 r w1 hb w2w1 hb r Not: w2 hb rr w2

Happens-Before Memory Model (HMM) Time T1 T2 rel acqrel acq w1 w2 r Read can see (1) the most recent write that happens-before it, or (2) a write that has no happens-before relation. r could see both w1 (which happens-before it) and w2 (with which there is no happens-before relation)

HMM – Relaxed Ordering x = 1; r1 = y; y = 1; r2 = x; r1 = r2 = 0? Initially: x = y = 0 Allowed in HMM

HMM – Examples with Global Analysis r1 = x; r2 = x; if (r1 == r2) y = 2; r3 = y; x = r3; Initially: x = 0, y = 1 r1 = r2 = r3 = 2? Speculation: r3 reads 2 Allowed in HMM! Justified!

HMM – Out-of-Thin-Air Read r1 = x; y = r1; r2 = y; x = r2; r1 = r2 = 42? Initially: x = y = 0 Allowed in HMM! Speculation: r1 will get 42 Justified! May break the security and type-safety of Java!

r1 = x; r2 = x; if (r1 == r2) y = 2; r3 = y; x = r3; r1 = r2 = r3 = 2? Speculation: r3 reads 2 r1 = x; y = r1; r2 = y; x = r2; r1 = r2 = 42? Speculation: r1 will get 42 Good speculation. Should allow! Bad speculation. Disallow!

JMM Take HMM as the core, and try hard to distinguish good speculation from bad speculation! Very complex, with surprising results and bugs. Introduce 9 axioms to constrain causality.

JMM – Surprising Results C1; lock l; C2; unlock l; C3 lock l; C1; C2; unlock l; C3 lock l; C1; unlock l; lock l; C2; unlock l; C3 Adding more synchronization may increase behaviors!

JMM – Surprising Results (2) C1; C3 C2; C1; C2; C3; Inlining threads may increase behaviors! More: Re-ordering independent operations may change behaviors. Adding/removing redundant reads may change behaviors.

Reading