You are on page 1of 16

..........................................................................................................................................................................................................................

REAL-TIME OPERATING SYSTEMS


FOR SMALL MICROCONTROLLERS
..........................................................................................................................................................................................................................
REAL-TIME OPERATING SYSTEMS HAVE GAINED POPULARITY IN MICROCONTROLLER- AND

PROCESSOR-BASED EMBEDDED SYSTEM DESIGN. THIS ARTICLE DISCUSSES DIFFERENCES

BETWEEN RTOSS AND GENERIC OPERATING SYSTEMS, THE ADVANTAGES AND

DISADVANTAGES OF USING RTOSS FOR SMALL MICROCONTROLLER SYSTEM DEVELOPMENT,

AND THE BENCHMARKING METHODS USED FOR RTOSS. BENCHMARKING RESULTS FOR

FOUR RTOSS SHOW NO CLEAR WINNER, WITH EACH RTOS PERFORMING BETTER ON SOME

CRITERIA THAN OTHERS.

...... Real-time embedded systems


serve various purposes, such as to control
First, RTOSs offer preemptive, priority-
based scheduling. A scheduling scheme refers
or process data. A real-time operating system to how the RTOS assigns CPU cycles to
is a piece of software with a set of APIs that tasks for execution. Thus, scheduling
developers can use to build applications. schemes affect how the operating system
RTOSs support the need of some embedded will execute the various software programs.
systems to meet deadlines. However, using Most generic operating systems are time-
Tran Nguyen an RTOS doesn’t guarantee that a system sharing systems, which allocate tasks the
will always meet the deadlines, because same number of time slices for execution
Bao Anh these systems also depend on the overall sys- (for example, by round-robin scheduling).
tem’s design. RTOSs often assign tasks priorities, and
Singapore Engineering Although RTOSs for embedded systems higher-priority tasks can preempt lower-
are predominantly used in high-end micro- priority tasks during execution (preemptive
Center processors or microcontrollers with 32-bit scheduling). Other RTOSs adopt coopera-
CPUs, there is a growing trend to provide tive scheduling, which usually implies that
Su-Lim Tan these features in mid-range (16-bit and the running task must explicitly invoke the
8-bit) processor systems. scheduler to switch between tasks.
Nanyang Technological In addition, RTOSs allow predictable
task synchronization. In generic operating
University Generic operating systems versus RTOSs systems, task synchronization is unpredict-
Operating systems manage resource shar- able because the operating system can di-
ing in computer systems. Unlike generic rectly or indirectly introduce delays into the
operating systems, an RTOS is specifically application software. In an RTOS, task syn-
designed to achieve real-time responses. chronization must be time-predictable. The
RTOS differ from generic operating systems system services must have a known and
in several other ways as well. expected duration of execution time.
..............................................................

30 Published by the IEEE Computer Society 


0272-1732/09/$26.00 c 2009 IEEE
The key difference between generic oper- can lead to bugs and software safety issues,
ating systems and RTOSs is that an RTOS especially in highly interrupt-driven systems
supports deterministic behaviors. In an (see the Embedded System Design 2006 survey
RTOS, task dispatch time, task switch la- at http://www.embedded.com/columns/
tency, and interrupt latency must be time- survey). Because these global variables are
predictable and consistent even when the often shared and accessed among functions,
number of tasks increases. In contrast, ge- they’re highly vulnerable to corruption dur-
neric operating systems (mainly owing to ing program execution. As the code begins
their time-sharing approach) reduce a sys- to grow, these bugs are more deeply hidden
tem’s overall responsiveness and don’t guar- and thus more difficult to uncover. Conse-
antee service call execution within a certain quently, development time can lengthen
amount of time when the number of tasks even for such small-scale systems. With an
increases. Dynamic memory allocation RTOS in place, tasks can safely pass messages
(malloc() in C language), although widely or synchronize with each other without cor-
supported in generic operating systems, ruption problems.
isn’t recommended in RTOSs because it Most RTOSs provide APIs that let devel-
generates unpredictable behavior.1 Instead, opers manage system resources to establish
RTOSs provide fixed-size memory allocation functions including task management, mem-
in which they allocate only a fixed-size mem- ory pool management, time management,
ory block for every request. interrupt management, communication,
and synchronization. RTOSs provide the ab-
RTOSs for small-scale embedded systems straction layer for developers to freely struc-
Available RTOSs include commercial, ture the software, to achieve cleaner code,
proprietary, and open source systems. Many and even to quickly port across different
system designers believe that small-scale hardware platforms with few code modifica-
embedded systems designed using small tions. In small system development in partic-
microcontrollers (that is, microcontrollers ular, hardware cost is a critical constraint and
with a maximum ROM of 128 Kbytes and development time is usually short.
maximum RAM of 4 Kbytes2) don’t need Time management functions let software
an RTOS. However, RTOSs offer significant designers achieve task delay, timer handling,
advantages for this range of devices.2,3 or time-triggered processing without having
For example, developers can use an to understand the underlying hardware
RTOS to optimize software development. mechanisms. Achieving timing-related fea-
In system development using small micro- tures in a small system with no RTOS can
controllers, software productivity is a critical be tricky because the software designer
issue because of time-to-market pressures as must understand the underlying peripherals
well as a shortened development cycle (see (such as timers), how to use them, and
the Embedded System Design 2004 survey at how to link them with the top-level applica-
http://www.embedded.com/columns/survey). tion code. Any modification, such as a longer
For projects involving complex code, an delay time, would require the developer to
RTOS is an efficient tool to manage the soft- re-examine the code and peripherals to
ware and to distribute tasks among develop- make changes appropriately. To port the
ers. Using an RTOS lets project leaders software to another platform using a differ-
partition the entire software into modular ent microcontroller with a different set of
tasks that individual programmers can han- peripherals, the developer must rewrite
dle. Moreover, other developers can develop these timing features. Unless the project
the low-level drivers. involves a critical timing issue with a unique
An RTOS also provides better and safer hardware peripheral, using an RTOS can
synchronization. In small embedded system help significantly speed up the development
development without an RTOS, developers time required to tackle these timing issues.
often use global variables for synchronization Ganssle illustrates the importance of
and communication among modules and RTOSs in small system design using a printer
functions. However, using global variables system example.3 Without an RTOS, the
....................................................................

SEPTEMBER/OCTOBER 2009 31
...............................................................................................................................................................................................
REAL-TIME OPERATING SYSTEMS

projects. (Results from the 2004—2006 sur-


Don’t know Don’t know
12%
veys are available at http://www.embedded.
2%
com/columns/survey.) In 2004, more than
No 49 percent of developers said they had used
No Yes 21% Yes an RTOS. This percentage rose to 80.9 per-
49% 49% 67% cent in the 2005 survey, and was 71 percent
in the 2006 survey. The percentage of devel-
opers who would consider using an RTOS in
(a) (b) an upcoming project was 66.6 in 2004 and
86 in 2005, indicating a steady trend toward
Figure 1. RTOS usage as reported in the 2004 Embedded Systems Design using RTOSs.
embedded market survey (http://www.embedded.com/columns/survey): Table 1, which shows results from the
have used (a) and would consider using (b). (Copyright 2009 TechInsights. 2006 Embedded System Design embedded
Used with permission.) market survey, suggests another trend in
RTOS selection. Companies are moving to-
ward open source RTOSs—from 16 percent
in current projects to 19 percent in upcom-
Table 1. Results from the 2006 Embedded System Design
ing projects; and toward commercial distri-
survey on the types of operating systems used
butions of open source RTOSs—from
(http://www.embedded.com/columns/survey).
12 percent in current projects to 17 percent
Type of Current project Upcoming project in upcoming projects. Use of commercial
operating system (%) (%) and in-house systems, although currently ex-
tensive, is declining—from 51 percent in
Commercial operating 51 47
current projects to 47 percent in upcoming
system
projects for commercial operating systems,
Internally developed or 21 17
and from 21 to 17 percent for in-house oper-
in-house operating
ating systems. In the 2007 survey, commer-
system
cial operating system use drops further, to
Open source operating 16 19
41 percent.4 The 2007 survey also shows
system without
that the key influencing factors in RTOS se-
commercial support
lection for commercial operating systems are
Commercial distribution 12 17
the quality and availability of technical sup-
of an open source
port. If adequate technical support is unavail-
operating system
....................................................................................................... able, companies might look for other, more
(Copyright 2009 TechInsights. Used with permission.) cost-effective choices.
RTOSs also have some disadvantages
system uses a single chunk of code to manage when used for small microcontrollers. Be-
all printer activities—paper feeding, user- cause an RTOS consumes additional mem-
input reading, and printing controls. An ory (both ROM and RAM), computational
RTOS lets individual tasks manage each of resources, and power,5 system designers
these activities. Except for passing status in- must determine whether the system can ab-
formation, each task doesn’t need to know sorb these overheads. For small microcon-
much about what other tasks are performing. trollers, the RTOS must have compact
Hence, having an RTOS in place can help in ROM and RAM requirements. Various
partitioning the software in the time domain RTOSs are available for these devices, and
(for tasks to run concurrently) and in terms some are flexible enough that designers can
of functionalities (for each task to perform configure them to have only those functions
a specific operation). and APIs that the application requires,2,6-8
Figure 1 shows results from the 2004 thus allowing a smaller code size. In addi-
Embedded Systems Design embedded market tion, most RTOSs require a periodic timer
survey on the number of developers who (an operating system ‘‘tick’’)9 to execute the
have used and would consider using an scheduler and other relevant system services.
RTOS in their current and upcoming RTOS services such as task synchronization
....................................................................

32 IEEE MICRO
must have a known execution time (that is, task via a semaphore. In this case, using a
the amount of time it takes for a task semaphore doesn’t seem to be the best
switch to occur). Depending on these tim- approach. Waking up the task directly
ing factors, and by making use of the rele- using a system service call (such as a sleep/
vant RTOS services, the system designer wakeup service call) is a better approach to
can decide on the API suite and structure reduce the overhead delay.
the whole system. Hence, designers must Other researchers have proposed tests for
understand the performance measurements measuring message transfer duration and
and benchmarking metrics among RTOSs. communication through a pipe, the speed
of task synchronization through proxy and
RTOS benchmarking signal, and task-switching duration.12 These
Most RTOS benchmarking approaches metrics are based only on the RTOS plat-
are based on applications or on the most fre- form distributed by QNX; some concepts,
quently used system services (fine-grained such as proxy and signal, don’t exist on
benchmarking).10 Because applications have most RTOSs.
different requirements, benchmarking against
a generic application won’t reflect an RTOS features and API comparison
RTOS’s strengths and weaknesses. Bench- We based our RTOS comparisons on
marking methods based on frequently used online documentation and APIs. We exam-
system services include the Rhealstone bench- ined the following systems: mITRON,2,13
mark, which measures task switch time, pre- mTKernel,7 mC-OS/II,6 EmbOS,14 Free-
emption time, interrupt latency time, RTOS,8 Salvo (http://www.pumpkininc.
semaphore shuffling time, deadlock breaking com), TinyOS (http://www.tinyos.net),
time, and datagram throughput time.11 How- SharcOS (http://www.sharcotech.com), eX-
ever, Rhealstone is unsuitable for RTOS treme Minimal Kernel (XMK, http://www.
benchmarking for several reasons. First, few shift-right.com/xmk/index.html), Echidna
RTOSs can break deadlock (as we discuss (http://www.ece.umd.edu/serts/research/
later). Datagram throughput time is based echidna/index.shtml), eCOS, 15 Erika, 16
on message passing, in which the RTOS cop- Hartik, 17 KeilOS (http://www.keil.com/
ies messages to a memory area managed by rtos), and PortOS.18
the operating system. However, not all
RTOSs use the same message-passing Criteria for comparing RTOSs
approach. Some RTOSs only pass the mem- Developers base their choice of an RTOS
ory pointer, so there’s no need to use the spe- on criteria such as language support, tool
cial memory area managed by the operating compatibility, system service APIs, memory
system. This approach is more suitable for footprint (ROM and RAM usage), perfor-
small microcontrollers, which have no extra mance, device drivers, operating system
memory for operating system internal use. In- awareness, debugging tools, technical sup-
terrupt latency time in Rhealstone isn’t deter- port, source and object code distribution,
mined by the RTOS; rather, it depends licensing scheme, and vendor reputation.19
purely on the CPU architecture. Rhealstone They might also consider installation
is generally somewhat ad hoc and doesn’t and configuration, RTOS architecture,
cover other common situations in real-time API richness, documentation and support,
applications.10 and tool support.20 As Figure 2 shows,
Garcia-Martinez et al. propose several the Embedded System Design 2005—2007
metrics based on frequently used system ser- embedded market surveys found that real-
vices: response to external events (interrupt), time capability is the top criteria for
intertask synchronization and resource shar- RTOS selection.4
ing, and intertask data transfer (message pass- We used these documents to establish a
ing).10 Intertask data transfer is similar to list of criteria for comparing the RTOSs,
Rhealstone’s datagram throughput time. In which we describe in the following sections.
the ‘‘response to external event (interrupt)’’ This article’s scope limits the number and
test, the interrupt handler wakes another type of criteria we could consider. Criteria
....................................................................

SEPTEMBER/OCTOBER 2009 33
...............................................................................................................................................................................................
REAL-TIME OPERATING SYSTEMS

70
2007 (N = 325)

2006 (N = 447)
61
59
60 2005 (N = 441)
58

52
50 49
50
46
45
Influence (percent) 43 43 43
41
40
40
38 37 37
36
35
34
31 32
3130 30 30 29
30 28 28
27

20

14

10

0
y

st

e
or
lit

ol

ilit

lit
tio

io

fre

ag
co
pp
bi

bi
to

at
tib

ta

us
ty
pa

pa
ll

ut
e
su

en
pa

ra

al
ar

ep

y
ca

ca
ve

oy
um

or
m
al

ftw

’r

em
ic

co

R
e

ng
oc

rs
so
m

hn

ki

lie

/m
e
-ti

D
c

ar

or

pp
al

Te

ze
oo

dw

w
Re

si
Su
et
G

ar

e
rh

od
ro

C
so
es
oc
Pr

Figure 2. Influential factors in operating system selection according to Embedded Systems


Design embedded market surveys in 2005, 2006, and 2007 (http://www.embedded.com/
columns/survey). The total number of people surveyed is N ¼ 441. (Copyright 2009
TechInsights. Used with permission.)

such as suppliers’ reputation and company Design objective. RTOSs can be open source,
reputation are subjective; overall cost personal hobby based, or commercial. A de-
depends on the project and application; roy- signer should understand an RTOS’s his-
alty fee is normally based on quantity, even tory and the motivation that led to its
though RTOS vendors might use other busi- creation. A personal hobby-based RTOS
ness models to charge their customers (such will likely be less stable than a popular
as per application, product model, or micro- open source or commercial RTOS.
controller unit [MCU] model); and memory
footprint might be unavailable and de- Author. A designer should also know who
pends on the compiler settings and RTOS originated the RTOS—whether it was a
configurations. person or an organization.
....................................................................

34 IEEE MICRO
Scheduling scheme. It’s also important to in- License type. This criterion determines how
vestigate the RTOS’s scheduling approach the RTOS is distributed: free or fee-based
to determine whether it uses preemptive and for purposes such as educational or
scheduling, cooperative scheduling, or commercial.
some other scheduling scheme.
Documentation. This criterion focuses on
Real-time capability and performance. Real- the type of documentation available for
time capability generally describes whether the RTOS (detailed APIs, simple tutorial,
a system can meet the timing deadline. book, or specification).
Using an RTOS takes up CPU cycles; how-
ever, the RTOS must not have nondeter-
Comparison results
Table 2 compares the RTOSs. We iden-
ministic behaviors. The amount of CPU
tified several significant similarities and
cycles and time consumed by the RTOS
idiosyncrasies among them:
for any service call should be measurable,
and of low or acceptable value to the system  Most RTOSs use priority-based preemp-
designers. Real-time capability and perfor- tive scheduling. Only two—Salvo and
mance information aren’t available for TinyOS—use cooperative scheduling.
some RTOSs. Even if this information is  Most RTOSs support C language,
available, it might not be based on the hard- which is the popular choice for
ware platform a designer is using. embedded system programming, espe-
cially in small system design.21
Memory footprint. In addition to CPU cycles,  Only a few RTOSs have operating-
an RTOS consumes ROM and RAM space, system-awareness support in an IDE:
which could increase the ROM and RAM mC-OS/II and EmbOS have plug-in
sizes for the entire system. A trade-off always modules for the IAR compiler; Kei-
exists between the memory footprint and the lOS is supported by the Keil com-
functionalities required from the RTOS. piler; and mITRON and mTKernel
More robust and reliable APIs typically re- are supported by the Renesas High-
quire more lines of code. However, simple Performance Embedded Workshop
APIs require only a minimum amount of (HEW) compiler.
code. Hence, designers should understand  The eCOS RTOS requires a bootloader
the features offered by the RTOS and the cor- (known as Redboot) of at least 64-
responding memory footprint requirement. Kbytes ROM.15 Redboot boots and
loads programs into the RAM via a
Language support. Another criterion to con- user terminal (typically over a serial
sider is the programming language sup- port). Hence, eCOS requires much
ported by the RTOS. more ROM and RAM space.
 Some RTOSs (KeilOS, PortOS, and
System call/API richness. This criterion deter- XMK) don’t make available details of
mines how comprehensive an RTOS’s APIs their APIs (marked ‘‘N/A’’ in the ‘‘System
are compared to the other RTOSs. We call/API richness’’ column). SharcOS is
count the total number of system calls for based on mC-OS/II, so uses the same
each RTOS. APIs. We therefore don’t consider these
RTOSs when comparing APIs.
Operating-system-awareness debugging support.
This criterion determines whether the RTOS Figure 3 compares the number of system
is supported by an integrated development APIs available for each RTOS. We categorize
environment (IDE). Operating-system- them (with examples) according to the fol-
awareness debugging will ease the develop- lowing functions:
ment work because users can employ the
RTOS internal information (for example,  System management: initialize operating
task states, system states, semaphores, and system, start/shut down operating sys-
event flags) provided by the IDE.3 tem, lock/unlock CPU
....................................................................

SEPTEMBER/OCTOBER 2009 35
...............................................................................................................................................................................................
REAL-TIME OPERATING SYSTEMS

Table 2. Basic features comparison of RTOSs for small microcontrollers.

Operating-
system-
System awareness
Design Scheduling call/API Language support
RTOS objective scheme License type Documentation richness supported in IDE

mITRON Commercial Priority-based Fee-based Open specification 93 C Renesas IDE


preemptive and user manual
mTKernel Commercial/ Priority-based Free for educa- Open specification 81 C Renesas IDE
educational/ preemptive tional and and user manual
research commercial
mC-OS/II Commercial/ Priority-based Free for Book 42 C IAR
educational/ preemptive educational
research
EmbOS Commercial Priority-based Fee-based Online document 56 C IAR
preemptive
Free- Hobby Priority-based Free for educa- Online document 27 C None
RTOS preemptive tional and
commercial
Salvo Commercial Cooperative Fee-based Online document 31 C None
TinyOS Educational/ Cooperative Free for educa- Tutorials N/A nesC None
research tional and
commercial
SharcOS Commercial Priority-based Fee-based User manual N/A C None
preemptive
eXtreme Educational/ Priority-based Free for educa- Online document N/A C None
Minimal research preemptive tional and (incomplete)
Kernel commercial
(XMK)
Echidna Educational/ Priority-based Free for educa- Online document 18 C None
research preemptive tional and (incomplete)
commercial
eCOS Commercial/ Priority-based Free for educa- Book and online N/A C None
educational/ preemptive tional and document
research commercial
Erika Educational/ Priority-based Free for educa- Online document 19 C None
research preemptive tional and
commercial
Hartik Educational/ Priority-based Free for educa- Online document 33 C None
research preemptive tional and
commercial
KeilOS Commercial Priority-based Fee-based Online document N/A C Keil IDE
preemptive
PortOS Research Priority-based Fee-based Online document N/A C None
preemptive

 Interrupt management: entry/exit func-  Communication and synchronization:


tion, begin/end critical section semaphore, data queue, event
 Task management: create task, delete flag, mailbox, mutex, and message
task, start task, and terminate task buffer
 Task-dependent synchronization: sleep  Memory management: fixed-size and
task, wake up task, and resume task variable-size memory pool
....................................................................

36 IEEE MICRO
Number of system APIs

14
12
10
8
6
4
2
0
µItron µTkernel µC-OS/II FreeRTOS Salvo Echidna emBos Erika Hartik
System management Interrupt management Task management
Task-dependent synchronization Semaphore Eventflag
Mailbox Data queue Mutex
Message buffer Fixed-size memory pool Variable-size memory pool
System time management Trace API

Figure 3. Number of system APIs for various RTOSs.

 Time management: get system operating For these reasons, we focus on mITRON,
time, operating system timer mTKernel, mC-OS/II, and EmbOS for our
 Trace API: hook the routine into certain subsequent comparison and benchmarking.
RTOS functions such as a scheduler In addition to the functions mentioned
in Figure 3, some RTOSs support the
Several of the RTOSs compared— following:
mITRON, mTKernel, mC-OS/II, and
EmbOS—support comprehensive APIs for  Some system APIs support timeout. For
these categories. Most commercial RTOSs example, a task can wait for a sema-
are well-implemented, with mITRON sup- phore for a maximum number of n
porting all the categories except for trace milliseconds. RTOSs such as mITRON
functions. EmbOS also supports most of and mTKernel have mechanisms that let
the categories, except for trace, system time users specify the timeout in absolute
management, system management, and mes- values. Other RTOSs, such as mC-
sage buffer. For each category, the number of OS/II, FreeRTOS, Salvo, and EmbOS,
APIs for these four RTOSs also exceeds those only let users specify timeout values in
for other RTOSs because they’ve been devel- terms of clock ticks.
oped and improved and have been on the  Debug APIs let a user’s application re-
market longer. trieve information managed by the ker-
Most open source RTOSs (such as Free- nel. Currently, only mTKernel supports
RTOS, Echidna, Erika, and Hartik) have these APIs (for example, get task regis-
minimal implementation. These RTOSs are ter and set task register).
more suitable for small system development.  A cyclic handler instructs the RTOS to
However, mC-OS/II stands out as having execute a function at a periodic interval,
more available APIs. This system was origi- and an alarm handler lets the RTOS ex-
nally an open source RTOS for personal ecute a function after a certain amount
and educational purposes. Its stability and of time. These APIs are currently avail-
popularity led to its commercialization and able in mITRON and mTKernel.
wide use.4 Next to mC-OS/II, mTKernel  A rendezvous mechanism allows syn-
has the most available APIs. This system sup- chronization and communication be-
ports all the function categories but data tween tasks (similar to Ada language22
queue. It has almost the same number of for real-time). Both mITRON and
APIs as the commercial RTOS mITRON, mTKernel support this mechanism.
because it’s backed by the T-Engine Forum
(http://www.t-engine.org), led by Ken Saka- For mITRON and mTKernel, several APIs
mura, the mITRON architecture designer. provide better controllability and flexibility.
....................................................................

SEPTEMBER/OCTOBER 2009 37
...............................................................................................................................................................................................
REAL-TIME OPERATING SYSTEMS

Table 3. User-controllable parameters for RTOS semaphore creation.

Parameters mC-OS/II EmbOS mTKernel mITRON


Name/information Not supported Not supported Extended information Semaphore name
Attributes Not supported Not supported Tasks can be queued in Tasks can be queued
first-in, first-out (FIFO) in FIFO or priority
or priority order order
Either the first task in the queue
or the task with fewer
requests has precedence
Initial count Initial semaphore Initial semaphore Initial semaphore count Initial semaphore
count count count
Maximum count Not supported Not supported Not supported Maximum value of
semaphore count

As Table 3 shows, tasks in mC-OS/II and The M16C/62P has a 16-bit complex in-
EmbOS are queued in a first-in, first-out struction set computer (CISC) architecture
(FIFO) buffer when waiting for a sema- CPU with a total of 91 instructions available.
phore, and developers may not change the Most instructions complete within two or
order. However, in mITRON and mTKernel, three clock cycles. The MCU has a four-
developers can specify whether tasks are stage instruction queue buffer, which is sim-
queued in FIFO or priority order. This flex- ilar to the simplified pipeline common in
ibility not only applies to semaphores, but larger 32-bit processors.
also to other APIs (including mailbox, mes- To ensure that all the RTOSs operate on
sage queue, memory pool, and event flag). the same platform with the same timer reso-
To achieve such features in mITRON and lution, we used the following settings. First,
mTKernel, developers must make trade-offs we took the OS tick resolution for all the
in both memory footprint and performance. RTOSs from timer A023 of the microcon-
troller. We used the NC30 compiler’s default
Performance and memory settings for compiling the workspaces.
footprint benchmarking We took the mC-OS/II original work-
We ran benchmarks for the four RTOSs space and full source code from the Micrium
identified earlier: mITRON, mTKernel, mC- website (http://www.micrium.com/renesas/
OS/II and EmbOS. For execution time index.html). We configured timer A0 for
measurements, we used oscilloscopes and the operating system, and compiled the en-
logic analyzers in combination with I/O tire workspace again using NC30 toolchain
port toggling to achieve the best accuracy version 5.43.00.
(in terms of microseconds). We took the mTKernel original work-
space and full source code from the Renesas
Ports of the RTOSs on the same website.24 We configured timer A0 at 10 ms.
M16C/62P platform We took the EmbOS original workspace
For our evaluations, we used the Renesas and library files (.lib) from the Segger website
M16C/62P microcontroller platform, which (http://www.segger.com). We configured
has the following characteristics: timer A0 for the operating system and con-
figured the entire workspace (except the .lib
 Operating frequency of 24 MHz files) with NC30 toolchain version 5.43.00.
 512 Kbytes of ROM We’re unaware of whether the .lib files
 31 Kbytes of RAM (no cache or mem- were compiled in an older toolchain
ory management unit) or with different optimization settings. This
 Seven-level interrupt mask means that the toolchain and compiler set-
 Renesas HEW version 4.03.00.001 IDE tings for EmbOS might differ from those
 NC30 toolchain version 5.43.00 for mC-OS/II or mTKernel.
....................................................................

38 IEEE MICRO
Table 4. System service call implementation and critical section implementation.

Call mC-OS/II mTKernel EmbOS mITRON


Service call Direct call Using software interrupt Direct call Using software interrupt
Critical section Disable all interrupts Raise interrupt mask Don’t disable any interrupt Raise interrupt mask level
level to level 4 (based on an internal to level 4
variable)

We generated the mITRON workspace, critical section, mC-OS/II disables all inter-
library files (.lib), and timer A0 configuration rupts, so no external interrupt can be
from the Renesas configuration tool for accepted. This lets the critical section execute
mITRON. We compiled the entire work- safely from start to finish without interven-
space (except for the .lib files) using NC30 tion, but it also implies that the system
toolchain version 5.43.00. This is similar to won’t accept a highly important real-time in-
EmbOS because the operating system is dis- terrupt during this period. The mITRON
tributed in the form of .lib files. Further- and mTKernel RTOSs implement a critical
more, the toolchain and compiler settings section by raising the interrupt mask level
used when generating the .lib files might dif- (for M16C/62P the interrupt mask level is
fer from those for mC-OS/II or mTKernel. set to 4, but can be changed) so that a critical
In addition, we used the same amount of interrupt can be accepted as long as the inter-
stack memory per task for all RTOSs. Fi- rupt handler doesn’t interfere with the
nally, if a particular RTOS feature isn’t RTOS internal variables. EmbOS doesn’t
used (for example, a semaphore or message disable or raise the interrupt mask level for
queue), it’s disabled by the C preprocessor a critical section. It allows all interrupts to
for mC-OS/II and mTKernel, or during link- come in but uses internal variables to control
ing for EmbOS. However, for mITRON, we the critical section. Thus, any interrupt can
included the unused features because the be accepted and handled during the critical
RTOS is provided in library format and sys- section; however, EmbOS requires addi-
tem calls are invoked via software interrupts. tional code to handle the critical section’s
Table 4 shows the differences in the im- internal variables.
plementation of the RTOSs’ system service
calls and critical sections. Benchmarking criteria
Whenever mC-OS/II and EmbOS issue a We aimed to make our benchmarking
system service call, they call the function di- criteria easy to port to different platforms.
rectly from the user task. The advantage is For each criterion, we collected execution
that the function is executed immediately time measurement and memory footprint
with minimal overhead time; the disadvan- (ROM and RAM).
tage is that the service call will use the cur-
rent task’s stack for execution. When Task switch time. Task switch time is the
mITRON and mTKernel issue a system time it takes for the RTOS to transfer the
service call, it raises a nonmaskable soft- current execution context from one task to
ware interrupt (an INT instruction in another. Figure 4a shows the measurement
M16C/62P). Hence, the current execution method.
context is to switch to the kernel space It includes two tasks, task 1 and task 2,
(that is, a separate stack) to execute the ser- with task 1 having higher priority. Each
vice call. The advantage of using this RTOS must first execute task 1, which
approach is that the service call won’t use then goes into a sleep or inactive state. The
the current task’s stack for execution; the dis- execution context then switches to task 2.
advantage is that every system service call will Task 2 wakes up or activates task 1. Right
incur a time overhead. after waking up, the execution context
Table 4 also shows different methods for switches back to task 1 because it has higher
implementing a critical section. To start a priority. Different RTOSs use different
....................................................................

SEPTEMBER/OCTOBER 2009 39
...............................................................................................................................................................................................
REAL-TIME OPERATING SYSTEMS

Task 1:
(A)
Get semaphore
(B)
Task 1: (higher priority) Task 2:
Release semaphore
Go to sleep (A) (C)
(B) Wake up task 1
Time to get semaphore: (A) to (B)
Task switch time: time from (A) to (B) Time to release semaphore: (B) to (C)
(a) (b)

Task 1:
(A)
Pass message to the queue
(that is, message is copied into the queue)
(B)
Task 1: (higher priority) Task 2:
Retrieve message from the same queue
Get semaphore (put into wait list) (A)
(C)
(B) Release semaphore
Time to put message onto queue: (A) to (B)
Time to pass semaphore from task 1 to task 2: (A) to (B) Time to retrieve message from queue: (B) to (C)
(c) (d)

Task 1:
(A)
Acquire fixed-size block
Task 1: (higher priority) Task 2:
(B)
Retrieve message from queue (A) Release fixed-size block
(will be put into wait list)
Put message onto queue (C)
(B)
Time to acquire memory block: (A) to (B)
Time to pass message from task 2 to task 1: (A) to (B) Time to release memory block: (B) to (C)
(e) (f)

Task 1: (higher priority) Task 2: Interrupt

Go to sleep Do some processing Do some processing

(B) … (A)

Do some processing Resume task 1

Time from interrupt handler resuming task 1 until task 1 is resumed: (A) to (B)
(g)

Figure 4. Benchmarking criteria measurements: task switch time (a), get/release semaphore time (b), semaphore-passing
time (c), pass/retrieve message time (d), message-passing time (e), acquire/release fixed-size memory time (f), and task
activation from interrupt handler time (g).

terms to describe sleep/inactive and ready/ Get/release semaphore time. RTOSs often use
active states (for example, mC-OS/II and semaphores for synchronizing primitives.25
EmbOS use suspend/resume, and mITRON For semaphore benchmarking, we measure
and mTKernel use sleep/wakeup). the time taken by the get and release sema-
Table 5 shows the system calls used in phore service calls as well as the time
each RTOS. required to pass the semaphore from one
....................................................................

40 IEEE MICRO
Table 5. APIs used for the task switch time benchmark.

API mC-OS/II mTKernel EmbOS mITRON


Pass message OSTaskSuspend() tk_slp_tsk() OS_Suspend() slp_tsk()
Retrieve message OSTaskResume() tk_wup_tsk() OS_Resume() wup_tsk()

Table 6. APIs used for the get/release semaphore benchmark.

API mC-OS/II mTKernel EmbOS mITRON


Get semaphore OSSemPend() tk_wai_sem() OS_WaitCSema() wai_sem()
Release semaphore OSSemPost() tk_sig_sem() OS_SignalCSema() signal_sem()

Table 7. APIs used for the message-passing benchmark.

API mC-OS/II mTKernel EmbOS mITRON


Pass message API OSQPost() tk_snd_mbx() OS_Q_Put() snd_mbx()
Retrieve message API OSQPend() tk_rcv_mbx() OS_Q_GetPtr() rcv_mbx()

task to another. Figure 4b shows how we support this approach. Figure 4d shows
measure the get and release semaphore time. how we perform this measurement.
Here there is only one task (task 1) and The measurement involves only one
one binary semaphore (initialized to 1). task (task 1). The task first passes the mes-
Task 1 gets and then releases the semaphore. sage pointer (usually to an internal message
Different RTOSs use different terms to de- queue), and then retrieves the same mes-
scribe this process. Table 6 shows the APIs sage pointer. Table 7 shows the APIs
used by each RTOS. used in each RTOS.

Semaphore-passing time. To measure the per- Intertask message-passing time. Figure 4e


formance of semaphore passing, we use the shows how we measure the message-passing
following method, as Figure 4c illustrates. time between tasks.
This measurement involves two tasks, task This measurement involves two tasks, task
1 and task 2, with task 1 having higher prior- 1 and task 2, with task 1 having higher pri-
ity, and a binary semaphore (initialized to 0). ority. Task 1 is executed first, and it tries
The system executes task 1, which tries to get to retrieve a message pointer from the
the semaphore. Because the semaphore’s queue. Because no message is yet available,
value is 0, task 1 enters a sleep/inactive task 1 enters a sleep/inactive state and waits
state, waiting for the semaphore’s release. for a new message. The current execution
The current execution context then switches context switches to task 2, which puts a
to task 2, which releases the semaphore. Once new message into the queue. The new mes-
released, the semaphore wakes task 1 and the sage wakes task 1, and the execution context
execution context switches to task 1. switches to task 1. The difference between
this measurement and the pass/receive mes-
Pass/receive message time. In addition to sem- sage time benchmark is that this method
aphores, message passing has become in- includes the RTOS’s overhead time to pro-
creasingly popular for synchronization.26 cess the message queue and wake the receiv-
This measurement uses a message-passing ing task.
mechanism based on memory pointer pass-
ing. It doesn’t copy the message into an in- Fixed-size memory acquire/release time. In an
ternal RTOS area because not all RTOSs RTOS, only fixed-size dynamic memory
....................................................................

SEPTEMBER/OCTOBER 2009 41
...............................................................................................................................................................................................
REAL-TIME OPERATING SYSTEMS

Table 8. APIs used for the fixed-size memory benchmark.

API mC-OS/II mTKernel EmbOS mITRON


Acquire fixed-size block API OSMemGet() tk_get_mpf() OS_MEMF_ Alloc() get_mpf()
Release fixed-size block API OSMemPut() tk_rel_mpf() OS_MEMF_ Release() rel_mpf()

Table 9. APIs for the task activation from within interrupt handler benchmark.

API mC-OS/II mTKernel EmbOS mITRON


Go to sleep API OSTaskSuspend() tk_slp_tsk() OS_Suspend() slp_tsk()
Resume from interrupt API OSTaskResume() tk_wup_tsk() OS_Resume() iwup_tsk()

allocation should be used. The allocation report. By averaging the ROM information
and deallocation time must be determinis- across all test criteria, we got the average
tic. Figure 4f illustrates how we measure ROM size. Figure 5a shows the code sizes
the time to acquire and to release a fixed- for the four RTOSs when running the
size memory block. seven benchmarks.
This measurement involves only one task. As the figure shows, mTKernel has a larger
Task 1 acquires a fixed-size memory block code size. This is due to its APIs’ flexibility
(128 bytes) and then releases it. Table 8 and comprehensive support. The commercial
shows the APIs used in this process. RTOSs, mITRON and EmbOS, offer a rela-
tively compact code size. Nevertheless, all
Task activation from within interrupt handler four RTOSs fit well into microcontrollers
time. An RTOS must deal with external of limited ROM sizes.
interrupts that might be asserted at any Figure 5b shows the RAM information
time. It will typically keep an interrupt han- for the four RTOSs. Two of the systems—
dler’s execution as short as possible to avoid mTKernel and mITRON—have relatively
affecting the system response. If the inter- lower RAM usage, while mC-OS/II and
rupt requires long processing, the handler EmbOS have slightly higher usage. Accord-
can activate another task to do the necessary ing to each benchmark’s requirement, we
processing. The time from when the inter- set the number of tasks, stack size, and
rupt handler resumes the task until the number of RTOS objects (for example,
time when the task is executed is crucial to semaphore and event flags) to be the same
the system’s design. for all RTOSs. The amount of RAM differ-
Figure 4g shows the measurement’s setup, ences among the RTOSs range from 7 to 10
which involves two tasks, task 1 and task 2, bytes, which might be due to internal
with task 1 having higher priority, and an ex- implementations or to the API design
ternal interrupt with a proper handler. Task approach. In summary, the ROM and
1 executes first. It goes to the sleep/inactive RAM usage of all these RTOSs are well
state, and the execution context switches to suited for small microcontrollers. However,
task 2. Task 2 runs continuously. When an mITRON has the optimal usage of both
external interrupt occurs, the interrupt han- ROM and RAM.
dler executes and resumes task 1. The execu-
tion context switches over to task 1. Table 9 Execution time
shows the APIs used for each RTOS. Figure 6 shows the execution time mea-
surement for the RTOSs for the different
Benchmarking results benchmark criteria. Because timer interrupt
For each criterion, we compiled the is the only variation in the system (for oper-
benchmarking code and obtained the ating system tick), we executed each bench-
ROM and RAM usage from the toolchain mark at least twice to ensure consistent
....................................................................

42 IEEE MICRO
results. Nevertheless, for all benchmarks,
running once is enough to yield the correct 12,000
measurement. For the task activation from
within interrupt handler benchmark, the ex-

Code size (ROM) in bytes


10,000
ternal interrupt is an additional variation.
When measuring this benchmark, the exter-
8,000
nal interrupt might or might not be asserted
during the operating system’s critical section
(during which the operating system disables 6,000
interrupts). If it’s asserted during the critical
section, the operating system’s response time 4,000
will be slightly longer. Hence, this measure-
ment might not include the worst-case 2,000
scenario.
As Figure 6 shows, mTKernel has the low-
0
est task-switching time, followed by µC-OS/II µTKernel EmbOS µITRON
mITRON, mC-OS/II, and EmbOS. It also (a)
Task switch time
shows that the mC-OS/II semaphore acquire
Get and release semaphore (one task)
and release times are the fastest. The fastest Pass semaphore (from one to another task)
intertask semaphore passing is achieved by Pass and retrieve message to queue
mITRON, whereas mC-OS/II and mTKernel Pass message (from one to another task)
have better message passing and retrieval Acquire and release fixed-size memory block
Task activation from interrupt
times than mITRON and EmbOS. As far
as fixed-size memory is concerned, mC-
OS/II has the best execution time, followed
2,000
by EmbOS, mITRON, and mTKernel. Fi-
nally, mTKernel has the best performance
time for task activation from interrupt han-
Data size (RAM) in bytes

dler, followed by mC-OS/II, mITRON, and


1,500
EmbOS.
As these benchmarking results show,
each RTOS has its own strengths and weak-
nesses. In the open source category, mC-
1,000
OS/II is useful as a small and compact
ROM-size RTOS. However, for more com-
prehensive API support, we recommend
mTKernel (at the expense of a slightly higher
500
ROM footprint). On the other hand, if the
developer prefers a commercial RTOS, we
recommend either mITRON or EmbOS,
with mITRON having a slighter lower 0
RAM footprint. µC-OS/II µTKernel EmbOS µITRON
(b)

O ur benchmarking criteria are simple,


easy to port to different platforms,
and representative of typical RTOS uses.
Figure 5. Benchmarking results for the four RTOSs: comparisons of code
size (a) and data size (b).
They show that each RTOS has different
strengths and weaknesses, but there’s no
clear winner. With these detailed perfor-
mance benchmarks, potential adopters of investigate the effectiveness of using RTOS
these RTOSs can simplify their selection by for applications development. It would also
examining their specific application require- be interesting to evaluate the power utiliza-
ments. One of our future plans is to tion between different RTOSs and develop
....................................................................

SEPTEMBER/OCTOBER 2009 43
...............................................................................................................................................................................................
REAL-TIME OPERATING SYSTEMS

45

40

35

30

25
µC-OS/II
20 µTKernel
EmbOS
15
µITRON

10

0
Task switch Get Release Pass Pass Retrieve Pass Acquire Release Task
time semaphore semaphore semaphore message message message fixed-size fixed-size activation
(from one to to queue from queue (from one to memory memory from
another task) another task) block block interrupt

Figure 6. Execution time benchmark for four RTOSs.

a common advanced configuration and 7. T-Engine Forum, ‘‘mTKernel specification,


power interface (ACPI) framework to en- 1.00.00,’’ Mar. 2007; http://www.t-engine.org.
sure efficient power usage. MICRO 8. R. Barry, ‘‘A Portable, Open Source Mini
Real-Time Kernel,’’ Oct. 2007; http://www.
.................................................................... freertos.org.
References 9. K. Curtis, ‘‘Doing Embedded Multitasking with
1. D. Kalinsky, ‘‘Basic Concepts of Real-Time Small Microcontrollers, Part 2,’’ Embedded
Operating Systems,’’ Linux Devices, Nov. System Design, Dec. 2006; http://www.
2003; http://www.jmargolin.com/uavs/jm_ embedded.com/columns/technicalinsights/
rpv2_npl_16.pdf. 196701565?_requestid=242226.
2. K. Sakamura and H. Takada, ‘‘mITRON for 10. A. Garcia-Martinez, J. F. Conde, and A. Vina,
Small-Scale Embedded Systems,’’ IEEE Micro, ‘‘A Comprehensive Approach in Perfor-
vol. 15, no. 6, Nov./Dec. 1995, pp. 46-54. mance Evaluation for Modern Real-Time
3. J. Ganssle, ‘‘The Challenges of Real-Time Operating Systems,’’ Proc. 22nd EuroMicro
Programming,’’ Embedded System Pro- Conf., IEEE CS Press, 1996, p. 61.
gramming, vol. 11, July 1997, pp. 20-26. 11. R.P. Kar and K. Porter, ‘‘Rhealstone: A Real-
4. R. Nass, ‘‘Annual Study Uncovers the Em- Time Benchmarking Proposal,’’ Dr. Dobb’s
bedded Market,’’ Embedded Systems Design, J. of Software Tools, vol. 14, no. 2, Feb.
2 Sept. 2007; http://www.embedded.com/ 1989, pp. 14-22.
design/opensource/201803499;jsessionid= 12. K.M. Sacha, ‘‘Measuring the Real-Time
NGMOMOIGE5ZNNQE1GHOSKHWATMY Operating System Performance,’’ Proc. 7th
32JVN?printable=true. EuroMicro Workshop Real-Time Systems,
5. K. Baynes et al., ‘‘The Performance and En- IEEE CS Press, 1995, pp. 34-40.
ergy Consumption of Embedded Real-time 13. K. Sakamura and H. Takada, mITRON 4.0 Spec-
Operating Systems,’’ IEEE Trans. Com- ifications, TRON Assoc., 2002; http://www.
puters, vol. 52, no. 11, 2003, pp. 1454-1469. ertl.jp/ITRON/SPEC/FILE/mitron-400e.pdf.
6. J.J. Labrosse, MicroC/OS-II: The Real-Time 14. EmbOS Real-Time Operating System, User
Kernel, R&D Books, 1999. & Reference Guide, Segger Microcontroller,
....................................................................

44 IEEE MICRO
2008; http://www.segger.com/cms/admin/ Tran Nguyen Bao Anh is a senior embedded
uploads/productDocs/embOS_Generic.pdf. engineer at STS Wireless Sound Solutions
15. A.J. Massa, Embedded Software Develop- Singapore. His research interests include
ment with eCos, Prentice Hall, 2002. embedded and real-time system development.
16. P. Gai et al., E.R.I.K.A.: Embedded Real-tIme Anh has an MSc in embedded systems from
Kernel Architecture; ERIKA Educational User Nanyang Technological University.
Manual, Realtime System (RETIS) Lab, Scuola
Superiore Sant’Anna, Italy, 2004; http://erika. Su-Lim Tan is an assistant professor in the
sssup.it/download.shtml#Doc. School of Computer Engineering at Nanyang
17. G.C. Buttazzo, ‘‘Hartik: A Hard Real-Time Technological University, Singapore. His
Kernel for Programming Robot Tasks research interests include embedded network
with Explicit Time Constraints and Guaran- sensing and smart sensors. Tan has a PhD in
teed Execution,’’ Proc. IEEE Int’l Conf. engineering from the University of Warwick.
Robotics and Automation, IEEE Press, Direct questions and comments about
1993, pp. 404-409. this article to Su-Lim Tan at the School of
18. R. Chrabieh, ‘‘Operating System with Prior- Computer Engineering, Nanyang Techno-
ity Functions and Priority Objects,’’ Tech- logical University, Blk N4-02a-32, Nan-
Online, Feb. 2005; http://www.techonline. yang Avenue, Singapore 639798; assltan@
com/learning/techpaper/193101942. ntu.edu.sg.
19. G. Hawley, ‘‘Selecting a Real-Time Operat-
ing System,’’ Embedded System Design,
vol. 12, no. 3, 1999, http://www.embedded.
com/1999/9903.
20. M. Timmerman and L. Perneel, ‘‘Understand-
ing RTOS Technology and Markets,’’
Dedicated Systems RTOS Evaluation proj-
ect report, 2005; http://www.dedicated-
systems.com/vpr/layout/display/pr.asp?PRID=
8972.
21. R. Bannatyne and G. Viot, ‘‘Introduction to
Microcontrollers, Part 2,’’ Northcon Conf.
Proc., IEEE Press, 1998, pp. 250-254.
22. B. Millard, D. Miller, and C. Wu, ‘‘Support
for ADA Intertask Communication in a
Message-Based Distributed Operating Sys-
tem,’’ Computers and Comm. Conf. Proc.,
IEEE Press, 1991, pp. 219-225.
23. M16c/62P Group Hardware Manual, Renesas
Technology, 2006; http://documentation.
renesas.com/eng/products/mpumcu/
rej09b0185_16c62pthm.pdf.
24. Renesas Technology, ‘‘mTKernel for M16C
Source Code and Documentation,’’ 2007;
http://www.superh-tkernel.org/eng/
do wnload/misc/software/M30626FJPGP_
micro_tkernel/software/index.html.
25. I. Ripoll et al., ‘‘RTOS State of the Art Anal-
ysis,’’ tech. report, Open Components for
Embedded Real-time Applications (OCERA)
project, 2002.
26. D. Kalinsky, ‘‘Asynchronous Direct Message
Passing Rapidly Gains Popularity,’’ Embedded
Control Europe, Nov. 2004, p. 32.
....................................................................

SEPTEMBER/OCTOBER 2009 45

You might also like