Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

88
Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories

Transcript of Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Page 1: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Synchronous Languagesand System Design with Esterel

Ellen Sentovich

Cadence Berkeley Laboratories

Page 2: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Outline

• Context : Reactive Systems• Principles : Synchronous languages• Esterel in-depth

– Language, Compilation– Causality– Optimization and Verification

• New applications: ECL• Implementing Esterel on CFSM networks

Page 3: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

System Design• Systems produce a steady sequence of input/output

sequences• Inconvenient to specify sequences; need models and

languages• Model

– Simple and intuitive– Accurate enough model of physical reality

– Mathematically efficient– General enough to allow different implementation styles

• Language– Accurate expression of the model– Convenient and efficient expression of the design

• Analysis• Implementation

– compilation to hardware, software

Page 4: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Reactive Systems

control

data

signals

sensors

signals

values

EsterelStatechartsArgosEsterelStudio

LustreSCADESignal

Page 5: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Applications• Software and hardware controllers

– process control, embedded systems,data-path control

• Communication Protocols– software protocols,bus interfaces,cache

coherence

• Drivers– man-machine interface,systems

drivers,pipeline logic

Concurrency + Determinism

Page 6: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Reactive System Characteristics

• Reactivity– continually react at a speed determined by the

environment

• Concurrency– at least between system and environment

• Strict time and reliability requirements• Deterministic• Mixed hardware/software implementations

Page 7: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Synchronous SystemsCycle based read inputs compute reaction produce outputs

Synchronous within the same cycle at the same time (0-delay)

(must be checked on implementation)

Synchronous control propagation signal broadcastingEquivalent FSM implementation

(good analysis techniques)

Page 8: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Synchronous Languages

• Invented for the design of reactive kernels– not the interactive interface or data management

• Programmer views system as an instantaneous reactor to events

• Program behavior is completely deterministic• Attempt to resolve concurrency and non-

determinism (in other models)

Page 9: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Esterel: Background• Esterel is one of a set of synchronous

languages developed in France:– Esterel: reactive control– Lustre, Signal: data flow– Argos, SyncCharts: graphical

• Esterel development goal: natural expression of control– Specific statements to deal with time, preemption– Departure from concurrency as interleaving and rendez-vous

to concurrency as instantaneous propagation of control

Page 10: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Esterel: Background• Synchronous programming environment...

– Language:• For control-dominated, reactive systems• Constructs for sequencing, concurrency, preemption

– Compiler:• Produces sorted Boolean equations• Causality checking, symbolic debugging, verification• Implementation as C-code or digital circuits

Page 11: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Esterel: Basic Principles• Synchronous hypothesis : instantaneous

communication• Communication via broadcast signals (event)

– signals, sensors, variables– pure, valued– Boolean and arithmetic operators

• Modularity : program = collection of modules• Concise programs : write things once !!• Concurrency, sequencing, preemption• Well-defined semantics

Page 12: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Overview of Syntax• Signal reading/writing

emit S emit S(value) present S then p else q

• Basic control and looping:

halt loop p end run module• Sequencing, concurrency

p ; q p || q• Preemption

suspend p when S abort p when Sweak abort when S abort when immediate S

Page 13: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Syntax : await statement• Most basic signal control statement

await S

• Equivalent toabortloop

haltend

when S

• Note: “Await” always stops– consider await S; await S– versus await immediate S; await immediate S

Page 14: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Variables and Ordering

• Variable manipulation (local)V := value if V=value then p else q

• Variable computations : orderedV := 5;V := V+1;Y := V;emit S(V)

• Signal emissions (communication) : unorderedLegal: emit S; emit SIllegal: emit S(3); emit S(5) (non-deterministic)

• Signal computations : orderedWell-defined: emit S; present SUndefined: present S then emit S

Page 15: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

The ABRO Example

• “Wait until both A and B have occurred, then output O, unless the reset R occurs”

A B

B/0 A/O

AB/O

R

R

R

Number of states is exponential in inputs

Page 16: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

The ABRO Example in Esterel

• Wait until both A and B concurrency

• Unless R preemption

[await A || await B] ;

emit O

abort

when R

loop

end

Write things ONCE !!

Code size is linear in inputs; efficient circuit

Page 17: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Compilation• Esterel program extended finite state machine

– finite # inputs, deterministic reaction finite program– FSM + data computations

• Can be compiled to a single automata - EXPENSIVE!!– exhaustive exploration of set of control states– Esterel v3

• Can be translated to sorted Boolean equations– Esterel v5

• State machine is represented implicitly

Page 18: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Translation to Boolean Circuits

• Structural translation• Network of interconnected cells• Implementation of control:

– control signal runs through the circuit– boot signal : latch, initially 1, thereafter 0

• Each cell contains– signal input/output; control input/output– suspend, kill, resume signals– return codes (nested preemption)

• One register per halting statement

Page 19: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Translation to Boolean Circuits

•present S then p else q

S

control

control for q

control for p

control

Page 20: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Causality

• Cycles occur naturally in Esterel specifications– Cyclic dependency between variables– Some are harmful, some not

• The Causality Problem is analyzing these cycles and deciding which to accept– It is related to analyzing hardware in circuits– Combinational cycles

• How do we define a causally correct program?– We want a unique, comprehensible solution– All present signals must be emitted somewhere– A solution is a set of consistent assignments to all signals– Need to be able to express program in a non-cyclic way

Constructive causality

Page 21: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Harmful Cycles

No Boolean solution (non-reactive),or several solutions (non-deterministic)

Electrically unstable

Useless !

Page 22: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

X = XX

X = not XX

present X then emit X end

present X else emit X end

Page 23: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Harmless Cycles

Unique Boolean solutionElectrical stabilization in bounded time

=> behaves as if acyclic

Natural in Esterel programmingNatural in high-level hardware synthesisPossible exponential saving in space!

Page 24: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

present I then present X then emit Y endelse present Y then emit X endend

Y

X

I

Page 25: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

X

Y

I

J

X = I and not YY = J and not X

OK unless I = J = 1

Page 26: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

1

0

X

Y

The non-constructive state (1,1) is unreachable => reachability analysis needed

Combinational Cycles in Sequential Circuits

Page 27: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Y = if C then G(F(X)) else F(G(X))

F

G

01

10

10

C

C

C

X Y

Naturally occurring harmless cycles:Operator sharing (S. Malik)

Page 28: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Causality: A Real Example• Bus arbitration

TokenOut GrantOut

TokenIn GrantInReqIn AckOutCell 1

TokenOut GrantOut

TokenIn GrantInReqIn AckOut

Cell n

TokenOut

AckOut

T

ReqIn

GrantOut

GrantInTokenIn

GrantOut

GrantIn

Page 29: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Strange Cycles

Unique Boolean solution

But electrically unstable !

=> Electricity = Boolean calculus/

Page 30: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

X

Y

X = XY = X and not Y

X = 0X = 1 ?

Want to build a theory with stable solutions.Also cheaper for compiler

(interpretation possible)

Page 31: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

present ToBe then emit ToBe else emit ToBeend

ToBe

Hamlet : ToBe = ToBe or not ToBe

Page 32: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Constructive Causality in Esterel

Step through programAnalyze what must be done (emit) what cannot be done (no possible emit) what can be done

Set a signal present iff it must be emittedSet a signal absent iff it cannot be emitted

Constructive causality permits interpretation

Page 33: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Executing Constructive Causality

module P1:input I;output O;signal S1, S2 in

present I then emit S1 end||

present S1 else emit S2 end||

present S2 then emit O endend signalend module

Page 34: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Circuits are Boolean proof builders

Trace values from inputs to outputs, neverguessing a value

Analysis equivalent to electron flow in a circuitA causal program is equivalent to an electrically

stable circuit, acyclic circuit

0

00 0

0

Analogy: constructive circuits

Page 35: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Derive facts from facts

E=0E and F = 0

F=0E and F = 0

E=1 F=1E and F = 1

E=0not E = 1

E=1not E = 0

X=E E=bX=b

Constructive Boolean Logic

Cannot determine E or not E unless E is known!

Page 36: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

X = I and not YY = J and not X

(1) I=0(2) J=1(3) X=0 from (1)(4) not X=1 from (3)(5) Y=1 from (2) and (4)

(1) I=1(2) J=0(3) Y=0 from (2)(4) not Y=1 from (3)(5) X=1 from (2) and (4)

No proof of X and Y if I=J=1

Page 37: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Semantic model : Scott’s 3-valued logic

B = { , 0, 1}

View circuit as fixpoint equation

X = F(X, I)

X=b holds in fixpoint iff provable

TT

Page 38: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Main Theorem (Shiple Berry from Brzozowski - Seger)

Given a circuit and an input :

X=b provable in CBL (proving facts)<=> X=b in the fixpoint (Scott’s view)<=> X stabilizes to b for any delay assignment (circuit view)

Compositionality

Page 39: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Algorithms (Esterel v5)Interpretation

Input-dependent analysislinear time

Compilation (Shiple = Malik + Bourdoncle)Input-independent fixpoint analysis:

Combinational loops are brokenthree-valued simulation performed (BDDs)reachable state computation (BDDs)

Check that all feedback wires are well-defined

Expensive! Interpretation option in Esterel==> equivalent acyclic version

Page 40: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

X = I and not YY = J and not X

I=0 . J=1 X : 2 Y : 2

J=1 . X=0 X : 1 Y : 2

X=0 X : 1 Y : 1

X : 1 Y : 0

Y=1 X : 1 Y : 0

X : 0 Y : 0

unknownsfacts

Interpretation Example

Page 41: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

X = I and not YY = J and not X

I=1 . J=1 X : 2 Y : 2

J=1 X : 1 Y : 2

X : 1 Y : 1

Deadlock = proof search stops

Page 42: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

X = I and not YY = J and not X

X = I and YX = I or YY = J and XY = J or X

X set of inputs that set X to 1 X set of inputs that set X to 0

The circuit is constructive for all inputs such that X or X = 1 for all X

Dual-Rail Encoding to Implement Constructive Analysis

X {

3-valued: 01 = 0, 10 = 1, 00 = unknown

Page 43: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

((I and J) or I) and ((J and I) or J))

X = I and YX = I or YY = J and XY = J or X

I = I I = not I

for I input {

not(I and J)

X = 0X = IY = 0Y = J

X = I and JX = IY = J and IY = J

Fixpoint iteration

X = 0X = 0Y = 0Y = 0

Need XX = 0, YY = 0; X + X = 1, Y + Y = 1

Page 44: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Causality Summary

Constructive Boolean logic characterizes delay-independent digital circuits

Solves the causality problem for Esterel Strong user request! Compositional semantics

Good implementation and decision algorithms

Page 45: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

• Xes

Graphical Symbolic Debugging

Page 46: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Optimization• Standard logic synthesis techniques can be applied

to generated hardware• Finite state machine optimization and analysis• Esterel state encoding:

– locally group-hot– efficient implementation– far more latches than the minimum

• Latch minimization algorithms– exploit the latch/logic tradeoff– progressively more powerful algorithms

Page 47: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Latch Optimization• Replacement of latches with logic

– compute the reachable state set– compute sets of latches that can be

replaced• single latch removal : Rl Rl’= 0

• 2-for-1 removal : Rij Ri’j’ + Ri’j Rij’ = 0

Reachable statesKarnaugh map

L

L1 … Ln-1

0

1

1

1

1

1

Page 48: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Latch Optimization• Generate decoding logic

–single-latch: remove latch–2-for-1: remove two latches, add logic for

one

• Generate encoding logic–single-latch: E = Rl (dependent on other

latches)

EL’D

LCircuit

In Out

Page 49: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Latch Optimization : Exclusive Sets

• Mutually exclusive latch activityawait s1 || await s2 || await s3;await s4 || await s5 || await s6

• Latch corresponds to each wait• (s1, s2, s3) # (s4, s5, s6)• Replace 6 latches with 3 plus a

multiplexing latch

Page 50: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Latch Optimization : Results

• Esterel encoding maintains the structure of the initial program

• single latch removal is always beneficial• More sophisticated algorithms exploit latch/logic

tradeoff• Cost functions depend on circuit size, BDD size• Typically 2-for-1 is performed until logic becomes

prohibitively expensive• Verification times are improved

Page 51: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Verification

• Simulation and debugging• Synchronous observers

– specify an Esterel module to monitor the system and report errors

– specify an Esterel module to model the environment– perform symbolic reachability analysis

• Temporal logic formulas translated to Esterel modules– TempEst work at U Texas

Page 52: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

The Esterel ToolsetLanguage + formal semanticsCompiler to hardware or software (Esterel v5) Automata (explicit FSM) Boolean circuits (implicit FSM) Proved correct w.r.t. the semanticsGraphical simulators / debuggers (xes)Verifier for safety properties Xeve, TempEstEsterelStudio : commercial product, including

graphical input, test generation

Page 53: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

ECL Project

• ECL for system design– Done at Cadence Berkeley Laboratories– Many industrial partners– Used in one commercial product

• Language & Compilation

• Status

Page 54: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

ECL Summary : Language• ECL = Esterel + C

– ANSI-C plus constructs for reactivity• signal communication: await(sig); emit(sig, value);• pre-emption: abort stmt when sig_exp• concurrency: par stmt; par stmt

– C : standard in embedded software, minimal learning curve, many good compilers, reactivity missing

– Esterel : high-level reactive control, rigorous mathematical semantics (FSM), strong analysis and optimization tools, limited support for data, non-reactive loops

Page 55: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

ECL Key Features• Language support for control and data

• Esterel + FSM synthesis technology for– Efficiency : implicit state FSMs– Robust analysis and optimization– Verification– Implementation HW and/or SW

Page 56: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Example : simple C

for (i = 0; i < SIZE; i++) { buf [ i ] = In [ i ];}create_frame_from_buffer(&f, buf);

Page 57: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Example : add reactivity / concurrency

for (i = 0; i < SIZE; i++) { buf [ i ] = IN ;}create_frame_from_buffer(&f, buf);

await ( IN );

emit (frame, f);

while (1) { /* check CRC */ await (frame); for (i = 0; i < HSIZE; i++) crc ^= frame.hdr[i] if (crc != frame.crc) emit (bad_crc);}

while (1) { /* get bytes into frame */

}

par

par

Page 58: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Example : complete ECL module

par while (1) { /* process address (if correct) */ await (frame); do { /* … */; emit (out, frame) } abort (bad_crc); }

typedef { byte hdr[HSIZE]; byte data[DSIZE]; int crc; } frame_t;

module frame_proc (input byte in, input frame_t out)

byte buf[SIZE]; frame_t f; int crc;

{ signal frame_t frame; signal int bad_crc;

}

par while (1) { /* get bytes into frame */ for (i = 0; i < SIZE; i++) {await (in); buf[i] = in;} create_frame_from_buffer(&f, buf); emit_v (frame, f); } par while (1) { /* check CRC */ await (frame); for (i = 0; i < HSIZE; i++) crc ^= frame.hdr[i]; if (crc != frame.crc) emit (bad_crc); }

Page 59: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

ECL compilation• Split ECL source: Esterel + C (by compiler capability)

• ECL module compiled to

– FSM (via Esterel) : reactive stmts + some C [Control +]

– C-code residue : functions and non-reactive loops [Data]

• Implementation

– SW (C) or HW (HDL) [Control +]

– C-code residue : SW produced by ECL compiler [Data]

• Trade-off: where exactly to split?

– more Esterel more optimization

– more C more predictable compilation process

Page 60: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

ECL compilation

Implementationin HW / SW

ECLSpecification

Esterel Code C - code

C functions

non-reactive loops

module calls: get_data (signal IN)reactive statements: await a;concurrency: par await a; par await b;C statements reactive loops

SimulationModel

EsterelCompiler to C

EsterelCompiler to C/FSM

Page 61: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Example : pre-compilationtypedef { byte hdr[HSIZE]; byte data[DSIZE]; int crc; } frame_t;module frame_proc (input byte in, output frame_t out){ signal frame_t frame; signal int bad_crc; byte buf[SIZE]; frame_t f; int crc; par while (1) {/* get bytes into frame */ for (i = 0; i < SIZE; i++) {await (in); buf[i] = in;} create_frame_from_buffer(&f, buf); emit (frame, f); } par while (1) {/* check CRC */ await (frame); for (i = 0; i < HSIZE; i++) crc ^= frame.hdr[i]; if (crc != frame.crc) emit (bad_crc); } par while (1) {/* process address (if correct) */ await (frame); abort{ /* … */; emit (out, frame) } when (bad_crc); }}

Non-reactive loop

Reactive loop

Page 62: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Example : post-compilationtypedef { byte hdr[HSIZE]; data[DSIZE]; int crc } frame_t;void crc_compute(int crc, frame_t frame) { for (i = 0; i < HSIZE; i++) crc ^= frame.hdr[i]; }/* plus interface functions such as set_buffer_i */

module frame_proc:input in : byte;output out : frame_t;signal frame : frame_t, bad_crc:integer invar buf : frame_t, crc:integer in loop % get bytes into frame trap DONE in cnt := 0; loop {await in; set_buffer_i(buffer, i, in); if (cnt < SIZE) else exit DONE end if;} end loop emit frame(?buffer); end trap; end loop|| loop % check CRC await frame; crc_compute(crc, frame); if (crc != get_frame_crc(frame) then emit bad_crc end if; end loop || etc

Compiled to C

Compiled toEsterel

Reactive loop

Non-reactive loop

Page 63: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

ECL Summary• ECL smoothly integrates

– C (standard for embedded software development)– Esterel (concurrency, preemption, FSM semantics)

into a single language and development environment • ECL compiler

– generates Esterel and C for embedded SW implementation– permits (partial) hardware implementation

• Opensource : http://www.sourceforge.net/projects/ecl– Java source code, test/tutorial examples, regression

tests, documentation (html, ps, pdf)• Ongoing work:

– ECL for hardware specification– ECL and Esterel in Metropolis

Page 64: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Implementing Esterel Programs in POLIS

• POLIS: system-level design tool created at UCB• Model of computation:

– GALS via communicating CFSMs– Global: asynchronous

• Events can arrive at any time• Different parts of system compute at different rates• Buffering of events for each module

• Goal : implement Esterel programs in a POLIS system while preserving their semantics

Page 65: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

POLIS : a GALS modelGlobally Asynchronous Locally Synchronous

CFSM

Input buffer

CFSM: FSM w/data, support for asynch communication

Page 66: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Input Buffer = presence + value

- A CFSM is runnable when an input comes in-Several inputs may come in before actual run- Presence / absence can be tested for each input- Value can be accessed for present signals-Transition in 0-delay-Inputs are consumed during the run- Output broadcast by the network, with delay- 1-place buffers can be overwritten

CFSM

Page 67: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

• Synchronous programs- nice semantics / mathematics- concurrency + deterministic - optimization + verification feasible- limited in scope : compact systems

• CFSM networks- POLIS implementation model- good for hardware / software codesign- formal semantics, but can be wild- semantics purely operational (scheduler)

Page 68: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Examplemodule m1:input a, ONE;output TWO;

loop await case [a and ONE] do emit TWO endend loop

module m2:input a, TWO;output ONE, THREE;[loop await case TWO do emit THREE endend loop]||[loop await case a do emit ONE endend loop]

a = 1m1 -> m2 -> m1 -> m2m2 -> m1 -> m2

await case : wait until at least one case is true

Page 69: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Can we implement synchronous languages on CFSM networks?

• Run large-scale synchronous programs on networks• Maintaining synchronous semantics

• Study classes of “well-behaved” CFSM networks• Study progressive relaxation of synchrony

Previous work : P. Caspi and A. Girault E,. Ledinot et.al., Dassault Aviation

Page 70: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Constructive and not gate as a CFSM - v1

AB

C

input A: boolean, B : boolean;output C : boolean;[ await A; if not ?A then emit C(false) end|| await B; if ?B then emit C(false) end];if ?A and not ?B then emit C(true) end

Page 71: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

• Encode facts in CFSM events• Create a logic network of gates representing the Esterel program• Use one CFSM per gate• Create at POLIS network of CFSMs to propagate the facts

POLIS Implementation

Combinational gates -> sequential CFSMsSynchronous cycle -> full network execution

Page 72: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Constructive and not gate as a CFSM - v1

AB

C

input A: boolean, B : boolean;output C : boolean;[ await A; if not ?A then emit C(false) end|| await B; if ?B then emit C(false) end];if ?A and not ?B then emit C(true) end

Problem: C can be emitted twice

Page 73: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

signal Caux : combine boolean with and in [ await A; if not ?A then emit Caux(false) end || await B; if ?B then emit Caux(false) end ]; if ?A and not ?B then emit Caux(true) end|| await Caux; emit C(?Caux)end signal

V2 : protecting double emission

Page 74: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Given an input assignment, the network builds a proof

• Each gate buffer is written at most once - no buffer overwriting - bounded time (linear)

• Termination when no more runnable CFSM - #events = #fanins -> constructive - else non-constructive

• Any scheduling gives the right answer!

Page 75: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

But works only for one global tick!

Macro-cycles - give synchronous events successively - logical timing by stream ordering

a0 a1 a2 a3 a4 b0 b1 b2 b3 b4 c0 c1 c2 c3 c4

Page 76: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Four basic solutions :

1. Wait long enough (as for circuits)

2. Compute explicit termination signal

3. Let the scheduler report termination

4. Use a flow control protocol

-> pipelining

Page 77: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Flow Control

AB

C

A_Free

B_FreeC_Free

Page 78: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

loop signal Caux : combine boolean with and in [ await A; emit A_Free; if not ?A then emit Caux(false) end || await B; emit B_Free; if ?B then emit Caux(false) end ]; if ?A and not ?B then emit Caux(true) end || [ await Caux || await C_Free ] ; emit C(?Caux) end signalend loop

V3 : flow control

Page 79: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

A gate resets for next tick when it has received all its input. No additional protocol needed!

A=0 A_FreeC_Free C=0B=1 B_Free loop

A=1 A_FreeC_Free B=0 B_Free C=1 loop

Automatic Gate Reset

Page 80: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Pipelining

Problem : out-of-order data for next cycle

A(0) -> A_FreeC_Free -> C(0)A(1) ->B(1) -> B_Free

3. Tell the scheduler that only arrival of B matters => sensitivity lists

1. Memorize A(1) in the CFSM - heavy!

2. Write back 1 in the A buffer but gate immediately made runnable again!

Page 81: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

module AndNot :

% Boolean IOinput A : boolean, B : boolean;output X : boolean;

% Flow control IOoutput A_Free, B_Free;input C_Free;

% Scheduling IOoutput A_Wait, B_Wait;output C_Free_Wait;

Page 82: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

loop signal Caux : combine boolean with and in < handle A and B > || < handle C > end signalend loop

Page 83: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

[ abort sustain A_Wait when A; emit A_Free; if not ?A then emit Caux(false) end|| abort sustain B_Wait when B; emit B_Free; if ?B then emit Caux(false) end];if ?A and not ?B then emit Caux(true)

Page 84: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

[ await Caux|| abort sustain C_Free_Wait when C_Free];emit C(?Caux)

Page 85: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Termination signal

X

Y

I

J

DONE

Too expensiveNon-local

Page 86: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

• One can implement a constructive circuit in POLIS by translating each gate into a CFSM

• Therefore, on can implement Esterel by first translating Esterel programs into gates

• Of course, this is inefficient : too fine grain

• But, we did not use compositionality yet!

Page 87: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Using Compositionality

• Any network of gates acts just as a gate• Group gates either synchronously, using v5 algo., or asynchronously, in the network• Adjust grouping according to geographical and performance requirements

Page 88: Synchronous Languages and System Design with Esterel Ellen Sentovich Cadence Berkeley Laboratories.

Summary

• Constructive logic semantics facts as information quanta• Propagate facts synchronously in CFSM nodes asynchronously in the network• Correct by construction• Applicable to (some) real problems