Deterministic Concurrency

Similar documents
A Deterministic Concurrent Language for Embedded Systems

Efficient, Deterministic, and Deadlock-free Concurrency

Dealing with Concurrency Problems

A Deterministic Concurrent Language for Embedded Systems

A Deterministic Concurrent Language for Embedded Systems

StreamIt: A Language for Streaming Applications

Atomic Transactions in Cilk Project Presentation 12/1/03

Arrays in SHIM: A Proposal

4/6/2011. Model Checking. Encoding test specifications. Model Checking. Encoding test specifications. Model Checking CS 4271

Design of Internet Protocols:

Dataflow Languages. Languages for Embedded Systems. Prof. Stephen A. Edwards. March Columbia University

Network Protocol Design and Evaluation

Design and Analysis of Distributed Interacting Systems

Model checking Timber program. Paweł Pietrzak

Embedded Systems 7 BF - ES - 1 -

EE382N.23: Embedded System Design and Modeling

The Spin Model Checker : Part I/II

SPIN: Part /614 Bug Catching: Automated Program Verification. Sagar Chaki November 12, Carnegie Mellon University

Software Engineering using Formal Methods

EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization

Lecture 3 SPIN and Promela

Lecture 16: Recapitulations. Lecture 16: Recapitulations p. 1

15-853:Algorithms in the Real World. Outline. Parallelism: Lecture 1 Nested parallelism Cost model Parallel techniques and algorithms

Computer Aided Verification 2015 The SPIN model checker

Petri Nets. Petri Nets. Petri Net Example. Systems are specified as a directed bipartite graph. The two kinds of nodes in the graph:

CMSC Computer Architecture Lecture 12: Multi-Core. Prof. Yanjing Li University of Chicago

Overview. Synchronous Languages Lecture 12. Code Generation for Sequential Constructiveness. Compilation Overview. The 5-Minute Review Session

The Problem with Threads

Software Engineering using Formal Methods

CS 450 Exam 2 Mon. 4/11/2016

Hardware Software Codesign

Formal Specification and Verification

Concurrency and Communication: Lessons from the SHIM Project

Hardware Description Languages & System Description Languages Properties

Formal Verification by Model Checking

An Architectural Framework for Accelerating Dynamic Parallel Algorithms on Reconfigurable Hardware

Applications of Formal Verification

From synchronous models to distributed, asynchronous architectures

Fundamental Algorithms for System Modeling, Analysis, and Optimization

CS477 Formal Software Development Methods / 39

Applications of Formal Verification

15-210: Parallelism in the Real World

Concurrent ML. John Reppy January 21, University of Chicago

Concurrency Abstractions in C#

CS4411 Intro. to Operating Systems Exam 1 Fall points 10 pages

fakultät für informatik informatik 12 technische universität dortmund Specifications Peter Marwedel TU Dortmund, Informatik /11/15

ESE532: System-on-a-Chip Architecture. Today. Process. Message FIFO. Thread. Dataflow Process Model Motivation Issues Abstraction Recommended Approach

Written Presentation: JoCaml, a Language for Concurrent Distributed and Mobile Programming

Thinking parallel. Decomposition. Thinking parallel. COMP528 Ways of exploiting parallelism, or thinking parallel

Reinhard v. Hanxleden 1, Michael Mendler 2, J. Aguado 2, Björn Duderstadt 1, Insa Fuhrmann 1, Christian Motika 1, Stephen Mercer 3 and Owen Brian 3

SPIN, PETERSON AND BAKERY LOCKS

INF672 Protocol Safety and Verification. Karthik Bhargavan Xavier Rival Thomas Clausen

Spin: Overview of PROMELA

EE382N.23: Embedded System Design and Modeling

Specifications Part 1

Applications of Formal Verification

Spin: Overview of PROMELA

Concurrency Abstractions in C#

What Came First? The Ordering of Events in

Concurrency Abstractions in C#

Using and Compiling Esterel

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions

Principles of Parallel Algorithm Design: Concurrency and Mapping

Teleport Messaging for. Distributed Stream Programs

Introduction 2 The first synchronous language (early 80 s) Gérard Berry and his team (École des Mines de Paris / INRIA Sophia-Antipolis) Imperative, s

Compiling Concurrent Languages for Sequential Processors

Advanced Threads & Monitor-Style Programming 1/24

Hardware Description Languages & System Description Languages Properties

fakultät für informatik informatik 12 technische universität dortmund Data flow models Peter Marwedel TU Dortmund, Informatik /10/08

Specifications and Modeling

T Parallel and Distributed Systems (4 ECTS)

The Esterel language

Principles of Parallel Algorithm Design: Concurrency and Mapping

A Deterministic Multi-Way Rendezvous Library for Haskell

Space Profiling for Parallel Functional Programs

ESUIF: An Open Esterel Compiler

A Verification Approach for GALS Integration of Synchronous Components

PROF. TAJANA SIMUNIC ROSING. Final Exam. Problem Max. Points Points 1 25 T/F 2 10 Esterel 3 20 Petri net 4 20 SDF 5 20 EDF/RM 6 20 LS/power Total 115

Implementation of Process Networks in Java

Embedded Systems CS - ES

Lecture 4: Synchronous Data Flow Graphs - HJ94 goal: Skiing down a mountain

Synchronization: Semaphores

Operating Systems. Lecture 4 - Concurrency and Synchronization. Master of Computer Science PUF - Hồ Chí Minh 2016/2017

Specifications and Modeling

Understandable Concurrency

Performance Throughput Utilization of system resources

Concurrent Models of Computation

CS477 Formal Software Development Methods / 32

CS3733: Operating Systems

A Schedulability-Preserving Transformation Scheme from Boolean- Controlled Dataflow Networks to Petri Nets

Beyond Nested Parallelism: Tight Bounds on Work-Stealing Overheads for Parallel Futures

AdaStreams : A Type-based Programming Extension for Stream-Parallelism with Ada 2005

Copyright 2008 CS655 System Modeling and Analysis. Korea Advanced Institute of Science and Technology

Predictable multithreading of embedded applications using PRET-C

A Tutorial on Model Checker SPIN

Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus

CS Programming Languages: Scala

Programming Safe Agents in Blueprint. Alex Muscar University of Craiova

What is SPIN(Simple Promela Interpreter) Elements of Promela. Material About SPIN. Basic Variables and Types. Typical Structure of Promela Model

Haskell to Hardware and Other Dreams

Transcription:

Candidacy Exam p. 1/35 Deterministic Concurrency Candidacy Exam Nalini Vasudevan Columbia University

Motivation Candidacy Exam p. 2/35

Candidacy Exam p. 3/35 Why Parallelism? Past Vs. Future Power wall: Power vs. transistors Static vs Dynamic power Memory wall: Multiply vs. load and stores Faster sequential computer? Clock frequency [Asanovic et al., The Landscape of Parallel Computing Research, 2006]

Candidacy Exam p. 4/35 Programming Models Performance Psychological: Ease of use No. of processors Types of Parallelism P1: main() Task level Data level P2: foo() P3: bar() P1: a[0] P2: a[1] P3: a[2] [Background and Jargon of Parallel Computing, Patterns for Parallel Programming, 2004]

Programming Models Nested Data Level Parallelism function quicksort(a) = if (#a < 2) then a else let pivot = a[#a/2]; lesser = {e in a e < pivot; equal = {e in a e == pivot; greater = {e in a e > pivot; result = {quicksort(v): v in [lesser,greater]; in result[0] ++ equal ++ result[1]; quicksort([8, 14, 8, 9, 5, 9, 3, 0, 17, 19]); [Programming Parallel Algorithms, Blelloch, ACM Communications, 1996.] Candidacy Exam p. 5/35

The Data Race Problem int x = 1; bar() { x++; foo() { spawn(bar); x++; ld x add x, x, 1 st x Candidacy Exam p. 6/35

The Data Race Problem int x = 1; bar() { x++; foo() { spawn(bar); x++; int x = 1; bar() { lock(x); x++; unlock(x); foo() { spawn(bar); lock(x); x++; unlock(x); ld x add x, x, 1 st x Candidacy Exam p. 6/35

Candidacy Exam p. 7/35 High Level Data Races T1 T2 lock(m) x = x 2; y = x + 2; unlock(m) lock(m) read(x); unlock(m).. lock(m) read(y); unlock(m) [Artho et al., High Level Data Races, 2003]

Candidacy Exam p. 8/35 Non-determinism int x = 1; void bar() { lock(m); x = x 2; unlock(m); void foo() { spawn(bar); lock(m); x++; unlock(m); x =?; Output: 2, 3 or 4 x = 1 x = 1 bar: x = 1 * 2 = 2 foo: x = 2 foo: x = 3 bar: x = 2*2 = 4

Concurrent Programming Models Candidacy Exam p. 9/35

The Cilk Programming Model Each thread is non-blocking Downward edges denote spawned threads Horizontal edges denote successors Work stealing scheduler Non-deterministic: Allows access to global resources [Blumofe et al., Cilk: An Efficient Multithreaded Runtime System, 1995] Candidacy Exam p. 10/35

Candidacy Exam p. 11/35 An Example in Cilk thread sum() { cont int x, y; spawn_next add(?x,?y); spawn getx (x); spawn gety (y); thread getx (cont int x) { send argument (x, 5); sum() add() thread gety (cont int y) { send argument (y, 3); thread add(int x, int y) { printf("%d", x + y); x y x = 5 getx() y = 3 gety()

Candidacy Exam p. 12/35 The X10 Programming Language Concurrent programming model Activities are light weight threads Places represent distributed memory A1 A2 A3 A4 A5 Place p1 Place p2 [Charles et al., X10: An Object-Oriented Approach to Non-Uniform Cluster Computing, 2005]

Candidacy Exam p. 13/35 The X10 Programming Language Activities created using async async { / Body of async executed locally / async (p2) { / Body of async executed at p2 / Synchronization between activities through finish atomic clocks Improper synchronization can lead to races

Deterministic Concurrent Programming Models Candidacy Exam p. 14/35

Candidacy Exam p. 15/35 Kahn Networks void f(int in u, int in v) { int i; bool b = true; while (1) { i = if (b) then wait (u) else wait (v); print (i); b = ~b; g u f v h void g(int out u) { u = 1; while (1) { send u; void h(int out v) { v = 0; while (1) { send v; // Body of main program; f(u, v) par g(u) par h(v);

Candidacy Exam p. 16/35 Properties of Kahn Networks Wait: Waits for the sender to send data Send: Nothing prevents a process to send No two stations are allowed to send data on the same channel Behaves like FIFO queues Deterministic behavior Problem: Unbounded Buffers

Candidacy Exam p. 17/35 Synchronous Data Flow 20 10 20 10 A B C Subset of Kahn Networks Actor: fires by removing tokens from its input edges and producing tokens on its output edges Edges represent communication channels, implemented as FIFO Each actor produces and consumes a fixed number (known apriori) Model suitable for DSP applications

Candidacy Exam p. 18/35 The StreamIt Model A synchronous data flow language A structured model for streams Data Source Low Pass Filter pipeline FMRadio { add DataSource(); add LowPassFilter(); add FMDemodulator(); add Equalizer(); add Speaker(); FM Demodulator Equalizer Speaker

Candidacy Exam p. 19/35 The StreamIt Model Filter Autonomous unit of computation No access to global resources Communicates through FIFO channels: pop(), peek(index), push(value) A Split Join B A B C B Join A Split

Candidacy Exam p. 20/35 Esterel: A synchronous model Suited for reactive systems Follows the synchrony hypothesis Let t be the communication time t arbitrary asynchrony t predictable vibration t = 0 synchrony Notion of a global clock [Berry et al., The ESTEREL Synchronous Programming Language, 1992]

Candidacy Exam p. 21/35 An Example in Esterel input COIN, TEA_BUTTON, COFFEE_BUTTON; output SERVE_TEA, SERVE_COFFEE; loop await COIN; await case TEA_BUTTON do emit SERVE_TEA; case COFFEE_BUTTON do emit SERVE_COFFEE; end await; end loop;

Candidacy Exam p. 22/35 Compiling Esterel loop emit A; await C; emit B; pause end [Edwards, Tutorial: Compiling Concurrent Languages for Sequential Processors, TODAES, 2003]

Candidacy Exam p. 22/35 Compiling Esterel loop emit A; await C; emit B; pause end void tick() { static int s = 0; A = B = 0; switch (s) { case 0: A = 1; s = 1; break; case 1: if (C) { B = 1; s = 0; break; main() { for(;;) tick(); [Edwards, Tutorial: Compiling Concurrent Languages for Sequential Processors, TODAES, 2003]

Candidacy Exam p. 22/35 Compiling Esterel loop emit A; await C; emit B; pause end void tick() { static int s = 0; A = B = 0; switch (s) { case 0: A = 1; s = 1; break; case 1: if (C) { B = 1; s = 0; break; main() { for(;;) tick(); [Edwards, Tutorial: Compiling Concurrent Languages for Sequential Processors, TODAES, 2003]

The SHIM Programming Language Candidacy Exam p. 23/35

Candidacy Exam p. 24/35 The SHIM Model Stands for Software Hardware Integration Medium Race free, scheduling independent, concurrent model Blocking CSP-style rendezvous communication Recv Task 1 Task 1 Send Recv Task 2 Recv Task 3 [Edwards et al., SHIM: A Deterministic Model for Embedded Systems, 2005.]

CSP Stands for Communicating Sequential Processes Model interactions between processes Supports synchronization, concurrency etc. Rendezvous, message passing Process A send (C, message) C Process B recv (C, message) [[] Hoare, Communicating sequential processes. Commun. ACM 21, 8 (Aug. 1978), 666-677.] Candidacy Exam p. 25/35

SHIM = Kahn + CSP Candidacy Exam p. 26/35

Candidacy Exam p. 27/35 An Example in SHIM Blocking: wait for all processes connected to c void f(chan int a) { // a is a copy of c a = 3; // change local copy recv a; // receive (wait for g) // a now 5 void g(chan int &b) { // b is an alias of c b = 5; // sets c send b; // send (wait for f) // b now 5 void main() { chan int c = 0; f(c); par g(c); c = c 2; f c [Tardieu et al., Scheduling-Independent Threads and Exceptions in SHIM] g

Candidacy Exam p. 28/35 The Problem void main() { chan int a, b; { // Task 1 a = 15, b = 10; send a; send b; f a b g par { // Task 2 int c; recv b; recv a; c = a + b;

Analysis of Concurrent Programs Candidacy Exam p. 29/35

Candidacy Exam p. 30/35 Why Analyze? Data Race Detection Deadlock Detection Optimization Analysis of concurrent programs is generally harder than sequential programs [Rinard, Analysis of Multi-threaded Programs, 2001. Corbett, Evaluating Deadlock Detection Methods for Concurrent Software, 1996. ]

Candidacy Exam p. 31/35 Abstraction [Clarke et al., Model checking and Abstraction, 1994]

Candidacy Exam p. 32/35 Model Checking Abstracted Model Property to Check Model Checker Yes/Dont-know Error trace

Candidacy Exam p. 33/35 The SPIN Model Checker mtype= {NONCRITICAL, TRYING, CRITICAL; show mtype state[2]; proc type process(int id) { beginning: trying: state[id] = TRYING; if :: goto trying; :: true; fi; critical: state[id] = CRITICAL; if :: goto critical; :: true; fi; noncritical: state[id] = NONCRITICAL; if :: goto noncritical; :: true; fi; goto beginning; t c nc #define cs0 (state[0] == critical ) #define cs1 (state[1] == critical )!(cs0 && cs1) init { run process(0); run process(1);

Candidacy Exam p. 34/35 Using Petri Nets to analyze concurrent languages Reachability analysis (finding deadlocks etc.) To generate sequential code from concurrent programs void ping() { for(;;) { send a; send b; send c; void pong() { for(;;) { send d; recv b; send e; [Lin, Efficient Compilation of Process-Based Concurrent Programs without Run-Time Scheduling, DATE 1998 Peterson, Petri Nets, ACM Computing Surveys 9, 1977.]

Candidacy Exam p. 34/35 Using Petri Nets to analyze concurrent languages Reachability analysis (finding deadlocks etc.) To generate sequential code from concurrent programs void ping() { for(;;) { send a; send b; send c; void pong() { for(;;) { send d; recv b; send e; [Lin, Efficient Compilation of Process-Based Concurrent Programs without Run-Time Scheduling, DATE 1998 Peterson, Petri Nets, ACM Computing Surveys 9, 1977.]

Candidacy Exam p. 35/35 Conclusions Problems with concurrent programming languages Concurrent programs are generally harder to analyze Bugs: Data Races, Deadlocks Future Work A language that is race-free and deadlock-free An auto-determinizing compiler