ICFEM 2002, Shanghai Reasoning about Hardware and Software Memory Models Abhik Roychoudhury School of Computing National University of Singapore.

Slides:



Advertisements
Similar presentations
Bounded Model Checking of Concurrent Data Types on Relaxed Memory Models: A Case Study Sebastian Burckhardt Rajeev Alur Milo M. K. Martin Department of.
Advertisements

Synchronization. How to synchronize processes? – Need to protect access to shared data to avoid problems like race conditions – Typical example: Updating.
Memory Consistency Models Kevin Boos. Two Papers Shared Memory Consistency Models: A Tutorial – Sarita V. Adve & Kourosh Gharachorloo – September 1995.
Architecture-aware Analysis of Concurrent Software Rajeev Alur University of Pennsylvania Amir Pnueli Memorial Symposium New York University, May 2010.
CS 162 Memory Consistency Models. Memory operations are reordered to improve performance Hardware (e.g., store buffer, reorder buffer) Compiler (e.g.,
© Krste Asanovic, 2014CS252, Spring 2014, Lecture 12 CS252 Graduate Computer Architecture Spring 2014 Lecture 12: Synchronization and Memory Models Krste.
CS492B Analysis of Concurrent Programs Consistency Jaehyuk Huh Computer Science, KAIST Part of slides are based on CS:App from CMU.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Slides 8d-1 Programming with Shared Memory Specifying parallelism Performance issues ITCS4145/5145, Parallel Programming B. Wilkinson Fall 2010.
“THREADS CANNOT BE IMPLEMENTED AS A LIBRARY” HANS-J. BOEHM, HP LABS Presented by Seema Saijpaul CS-510.
Formalisms and Verification for Transactional Memories Vasu Singh EPFL Switzerland.
1 Lecture 7: Consistency Models Topics: sequential consistency, requirements to implement sequential consistency, relaxed consistency models.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
Lecture 13: Consistency Models
Computer Architecture II 1 Computer architecture II Lecture 9.
1 Lecture 15: Consistency Models Topics: sequential consistency, requirements to implement sequential consistency, relaxed consistency models.
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
Memory Consistency Models
CS510 Concurrent Systems Class 5 Threads Cannot Be Implemented As a Library.
Analyzing the CRF Java Memory Model Yue Yang Ganesh Gopalakrishnan Gary Lindstrom School of Computing University of Utah.
Shared Memory Consistency Models: A Tutorial By Sarita V Adve and Kourosh Gharachorloo Presenter: Sunita Marathe.
Memory Consistency Models Some material borrowed from Sarita Adve’s (UIUC) tutorial on memory consistency models.
Evaluation of Memory Consistency Models in Titanium.
9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides.
Distributed Shared Memory Systems and Programming
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
ICOM 5995: Performance Instrumentation and Visualization for High Performance Computer Systems Lecture 7 October 16, 2002 Nayda G. Santiago.
Parallel Programming Models Jihad El-Sana These slides are based on the book: Introduction to Parallel Computing, Blaise Barney, Lawrence Livermore National.
Multi-core systems System Architecture COMP25212 Daniel Goodman Advanced Processor Technologies Group.
Shared Memory Consistency Models: A Tutorial Sarita V. Adve Kouroush Ghrachorloo Western Research Laboratory September 1995.
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.
Processes and Threads Processes have two characteristics: – Resource ownership - process includes a virtual address space to hold the process image – Scheduling/execution.
Dynamic Analysis of Multithreaded Java Programs Dr. Abhik Roychoudhury National University of Singapore.
Foundations of the C++ Concurrency Memory Model Hans-J. Boehm Sarita V. Adve HP Laboratories UIUC.
Memory Consistency Models Alistair Rendell See “Shared Memory Consistency Models: A Tutorial”, S.V. Adve and K. Gharachorloo Chapter 8 pp of Wilkinson.
Shared Memory Consistency Models. SMP systems support shared memory abstraction: all processors see the whole memory and can perform memory operations.
Anshul Kumar, CSE IITD CSL718 : Multiprocessors Synchronization, Memory Consistency 17th April, 2006.
Anshul Kumar, CSE IITD ECE729 : Advance Computer Architecture Lecture 26: Synchronization, Memory Consistency 25 th March, 2010.
Fence Scoping Changhui Lin †, Vijay Nagarajan*, Rajiv Gupta † † University of California, Riverside * University of Edinburgh.
Memory Consistency Models. Outline Review of multi-threaded program execution on uniprocessor Need for memory consistency models Sequential consistency.
Java Thread and Memory Model
Multiprocessor Cache Consistency (or, what does volatile mean?) Andrew Whitaker CSE451.
CS 295 – Memory Models Harry Xu Oct 1, Multi-core Architecture Core-local L1 cache L2 cache shared by cores in a processor All processors share.
Memory Consistency Zhonghai Lu Outline Introduction What is a memory consistency model? Who should care? Memory consistency models Strict.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
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:
740: Computer Architecture Memory Consistency Prof. Onur Mutlu Carnegie Mellon University.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Symmetric Multiprocessors: Synchronization and Sequential Consistency
An Operational Approach to Relaxed Memory Models
Memory Consistency Models
Threads Cannot Be Implemented As a Library
Lecture 11: Consistency Models
Memory Consistency Models
Specifying Multithreaded Java semantics for Program Verification
Threads and Memory Models Hal Perkins Autumn 2011
Chapter 4: Threads.
Symmetric Multiprocessors: Synchronization and Sequential Consistency
Shared Memory Consistency Models: A Tutorial
Symmetric Multiprocessors: Synchronization and Sequential Consistency
Threads and Memory Models Hal Perkins Autumn 2009
Background for Debate on Memory Consistency Models
Memory Consistency Models
Relaxed Consistency Part 2
Relaxed Consistency Finale
Programming with Shared Memory Specifying parallelism
CS 152 Computer Architecture and Engineering CS252 Graduate Computer Architecture Lecture 19 Memory Consistency Models Krste Asanovic Electrical Engineering.
Presentation transcript:

ICFEM 2002, Shanghai Reasoning about Hardware and Software Memory Models Abhik Roychoudhury School of Computing National University of Singapore

ICFEM 2002, Shanghai Salient Points Memory Model – What ? Hardware and Software Memory Models – Why ? Memory Model: Formal Executable Specs. Comparing Memory Models for efficiency MM comparison for reasoning about programs Concluding Remarks

ICFEM 2002, Shanghai Memory Model Order in which memory operations (read / write) appear to execute to the programmer. For uni-processors, the MM is s.t. –Memory Read / Write appear to execute one at a time (atomic) –They execute in the program order.

ICFEM 2002, Shanghai Memory Model Traditionally used to describe allowed behaviors of shared memory multiprocessors. ….Proc 1Proc 2 Proc n SHARED MEMORY

ICFEM 2002, Shanghai Hardware Memory Models Initially Data1 = 0  Data2 = 0  Flag = 0 Data1 := 42; Data2 := Data1 Flag := 1; || While (Flag != 1) {}; Register := Data2 Programmer’s intuition: Register should be 42, not 0 SEQUENTIAL CONSISTENCY

ICFEM 2002, Shanghai Sequential Consistency Simple extension of Uni-processor model. Each processor executes in program order. Operations appear to execute one at a time in some sequential order. Other relaxed Memory models also possible. –Certain (not all ) operations in a processor may be executed out-of-order.

ICFEM 2002, Shanghai Relaxed Memory Models Initially Data1 = 0  Data2 = 0  Flag = 0 Data1 := 42; Data2 := Data1; Flag := 1; While (Flag != 1) {}; Register := Data2 Data1 := 42; Data2 := Data1 and Flag := 1 can be re-ordered e.g. SPARC PSO Register = 0 is also possible

ICFEM 2002, Shanghai Multithreaded programming Multithreaded programming on multiprocessors is difficult due to the hardware memory model. The execution platform supports behaviors other than Sequential Consistency. Shared memory parallelism is becoming important because of Symmetric Multiprocessors (SMP). Multithreaded program popularized by Java. Your multithreaded Java program may run diff. threads on diff. processors without you knowing it !

ICFEM 2002, Shanghai Java Multithreading Can structure different parts of the program as diff. threads e.g. the User Interface as separate thread. Threads communicate via shared variables. Threads can run on uni- or multi-processors. Semantics called the Java Memory Model (JMM) JMM describes all possible allowed behaviors of a pgm. on any implementation (uni- / multi-processor). Supports locking of shared variables via synchronized statements.

ICFEM 2002, Shanghai Java Memory Model Weaker than S.C. (to allow compiler/hardware opt.) Each shared variable has –Master copy –Local copy in each thread Threads read/write local/master copies on actions. Imposes ordering constraints on actions. But does not impose total order on actions in a thread. Being considered for revision. Future JMMs are also bound to be weaker than S.C.

ICFEM 2002, Shanghai Compiler Multithreaded Java Pgm JVM (Introduce barriers ?) Hardware MM (Abstraction of multiprocessor) Bytecode Hardware Instructions … Should respect JMM

ICFEM 2002, Shanghai Hardware and Software MM MM 1 > MM 2 –Behaviors allowed by MM 1  Behaviors allowed by MM 2 –Memory barriers introduced by JMM to prevent certain behaviors if the hardware MM is too weak. If we prove: JMM > Hardware MM –JVM can be tuned to avoid inserting any memory barrier. If we have: JMM > HW MM 1 > HW MM 2 –Certain multithreaded Java programs can behave differently on different multiprocessor platforms !! Need to formally specify and analyze MMs

ICFEM 2002, Shanghai Developing Exec. Spec. – Hard ! JMM imposes ordering constraints on read/write actions of shared variables. The ordering constraints are given informally as set of rules which must never be violated. Past work: Operational exec. spec. of JMM [ICSE02] –Th 1 || Th 2 || … || Th n || Memory (Asynchronous Composition) –Th i executes read/write actions which are modeled as guarded commands Executable Spec. of Hardware MMs (e.g. TSO/PSO from Sun SPARC) developed earlier [Dill et. al. 93]

ICFEM 2002, Shanghai Total Store Order (TSO) One of the hardware memory models in Sun SPARC. All instructions complete in program order, Except can complete as Write completion can be delayed. store u; store v cannot be re-ordered. store u; load u cannot be re-ordered. Store u; Load v Load v; Store u

ICFEM 2002, Shanghai Comparing JMM and TSO Only re-ordering allowed is store  load Initially u = v = 0 Store u,1 Load v, reg1 Store v,1 Load u, reg2 Seq. Consistency: reg1 = 1  reg2 = 1 TSO : reg1 = 0 or 1, reg2 = 0 or 1 JMM > TSO (Proved by JMM checker) JVM can execute on TSO without barriers.

ICFEM 2002, Shanghai Comparing Memory Models 1. Develop formal executable specifications of software and hardware memory models M s, M h 2. Select terminating test programs {P 1,…,P k } which exploit the re-orderings allowed by M h –Based on informal understanding of M h –Typically lifted from multiprocessor architecture manuals. 3. Verify that the set of selected test programs {P 1,…,P k } is complete w.r.t. the re-orderings of M h –Formal reasoning step. Automated if the test programs are selected methodically.

ICFEM 2002, Shanghai Comparing Memory Models 4. Perform reachable state space exploration (as in Model Checking) of test programs {P 1,…,P k } on executable models M h and M s –Use formal executable specs of M h and M s –Generate all possible behaviors of test pgms on M h and M s –Automated formal reasoning step 5. Check whether the re-orderings of M h exposed by programs {P 1,…,P k } are also allowed by M s Combines formal and informal reasoning.

ICFEM 2002, Shanghai Another Application Unsynchronized programs: Multithreaded programs where threads access shared variables without locks. Allow more behaviors under relaxed hardware MMs. Use executable specification of JMM to find all possible behaviors. If any of these is “unexpected”  Can be manifested in certain (not all) Multiprocessor platforms !! Verify presence / absence of this behavior by using executable versions of Hardware memory models.

ICFEM 2002, Shanghai Unsynchronized Programs Allowed behaviors differ on different HW Mem. Models. Used in low-level libraries which are executed often. Data1 := 42; Data2 := Data1 Flag := 1; || While (Flag != 1) {}; Register := Data2 Absence of locks allows write re-orderings in a thread to be visible in other threads.

ICFEM 2002, Shanghai Idiom for lazy instantiation of a singleton – Double checked Locking idiom. Check whether garbage data-fields can be returned If (inst == null) synchronized(Singleton.class){ if (inst == null) { inst = new Singleton(); } Return inst; Case Study Run by each thread

ICFEM 2002, Shanghai Results from DC Locking Allowed behaviors from JMM checker show –Incompletely instantiated object can be returned. –Due to re-ordering of writes within constructor. Allowed behaviors from TSO checker show –Incompletely instantiated obj. cannot be returned. –Proved by State Space Exploration in 0.01 s Other hardware MM (such as Partial Store Order) can show this behavior : proved by PSO checker.

ICFEM 2002, Shanghai Concluding Remarks Formal understanding of MMs was necessary for low- level multiprocessor code. Advent of Java multithreading and SMP requires us to understand hardware MMs for running low-level multithreaded Java code. Language level memory model in Java (JMM) necessitates comparison of JMM with hardware MMs Accomplished by formal Executable Specifications and formal analysis techniques (Model Checking).