3910583a3a42163e7ae8e15fa5815f8379a2ed4e
[phd-thesis.git] / top / finale.tex
1 \documentclass[../thesis.tex]{subfiles}
2
3 \input{subfilepreamble}
4
5 \begin{document}
6 \input{subfileprefix}
7 \chapter{Finale}%
8 \label{chp:finale}
9 \begin{chapterabstract}
10 \noindent This chapter wraps up the monograph by means of:
11 \begin{itemize}
12 \item a conclusion;
13 \item an outlook on future work;
14 \item an overview of the related work;
15 \item and a history of the \gls{MTASK} system.
16 \end{itemize}
17 \end{chapterabstract}
18
19 \section{Finale}
20 The \gls{MTASK} system is a proof-of-concept system, though fully functioning, for integrating \gls{IOT} edge devices in \gls{TOP}.
21 In conjunction with \gls{ITASK}, it is possible to program all layers of the \gls{IOT} from a single declarative specification.
22
23 Deep embedding.
24
25 \subsection{Future work}
26 There are many ways of extending the research on the \gls{MTASK} system that also concerns \gls{TOP} for resource constrained devices in general.
27
28 Edge devices may produce a lot of data and it is not always effective to send this data to the server for processing.
29 Leaving the produced data and computations on the edge device is called \emph{edge computing} \citep{shi_edge_2016}.
30 The \gls{MTASK} exhibits many properties of edge computing because it is possible to run entire workflows on the device.
31 However, it would be interesting to see how far this can be extended.
32 The \gls{MTASK} language is a high-level \gls{DSL} so it would be obvious to introduce abstractions for edge computations.
33 For example, add \gls{TOP} support for machine learning on the edge device using TinyML \citep{sanchez-iborra_tinyml-enabled_2020}.
34
35 Another recent advance in \gls{IOT} programming is intermittent computing.
36 Intermittent computing
37
38 Formal semantics
39
40 Automatic peripherals
41
42 Different architectures (FPGA?)
43
44 Mesh communication
45
46 \section{Related work}
47 The novelties of the \gls{MTASK} system can be compared to existing systems in several categories.
48 It is a interpreted (\cref{sec:related_int}) \gls{TOP} (\cref{sec:related_top}) \gls{DSL} (\cref{sec:related_dsl}) that may seem similar at first glance to \gls{FRP} (\cref{sec:related_frp}), it is implemented in a functional language (\cref{sec:related_fp}) and due to the execution semantics, multitasking is automatically supported (\cref{sec:related_multi}).
49 \Cref{sec_t4t:TiredvsTierless} contains an elaborate related work section regarding tierless systems in general.
50
51 \subsection{Interpretation}\label{sec:related_int}
52 There are a myriad of interpreted programming languages available for some of the bigger more powerful edge devices.
53 For example, for the popular ESP8266 chip there are ports of \gls{MICROPYTHON}, LUA, Basic, JavaScript and Lisp.
54 All of these languages, except the Lisp dialect uLisp (see \cref{sec:related_fp}), are imperative and do not support multiasking out of the box.
55 They lay pretty hefty constraints on the memory and as a result do not work on smaller microcontrollers.
56 Another interpretation solution for the tiniest devices is Firmata, a protocol for remotely controlling the microcontroller and using a server as the interpreter host \citep{steiner_firmata:_2009}.
57 \citet{grebe_haskino:_2016} wrapped this in a remote monad for integration with \gls{HASKELL} that allowed imperative code to be interpreted on the microprocessors.
58 Later this system was extended to support multithreading as well, stepping away from Firmata as the basis and using their own \gls{RTS} \citep{grebe_threading_2019}.
59 It differs from our approach because continuation points need to be defined by hand there is no automatic safe data communication.
60 \Citet{baccelli_reprogramming_2018} provide a single language \gls{IOT} system based on the RIOT \gls{OS} that allows runtime deployment of code snippets called containers.
61 Both client and server are written in JavaScript.
62 However, there is no integration between the client and the server other than that they are programmed from a single source.
63 Mat\`e is an example of an early tierless sensor network framework where devices are provided with a virtual machine using TinyOS for dynamic provisioning \citep{levis_mate_2002}.
64
65 \subsubsection{\texorpdfstring{\Glsxtrlongpl{DSL}}{DSLs} for microcontrollers}\label{sec:related_dsl}
66 Many \glspl{DSL} provide higher-level programming abstractions for microcontrollers, for example providing strong typing or memory safety.
67 For example Copilot \citep{hess_arduino-copilot_2020} and Ivory \citep{elliott_guilt_2015} are imperative \glspl{DSL} embedded in a functional language that compile to \ccpp{}.
68 \todo{uit\-brei\-den?}
69
70 \subsection{\texorpdfstring{\Glsxtrlong{FP}}{Functional programming}}\label{sec:related_fp}
71 \Citet{haenisch_case_2016} showed that there are major benefits to using functional languages for \gls{IOT} applications.
72 They showed that using function languages increased the security and maintainability of the applications.
73 Traditional implementations of general purpose functional languages have high memory requirements rendering them unusable for tiny computers.
74 There have been many efforts to create a general purpose functional language that does fit in small memory environments, albeit with some concessions.
75 For example, there has been a history of creating tiny Scheme implementations for specific microcontrollers.
76 It started with BIT \citep{dube_bit:_2000} that only required \qty{64}{\kibi\byte} of memory, followed by {PICBIT} \citep{feeley_picbit:_2003} and {PICOBIT} \citep{st-amour_picobit:_2009} that lowered the memory requirements even more.
77 \Citep{suchocki_microscheme:_2015} created Microscheme, a functional language targeting \gls{ARDUINO} compatible microcontrollers.
78 The {*BIT} languages all compile to assembly while Microscheme compiles to \gls{CPP}, heavily supported by \gls{CPP} lambdas available even on \gls{ARDUINO} AVR targets.
79 An interpreted Lisp implementation called uLisp also exists that runs on microcontrollers with as small as the \gls{ARDUINO} {UNO} \citep{johnson-davies_lisp_2020}.
80
81 \subsection{Multitasking}\label{sec:related_multi}
82 Applications for tiny computers are often parallel in nature.
83 Tasks like reading sensors, watching input devices, operating actuators and maintaining communication are often loosely dependent on each other and are preferably executed in parallel.
84 Microcontrollers often do not benefit from an \gls{OS} due to memory and processing constraints.
85 Therefore, writing multitasking applications in an imperative language is possible but the tasks have to be interleaved by hand \citep{feijs_multi-tasking_2013}.
86 This results in hard to maintain, error prone and unscalable spaghetti code.
87
88 There are many solutions to overcome this problem in imperative languages.
89 If the host language is a functional language (e.g.\ the aforementioned scheme variants) multitasking can be achieved without this burden relatively easy using continuation style multiprocessing \citep{wand_continuation-based_1980}.
90 Writing in this style is complicated and converting an existing program in this continuation passing style results in relatively large programs.
91 Furthermore, there is no built-in thread-safe communication possible between the tasks.
92 A \gls{TOP} or \gls{FRP} based language benefits even more because the programmer is not required to explicitly define continuation points.
93
94 Regular preemptive multithreading is too memory intensive for smaller microcontrollers and therefore not suitable.
95 Manual interleaving of imperative code can be automated to certain extents.
96 Solutions often require an \gls{RTOS}, have a high memory requirement, do not support local variables, no thread-safe shared memory, no composition or no events as described in \cref{tbl:multithreadingcompare}.
97 The table compares the solutions in the relevant categories with \gls{MTASK}.
98
99 \begin{table}[ht]
100 \begin{threeparttable}
101 \caption{%
102 An overview of imperative multithreading solutions for tiny computers with their relevant characteristics.
103 The characteristics are: sequential execution, local variable support, parallel composition, deterministic execution, bounded execution and safe shared memory (adapted from \citet[p.\ 12]{santanna_safe_2013}).
104 }\label{tbl:multithreadingcompare}
105 % \begin{tabular}{lc>{\columncolor[gray]{0.95}}cc>{\columncolor[gray]{0.95}}cc>{\columncolor[gray]{0.95}}cc}
106 \small
107 \begin{tabular}{lccccccc}
108 \toprule
109 \multicolumn{2}{c}{Language} & \multicolumn{3}{c}{Complexity} & \multicolumn{3}{c}{Safety}\\
110 \midrule
111 Name & Year & SeqCmp & LocVar & ParCmp & DetEx & BndEx & SafeMem\\
112 \midrule
113 Preemptive & many & \CIRCLE{} & \CIRCLE{} & \Circle{} & \Circle{} & rt & \Circle{}\\
114 nesC & 2003 & \Circle{} & \Circle{} & \Circle{} & \CIRCLE{} & async & \Circle{}\\
115 OSM & 2005 & \Circle{} & \CIRCLE{} & \CIRCLE{} & \Circle{} & \Circle{} & \Circle{}\\
116 Protothreads & 2006 & \CIRCLE{} & \Circle{} & \Circle{} & \CIRCLE{} & \Circle{} & \Circle{}\\
117 TinyThreads & 2006 & \CIRCLE{} & \CIRCLE{} & \Circle{} & \CIRCLE{} & \Circle{} & \Circle{}\\
118 Sol & 2007 & \CIRCLE{} & \CIRCLE{} & \CIRCLE{} & \CIRCLE{} & \Circle{} & \Circle{}\\
119 FlowTask & 2011 & \CIRCLE{} & \CIRCLE{} & \Circle{} & \Circle{} & \Circle{} & \Circle{}\\
120 Ocram & 2013 & \CIRCLE{} & \CIRCLE{} & \Circle{} & \CIRCLE{} & \Circle{} & \Circle{}\\
121 C\'eu & 2013 & \CIRCLE{} & \CIRCLE{} & \CIRCLE{} & \CIRCLE{} & \CIRCLE{} & \CIRCLE{}\\
122 \Gls{MTASK} & 2022 & \CIRCLE{} & \CIRCLE{} & \CIRCLE{} & \CIRCLE{} & \LEFTcircle{}\tnote{1} & \LEFTcircle{}\tnote{2}\\
123 \bottomrule
124 \end{tabular}
125 \begin{tablenotes}
126 \item [1] Only for tasks, not for expressions.
127 \item [2] Using \glspl{SDS}.
128 \end{tablenotes}
129 \end{threeparttable}
130 \end{table}
131
132 \subsection{\texorpdfstring{\Glsxtrlong{FRP}}{Functional reactive programming}}\label{sec:related_frp}
133 The \gls{TOP} paradigm is often compared to \gls{FRP} and while they appear to be similar---they are both event driven---in fact they are very different.
134 \Gls{FRP} was introduced by \citet{elliott_functional_1997}.
135 The paradigm strives to make modelling systems safer, more efficient, composable.
136 The core concepts are behaviours and events.
137 A behaviour is a value that varies over time.
138 Events are happenings in the real world and can trigger behaviours.
139 Events and behaviours may be combined using combinators.
140 \Gls{TOP} allows for more complex collaboration patterns than \gls{FRP} \citep{wang_maintaining_2018}, and in consequence is unable to provide the strong guarantees on memory usage available in a restricted variant of \gls{FRP} such as arrowized \gls{FRP} \citep{nilsson_functional_2002}.
141
142 The way \gls{FRP}, and for that matter \gls{TOP}, systems are programmed stays close to the design when the domain matches suits the paradigm.
143 The \gls{IOT} domain seems to suit this style of programming very well in just the device layer but also for entire \gls{IOT} systems.
144
145 For example, Potato is an \gls{FRP} language for building entire \gls{IOT} systems using powerful devices such as the Raspberry Pi leveraging the Erlang \gls{VM} \citep{troyer_building_2018}.
146 It requires client devices to be able to run the Erlang \gls{VM} which makes it unsuitable for low memory environments.
147
148 The emfrp language compiles a \gls{FRP} specification for a microcontroller to \gls{C} code \citep{sawada_emfrp:_2016}.
149 The \gls{IO} part, the bodies of some functions, still need to be implemented.
150 These \gls{IO} functions can then be used as signals and combined as in any \gls{FRP} language.
151 Due to the compilation to \gls{C} it is possible to run emfrp programs on tiny computers.
152 However, the tasks are not interpreted and there is no communication with a server.
153
154 Other examples are mfrp \citep{sawada_emfrp:_2016}, CFRP \citep{suzuki_cfrp_2017}, XFRP \citep{10.1145/3281366.3281370}, Juniper \citep{helbling_juniper:_2016}, Hailstorm \citep{sarkar_hailstorm_2020}, Haski \citep{valliappan_towards_2020}, arduino-copilot \citep{hess_arduino-copilot_2020}.
155
156 \subsection{\texorpdfstring{\Glsxtrlong{TOP}}{Task-oriented programming}}\label{sec:related_top}
157 \Gls{TOP} as a paradigm with has been proven to be effective for implementing distributed, multi-user applications in many domains.
158 Examples are conference management \citep{plasmeijer_conference_2006}, coastal protection \citep{lijnse_capturing_2011}, incident coordination \citep{lijnse_incidone:_2012}, crisis management \citep{jansen_towards_2010} and telemedicine \citep{van_der_heijden_managing_2011}.
159 In general, \gls{TOP} results in a higher maintainability, a high separation of concerns and more effective handling of interruptions of workflow.
160 \Gls{IOT} applications contain a distributed and multi-user component, but the software on the device is mostly follows multiple loosely dependent workflows.
161 The only other \gls{TOP} language for embedded systems is $\mu$Tasks \citep{piers_task-oriented_2016}.
162 It is a non-distributed \gls{TOP} \gls{EDSL} hosted in \gls{HASKELL} designed for embedded systems such as payment terminals.
163 They showed that applications tend to be able to cope well with interruptions and be more maintainable.
164 However, the hardware requirements for running the standard \gls{HASKELL} system are high.
165
166 \section{History of \texorpdfstring{\gls{MTASK}}{mTask}}
167 The development of \gls{MTASK} or its predecessors has been going on for almost seven years now though it really set off during my master's thesis.
168 This section provides an exhaustive overview of the work on \gls{MTASK} and its predecessors.
169
170 \subsection{Generating \texorpdfstring{\ccpp{}}{\ccpp{}} code}
171 A first throw at a class-based shallowly \gls{EDSL} for microcontrollers was made by \citet{plasmeijer_shallow_2016}.
172 The language was called \gls{ARDSL} and offered a type safe interface to \gls{ARDUINO} \gls{CPP} dialect.
173 A \gls{CPP} code generation backend was available together with an \gls{ITASK} simulation backend.
174 There was no support for tasks nor even functions.
175 Some time later in the 2015 \gls{CEFP} summer school, an extended version was created that allowed the creation of imperative tasks, local \glspl{SDS} and the usage of functions \citep{koopman_type-safe_2019}.
176 The name then changed from \gls{ARDSL} to \gls{MTASK}.
177
178 \subsection{Integration with \texorpdfstring{\gls{ITASK}}{iTask}}
179 \Citet{lubbers_task_2017} extended this in his Master's Thesis by adding integration with \gls{ITASK} and a bytecode compiler to the language.
180 \Gls{SDS} in \gls{MTASK} could be accessed on the \gls{ITASK} server.
181 In this way, entire \gls{IOT} systems could be programmed from a single source.
182 However, this version used a simplified version of \gls{MTASK} without functions.
183 This was later improved upon by creating a simplified interface where \glspl{SDS} from \gls{ITASK} could be used in \gls{MTASK} and the other way around \citep{lubbers_task_2018}.
184 It was shown by \citet{amazonas_cabral_de_andrade_developing_2018} that it was possible to build real-life \gls{IOT} systems with this integration.
185 Moreover, a course on the \gls{MTASK} simulator was provided at the 2018 \gls{CEFP}\slash\gls{3COWS} winter school in Ko\v{s}ice, Slovakia \citep{koopman_simulation_2018}.
186
187 \subsection{Transition to \texorpdfstring{\gls{TOP}}{TOP}}
188 The \gls{MTASK} language as it is now was introduced in 2018 \citep{koopman_task-based_2018}.
189 This paper updated the language to support functions, simple tasks, and \glspl{SDS} but still compiled to \gls{ARDUINO} \gls{CPP} code.
190 Later the byte code compiler and \gls{ITASK} integration was added to the language \citep{lubbers_interpreting_2019}.
191 Moreover, it was shown that it is very intuitive to write microcontroller applications in a \gls{TOP} language \citep{lubbers_multitasking_2019}.
192 One reason for this is that a lot of design patterns that are difficult using standard means are for free in \gls{TOP} (e.g.\ multithreading).
193 In 2019, the \gls{CEFP}\slash\gls{3COWS} summer school in Budapest, Hungary hosted a course on developing \gls{IOT} applications with \gls{MTASK} as well \citep{lubbers_writing_2019}.
194
195 \subsection{\texorpdfstring{\Glsxtrshort{TOP}}{TOP}}
196 In 2022, the SusTrainable summer school in Rijeka, Croatia hosted a course on developing greener \gls{IOT} applications using \gls{MTASK} as well \citep{lubbers_green_2022}.
197 Several students worked on extending \gls{MTASK} with many useful features:
198 \Citet{van_der_veen_mutable_2020} did preliminary work on a green computing analysis, built a simulator, and explored the possibilities for adding bounded datatypes; \citet{de_boer_secure_2020} investigated the possibilities for secure communication channels; \citeauthor{crooijmans_reducing_2021} \citeyearpar{crooijmans_reducing_2021,crooijmans_reducing_2022} added abstractions for low-power operation to \gls{MTASK} such as hardware interrupts and power efficient scheduling; and \citet{antonova_mtask_2022} defined a preliminary formal semantics for a subset of \gls{MTASK}.
199 In 2023, the SusTrainable summer school in Coimbra, Portugal will host a course on \gls{MTASK} as well.
200
201 \subsection{\texorpdfstring{\gls{MTASK}}{mTask} in practise}
202 Funded by the Radboud-Glasgow Collaboration Fund, collaborative work was executed with Phil Trinder, Jeremy Singer, and Adrian Ravi Kishore Ramsingh.
203 An existing smart campus application was developed using \gls{MTASK} and quantitatively and qualitatively compared to the original application that was developed using a traditional \gls{IOT} stack \citep{lubbers_tiered_2020}.
204 This research was later extended to include a four-way comparison: \gls{PYTHON}, \gls{MICROPYTHON}, \gls{ITASK}, and \gls{MTASK} \citep{lubbers_could_2022}.
205 Currently, power efficiency behaviour of traditional versus \gls{TOP} \gls{IOT} stacks is being compared as well adding a \gls{FREERTOS}, and an elixer/potato implementation to the mix as well.
206
207 \input{subfilepostamble}
208 \end{document}