Embedded Operating Systems
Embedded Operating Systems
Embedded Operating Systems
7.1 Introduction
In the past, OSs for high-performance computing (HPC) were based on
custom-tailored solutions to fully exploit all performance opportunities of
supercomputers. Nowadays, instead, HPC systems are being moved away
from in-house OSs to more generic OS solutions like Linux. Such a trend
can be observed in the TOP500 list [1] that includes the 500 most powerful
supercomputers in the world, in which Linux dominates the competition.
In fact, in around 20 years, Linux has been capable of conquering all the
TOP500 list from scratch (for the first time in November 2017).
Each manufacturer, however, still implements specific changes to the
Linux OS to better exploit specific computer hardware features. This is
especially true in the case of computing nodes in which lightweight kernels
are used to speed up the computation.
173
174 Embedded Operating Systems
This chapter is structured as follows. Section 7.2 describes the state of the
art of the real-time support for the Linux OS and as well for small RTOSes.
Section 7.3 describes the requirements that influenced the choice of the
RTOS, which is described in detail in Section 7.4. Section 7.5 provides some
insights about the OS support for the host processor and for the many-core
processor. Finally, Section 7.6 summarizes the chapter.
approaches have been proposed in the last years to modify Linux in order to
make it more “real-time.” These approaches can be grouped in the following
classes [4]:
1. Hard real-time scheduling through a Hardware Abstraction Layer
(HAL);
2. Latency reduction through better preemption mechanisms and interrupt
handling;
3. Proper real-time scheduling policies.
The following subsections describe each approach in detail.
For these reasons, this approach is usually followed only to build hard real-
time systems with very tight requirements.
was non-existent or very low. Thus, they had enough time to create a
strong business built on top of popular and reliable products. Nowadays, the
market is full of commercial solutions, which differentiate in the applica-
tion domain (e.g., automotive, avionics, railway, etc.) and in the licensing
model. Most popular commercial RTOSs are: Windriver VxWorks [8], Green
Hills Integrity [18], QNX [19], SYSGO PikeOS [20], Mentor Graphics
Nucleus RTOS [21], LynuxWorks LynxOS [22], and Micrium µc/OS-III [23].
However, there are some other interesting commercial products like Segger
EmbOS [24], ENEA OSE [25], and Arccore Arctic core [26].
On the other hand, valid Open-Source alternatives exist. The development
of a completely free software tool chain being our target, the focus of this
subsection will be more on the free RTOSs available publicly. Some free
RTOSs, in fact, have now reached a level of maturity in terms of reliability
and popularity that can compete with commercial solutions. The Open-
Source licenses allow the modification of the source code and porting the
RTOS on the newest many-core architectures.
This section provides an overview of the free RTOSs available. For each
RTOS, the list of supported architectures, the level of maturity and the kind
of real-time support are briefly provided. Other information about existing
RTOSs can be found in [27].
FreeRTOS
FreeRTOS [28] is a small RTOS written in C. It provides threads, tasks,
mutexes, semaphores and software timers. A tick-less mode is provided for
low-power applications.
It supports several architectures, including ARM (ARM7/9, Cortex-A/M),
Altera Nios2, Atmel AVR and AVR32, Cortus, Cypress PSoC, Freescale
Coldfire and Kinetis, Infineon TriCore, Intel x86, Microchip dsPIC
and PIC18/24/32 and dsPIC, Renesas H8/S, SuperH, Fujitsu, Xilinx
Microblaze, etc.
It does not implement very advanced scheduling algorithms, but it offers
a classical preemptive or cooperative fixed-priority round-robin with priority
inheritance mutexes.
The RTOS is Open Source, and was initially distributed under a license
similar to GPL with linking exception [29]. Recently the FreeRTOS kernel
has been relicensed under the MIT license thanks to the collaboration with
Amazon AWS. A couple of commercial versions called SafeRTOS and
OpenRTOS are available as well. The typical footprint is between 5 KB
and 10 KB.
182 Embedded Operating Systems
Contiki
Contiki [30] is an Open-Source OS for networked, memory-constrained
systems with a particular focus on low-power Internet of things devices. It
supports about a dozen microcontrollers, even if the ARM architecture is not
included. The Open-Source license is BSD, which allows the usage of the OS
in commercial devices without releasing proprietary code.
Although several resources include Contiki in the list of free RTOSs,
Contiki is not a proper RTOS. The implementation is based on the concept
of protothreads, which are non-preemptible stack-less threads [31]. Context
switch can only take place on blocking operations, and does not preserve the
content of the stack (i.e., global variables must be used to maintain variables
across context switches).
Stack sharing is a useful feature, but the lack of preemptive support and
advanced scheduling mechanisms made this OS not suitable to meet the needs
of the parallel programming software framework we want to implement.
Marte OS
Marte OS [32] is a hard RTOS that follows the Minimal Real-Time POSIX.13
subset. It has been developed by the University of Cantabria. Although it
is claimed to be designed for the embedded domain, the only supported
platform is the x86 architecture. The development is discontinued, and the
latest contributions date back to June 2011.
FreeOSEK
FreeOSEK [34] is a minimal RTOS implementing the OSEK/VDX automo-
tive standard, like Erika Enterprise. The Open-Source license (GNU GPLv3
with linking exception) is similar to the one of Erika Enterprise too. However,
7.2 State of The Art 183
QP
Quantum platform (QP) [35] is a family of lightweight, open source soft-
ware frameworks developed by company Quantum Leaps. These frameworks
allow building modular real-time embedded applications as systems of coop-
erating, event-driven active objects (actors). In particular, QK (Quantum
Kernel) is a tiny preemptive non-blocking run-to-completion kernel designed
specifically for executing state machines in a run-to-completion (RTC)
fashion.
Quantum platform supports several microcontrollers, including ARM
Cortex-M, ARM 7/9/Cortex-M, Atmel AVR Mega and AVR32, Texas
Instruments MSP430/TMS320C28x/TMS320C55x, Renesas Rx600/R8C/H8,
Freescale Coldfire/68HC08, Altera Nios II, Microchip PIC24/dsPIC, and
Cypress PSoC1.
The software is released in dual licensing: an Open-Source and a com-
mercial license. The Open-Source license is GNU GPL v3, which requires
the release of the source code to any end user. Unfortunately, the Open-
Source license chosen is not suitable for consumer electronics, where
the companies want to keep the intellectual property of their application
software.
Trampoline
Trampoline [36] is an RTOS which aims at OSEK/VDX automotive certifi-
cation. However, unlike ERIKA Enterprise, it has not yet been certified.
Only the following architectures are supported: Cortex M, Cortex A7
(alone or with the Hypervisor XVisor), RISC-V, PowerPC 32 bits, AVR,
ARM 32 bit.
The Open-Source license at the time the evaluation was made was LGPL
v2.1. This license is not very suitable for consumer electronics because it
implies that any receiver of the binary (e.g., final user buying a product) must
be given access to the low-level and the possibility of relinking the application
towards a newer version of the RTOS. The license was changed afterwards to
GPL v2 in September 2015.
RTEMS
RTEMS [37] is a fully-featured Open-Source RTOS supporting several appli-
cation programming interfaces (APIs) such as POSIX and BSD sockets. It
184 Embedded Operating Systems
TinyOS
TinyOS [40] is an Open-Source OS specifically designed for low-power
wireless devices (e.g., sensor networks) and mainly used in research insti-
tutions. It has been designed for very resource-constrained devices, such as
microcontrollers with a few KB of RAM and a few tens of KB of code space.
It’s also been designed for devices that need to be very low power.
TinyOS programs are built out of software components, some of which
present hardware abstractions. Components are connected to each other
using interfaces. TinyOS provides interfaces and components for common
abstractions such as packet communication, routing, sensing, actuation, and
storage.
TinyOS cannot be considered a proper real-time OS, since it implements
a non-preemptive thread model.
The OS is licensed under BSD license which, like GPL with link-
ing exception, does not require redistribution of the source code of the
application.
TinyOS supports Texas Instruments MSP430, Atmel Atmega128, and
Intel px27ax families of microcontrollers. Currently, it does not support the
family of ARM Cortex processors. The development of TinyOS has been
discontinued since a few years.
ChibiOS/RT
ChibiOS/RT [41] is a compact and Open-Source RTOS. It is designed for
embedded real-time applications where execution efficiency and compact
code are important requirements. This RTOS is characterized by its high
portability, compact size and, mainly, by its architecture optimized for
extremely efficient context switching. It supports a preemptive thread model
but it does not support stack sharing among threads.
7.2 State of The Art 185
ERIKA Enterprise v2
Erika Enterprise v2 [43] is a minimal RTOS providing hard real-time guar-
antees. It is developed by partner Evidence Srl, but it is released for free.
The Open-Source license – GPL with linking exception (also known as
“Classpath”) [29] – is suitable for industrial usage because it allows linking
(even statically) the proprietary application code with the RTOS without the
need of releasing the source code.
The RTOS was born in 2002 to target the automotive market. During the
course of the years it has been certified OSEK/VDX and it is currently used
by either automotive companies (as Magneti Marelli and Cobra) or research
institutions. ERIKA Enterprise v2 implements the AUTOSAR API 4.0.3 as
well, up to Scalability Class 4.
Besides the very small footprint (about 2–4 KB), ERIKA Enterprise
has innovative features, like advanced scheduling algorithms (e.g., resource
reservation, immediate priority ceiling, etc.) and stack sharing to reduce
memory usage.
It supports several microcontrollers (from 8-bit to 32-bit) and it has been
one of the first RTOSs supporting multicore platforms (i.e., Altera NiosII).
The current list of supported architectures includes Atmel AVR and Atmega,
ARM 7 and Cortex-M, Altera NiosII, Freescale S12 and MPC, Infineon Aurix
and Tricore, Lattice Mico32, Microchip dsPIC and PIC32, Renesas RX200,
and TI MSP430. A preliminary support for ARM Cortex-A as well as the
integration with Linux on the same multicore chip has been shown during a
talk at the Automotive Linux Summit Fall [44] in October 2013.
186 Embedded Operating Systems
Version 3 of ERIKA Enterprise has also been released recently [45]. The
architecture of ERIKA Enterprise v3 has been directly derived as an evolution
of the work described in this chapter, and is aimed to support full AUTOSAR
OS compliance on various single and multi-/manycore platforms, including
support for hypervisors.
allocate and arbitrate the access to the system resources are thoroughly
documented and do not make use of any procedure that involves randomness
or based on non-deterministic parameters.
Task-to-thread and thread-to-core mapping: The allocation of the tasks to
the threads and the mapping of the threads to the cores must be documented;
ideally, it should also be static and known at design time. If the alloca-
tion is dynamic, i.e., computed at run-time, then the allocation/scheduling
algorithm should follow a set of deterministic (and fully documented) rules.
The knowledge of where and when the tasks execute considerably facilitates
the timing analysis process, as it allows for deriving an accurate utilization
profile of each resource and then uses those profiles to compute safe bounds
on the time it takes to access these resources.
Contract-based resource allocation scheme: Before executing, each appli-
cation or task has a “contract” with every system resource that it may need to
access. Each contract stipulates the minimum share of the system resource
(hardware and software) that the task must be allowed to use over time.
Considering a communication bus shared between several tasks, a TDMA
(Time Division Multiple Access) bus arbitration policy is a good example
of a contract-based allocation scheme: the number of time-slots dedicated to
each task in a time-frame of fixed length gives the minimum share of the bus
that is guaranteed to be granted to the task at run-time. When the resource
is a core, contract-based mechanisms are often referred to as reservation-
based scheduling. Before executing, an execution budget is assigned to every
task and a task can execute on a core only if its allocated budget is not
exhausted. Technically speaking, within such reservation-based mechanisms,
the scheduling algorithm of the OS does not schedule the execution of the
tasks as such, but rather it manages the associated budgets (i.e., empties
and replenishes them) and defines the order in which those budgets are
granted to the tasks. There are many advantages of using contract-based
mechanisms. For example, they provide a simple way of protecting the system
against a violation of the timing parameters. If a task fails and starts looping
infinitely, for instance, the task will eventually be interrupted once it runs out
of budget, without affecting the planned execution of the next tasks. These
budgets/contracts can be seen as fault containers. They guarantee a minimum
service to every task while enabling the system to identify potential task
failure and avoid propagating the potentially harmful consequences of a faulty
task through the execution of the other tasks.
190 Embedded Operating Systems
core’s linker scripts (see also [48]). Figure 7.2 shows the structure of the two
ELF files, highlighting the first core (master), which has everything defined,
and the subsequent slave cores, which have the shared symbols addresses
appended in the linker script.
The single-ELF approach required a complete restructuring of the binary
image. The complete system is compiled in a single binary image, and the
data structures are designed to let the cores access the relevant per-CPU
data. The main guidelines used when designing the data structures are the
following:
• All data is shared among all cores.
• The code must be able to know on which core it is running. This is done
typically using a special register of the architecture that holds the CPU
number.
• Given the CPU number, it is possible to access “private” data structures
to each core (see Figure 7.3). Note that those “private” data structures
can be allocated in special memory regions “near” each core (for exam-
ple, they could be allocated in sections which can be pinned to per-core
caches).
• Clear distinction between Flash Descriptor Blocks (named *DB) and
RAM Control Blocks (named *CB). In this way the reader has a clear
idea of the kind of content from the name of the data structure.
• Limited usage of pointers (used to point only from Flash to RAM), to
make the certification process easier.
Figure 7.2 Structure of the multicore images in the original ERIKA Enterprise structure.
196 Embedded Operating Systems
1
The footprint takes into account only kernel and support for the OpenMP runtime library;
it does not include the library itself.
2
128 = 44 (core data structures) + 84 (idle task).
7.5 Operating System Support 199
Table 7.4 Footprint comparison between ERIKA and NodeOS for a 16-core cluster
(expressed in bytes)
ERIKA New Version, Multicore
Description with Services for Supporting OpenMP NodeOS
Code footprint 44843 10060
RAM 2184 2196
3
The footprint takes into account only kernel and support for libgomp; it does not include
the whole libgomp library.
200 Embedded Operating Systems
7.6 Summary
This chapter illustrated the state of the art of the OSs suitable for the reference
parallel programming model. After reviewing the main requirements that
influenced the implementation, the selection of the RTOS for the reference
platform has been described for both the host processor and the manycore
accelerators. Furthermore, a description of the main implementation choices
for the ERIKA Enterprise v3 and Linux OS have been detailed. As can be
seen, the result of the implementation provides a complete system which is
capable of addressing high-performance workloads thanks to the synergies
between the general-purpose OS Linux and the ERIKA Enterprise RTOS.
References
[1] Top500, Linux OS. Available at: http://www.top500.org/statistics/details/
osfam/1
[2] RCU, available at: http://en.wikipedia.org/wiki/Read-copy-update
[3] GNU General Public License (GPL), available at: https://www.gnu.org/
copyleft/gpl.html
[4] Lipari, G., Scordino, C., Linux and Real-Time: Current Approaches
and Future Opportunities, International Congress ANIPLA, Rome, Italy,
2006.
[5] RTLinux, available at: http://en.wikipedia.org/wiki/RTLinux
[6] RTAI – the RealTime Application Interface for Linux, available at:
https://www.rtai.org/
[7] Xenomai, Real-Time Framework for Linux. Available at: http://www.
xenomai.org/
[8] Windriver, VxWorks RTOS. Available at: http://www.windriver.com/
products/vxworks/
[9] POSIX IEEE standard, available at: http://en.wikipedia. org/wiki/POSIX
[10] The Real Time Linux project, available at: https://wiki.linuxfoundation.
org/realtime/start
[11] The Linux Foundation, available at: https://www.linuxfoundation.org/
[12] Libenzi, D., SCHED SOFTRR Linux Scheduler Policy, available at:
http://xmailserver.org/linux-patches/softrr.html
[13] Kolivas, C., Isochronous class for unprivileged soft RT scheduling.
Available at: http://ck.kolivas.org/patches/
[14] SCHED DEADLINE Linux Patch, available at: http://en.wikipedia.org/
wiki/SCHED DEADLINE
References 201
[15] Lelli, J., Scordino, C., Abeni, L., Faggioli, D., Deadline scheduling in
the Linux kernel, Software: Practice and Experience, 46, pp. 821–839,
2016.
[16] ACTORS European Project, available at: http://www.actors-project.eu/
[17] Earliest Deadline First (EDF), available at: http://en.wikipedia.org/wiki/
Earliest deadline first scheduling
[18] Green Hills, Integrity RTOS. Available at: http://www.ghs.com/products/
rtos/integrity.html
[19] QNX RTOS, available at: http://www.qnx.com/
[20] SYSGO PikeOS, available at: http://www.sysgo.com/products/pikeos-
rtos-and-virtualization-concept/
[21] Mentor Graphics, Nucleus RTOS. Available at: http://www.mentor.com/
embedded-software/nucleus/
[22] LynuxWorks LynxOS, available at: http://www.lynuxworks.com/rtos/
[23] Micrium µc/OS-III, available at: http://micrium.com/
[24] Segger EmbOS, available at: http://www.segger.com/embos.html
[25] ENEA OSE, available at: http://www.enea.com/ose
[26] Arccore Arctic Core, available at: http://www.arccore.com/products/
[27] Wikipedia, List of Real-Time Operating Systems, available at: http://
en.wikipedia.org/wiki/List of real-time operating systems
[28] FreeRTOS, available at: http://www.freertos.org/
[29] GPL Linking Exception, available at: http://en.wikipedia.org/wiki/
GPL linking exception
[30] Contiki, available at: http://www.contiki-os.org/
[31] Wikipedia, Protothreads. Available at: http://en.wikipedia.org/wiki/
Protothreads
[32] Marte OS, available at: http://marte.unican.es/
[33] Ecos RTOS, available at: http://ecos.sourceware.org/
[34] FreeOSEK RTOS, available at: http://opensek.sourceforge.net/
[35] Quantum Leaps, QPT M Active Object Frameworks for Embedded
Systems, available at: http://www.state-machine.com/
[36] Trampoline RTOS, available at: http://trampoline.rts-software.org/
[37] RTEMS, available at: http://www.rtems.org/
[38] Footprint of RTEMS, available at: http://www.rtems.org/ml/rtems-
users/2004/september/msg00188.html
[39] Tiny RTEMS, available at: https://code.google.com/p/tiny-rtems/
[40] TinyOS, available at: http://www.tinyos.net/
[41] ChibiOS/RT, available at: http://www.chibios.org/
[42] Tivoization, available at: http://en.wikipedia.org/wiki/Tivoization
202 Embedded Operating Systems