THE ACTOR MODEL APPLIED TO THE RASPBERRY PI AND THE EMBEDDED DOMAIN - - PowerPoint PPT Presentation

the actor model applied to the raspberry pi and the
SMART_READER_LITE
LIVE PREVIEW

THE ACTOR MODEL APPLIED TO THE RASPBERRY PI AND THE EMBEDDED DOMAIN - - PowerPoint PPT Presentation

THE ACTOR MODEL APPLIED TO THE RASPBERRY PI AND THE EMBEDDED DOMAIN Omer Kilic || @OmerK Erlang Solutions Ltd. 1 Agenda Current state of Embedded Systems Overview of the Actor Model Erlang Embedded Project Modelling and


slide-1
SLIDE 1

THE ACTOR MODEL APPLIED TO THE RASPBERRY PI AND THE EMBEDDED DOMAIN

Omer Kilic || @OmerK

Erlang Solutions Ltd.

1

slide-2
SLIDE 2

01/10/2012 GOTO Aarhus

Agenda

  • Current state of Embedded Systems
  • Overview of the Actor Model
  • Erlang Embedded Project
  • Modelling and developing systems using Erlang
  • Experiments with the Raspberry Pi
  • Future Explorations
  • Q & A

2

slide-3
SLIDE 3

01/10/2012 GOTO Aarhus

Embedded Systems

An embedded system is a computer system designed for specific control functions within a larger system, often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal computer (PC), is designed to be flexible and to meet a wide range of end-user needs

– Infinite Wisdom of Wikipedia

3

slide-4
SLIDE 4

01/10/2012 GOTO Aarhus

#include “stats.h”

Source: http://embedded.com/electronics-blogs/programming-pointers/4372180/Unexpected-trends 4

slide-5
SLIDE 5

01/10/2012 GOTO Aarhus

Current Challenges

  • Complex SoC platforms
  • “Internet of Things”
  • Connected and distributed systems
  • Multicore and/or heterogeneous devices
  • Time to market constraints

5

slide-6
SLIDE 6

01/10/2012 GOTO Aarhus

Embedded Systems

  • Bare Metal
  • No underlying OS or high level abstractions
  • RTOS
  • Minimal interrupt and thread switching latency,

scheduling guarantees, minimal jitter

  • Embedded Linux
  • Slimmed down Linux, with hardware interfaces

6

slide-7
SLIDE 7

01/10/2012 GOTO Aarhus

Embedded Systems

  • Bare Metal
  • No underlying OS or high level abstractions
  • RTOS
  • Minimal interrupt and thread switching latency,

scheduling guarantees, minimal jitter

  • Embedded Linux
  • Slimmed down Linux, with hardware interfaces

6

slide-8
SLIDE 8

01/10/2012 GOTO Aarhus

RTOS Concepts

  • Notion of “tasks”
  • OS-supervised interprocess messaging
  • Shared memory
  • Mutexes/Semaphores/Locks
  • Scheduling
  • Pre-emptive: event driven
  • Round-robin: time multiplexed

7

slide-9
SLIDE 9

01/10/2012 GOTO Aarhus

Embedded Linux

  • Not a new concept, increased popularity due to

abundant supply of cheap boards

  • Raspberry Pi, Beagleboard/Beaglebone, Gumstix et al.
  • Familiar set of tools for software developers,

new territory for embedded engineers

  • No direct mapping for RTOS concepts, expecially

tasks

  • Complex device driver framework
  • Here be dragons

8

slide-10
SLIDE 10

01/10/2012 GOTO Aarhus

Actor Model

  • Proposed in 1973 by Hewitt, Bishop, and Steiger
  • “Universal primitives of concurrent computation”
  • Building blocks for modular, distributed and

concurrent systems

  • No shared-state, self-contained and atomic
  • Implemented in a variety of programming

languages

9

slide-11
SLIDE 11

01/10/2012 GOTO Aarhus

Actor Model

  • Asynchronous message passing
  • Messages kept in a mailbox and processes in the
  • rder they are received in
  • Upon receiving a message, actors can:
  • Make local decisions and change internal state
  • Spawn new actors
  • Send messages to other actors

functionality mailbox state

10

slide-12
SLIDE 12

01/10/2012 GOTO Aarhus

Actor Model

11

slide-13
SLIDE 13

01/10/2012 GOTO Aarhus

Actor Model

number_cruncher

11

slide-14
SLIDE 14

01/10/2012 GOTO Aarhus

Actor Model

number_cruncher

{calc, Values}

11

slide-15
SLIDE 15

01/10/2012 GOTO Aarhus

Actor Model

number_cruncher worker_a worker_b worker_c

{calc, Values}

11

slide-16
SLIDE 16

01/10/2012 GOTO Aarhus

Actor Model

number_cruncher worker_a worker_b worker_c

{calc, ValSubsetA} {calc, ValSubsetB} {calc, ValSubsetA} {calc, Values}

11

slide-17
SLIDE 17

01/10/2012 GOTO Aarhus

Actor Model

number_cruncher worker_a worker_b worker_c

{result, ResSubsetA} {result, ResSubsetB} {result, ResSubsetC}

12

slide-18
SLIDE 18

01/10/2012 GOTO Aarhus

Actor Model

number_cruncher worker_a worker_b worker_c

{result, ResSubsetA} {result, ResSubsetB} {result, ResSubsetC} {result, Values}

12

slide-19
SLIDE 19

01/10/2012 GOTO Aarhus

Limitations of the Actor Model

  • No notion of inheritance or general hierarchy
  • Specific to the language and library implementation
  • Asynchronous message passing can be

problematic for certain applications

  • Ordering of messages received from multiple

processes

  • Abstract definition may lead to inconsistency in

larger systems

  • Fine/Coarse Grain

13

slide-20
SLIDE 20

01/10/2012 GOTO Aarhus

Erlang Embedded

  • Knowledge Transfer Partnership between Erlang

Solutions and University of Kent

  • Aim of the project: Bring the benefits of concurrent

systems development using Erlang to the field of embedded systems; through investigation, analysis, software development and evaluation.

  • http://erlang-embedded.com

14

slide-21
SLIDE 21

01/10/2012 GOTO Aarhus

Why Erlang

  • Implements the Actor model
  • Battle-tested at Ericsson and many other

companies

  • Originally designed for embedded applications
  • Support for concurrency and distributed systems
  • ut of the box
  • Easy to create robust systems
  • (...and more!)

15

slide-22
SLIDE 22

01/10/2012 GOTO Aarhus

High Availability/Reliability

  • Simple and consistent error recovery and

supervision hierarchies

  • Built in fault-tolerance
  • Isolation of Actors
  • Support for dynamic reconfiguration
  • Hot code loading

16

slide-23
SLIDE 23

01/10/2012 GOTO Aarhus

spawn(math, fact, [5]) Pid1

Creating an Actor

17

slide-24
SLIDE 24

01/10/2012 GOTO Aarhus

spawn(math, fact, [5]) math:fact(5) Pid2 Pid1

Creating an Actor

17

slide-25
SLIDE 25

01/10/2012 GOTO Aarhus

Pid2 Pid1 Pid2 ! {self(),msg}

Communication

18

slide-26
SLIDE 26

01/10/2012 GOTO Aarhus

Pid2 Pid1 Pid2 ! {self(),msg} {Pid1,msg}

Communication

18

slide-27
SLIDE 27

01/10/2012 GOTO Aarhus

PidB PidA link(PidB)

Bidirectional Links

19

slide-28
SLIDE 28

01/10/2012 GOTO Aarhus

PidB PidA link(PidB)

Bidirectional Links

19

slide-29
SLIDE 29

01/10/2012 GOTO Aarhus

Process Error Handling

  • Let it Fail!
  • Abstract error handling away from the modules
  • Leaner modules
  • Supervision hierarchies

Supervisor Worker

20

slide-30
SLIDE 30

01/10/2012 GOTO Aarhus

PidA PidB PidC

Propagating Exit Signals

21

slide-31
SLIDE 31

01/10/2012 GOTO Aarhus

PidA PidB PidC

Propagating Exit Signals

21

slide-32
SLIDE 32

01/10/2012 GOTO Aarhus

PidB {'EXIT', PidA, Reason} PidC

Propagating Exit Signals

21

slide-33
SLIDE 33

01/10/2012 GOTO Aarhus

PidB PidC

Propagating Exit Signals

21

slide-34
SLIDE 34

01/10/2012 GOTO Aarhus

PidC {'EXIT', PidB, Reason}

Propagating Exit Signals

21

slide-35
SLIDE 35

01/10/2012 GOTO Aarhus

Propagating Exit Signals

21

slide-36
SLIDE 36

01/10/2012 GOTO Aarhus

PidA PidC PidB

Trapping Exits

22

slide-37
SLIDE 37

01/10/2012 GOTO Aarhus

PidA PidC PidB

Trapping Exits

22

slide-38
SLIDE 38

01/10/2012 GOTO Aarhus

{'EXIT', PidA, Reason} PidC PidB

Trapping Exits

22

slide-39
SLIDE 39

01/10/2012 GOTO Aarhus

PidC PidB

Trapping Exits

22

slide-40
SLIDE 40

01/10/2012 GOTO Aarhus

External Interfaces

  • Native Implemented Functions (NIFs) and ports

used to interface external world to the Erlang runtime.

app hw_if hw_driver.c

Erlang VM

23

slide-41
SLIDE 41

01/10/2012 GOTO Aarhus

Erlang, the Maestro

(flickr/dereckesanches)

24

slide-42
SLIDE 42

01/10/2012 GOTO Aarhus

Raspberry Pi

  • 700 MHz ARM11
  • 256 MB DDR2 RAM
  • 10/100Mb Ethernet
  • 2x USB 2.0
  • (HDMI, Composite

Video, 3.5mm Stereo Jack, DSI, CSI-2)

$35

25

slide-43
SLIDE 43

01/10/2012 GOTO Aarhus

Raspberry Pi in Education

  • The Raspberry Pi Foundation is a

UK registered charity.

  • Mission statement: "...to promote

the study of computer science and related topics, especially at school level, and to put the fun back into learning computing."

  • Future Engineers/Programmers!

(flickr/lebeus)

26

slide-44
SLIDE 44

01/10/2012 GOTO Aarhus

Raspberry Pi Peripherals

  • GPIO
  • UART
  • I2C
  • I2S
  • SPI
  • PWM
  • DSI
  • CSI-2

27

slide-45
SLIDE 45

01/10/2012 GOTO Aarhus

The ErlBuggy!

28

slide-46
SLIDE 46

01/10/2012 GOTO Aarhus

ErlBuggy

http://vimeo.com/48375416

29

slide-47
SLIDE 47

01/10/2012 GOTO Aarhus

Example: GPIO

pin17 proc_a {state, high}

30

slide-48
SLIDE 48

01/10/2012 GOTO Aarhus

Example: GPIO

pin17 proc_a {state, high} proc_b {state, low} proc_c {state, high}

30

slide-49
SLIDE 49

01/10/2012 GOTO Aarhus

Example: GPIO

pin17 proc_a {state, high}

???

proc_b {state, low} proc_c {state, high}

30

slide-50
SLIDE 50

01/10/2012 GOTO Aarhus

Example: GPIO

GPIO proc_a pin17 {state, 17, high} proc_b {state, 17, low} proc_c {state, 17, high}

31

slide-51
SLIDE 51

01/10/2012 GOTO Aarhus

GPIO Proxy

  • Replaces ‘locks’ in traditional sense of

embedded design

  • Access control/mutual exclusion
  • Can be used to implement safety constraints
  • Toggling rate, sequence detection, direction

control, etc.

32

slide-52
SLIDE 52

01/10/2012 GOTO Aarhus

Fine Grain Abstraction

  • Advantages
  • Application code becomes simpler
  • Concise and shorter modules
  • Testing becomes easier
  • Code re-use (potentially) increases
  • Disadvantage
  • Architecting fine grain systems is difficult

33

slide-53
SLIDE 53

01/10/2012 GOTO Aarhus

Component API

Universal Peripheral/Component Modules

Peripheral API Peripheral Implementation Platform Specific Universal

34

slide-54
SLIDE 54

01/10/2012 GOTO Aarhus

Universal Peripheral/Component Modules

An Example:

TMP102 Temperature Sensor I2C Bus Driver Linux Kernel Driver Sensor API

I2C Bus Driver Linux sysfs

TMP102 Temperature Sensor I2C Bus Driver Linux Kernel Driver

Sensor API I2C Bus Driver BSD sysctl

TMP102 Temperature Sensor I2C Bus Driver Linux Kernel Driver

Sensor API I2C Bus Driver mmap()'ed register voodoo Temperature Sensor with I2C Interface

35

slide-55
SLIDE 55

01/10/2012 GOTO Aarhus

TI OMAP Reference System

36

slide-56
SLIDE 56

01/10/2012 GOTO Aarhus

Ponte Prototype

(flickr/carrierdetect)

37

slide-57
SLIDE 57

01/10/2012 GOTO Aarhus

Ponte Prototype

38

slide-58
SLIDE 58

01/10/2012 GOTO Aarhus

Ponte Prototype

39

slide-59
SLIDE 59

01/10/2012 GOTO Aarhus

Hardware Simulator (WIP)

40

slide-60
SLIDE 60

01/10/2012 GOTO Aarhus

Erlang Embedded Training Stack

  • A complete package for people interested in

developing the next generation of concurrent/ distributed Embedded Systems

  • Training Modules
  • Embedded Linux Primer
  • Erlang/OTP 101
  • Erlang Embedded Framework

Erlang Embedded Framework Erlang/OTP 101 Embedded Linux Primer Hardware Platform

Get in touch if you’re interested.

41

slide-61
SLIDE 61

01/10/2012 GOTO Aarhus

Thank you

Any sufficiently complicated concurrent program in another language contains an ad-hoc, informally- specified, bug-ridden, slow implementation of half of Erlang.

– Robert Virding

Co-Inventor of Erlang

  • http://erlang-embedded.com
  • embedded@erlang-solutions.com
  • @ErlangEmbedded

42