Low-Level Reactive Languages Jan Tobias Mhlberg - - PowerPoint PPT Presentation

low level reactive languages
SMART_READER_LITE
LIVE PREVIEW

Low-Level Reactive Languages Jan Tobias Mhlberg - - PowerPoint PPT Presentation

empty Low-Level Reactive Languages Jan Tobias Mhlberg jantobias.muehlberg@cs.kuleuven.be iMinds-DistriNet PLaNES Reading Club, KU Leuven, 13 th May 2015 13 th May 2015 1 /32 Low-Level Reactive Languages empty Motivation Around 2010:


slide-1
SLIDE 1

empty

Low-Level Reactive Languages

Jan Tobias Mühlberg

jantobias.muehlberg@cs.kuleuven.be iMinds-DistriNet

PLaNES Reading Club, KU Leuven, 13th May 2015

1 /32 13th May 2015 Low-Level Reactive Languages

slide-2
SLIDE 2

empty

Motivation

Around 2010: Course on “Reactive Systems Design” for MSc in Software Engineering and Gas Turbine Control at York

  • Focus on synchronous languages for reactive control systems

2 /32 13th May 2015 Low-Level Reactive Languages

slide-3
SLIDE 3

empty

Motivation

Around 2010: Course on “Reactive Systems Design” for MSc in Software Engineering and Gas Turbine Control at York

  • Focus on synchronous languages for reactive control systems
  • Lectures: Mathematical foundations, Lustre, Esterel, Statecharts, compilation

and design verification

2 /32 13th May 2015 Low-Level Reactive Languages

slide-4
SLIDE 4

empty

Motivation

Around 2010: Course on “Reactive Systems Design” for MSc in Software Engineering and Gas Turbine Control at York

  • Focus on synchronous languages for reactive control systems
  • Lectures: Mathematical foundations, Lustre, Esterel, Statecharts, compilation

and design verification

  • Practicals: SCADE and Lego Mindstorms

2 /32 13th May 2015 Low-Level Reactive Languages

slide-5
SLIDE 5

empty

Motivation

SCADE: “The Standard for the Development of Safety-Critical Embedded Software in Aerospace & Defense, Rail Transportation, Energy and Heavy Equipment Industries” – http://www.esterel-technologies.com/

  • Graphical modelling of reactive systems using synchronous language
  • Graphical debugging and efficient simulation
  • Design Verifier – formal verification
  • Generation of safe, efficient, small print production code (qual. DO-178B;
  • cert. IEC 61508, EN 50128)

3 /32 13th May 2015 Low-Level Reactive Languages

slide-6
SLIDE 6

empty

Motivation

SCADE: “The Standard for the Development of Safety-Critical Embedded Software in Aerospace & Defense, Rail Transportation, Energy and Heavy Equipment Industries” – http://www.esterel-technologies.com/

  • Graphical modelling of reactive systems using synchronous language
  • Graphical debugging and efficient simulation
  • Design Verifier – formal verification
  • Generation of safe, efficient, small print production code (qual. DO-178B;
  • cert. IEC 61508, EN 50128)

What are the new trends for RP in safety-critical systems?

3 /32 13th May 2015 Low-Level Reactive Languages

slide-7
SLIDE 7

empty

This Talk

To distinguish this from previous talks: Imperative languages, no distribution, deterministic w.r.t. timing, aiming at safety critical deployment & verification

4 /32 13th May 2015 Low-Level Reactive Languages

slide-8
SLIDE 8

empty

This Talk

To distinguish this from previous talks: Imperative languages, no distribution, deterministic w.r.t. timing, aiming at safety critical deployment & verification Outline

  • Outline of synchronous languages
  • Reactive C [Bou91]
  • Synchronous C [vH09] (and SJ)
  • PRET-C [ARGT14] (2009)

4 /32 13th May 2015 Low-Level Reactive Languages

slide-9
SLIDE 9

empty

Synchronous Languages

[BCC+13] mentions Esterel, StateCharts, Lustre, LabVIEW, Simulink and others.

5 /32 13th May 2015 Low-Level Reactive Languages

slide-10
SLIDE 10

empty

Synchronous Languages

[BCC+13] mentions Esterel, StateCharts, Lustre, LabVIEW, Simulink and others. Overview & survey: [BCE+03] (focusing on Esterel, Lustre and Signal)

5 /32 13th May 2015 Low-Level Reactive Languages

slide-11
SLIDE 11

empty

Synchronous Languages

[BCC+13] mentions Esterel, StateCharts, Lustre, LabVIEW, Simulink and others. Overview & survey: [BCE+03] (focusing on Esterel, Lustre and Signal) Properties Include specific/dedicated features for programming reactive controllers with real-time constraints:

  • synchrony

5 /32 13th May 2015 Low-Level Reactive Languages

slide-12
SLIDE 12

empty

Synchronous Languages

[BCC+13] mentions Esterel, StateCharts, Lustre, LabVIEW, Simulink and others. Overview & survey: [BCE+03] (focusing on Esterel, Lustre and Signal) Properties Include specific/dedicated features for programming reactive controllers with real-time constraints:

  • synchrony
  • typically first-order
  • concurrency
  • determinism

5 /32 13th May 2015 Low-Level Reactive Languages

slide-13
SLIDE 13

empty

Synchronous Languages

The Synchrony Hypothesis: Let ∆(f(x)) denote the time to compute a reaction f

  • n inputs x. ∆(f(x)) depends on (1) the implementation of f, (2) the target

machine, and (3) the nature of x. Problem: We wish to abstract ∆(f(x)) to some δ, but also require compositionality, i.e. if f(x) = g(h(x)), then ∆f = ∆g + ∆h. How can we obtain the required identity δ = δ + δ?

6 /32 13th May 2015 Low-Level Reactive Languages

slide-14
SLIDE 14

empty

Synchronous Languages

The Synchrony Hypothesis: Let ∆(f(x)) denote the time to compute a reaction f

  • n inputs x. ∆(f(x)) depends on (1) the implementation of f, (2) the target

machine, and (3) the nature of x. Problem: We wish to abstract ∆(f(x)) to some δ, but also require compositionality, i.e. if f(x) = g(h(x)), then ∆f = ∆g + ∆h. How can we obtain the required identity δ = δ + δ? Solutions (1) δ = 0 – synchrony, reactive control systems (2) δ = ? – asynchrony, interactive systems Synchronous languages achieve separation of concerns: qualitative (logical) time versus of quantitative (physical) time.

6 /32 13th May 2015 Low-Level Reactive Languages

slide-15
SLIDE 15

empty

Synchronous Languages

Reality

  • Valid abstraction as long as δi ≤ ∆i
  • This needs to be checked and verified for the implementation (worst-case

execution time analysis, etc.)

  • Two views of the system:
  • External view: Reactions are atomic
  • Internal view: Reactions are non-atomic

7 /32 13th May 2015 Low-Level Reactive Languages

slide-16
SLIDE 16

empty

Synchronous Programming

. . . for Control Engineers in SCADE: ControlVehicle

8 /32 13th May 2015 Low-Level Reactive Languages

slide-17
SLIDE 17

empty

Synchronous Programming

Synchronous Programming: OperateMotor

9 /32 13th May 2015 Low-Level Reactive Languages

slide-18
SLIDE 18

empty

Synchronous Programming

Synchronous Programming: OperateMotor as SM

10 /32 13th May 2015 Low-Level Reactive Languages

slide-19
SLIDE 19

empty

Synchronous Programming

Synchronous Programming: Compilation & Execution Event Driven Sample Driven Initialise Memory for each input event do Compute Outputs Update Memory end Initialise Memory for each clock tick do Read Inputs Compute Outputs Update Memory end e.g. Esterel e.g. Lustre

11 /32 13th May 2015 Low-Level Reactive Languages

slide-20
SLIDE 20

empty

Synchronous Programming

Design Verification

12 /32 13th May 2015 Low-Level Reactive Languages

slide-21
SLIDE 21

empty

Synchronous Programming

Design Verification

12 /32 13th May 2015 Low-Level Reactive Languages

slide-22
SLIDE 22

empty

Synchronous Programming

Design Verification

12 /32 13th May 2015 Low-Level Reactive Languages

slide-23
SLIDE 23

empty

Reactive C

13 /32 13th May 2015 Low-Level Reactive Languages

slide-24
SLIDE 24

empty

Reactive C [Bou91]

Frederic Boussinot, 1991. Extends C with parallelism, exceptions and reactive statements. Semantics of RC extensions is based directly on Esterel: parallelism is evaluated deterministically with no run-time concurrency. Embedding of RC in C is done by preprocessor. Compiler enforces deadlock freedom for reactive statements.

14 /32 13th May 2015 Low-Level Reactive Languages

slide-25
SLIDE 25

empty

Reactive C [Bou91]

An Example: Time, Signals and Parallelism

signal SYNC, REQ, OK, NOK, ALARM; rproc req_handler() { every (present(SYNC)) { await (present(REQ)); emit (OK); stop; every (present(REQ)) emit (NOK); } } rproc alarm_handler() { loop { watching { await (present(SYNC)); emit (ALARM); } timeout await(present(SYNC)); stop; } } rproc sync_req_handler() { par exec req_handler(); exec alarm_handler(); }

15 /32 13th May 2015 Low-Level Reactive Languages

slide-26
SLIDE 26

empty

Reactive C [Bou91]

RC Esterel

par printf("1"); printf("2");

12 12

16 /32 13th May 2015 Low-Level Reactive Languages

slide-27
SLIDE 27

empty

Reactive C [Bou91]

RC Esterel

par printf("1"); printf("2");

12 12

present S else emit S end

valid invalid: causality cycle!

16 /32 13th May 2015 Low-Level Reactive Languages

slide-28
SLIDE 28

empty

Reactive C [Bou91]

RC Esterel

par printf("1"); printf("2");

12 12

present S else emit S end

valid invalid: causality cycle!

present S1 then emit S2 end || emit S1; present S2 then emit S3 end

can be implemented with run-time checks valid: instantaneous dialogue

16 /32 13th May 2015 Low-Level Reactive Languages

slide-29
SLIDE 29

empty

Reactive C [Bou91]

RC Esterel

par printf("1"); printf("2");

12 12

present S else emit S end

valid invalid: causality cycle!

present S1 then emit S2 end || emit S1; present S2 then emit S3 end

can be implemented with run-time checks valid: instantaneous dialogue Data Types Signals, primitive types, structured data Signals and numeric values

16 /32 13th May 2015 Low-Level Reactive Languages

slide-30
SLIDE 30

empty

Reactive C [Bou91]

RC Esterel

par printf("1"); printf("2");

12 12

present S else emit S end

valid invalid: causality cycle!

present S1 then emit S2 end || emit S1; present S2 then emit S3 end

can be implemented with run-time checks valid: instantaneous dialogue Data Types Signals, primitive types, structured data Signals and numeric values Process Management dynamic static

16 /32 13th May 2015 Low-Level Reactive Languages

slide-31
SLIDE 31

empty

Reactive C [Bou91]

RC Esterel

par printf("1"); printf("2");

12 12

present S else emit S end

valid invalid: causality cycle!

present S1 then emit S2 end || emit S1; present S2 then emit S3 end

can be implemented with run-time checks valid: instantaneous dialogue Data Types Signals, primitive types, structured data Signals and numeric values Process Management dynamic static Compilation and Execution compiled directly automaton → validation → code

16 /32 13th May 2015 Low-Level Reactive Languages

slide-32
SLIDE 32

empty

Synchronous C

17 /32 13th May 2015 Low-Level Reactive Languages

slide-33
SLIDE 33

empty

Synchronous C [vH09] (and SJ)

Reinhard von Hanxleden, 2009. Based on Statecharts [Har87] (sequential reactive control flow & visual syntax) SyncCharts [And95] (synchronous semantics) Light-weight approach to embed deterministic reactive control flow constructs into widely used programming languages (C and Java). Fairly small number of primitives suffices to cover all of SyncCharts. Multi-threaded, priority-based approach inspired by synchronous reactive processing – where it required special HW & special compiler.

18 /32 13th May 2015 Low-Level Reactive Languages

slide-34
SLIDE 34

empty

Synchronous C [vH09] (and SJ)

Idea: Cooperative thread scheduling at application level Problem: High-level languages do not provide access to program counter Solution: Explicit labelling of continuation points

  • Expressed as program labels or switch cases
  • Each thread maintains a coarse program counter that points to continuation

point Furthermore:

  • Synchronous model of time, threads execute ticks in lock-step
  • Shared address space, broadcast communication via ordinary variables or

signals

  • Dynamic priorities, may switch control back and forth within tick

19 /32 13th May 2015 Low-Level Reactive Languages

slide-35
SLIDE 35

empty

Synchronous C [vH09] (and SJ)

SC Thread Operators

TICKSTART∗(init, p) Start (initial) tick, assign main thread priority p. TICKEND Return true (1) iff there is still an enabled thread. PAUSE∗+ Deactivate current thread for this tick. TERM∗ Terminate current thread. ABORT Abort descendant threads. TRANS(l) Shorthand for ABORT; GOTO(l). SUSPEND∗(cond) Suspend (pause) thread + descendants if cond holds. FORK(l, p) Create a thread with start address l and priority p. FORKE∗(l) Finalize FORK, resume at l. JOINELSE∗+(lelse) If descendant threads have terminated normally, proceed; else pause, jump to lelse. JOIN∗+ Waits for descendant threads to terminated normally. Shorthand for lelse: JOINE(lelse). PRIO∗+(p) Set current thread priority to p.

∗ possible thread dispatcher call + automatically generates continuation label

20 /32 13th May 2015 Low-Level Reactive Languages

slide-36
SLIDE 36

empty

Synchronous C [vH09] (and SJ)

Producer-Consumer-Observer in SC

1 int tick ( int isInit ) 2 { 3 static int BUF, fd, i , j , 4 k = 0, tmp, arr [8]; 5 6 TICKSTART(isInit, 1); 7 8 PCO: 9 FORK(Producer, 3); 10 FORK(Consumer, 2); 11 FORKE(Observer); 12 Producer: 13 for (i = 0; ; i++) { 14 PAUSE; 15 BUF = i; } 16 17 Consumer: 18 for (j = 0; j < 8; j++) 19 arr [ j ] = 0; 20 for (j = 0; ; j++) { 21 PAUSE; 22 tmp = BUF; 23 arr [ j % 8] = tmp; } 24 25 Observer: 26 for ( ; ; ) { 27 PAUSE; 28 fd = BUF; 29 k++; } 30 31 TICKEND; 32 }

21 /32 13th May 2015 Low-Level Reactive Languages

slide-37
SLIDE 37

empty

Synchronous C [vH09] (and SJ)

Producer-Consumer-Observer with Preemption in SC

1 int tick ( int isInit ) 2 { 3 static int BUF, fd, i , j , 4 k = 0, tmp, arr [8]; 5 6 TICKSTART(isInit, 1); 7 8 PCO: 9 FORK(Producer, 4); 10 FORK(Consumer, 3); 11 FORK(Observer, 2); 12 FORKE(Parent); 13 Producer: 14 for (i = 0; ; i++) { 15 BUF = i; 16 PAUSE; } 17 18 Consumer: 19 for (j = 0; j < 8; j++) 20 arr [ j ] = 0; 21 for (j = 0; ; j++) { 22 tmp = BUF; 23 arr [ j % 8] = tmp; 24 PAUSE; } 25 26 Observer: 27 for ( ; ; ) { 28 fd = BUF; 29 k++; 30 PAUSE; } 31 32 Parent: 33 while (1) { 34 if (k == 20) 35 TRANS(Done); 36 if (BUF == 10) 37 TRANS(PCO); 38 PAUSE; 39 } 40 41 Done: 42 TERM; 43 TICKEND; 44 }

22 /32 13th May 2015 Low-Level Reactive Languages

slide-38
SLIDE 38

empty

PRET-C

23 /32 13th May 2015 Low-Level Reactive Languages

slide-39
SLIDE 39

empty

PRET-C [ARGT14]

“Precision Timed C”, Sidharta Anadlam et al., 2009. Synchronous extension of C; compiler provides worst-case reaction time analysis and allows mapping of logical time to physical time. Offers safe, C-based shared memory communications between concurrent

  • threads. Concurrency is logical, execution is sequential.

Minimal extensions to C, implemented as macros. Only language with quantitative evaluation: generated code is generally more efficient than Esterel.

24 /32 13th May 2015 Low-Level Reactive Languages

slide-40
SLIDE 40

empty

PRET-C [ARGT14]

C Language Extensions Statement Meaning ReactiveInput I declares I as a reactive input coming from the environ- ment ReactiveOutput O declares O as a reactive output emitted to the environ- ment PAR(T1, ..., Tn) synchronously executes in parallel the n threads Ti, with higher priority of Ti over Ti+1 EOT marks the end of a tick (local or global depending on its position) [weak] abort P when pre C immediately kills P when C is true in the previous in- stant

25 /32 13th May 2015 Low-Level Reactive Languages

slide-41
SLIDE 41

empty

PRET-C [ARGT14]

Restrictions:

  • Pointers and dynamic memory allocation are disallowed.
  • All loops must have at least one EOT in their body.
  • All function calls have to be non-recursive.
  • Jumps via goto are not allowed to cross logical instants (i.e. EOT).

26 /32 13th May 2015 Low-Level Reactive Languages

slide-42
SLIDE 42

empty

Summary

27 /32 13th May 2015 Low-Level Reactive Languages

slide-43
SLIDE 43

empty

Summary

Esterel RC SC PRET-C Commutativity of || yes no no no Communication signals signals & variables variables variables Instantaneous dialogue yes yes/no no no Signals/variable values/ . . . instants single multiple multiple multiple Types of aborts 4 4 2 2 Types of suspend 4 4 4 2 Traps yes yes no no Non-causal programs possible possible not possible not possible Dynamic processes no yes no no Compilation complex macro exp. ??? macro exp. resolve || WCRT cycle det.

28 /32 13th May 2015 Low-Level Reactive Languages

slide-44
SLIDE 44

empty

Summary

The original synchronous languages were designed for safety-critical reactive control systems: determinism and support verification. Embedding of synchronous constructs in general-purpose programming languages appears to be less adequate for safety-critical applications. Yet, Esterel programs also need to interact with OS and drivers. There are many (mostly syntactic) variants of the languages discussed here. Many semantical extensions being proposed. There are many alternative approaches: ECL (Esterel C), Jester (Java Esterel), etc. Suggestion There is real-time FRP [WTH01]. Anyone?

29 /32 13th May 2015 Low-Level Reactive Languages

slide-45
SLIDE 45

empty

Thank you!

Thank you! Questions?

30 /32 13th May 2015 Low-Level Reactive Languages

slide-46
SLIDE 46

empty

References I

  • C. André.

SyncCharts: A visual representation of reactive behaviors. Rapport de recherche tr95-52, Université de Nice-Sophia Antipolis, 1995.

  • S. Andalam, P

. S. Roop, A. Girault, and C. Traulsen. A predictable framework for safety-critical embedded systems. IEEE Trans. Comput., 63(7):1600–1612, 2014.

  • E. Bainomugisha, A. L. Carreton, T. v. Cutsem, S. Mostinckx, and W. d. Meuter.

A survey on reactive programming. ACM Comput. Surv., 45(4):52:1–52:34, 2013.

  • A. Benveniste, P

. Caspi, S. Edwards, N. Halbwachs, P . Le Guernic, and R. de Simone. The synchronous languages 12 years later. Proceedings of the IEEE, 91(1):64–83, Jan 2003.

  • F. Boussinot.

Reactive C: An extension of C to program reactive systems.

  • Softw. Pract. Exper., 21(4):401–428, 1991.
  • D. Harel.

Statecharts: A visual formalism for complex systems. Science of Computer Programming, 8(3):231 – 274, 1987. 31 /32 13th May 2015 Low-Level Reactive Languages

slide-47
SLIDE 47

empty

References II

  • R. von Hanxleden.

SyncCharts in C: A proposal for light-weight, deterministic concurrency. In Proceedings of the Seventh ACM International Conference on Embedded Software, EMSOFT ’09, pp. 225–234, New York, NY, USA, 2009. ACM.

  • Z. Wan, W. Taha, and P

. Hudak. Real-time FRP. In Proceedings of the Sixth ACM SIGPLAN International Conference on Functional Programming, ICFP ’01, pp. 146–156, New York, NY, USA,

  • 2001. ACM.

32 /32 13th May 2015 Low-Level Reactive Languages