A Deterministic Concurrent Language for Embedded Systems

Similar documents
A Deterministic Concurrent Language for Embedded Systems

A Deterministic Concurrent Language for Embedded Systems

Efficient, Deterministic, and Deadlock-free Concurrency

Dealing with Concurrency Problems

Deterministic Concurrency

Arrays in SHIM: A Proposal

Concurrency and Communication: Lessons from the SHIM Project

SHIM: A Language for Hardware/Software Integration

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

ESUIF: An Open Esterel Compiler

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

CSCE 314 Programming Languages. Type System

Concurrency Abstractions in C#

Embedded Systems 8. Identifying, modeling and documenting how data moves around an information system. Dataflow modeling examines

Concurrent Models of Computation

Introduction to Model Checking

Last Time. Introduction to Design Languages. Syntax, Semantics, and Model. This Time. Syntax. Computational Model. Introduction to the class

Ordering Within Expressions. Control Flow. Side-effects. Side-effects. Order of Evaluation. Misbehaving Floating-Point Numbers.

Control Flow COMS W4115. Prof. Stephen A. Edwards Fall 2006 Columbia University Department of Computer Science

Concurrency COMS W4115. Prof. Stephen A. Edwards Spring 2002 Columbia University Department of Computer Science

Implementing Coroutines. Faking Coroutines in Java

EE382N.23: Embedded System Design and Modeling

Safe Reactive Programming: the FunLoft Proposal

Embedded System Design and Modeling EE382V, Fall 2008

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

Lecture 3 SPIN and Promela

Informatica 3. Marcello Restelli. Laurea in Ingegneria Informatica Politecnico di Milano 9/15/07 10/29/07

Chapter 5 Concurrency: Mutual Exclusion. and. Synchronization. Operating Systems: Internals. and. Design Principles

Dynamic Types, Concurrency, Type and effect system Section and Practice Problems Apr 24 27, 2018

Haskell to Hardware and Other Dreams

Concurrency Abstractions in C#

The Esterel language

Relation Overriding. Syntax and Semantics. Simple Semantic Domains. Operational Semantics

Chapter 7 Control I Expressions and Statements

The S-Expression Design Language (SEDL) James C. Corbett. September 1, Introduction. 2 Origins of SEDL 2. 3 The Language SEDL 2.

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

From synchronous models to distributed, asynchronous architectures

Programming Kotlin. Familiarize yourself with all of Kotlin s features with this in-depth guide. Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI

Tom Ball Sebastian Burckhardt Madan Musuvathi Microsoft Research

Ch 9: Control flow. Sequencers. Jumps. Jumps

SHIM: A Deterministic Approach to Programming with Threads

CSE 307: Principles of Programming Languages

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

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

Language Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science

Concurrency. Lecture 14: Concurrency & exceptions. Why concurrent subprograms? Processes and threads. Design Issues for Concurrency.

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

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

Overview of Dataflow Languages. Waheed Ahmad

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Chapter 3 Processes. Process Concept. Process Concept. Process Concept (Cont.) Process Concept (Cont.) Process Concept (Cont.)

Advanced MEIC. (Lesson #18)

Threads and Continuations COS 320, David Walker

Pace University. Fundamental Concepts of CS121 1

CS3733: Operating Systems

Concurrency Abstractions in C#

Using and Compiling Esterel

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

Dept. of CSE, York Univ. 1

CS 314 Principles of Programming Languages

Control Flow. Stephen A. Edwards. Fall Columbia University

Structuring the Computation. Structuring the Computation

The Java Memory Model

The Esterel Language. The Esterel Version. Basic Ideas of Esterel

Chapter 5 Concurrency: Mutual Exclusion and Synchronization

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

Lexical Considerations

Partial Evaluation for Code Generation from Domain-Specific Languages. Jia Zeng

Specifications Part 1

What are Embedded Systems?

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

CMSC 330: Organization of Programming Languages

Languages for Embedded System Design

1 Lexical Considerations

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

ECL: A SPECIFICATION ENVIRONMENT FOR SYSTEM-LEVEL DESIGN

Lecture 16: Static Semantics Overview 1

A Transactional Model and Platform for Designing and Implementing Reactive Systems

Concurrent Programming

CHAPTER 6: PROCESS SYNCHRONIZATION

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

Programming Languages

Modular code generation from synchronous models:

Semaphores. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

05-concurrency.txt Tue Sep 11 10:05: , Fall 2012, Class 05, Sept. 11, 2012 Randal E. Bryant

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

Concurrent Models of Computation

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

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

Chapter 3: Process Concept

Chapter 3: Process Concept

Compiling Parallel Algorithms to Memory Systems

EE249 Discussion Petri Nets: Properties, Analysis and Applications - T. Murata. Chang-Ching Wu 10/9/2007

Predictable Programming on a Precision Timed Architecture

Process Coordination

Shared Channels etc.

High Performance Computing. University questions with solution

Chapter 3: Process Concept

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

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Transcription:

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 1/28 A Deterministic Concurrent Language for Embedded Systems Stephen A. Edwards Columbia University Joint work with Olivier Tardieu

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 2/28 Definition shim \ shim\ n 1 : a thin often tapered piece of material (as wood, metal, or stone) used to fill in space between things (as for support, leveling, or adjustment of fit). 2 : Software/Hardware Integration Medium, a model for describing hardware/software systems

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 3/28 Robby Roto (Bally/Midway 1981)

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 4/28 Robby Roto Block Diagram Z80 Bus Bridge ROM 40K SRAM 6K NV SRAM 2K blitter Custom Address Custom Data Sound I/O Sound I/O Video DRAM 16K Switches Audio Left Audio Right

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 5/28 HW/SW Interaction Software Blitter Memory Video Interrupt Blit Blit Pixels Pixels Line Line Line Blit Pixels Interrupt Line Line

SHIM Wishlist Concurrent Hardware always concurrent Mixes synchronous and asynchronous styles Need multi-rate for hardware/software systems Only requires bounded resources Hardware resources fundamentally bounded Formal semantics Do not want arguments about what something means Scheduling-independent Want the functionality of a program to be definitive Always want simulated behavior to reflect reality Verify functionality and performance separately SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 6/28

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 7/28 The SHIM Model Sequential processes Unbuffered one-to-many communication channels exchange data tokens Dynamic topology with an easily-defined static subset Asynchronous Synchronous communication events Delay-insensitive: sequence of data through any channel independent of scheduling policy (the Kahn principle) Kahn networks with rendezvous communication

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 8/28 Basic SHIM An imperative language with familiar C/Java-like syntax int32 gcd(int32 a, int32 b) { while (a!= b) { if (a > b) a = b; else b = a; return a; struct foo { int x; bool y; uint15 z; ; // Composite types // Explicit-width integers int< 3,5> w; // Explicit-range integers int8 p[10]; // Arrays bar q; // Recursive types

Three Additional Constructs stmt 1 par stmt 2 Run stmt 1 and stmt 2 concurrently send var recv var next var Communicate on channel var try.. throw exc catch( exc ) stmt Define the scope of an exception Raise an exception SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 9/28

Concurrency & par Par statements run concurrently and asynchronously Terminate when all terminate Each thread gets private copies of variables; no sharing Writing thread sets the variable s final value void main() { int a = 3, b = 7, c = 1; { a = a + c; // a 4, b = 7, c = 1 a = a + b; // a 11, b = 7, c = 1 par { b = b c; // a = 3, b 6, c = 1 b = b + a; // a = 3, b 9, c = 1 // a 11, b 9, c = 1 SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 10/28

Restrictions Both pass-by-reference and pass-by-value arguments Simple syntactic rules avoid races void f(int &x) { x = 1; // x passed by reference void g(int x) { x = 2; // x passed by value void main() { int a = 0, b = 0; a = 1; par b = a; // OK: a and b modified separately a = 1; par a = 2; // Error: a modified by both f(a); par f(b); // OK: a and b modified separately f(a); par g(a); // OK: a modified by f only g(a); par g(a); // OK: a not modified f(a); par f(a); // Error: a passed by reference twice SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 11/28

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 12/28 Communication Blocking: thread waits for all processes that know about a 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 next b = 5; // sets c and send (wait for f) // b now 5 void main() { chan int c = 0; f(c); par g(c);

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 13/28 Synchronization, Deadlocks Blocking communication makes for potential deadlock { next a; next b; par { next b; next a; // deadlocks Only threads responsible for a variable must synchronize { next a; next b; par next b; par next a; // OK When a thread terminates, it is no longer responsible { next a; next a; par next a; // OK Philosophy: deadlocks easy to detect; races are too subtle SHIM prefers deadlocks to races (always reproducible)

An Example void main() { chan uint8 A, B, C; { // source: generate four values next A = 17; next A = 42; next A = 157; next A = 8; par { // buf1: copy from input to output for (;;) next B = next A; par { // buf2: copy, add 1 alternately for (;;) { next C = next B; next C = next B + 1; par { // sink for (;;) recv C; source buf1 buf2 sink A B C SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 14/28

Message Sequence Chart sender c=0 c=1 receiver d=1 c=1 c=0 d=2 c=1 c=2 c=1 c=1 c=0 d=3 c=1 c=3 c=1 c=2 c=1 c=1 c=0 d=4 sink int a, b; chan int c, d; { d = 0; for (;;) { e = d; while (e > 0) { next c = 1; next c = e; e = e 1; next c = 0; next d = d + 1; par { a = b = 0; for (;;) { do { if (next c!= 0) a = a + next c; while (c); b = b + 1; par { for (;;) recv d; SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 15/28

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 16/28 Recursion & Concurrency A bounded FIFO: compiler will analyze & expand void buffer1(chan int in, chan int &out) { for (;;) next out = next in; fifo(3,i,o) void fifo(int n, chan int in, chan int &out) { if (n == 1) buffer1(in, out); else { chan int channel; buffer1(in, channel); par fifo(n 1, channel, out); buffer1(i,c) fifo(2,c,o) buffer1(i,c) fifo(1,c,o) buffer1(i,o)

Robby Roto in SHIM start-of-frame Pixel Clock Software more command pixel Blitter buffer frame Video out buffer pixels sync while (player is alive) next start-of-frame;...game logic... next more = true; next command =...;...game logic... next more = false; for (;;) while (next more) next command; Write to buffer next frame = buffer; for (;;) next start-of-frame; for each line next sync =...; for each pixel next clock Read pixel next pixel =...; buffer = next frame; SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 17/28

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 18/28 Exceptions Sequential semantics are classical void main() { int i = 1; try { throw T; i = i * 2; catch (T) { i = i * 3; // Not executed // Executed by throw T // i = 3 on exit

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 19/28 Exceptions & Concurrency void main() { chan int i = 0, j = 0; try { while (i < 5) next i = i + 1; throw T; par { for (;;) { next j = next i + 1; par { for (;;) recv j; catch (T) { Exceptions propagate through communication actions to preserve determinism Idea: transitive poisoning Raising an exception poisons a process Any process attempting to communicate with a poisoned process is itself poisoned (within exception scope) Best effort preemption

Generating Software from SHIM SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 20/28

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 21/28 Static Scheduling source buf1 buf2 sink A B C Build an automaton through abstract simulation State signature: Running/blocked status of each process Blocked on reading/writing status of each channel Trick: does not include control or data state of each process

Abstract Simulation { // buf1 1for (;;) 2next B = 3next A; par { // buf2 4for (;;) { 5next C = 6next B; 7next C = 8next B + 1; buf1 ready buf2 blocked buf1 PCs buf2 PCs {1, 2 {3 A clear C waiting for writer buf1 send C {2 {5, 7 receive A {3 {5, 7 {1 {4 buf2 {1 {6 buf1 {3 {6, 8 receive A {3 {6, 8 buf1 {2 {5, 6, 7, 8 buf2 {2 {5, 7 buf1 send C {3 {5, 7 buf2 {3 {5, 7 SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 22/28

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 23/28 Benchmarks Example Lines Processes Berkeley 36 3 Buffer2 25 4 Buffer3 26 5 Buffer10 33 12 Esterel1 144 5 Esterel2 127 5 FIR5 78 19 FIR19 190 75

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 24/28 Executable Sizes Example Switch Tail- Static (partial) Static (full) Recursive size states size states Berkeley 860 1299 1033 5 551 6 Buffer2 832 1345 1407 10 403 8 Buffer3 996 1579 1771 20 443 10 Buffer10 2128 3249 5823 174 687 24 Esterel1 3640 5971 8371 49 5611 56 Esterel2 4620 7303 6871 24 2539 18 FIR5 4420 6863 6819 229 1663 79 FIR19 17052 25967 67823 2819 7287 372

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 25/28 Speedups vs. Switch Example Tail-Recursive Static (partial) Static (full) Berkeley 2.9 2.6 7.8 Buffer2 2.0 2.4 11 Buffer3 2.1 2.6 10 Buffer10 1.7 4.8 12 Esterel1 1.9 2.9 5.9 Esterel2 2.0 2.5 5.2 FIR5 0.92 4.8 7 FIR19 0.90 5.9 7.1

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 26/28 Conclusions The SHIM Model: Sequential processes communicating through rendezvous Sequential language plus concurrency, communication, and exceptions. Scheduling-independent Kahn networks with rendezvous Nondeterministic scheduler produces deterministic behavior

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 27/28 Future Work Automata abstract communication patterns Useful for deadlock detection, protocol violation

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 27/28 Future Work Automata abstract communication patterns Useful for deadlock detection, protocol violation Synthesis for multicore processors Compile together the processes on each core

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 27/28 Future Work Automata abstract communication patterns Useful for deadlock detection, protocol violation Synthesis for multicore processors Compile together the processes on each core Hardware/software cosynthesis Bounded subset has reasonable hardware semantics

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 27/28 Future Work Automata abstract communication patterns Useful for deadlock detection, protocol violation Synthesis for multicore processors Compile together the processes on each core Hardware/software cosynthesis Bounded subset has reasonable hardware semantics Richer data structures Shared arrays, Trees, etc.

SHIM:A A Deterministic Concurrent Language for Embedded Systems p. 27/28 Future Work Automata abstract communication patterns Useful for deadlock detection, protocol violation Synthesis for multicore processors Compile together the processes on each core Hardware/software cosynthesis Bounded subset has reasonable hardware semantics Richer data structures Shared arrays, Trees, etc. Convince world: scheduling-independent concurrency is good