Multitasking Design and Implementation Issues in Embedded Systems
Multitasking Design and Implementation Issues in Embedded Systems
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE
by Larry Mittag
1
Overview
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE
Speaker
Larry Mittag (Stellcom Technologies)
Presentation
first part was basic but interesting
second part: hints & tricks
ESC Europe 1999 report
no groundbreaking concepts
2
Part 1: Properties of RTOS’s
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
Communication
Priorities
3
In The Beginning: Linear Code
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE
Simple and effective
Augmented by interrupts
Preferred method for systems dedicated to simple
tasks
ESC Europe 1999 report
4
Next Step: Event Loops
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE
while (1)
{
ESC Europe 1999 report
Do_Task_1();
Do_Task_2();
Do_Task_3();
}
5
Next Step: Event Loops
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE
Allows to handle multiple logical tasks in one thread
Nice design to keep separate code segments away
from each other
Can eventually fall victim to complexity
ESC Europe 1999 report
6
Asynchronous Multitasking
KATHOLIEKE
UNIVERSITEIT
LEUVEN
debugging
7
Multitasking Flavors
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE
Lightweight multitasking
another word for multithreading
Heavy-duty multitasking
ESC Europe 1999 report
8
Lightweight Tasking: Threads
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE
Address and global name space shared among tasks
Separate stacks, so local variables are not shared
Very fast context switches
only need to save registers and stack pointer
No memory management required
ESC Europe 1999 report
9
Monolithic Load Module
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE
All (or most) references resolved at link time
Difficult to add load modules at runtime
Very simple and fast
ESC Europe 1999 report
10
Heavy-Duty Multitasking
KATHOLIEKE
UNIVERSITEIT
LEUVEN
11
Dynamic Load Capability
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER Allows new tasks to be loaded from disk or
SCIENCE
communications link
Requires virtual memory, position-independent code,
or trickery
Not necessary in many systems, required in others
ESC Europe 1999 report
12
Pros and Cons of Multithreading
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE
Pro
Simple, fast multitasking
Easy, fast communications through global variables
Contra
difficult to implement dynamic loading
ESC Europe 1999 report
13
Pros and Cons of Multitasking
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE
Pro
Very easy to build smaller, more easily debugged tasks
Damage from a misbehaving task can be contained
Contra
overhead at runtime
ESC Europe 1999 report
complex CPU
may require swap medium
14
Which for Embedded Systems?
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE
In general, go with lightweight threads
Exceptions:
Virtual memory required
Need to use large amounts of ported “workstation” code
Need to dynamically load external code
ESC Europe 1999 report
15
When NOT to Use Multitasking
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE Small, simple applications
Applications that need to be validated
When determinism is important
ESC Europe 1999 report
16
Communications
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
Shared memory
COMPUTER
SCIENCE
fast
but: deadly
Semaphores
simple
ESC Europe 1999 report
but: deadlocks
Message queues
decoupling sink and source
but: out of sync consume/produce rates
17
Task Prioritization: Crutch?
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
importance of tasks
Can be very important - allows the use of
“background” processing
Also can act as a crutch for a poor system design
ESC Europe 1999 report
18
Why Prioritize?
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER Creates hierarchies of task importance
SCIENCE
19
Priority Overkill
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
20
Rules for Sane Prioritization
KATHOLIEKE
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE Divide the tasks into time-critical and non time
critical
Among critical tasks, give short-duration tasks
higher priority
ESC Europe 1999 report
21
Part II: Designing Multitasking
KATHOLIEKE
Systems
UNIVERSITEIT
LEUVEN
DEPT. OF
COMPUTER
SCIENCE
Selecting an RTOS
Partitioning tasks
Communications and synchronization
ESC Europe 1999 report
22