The Actor Model applied to the Raspberry Pi and the Embedded Domain
.
The Erlang Embedded Project Omer Kilic || @OmerK
- mer@erlang-solutions.com
Raspberry Pi and the Embedded Domain . The Erlang Embedded Project - - PowerPoint PPT Presentation
The Actor Model applied to the Raspberry Pi and the Embedded Domain . The Erlang Embedded Project Omer Kilic || @OmerK omer@erlang-solutions.com Outline Current state of Embedded Systems Overview of Erlang and the Actor Model
The Actor Model applied to the Raspberry Pi and the Embedded Domain
.
The Erlang Embedded Project Omer Kilic || @OmerK
Slide 2 of 49
11/04/2013 GOTO Zurich 2013
Slide 3 of 49
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.
11/04/2013 GOTO Zurich 2013
Slide 4 of 49
11/04/2013 GOTO Zurich 2013
functions
application
any computing needs
Slide 5 of 49
– Connected and distributed systems
– The Kickstarter Era – Rapid prototyping – Maker Culture
11/04/2013 GOTO Zurich 2013
Slide 6 of 49
11/04/2013 GOTO Zurich 2013
Slide 7 of 49
11/04/2013 GOTO Zurich 2013
Slide 8 of 49
11/04/2013 GOTO Zurich 2013
Slide 9 of 49
11/04/2013 GOTO Zurich 2013
Slide 10 of 49
11/04/2013 GOTO Zurich 2013
Slide 11 of 49
11/04/2013 GOTO Zurich 2013
Slide 12 of 49
– No underlying OS or high level abstractions
– Minimal interrupt and switching latency, scheduling guarantees, minimal jitter
– Slimmed down Linux with hardware interfaces
11/04/2013 GOTO Zurich 2013
Slide 13 of 49
– Shared memory
– Pre-emptive: event driven – Round-robin: time multiplexed
11/04/2013 GOTO Zurich 2013
Slide 14 of 49
to abundant supply of cheap boards
– Raspberry Pi, Beagleboard/Beaglebone, Gumstix et al.
new territory for embedded engineers
– No direct mapping for RTOS concepts, especially tasks
– Here be dragons
11/04/2013 GOTO Zurich 2013
Slide 15 of 49
Source: http://embedded.com/electronics-blogs/programming-pointers/4372180/Unexpected-trends
11/04/2013 GOTO Zurich 2013
Slide 16 of 49
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.
11/04/2013 GOTO Zurich 2013
Slide 17 of 49
11/04/2013 GOTO Zurich 2013
Slide 18 of 49
– Open-sourced in 1998.
companies
– Originally designed for Embedded Systems!
– Support for concurrency and distributed systems
11/04/2013 GOTO Zurich 2013
Slide 19 of 49
constraints
– Nine 9s availability
supervision hierarchies
– Isolation provided by Actors
– Hot code loading
11/04/2013 GOTO Zurich 2013
Slide 20 of 49
– “Universal primitives for concurrent computation”
concurrent systems
languages
11/04/2013 GOTO Zurich 2013
Slide 21 of 49
– Messages kept in a mailbox and processed in the
– Make local decisions and change internal state – Spawn new actors – Send messages to other actors
11/04/2013 GOTO Zurich 2013
Slide 22 of 49
– Specific to language and library implementation
problematic for certain applications
– Ordering of messages received from multiple processes – Abstract definition may lead to inconsistency in larger systems
11/04/2013 GOTO Zurich 2013
Slide 23 of 49
spawn(math, fact, [5])
11/04/2013 GOTO Zurich 2013
Pid1 Pid2
math:fact(5)
Slide 24 of 49
11/04/2013 GOTO Zurich 2013
{Pid1, msg}
Pid1 Pid2
Pid2 ! {msg, data}
Slide 25 of 49
11/04/2013 GOTO Zurich 2013
Pid1 Pid2
link(Pid2)
Slide 26 of 49
11/04/2013 GOTO Zurich 2013
PidA PidB PidC {'EXIT', PidA, Reason} {'EXIT', PidB, Reason}
Slide 27 of 49
11/04/2013 GOTO Zurich 2013
PidA PidB PidC {'EXIT', PidA, Reason}
process_flag(trap_exit, true)
Slide 28 of 49
– Abstract error handling away from the modules
11/04/2013 GOTO Zurich 2013
Slide 29 of 49
– Application code becomes simpler – Concise and shorter modules – Testing becomes easier – Code re-use (potentially) increases
– Architecting fine grain systems is difficult
11/04/2013 GOTO Zurich 2013
Slide 30 of 49
11/04/2013 GOTO Zurich 2013
Slide 31 of 49
(flickr/dereckesanches)
11/04/2013 GOTO Zurich 2013
Slide 32 of 49
UK registered charity.
the study of computer science and related topics, especially at school level, and to put the fun back into learning computing."
Future Engineers/Programmers!
11/04/2013 GOTO Zurich 2013
(flickr/lebeus)
Slide 33 of 49
11/04/2013 GOTO Zurich 2013
Slide 34 of 49
abstractions in the embedded domain
11/04/2013 GOTO Zurich 2013
Slide 35 of 49
– Faster, needs root, potentially dangerous!
– Slower, doesn’t need root, easier, relatively safer
11/04/2013 GOTO Zurich 2013
Slide 36 of 49
init(Pin, Direction) -> {ok, FdExport} = file:open("/sys/class/gpio/export", [write]), file:write(FdExport, integer_to_list(Pin)), file:close(FdExport), {ok, FdPinDir} = file:open("/sys/class/gpio/gpio" ++ integer_to_list(Pin) ++ "/direction", [write]), case Direction of in -> file:write(FdPinDir, "in");
end, file:close(FdPinDir), {ok, FdPinVal} = file:open("/sys/class/gpio/gpio" ++ integer_to_list(Pin) ++ "/value", [read, write]), FdPinVal.
11/04/2013 GOTO Zurich 2013
Slide 37 of 49
write(Fd, Val) -> file:position(Fd, 0), file:write(Fd, integer_to_list(Val)). read(Fd) -> file:position(Fd, 0), {ok, Val} = file:read(Fd, 1), Val. release(Pin) -> {ok, FdUnexport} = file:open("/sys/class/gpio/unexport", [write]), file:write(FdUnexport, integer_to_list(Pin)), file:close(FdUnexport).
11/04/2013 GOTO Zurich 2013
Slide 38 of 49
11/04/2013 GOTO Zurich 2013
PidA Pin17 PidB PidC
Slide 39 of 49
11/04/2013 GOTO Zurich 2013
PidA Pin17 PidB PidC GPIO Proxy
Slide 40 of 49
embedded design
– Access control/mutual exclusion
– Toggling rate, sequence detection, direction control, etc.
11/04/2013 GOTO Zurich 2013
Slide 41 of 49
11/04/2013 GOTO Zurich 2013
Slide 42 of 49
Universal Peripheral/Component Modules
11/04/2013 GOTO Zurich 2013
Slide 43 of 49
Universal Peripheral/Component Modules
11/04/2013 GOTO Zurich 2013
Slide 44 of 49
11/04/2013 GOTO Zurich 2013
Slide 45 of 49
11/04/2013 GOTO Zurich 2013
Slide 46 of 49
11/04/2013 GOTO Zurich 2013
Slide 47 of 49
Parallella:
11/04/2013 GOTO Zurich 2013
Slide 48 of 49
https://www.erlang-solutions.com/downloads/download-erlang-otp
11/04/2013 GOTO Zurich 2013
Slide 49 of 49
11/04/2013 GOTO Zurich 2013
The world is concurrent. Things in the world don't share data. Things communicate with messages. Things fail.
Father of Erlang