Copyright © 2001 Stephen A. Edwards All rights reserved The Synchronous Language Esterel Prof. Stephen A. Edwards.

Slides:



Advertisements
Similar presentations
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Advertisements

GCSE Computing Lesson 5.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
© S. Ramesh / Kavi Arya / Krithi Ramamritham IT-606 Embedded Systems (Software) S. Ramesh Kavi Arya Krithi Ramamritham KReSIT/ IIT Bombay.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
ISBN Chapter 3 Describing Syntax and Semantics.
Introductory Comments Regarding Hardware Description Languages.
Concurrency: Mutual Exclusion and Synchronization Why we need Mutual Exclusion? Classical examples: Bank Transactions:Read Account (A); Compute A = A +
Copyright © 2001 Stephen A. Edwards All rights reserved Research Areas Stephen A. Edwards.
Esterel Overview Roberto Passerone ee249 discussion section.
Concurrency in Ada What concurrency is all about Relation to operating systems Language facilities vs library packages POSIX threads Ada concurrency Real.
Concurrency CS 510: Programming Languages David Walker.
Microprocessors Introduction to ia64 Architecture Jan 31st, 2002 General Principles.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
Chapter 16 Control Unit Implemntation. A Basic Computer Model.
Copyright © 1998 Wanda Kunkle Computer Organization 1 Chapter 2.1 Introduction.
Copyright © 2001 Stephen A. Edwards All rights reserved Esterel and Other Projects Prof. Stephen A. Edwards Columbia University, New York
1 Concurrency: Deadlock and Starvation Chapter 6.
Testing an individual module
Describing Syntax and Semantics
Principle of Functional Verification Chapter 1~3 Presenter : Fu-Ching Yang.
A Mystery Esterel –small no type inference, subtyping, … no recursion, functions, … no pointers, malloc, GC, … no complex data structures, libraries,
Copyright © 2001 Stephen A. Edwards All rights reserved ESUIF: An Open Esterel Compiler Stephen A. Edwards Department of Computer Science Columbia University,
Concurrency: Deadlock and Starvation Chapter 6. Goal and approach Deadlock and starvation Underlying principles Solutions? –Prevention –Detection –Avoidance.
1 Concurrency: Deadlock and Starvation Chapter 6.
Ch.2 Part A: Requirements, State Charts EECE **** Embedded System Design.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
ECE 720T5 Winter 2014 Cyber-Physical Systems Rodolfo Pellizzoni.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
Operating Systems Lecture 2 Processes and Threads Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
- 1 - Embedded Systems - SDL Some general properties of languages 1. Synchronous vs. asynchronous languages Description of several processes in many languages.
An introduction to Esterel and its compilation
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
“Software” Esterel Execution (work in progress) Dumitru POTOP-BUTUCARU Ecole des Mines de Paris
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
Introduction to Problem Solving. Steps in Programming A Very Simplified Picture –Problem Definition & Analysis – High Level Strategy for a solution –Arriving.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
© S. Ramesh / Kavi Arya / Krithi Ramamritham 1 IT-606 Embedded Systems (Software) S. Ramesh Kavi Arya Krithi Ramamritham KReSIT/ IIT Bombay.
Fall 2004EE 3563 Digital Systems Design EE 3563 VHSIC Hardware Description Language  Required Reading: –These Slides –VHDL Tutorial  Very High Speed.
Conformance Test Experiments for Distributed Real-Time Systems Rachel Cardell-Oliver Complex Systems Group Department of Computer Science & Software Engineering.
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.
Semantics In Text: Chapter 3.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Introduction to Operating Systems and Concurrency.
CSCI1600: Embedded and Real Time Software Lecture 33: Worst Case Execution Time Steven Reiss, Fall 2015.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Basic Elements of Processor ALU Registers Internal data pahs External data paths Control Unit.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Model Checking Lecture 1. Model checking, narrowly interpreted: Decision procedures for checking if a given Kripke structure is a model for a given formula.
Software Systems Verification and Validation Laboratory Assignment 4 Model checking Assignment date: Lab 4 Delivery date: Lab 4, 5.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Model Checking Lecture 1: Specification Tom Henzinger.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Overview: Using Hardware.
Learning to Program D is for Digital.
Esterel By: Sam Weinberg.
CSCI1600: Embedded and Real Time Software
Threads Chapter 4.
Basic Concepts of Algorithm
CSCI1600: Embedded and Real Time Software
Presentation transcript:

Copyright © 2001 Stephen A. Edwards All rights reserved The Synchronous Language Esterel Prof. Stephen A. Edwards

Copyright © 2001 Stephen A. Edwards All rights reserved A Simple Example  The specification: The output O should occur when inputs A and B have both arrived. The R input should restart this behavior.

Copyright © 2001 Stephen A. Edwards All rights reserved A First Try: An FSM  Fairly complicated: R/ AR’/ BR’/ ABR’/O BR’/O AR’/O R/

Copyright © 2001 Stephen A. Edwards All rights reserved The Esterel Version  Much simpler Ideas of signal, wait, reset part of the language module ABRO input A, B, R; output O; loop [ await A || await B ]; emit O each R end module Means the same thing as the FSM

Copyright © 2001 Stephen A. Edwards All rights reserved The Esterel Version module ABRO: input A, B, R; output O; loop [ await A || await B ]; emit O each R end module Esterel programs built from modules Each module has an interface of input and output signals

Copyright © 2001 Stephen A. Edwards All rights reserved The Esterel Version module ABRO: input A, B, R; output O; loop [ await A || await B ]; emit O each R end module loop … each statement implements the reset await waits for the next cycle in which its signal is present || operator means run the two awaits in parallel

Copyright © 2001 Stephen A. Edwards All rights reserved The Esterel Version module ABRO: input A, B, R; output O; loop [ await A || await B ]; emit O each R end module Parallel statements terminate immediately when all branches have Emit O makes signal O present when A and B have both arrived

Copyright © 2001 Stephen A. Edwards All rights reserved Basic Ideas of Esterel  Imperative, textual language  Concurrent  Based on synchronous model of time Program execution synchronized to an external clock Like synchronous digital logic Suits the cyclic executive approach  Two types of statements Those that take “zero time” (execute and terminate in same instant, e.g., emit) Those that delay for a prescribed number of cycles (e.g., await)

Copyright © 2001 Stephen A. Edwards All rights reserved Uses of Esterel  Wristwatch Canonical example Reactive, synchronous, hard real-time  Controllers Communication protocols  Avionics Fuel control system Landing gear controller Other user interface tasks  Processor components (cache controller, etc.)

Copyright © 2001 Stephen A. Edwards All rights reserved Advantages of Esterel  Model of time gives programmer precise control  Concurrency convenient for specifying control systems  Completely deterministic Guaranteed: no need for locks, semaphores, etc.  Finite-state language Easy to analyze Execution time predictable Much easier to verify formally  Amenable to implementation in both hardware and software

Copyright © 2001 Stephen A. Edwards All rights reserved Disadvantages of Esterel  Finite-state nature of the language limits flexibility No dynamic memory allocation No dynamic creation of processes  Virtually nonexistent support for handling data  Really suited for simple decision-dominated controllers  Synchronous model of time can lead to overspecification  Semantic challenges Avoiding causality violations often difficult Difficult to compile  Limited number of users, tools, etc.

Copyright © 2001 Stephen A. Edwards All rights reserved Signals  Esterel programs communicate through signals  These are like wires Each signal is either present or absent in each cycle Can’t take multiple values within a cycle  Presence/absence not held between cycles  Broadcast across the program Any process can read or write a signal

Copyright © 2001 Stephen A. Edwards All rights reserved Basic Esterel Statements  emit S Make signal S present in the current instant A signal is absent unless it is emitted  pause Stop and resume after the next cycle after the pause  present S then stmt1 else stmt1 end If signal S is present in the current instant, immediately run stmt1, otherwise run stmt2

Copyright © 2001 Stephen A. Edwards All rights reserved Basic Esterel Statements  Thus emit A; present A then emit B end; pause; emit C  Makes A & B present the first instant, C present the second ABAB C

Copyright © 2001 Stephen A. Edwards All rights reserved Signal Coherence Rules  Each signal is only present or absent in a cycle, never both  All writers run before any readers do  Thus present A else emit A end is an erroneous program

Copyright © 2001 Stephen A. Edwards All rights reserved Advantage of Synchrony  Easy to control time  Speed of actual computation nearly uncontrollable  Allows function and timing to be specified independently  Makes for deterministic concurrency Explicit control of “before” “after” “at the same time”

Copyright © 2001 Stephen A. Edwards All rights reserved Time Can Be Controlled Precisely  This guarantees every 60 th Sec a “Min” signal is emitted every 60 Sec do emit Min end  Timing diagram: Sec Min … “every” invokes its body every 60 Sec exactly emit takes no time

Copyright © 2001 Stephen A. Edwards All rights reserved The || Operator  Groups of statements separated by || run concurrently and terminate when all groups have terminated [ emit A; pause; emit B; || pause; emit C; pause; emit D ]; emit E ABCBC DEDE

Copyright © 2001 Stephen A. Edwards All rights reserved Communication Is Instantaneous  A signal emitted in a cycle is visible immediately [ pause; emit A; pause; emit A || pause; present A then emit B end ] ABAB A

Copyright © 2001 Stephen A. Edwards All rights reserved Bidirectional Communication  Processes can communicate back and forth in the same cycle [ pause; emit A; present B then emit C end; pause; emit A || pause; present A then emit B end ] ABCABC A

Copyright © 2001 Stephen A. Edwards All rights reserved Concurrency and Determinism  Signals are the only way for concurrent processes to communicate  Esterel does have variables, but they cannot be shared  Signal coherence rules ensure deterministic behavior  Language semantics clearly defines who must communicate with whom when

Copyright © 2001 Stephen A. Edwards All rights reserved The Await Statement  The await statement waits for a particular cycle  await S waits for the next cycle in which S is present [ emit A ; pause ; pause; emit A || await A; emit B ] AABAB

Copyright © 2001 Stephen A. Edwards All rights reserved The Await Statement  Await normally waits for a cycle before beginning to check  await immediate also checks the initial cycle [ emit A ; pause ; pause; emit A || await immediate A; emit B ] ABAB A

Copyright © 2001 Stephen A. Edwards All rights reserved Loops  Esterel has an infinite loop statement  Rule: loop body cannot terminate instantly Needs at least one pause, await, etc. Can’t do an infinite amount of work in a single cycle loop emit A; pause; pause; emit B end AABAB ABAB ABAB

Copyright © 2001 Stephen A. Edwards All rights reserved Loops and Synchronization  Instantaneous nature of loops plus await provide very powerful synchronization mechanisms loop await 60 Sec; emit Min end Sec Min …

Copyright © 2001 Stephen A. Edwards All rights reserved Preemption  Often want to stop doing something and start doing something else  E.g., Ctrl-C in Unix: stop the currently-running program  Esterel has many constructs for handling preemption

Copyright © 2001 Stephen A. Edwards All rights reserved The Abort Statement  Basic preemption mechanism  General form: abort statement when condition  Runs statement to completion. If condition ever holds, abort terminates immediately.

Copyright © 2001 Stephen A. Edwards All rights reserved The Abort Statement abort pause; emit A when B; emit C ACAC BCBC B ACAC BCBC Normal termination Aborted termination. Execution of emit A preempted. Aborted termination. Normal termination. B not checked in first cycle (like await)

Copyright © 2001 Stephen A. Edwards All rights reserved Strong vs. Weak Preemption  Strong preemption: The body does not run when the preemption condition holds The previous example illustrated strong preemption  Weak preemption: The body is allowed to run even when the preemption condition holds, but is terminated thereafter “weak abort” implements this in Esterel

Copyright © 2001 Stephen A. Edwards All rights reserved Strong vs. Weak Abort abort pause; emit A; pause when B; emit C BCBC weak abort pause; emit A; pause when B; emit C ABCABC Strong abort: emit A not allowed to run Weak abort: emit A allowed to run, body terminated afterwards

Copyright © 2001 Stephen A. Edwards All rights reserved Strong vs. Weak Preemption  Important distinction  Something cannot cause its own strong preemption abort emit A when A  Erroneous: if body runs then it could not have

Copyright © 2001 Stephen A. Edwards All rights reserved The Trap Statement  Esterel provides an exception facility for weak preemption  Interacts nicely with concurrency  Rule: outermost trap takes precedence

Copyright © 2001 Stephen A. Edwards All rights reserved The Trap Statement trap T in [ pause; emit A; pause; exit T || await B; emit C ] end trap; emit D D ABCABC Normal termination from first process Emit C also runs BCDBCD Second process allowed to run even though first process has exited A A D

Copyright © 2001 Stephen A. Edwards All rights reserved Nested Traps trap T1 in trap T2 in [ exit T1 || exit T2 ] end; emit A end; emit B Outer trap takes precedence: control transferred directly to outer trap statement. emit A not allowed to run B

Copyright © 2001 Stephen A. Edwards All rights reserved The Suspend Statement  Preemption (abort, trap) terminate something, but what if you want to pause it?  Like the unix Ctrl-Z  Esterel’s suspend statement pauses the execution of a group of statements  Strong preemption: statement does not run when condition holds

Copyright © 2001 Stephen A. Edwards All rights reserved The Suspend Statement suspend loop emit A; pause; pause end when B A B delays emission of A by one cycle ABABA B prevents A from being emitted; resumed the next cycle

Copyright © 2001 Stephen A. Edwards All rights reserved Causality  Unfortunate side-effect of instantaneous communication coupled with the single valued signal rule  Easy to write contradictory programs, e.g.,  present A else emit A end  abort emit A when A  present A then nothing end; emit A  These sorts of programs are erroneous and flagged by the Esterel compiler as incorrect

Copyright © 2001 Stephen A. Edwards All rights reserved Causality  Can be very complicated because of instantaneous communication  For example: this is also erroneous abort emit B when A || [ present B then emit A end; pause ] Emission of B indirectly causes emission of A

Copyright © 2001 Stephen A. Edwards All rights reserved Causality  Definition has evolved since first version of the language  Original compiler had concept of “potentials” Static concept: at a particular program point, which signals could be emitted along any path from that point  Latest definition based on “constructive causality” Dynamic concept: whether there’s a “guess-free proof” that concludes a signal is absent

Copyright © 2001 Stephen A. Edwards All rights reserved Causality Example  Consider the following program emit A; present B then emit C end; present A else emit B end;  Considered erroneous under the original compiler  After emit A runs, there’s a static path to emit B  Therefore, the value of B cannot be decided yet  Execution procedure deadlocks: program is bad

Copyright © 2001 Stephen A. Edwards All rights reserved Causality Example emit A; present B then emit C end; present A else emit B end;  Considered acceptable to the latest compiler  After emit A runs, it is clear that B cannot be emitted because A’s presence runs the “then” branch of the second present  B declared absent, both present statements run

Copyright © 2001 Stephen A. Edwards All rights reserved Compiling Esterel  Semantics of the language are formally defined and deterministic  It is the responsibility of the compiler to ensure the generated executable behaves correctly w.r.t. the semantics  Challenging for Esterel

Copyright © 2001 Stephen A. Edwards All rights reserved Compilation Challenges  Concurrency  Interaction between exceptions and concurrency  Preemption  Resumption (pause, await, etc.)  Checking causality  Reincarnation Loop restriction generally prevents any statement from executing more than once in a cycle Complex interaction between concurrency, traps, and loops can make certain statements execute more than once

Copyright © 2001 Stephen A. Edwards All rights reserved Automata-Based Compilation  First key insight: Esterel is a finite-state language  Each state is a set of program counter values where the program has paused between cycles  Signals are not part of these states because they do not hold their values between cycles  Esterel has variables, but these are not considered part of the state

Copyright © 2001 Stephen A. Edwards All rights reserved Automata-based Compilation  First compiler simulated an Esterel program in every possible state and generated code for each one  For example

Copyright © 2001 Stephen A. Edwards All rights reserved Automata Example emit A; emit B; await C; emit D; present E then emit B end; switch (state) { case 0: A = 1; B= 1; state = 1; break; case 1: if (C) { D = 1; if (E) { B = 1; } state = 3; } else { state = 1; } } First state: A, B, emitted, go to second Second state: if C is present, emit D, check E & emit F & go on, otherwise, stay in second state

Copyright © 2001 Stephen A. Edwards All rights reserved Automata Compilation Considered  Very fast code  Internal signaling can be compiled away  Can generate a lot of code because  Concurrency can cause exponential state growth  n-state machine interacting with another n-state machine can produce n 2 states  Language provides input constraints for reducing state count “these inputs are mutually exclusive,” “if this input arrives, this one does, too”

Copyright © 2001 Stephen A. Edwards All rights reserved Automata Compilation  Not practical for large programs  Theoretically interesting, but don’t work for most programs longer than 1000 lines  All other techniques produce slower code

Copyright © 2001 Stephen A. Edwards All rights reserved Netlist-Based Compilation  Second key insight: Esterel programs can be translated into Boolean logic circuits  Netlist-based compiler:  Translate each statement into a small number of logic gates A straightforward, mechanical process  Generate code that simulates the netlist

Copyright © 2001 Stephen A. Edwards All rights reserved Netlist Example emit A; emit B; await C; emit D; present E then emit B end; A B C D E

Copyright © 2001 Stephen A. Edwards All rights reserved Netlist Compilation Considered  Scales very well Netlist generation roughly linear in program size Generated code roughly linear in program size  Good framework for analyzing causality Semantics of netlists straightforward Constructive reasoning equivalent to three-valued simulation  Terribly inefficient code Lots of time wasted computing ultimately irrelevant results Can be hundreds of time slower than automata Little use of conditionals

Copyright © 2001 Stephen A. Edwards All rights reserved Netlist Compilation  Currently the only solution for large programs that appear to have causality problems  Scalability attractive for industrial users  Currently the most widely-used technique

Copyright © 2001 Stephen A. Edwards All rights reserved Control-Flow Graph-Based  Key insight: Esterel looks like a imperative language, so treat it as such  Esterel has a fairly natural translation into a concurrent control-flow graph  Trick is simulating the concurrency  Concurrent instructions in most Esterel programs can be scheduled statically  Use this schedule to build code with explicit context switches in it

Copyright © 2001 Stephen A. Edwards All rights reserved Control-flow Approach Considered  Scales as well as the netlist compiler, but produces much faster code, almost as fast as automata  Not an easy framework for checking causality  Static scheduling requirement more restrictive than netlist compiler This compiler rejects some programs the others accept  Only implementation hiding within Synopsys’ CoCentric System Studio. Will probably never be used industrially.  See my recent IEEE Transactions on Computer-Aided Design paper for details

Copyright © 2001 Stephen A. Edwards All rights reserved What To Understand About Esterel  Synchronous model of time Time divided into sequence of discrete instants Instructions either run and terminate in the same instant or explicitly in later instants  Idea of signals and broadcast “Variables” that take exactly one value each instant and don’t persist Coherence rule: all writers run before any readers  Causality Issues Contradictory programs How Esterel decides whether a program is correct

Copyright © 2001 Stephen A. Edwards All rights reserved What To Understand About Esterel  Compilation techniques Automata  Fast code  Doesn’t scale Netlists  Scales well  Slow code  Good for causality Control-flow  Scales well  Fast code  Bad at causality  Compilers, documentation, etc. available from