the actor model applied to the raspberry pi and the
play

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


  1. THE ACTOR MODEL APPLIED TO THE RASPBERRY PI AND THE EMBEDDED DOMAIN Omer Kilic || @OmerK Erlang Solutions Ltd. 1

  2. 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 01/10/2012 GOTO Aarhus 2

  3. 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 01/10/2012 GOTO Aarhus 3

  4. #include “stats.h” Source: http://embedded.com/electronics-blogs/programming-pointers/4372180/Unexpected-trends 01/10/2012 GOTO Aarhus 4

  5. Current Challenges ● Complex SoC platforms ● “Internet of Things” ● Connected and distributed systems ● Multicore and/or heterogeneous devices ● Time to market constraints 01/10/2012 GOTO Aarhus 5

  6. 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 01/10/2012 GOTO Aarhus 6

  7. 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 01/10/2012 GOTO Aarhus 6

  8. RTOS Concepts ● Notion of “tasks” ● OS-supervised interprocess messaging ● Shared memory ● Mutexes/Semaphores/Locks ● Scheduling ● Pre-emptive: event driven ● Round-robin: time multiplexed 01/10/2012 GOTO Aarhus 7

  9. 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 01/10/2012 GOTO Aarhus 8

  10. 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 01/10/2012 GOTO Aarhus 9

  11. Actor Model ● Asynchronous message passing ● Messages kept in a mailbox and processes in the order they are received in ● Upon receiving a message, actors can: ● Make local decisions and change internal state ● Spawn new actors state ● Send messages to other actors functionality mailbox 01/10/2012 GOTO Aarhus 10

  12. Actor Model 01/10/2012 GOTO Aarhus 11

  13. Actor Model number_cruncher 01/10/2012 GOTO Aarhus 11

  14. Actor Model {calc, Values} number_cruncher 01/10/2012 GOTO Aarhus 11

  15. Actor Model worker_a {calc, Values} worker_b number_cruncher worker_c 01/10/2012 GOTO Aarhus 11

  16. Actor Model worker_a {calc, ValSubsetA} {calc, {calc, Values} ValSubsetB} worker_b number_cruncher {calc, ValSubsetA} worker_c 01/10/2012 GOTO Aarhus 11

  17. Actor Model worker_a {result, ResSubsetA} {result, ResSubsetB} worker_b number_cruncher {result, ResSubsetC} worker_c 01/10/2012 GOTO Aarhus 12

  18. Actor Model worker_a {result, ResSubsetA} {result, {result, Values} ResSubsetB} worker_b number_cruncher {result, ResSubsetC} worker_c 01/10/2012 GOTO Aarhus 12

  19. 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 01/10/2012 GOTO Aarhus 13

  20. 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 01/10/2012 GOTO Aarhus 14

  21. 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 out of the box ● Easy to create robust systems ● (...and more!) 01/10/2012 GOTO Aarhus 15

  22. 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 01/10/2012 GOTO Aarhus 16

  23. Creating an Actor Pid1 spawn(math, fact, [5]) 01/10/2012 GOTO Aarhus 17

  24. Creating an Actor Pid1 spawn(math, fact, [5]) math:fact(5) Pid2 01/10/2012 GOTO Aarhus 17

  25. Communication Pid1 Pid2 Pid2 ! {self(),msg} 01/10/2012 GOTO Aarhus 18

  26. Communication Pid1 Pid2 {Pid1,msg} Pid2 ! {self(),msg} 01/10/2012 GOTO Aarhus 18

  27. Bidirectional Links PidA PidB link(PidB) 01/10/2012 GOTO Aarhus 19

  28. Bidirectional Links PidA PidB link(PidB) 01/10/2012 GOTO Aarhus 19

  29. Process Error Handling ● Let it Fail! ● Abstract error handling away from the modules ● Leaner modules ● Supervision hierarchies Supervisor Worker 01/10/2012 GOTO Aarhus 20

  30. Propagating Exit Signals PidA PidB PidC 01/10/2012 GOTO Aarhus 21

  31. Propagating Exit Signals PidA PidB PidC 01/10/2012 GOTO Aarhus 21

  32. Propagating Exit Signals {'EXIT', PidA, Reason} PidB PidC 01/10/2012 GOTO Aarhus 21

  33. Propagating Exit Signals PidB PidC 01/10/2012 GOTO Aarhus 21

  34. Propagating Exit Signals {'EXIT', PidB, Reason} PidC 01/10/2012 GOTO Aarhus 21

  35. Propagating Exit Signals 01/10/2012 GOTO Aarhus 21

  36. Trapping Exits PidB PidA PidC 01/10/2012 GOTO Aarhus 22

  37. Trapping Exits PidB PidA PidC 01/10/2012 GOTO Aarhus 22

  38. Trapping Exits {'EXIT', PidA, Reason} PidB PidC 01/10/2012 GOTO Aarhus 22

  39. Trapping Exits PidB PidC 01/10/2012 GOTO Aarhus 22

  40. External Interfaces ● Native Implemented Functions (NIFs) and ports used to interface external world to the Erlang runtime. Erlang VM app hw_driver.c hw_if 01/10/2012 GOTO Aarhus 23

  41. Erlang, the Maestro (flickr/dereckesanches) 01/10/2012 GOTO Aarhus 24

  42. Raspberry Pi ● 700 MHz ARM11 ● 256 MB DDR2 RAM ● 10/100Mb Ethernet ● 2x USB 2.0 ● (HDMI, Composite Video, 3.5mm Stereo $35 Jack, DSI, CSI-2) 01/10/2012 GOTO Aarhus 25

  43. 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) 01/10/2012 GOTO Aarhus 26

  44. Raspberry Pi Peripherals ● GPIO ● UART ● I2C ● I2S ● SPI ● PWM ● DSI ● CSI-2 01/10/2012 GOTO Aarhus 27

  45. The ErlBuggy! 01/10/2012 GOTO Aarhus 28

  46. ErlBuggy http://vimeo.com/48375416 01/10/2012 GOTO Aarhus 29

  47. Example: GPIO proc_a {state, high} pin17 01/10/2012 GOTO Aarhus 30

  48. Example: GPIO proc_a proc_b {state, high} {state, low} proc_c {state, high} pin17 01/10/2012 GOTO Aarhus 30

  49. Example: GPIO proc_a proc_b {state, high} {state, low} proc_c {state, high} pin17 ??? 01/10/2012 GOTO Aarhus 30

  50. Example: GPIO proc_a proc_b {state, 17, low} {state, 17, high} proc_c {state, 17, high} GPIO pin17 01/10/2012 GOTO Aarhus 31

  51. 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. 01/10/2012 GOTO Aarhus 32

  52. 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 01/10/2012 GOTO Aarhus 33

  53. Universal Peripheral/Component Modules Component API Universal Peripheral API Platform Specific Peripheral Implementation 01/10/2012 GOTO Aarhus 34

  54. Universal Peripheral/Component Modules An Example: Temperature Sensor with I2C Interface TMP102 Temperature Sensor Sensor API TMP102 Temperature Sensor TMP102 Temperature Sensor Sensor API Sensor API I2C Bus Driver I2C Bus Driver I2C Bus Driver I2C Bus Driver I2C Bus Driver I2C Bus Driver Linux Kernel Driver Linux Kernel Driver Linux Kernel Driver Linux sysfs BSD sysctl mmap()'ed register voodoo 01/10/2012 GOTO Aarhus 35

  55. TI OMAP Reference System 01/10/2012 GOTO Aarhus 36

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend