Sie sind auf Seite 1von 52

[제 9 차]

Introduction to RTOS

경종민
kyung@ee.kaist.ac.kr

1
Agenda
• Overview
– What is Real-Time Embedded System
– What is RTOS?
• Structure of RTOS
– Priority Scheduling
– Synchronization
• Example: uC/OS
• Debugging Feature
• Market Status
2
Agenda
• Overview
– What is Real-Time Embedded System
– What is RTOS?
• Structure of RTOS
– Priority Scheduling
– Synchronization
• Example: uC/OS
• Debugging Feature
• Market Status
3
What is Embedded System
• Definition
– Electrical control system which is designed
to perform predefined specific function
with combination of computer hardware
and software. (Mechanical parts can be
included for its needs.)
• As processor power increases,
– More complex work can be handled by
processor.

4
Embedded System
• Embedded system
= processor-based embedded system
• SoC = Embedded system on silicon chip
= Core-based SoC
• Embedded System is already the
common solution
– “Latest top-level BMWs contain over 1000
microprocessors”
– “… the New York Times has estimated that
the average American comes into contact
with about 60 micro-processors every day…”

5
Processor-embedded System

• Most of the embedded designs


includes processor(s)
– Adopting processor-based design
shortens time-to-market.
– Processor has become powerful
enough to execute complex workload.

6
Real-Time Embedded System

• Definition
– Devices designed for dedicated
purposes where the correctness of
the system depends not only on the
logical result of the computation but
also on the time at which the results
are produced.

7
What is RTOS?
• What is real-time?
– Hard real-time
• Job must be completed within the dead-line.
• Static or dynamic scheduled task
– Hard to solve if the task is invoked by external event.
– Has been researched over 20 years but there is no
successful commercial products yet.
– Soft real-time
• There is no hard dead line.
• Order of execution is determined by priority.
• OS can not generally guarantee the specified timing
behavior, but it works in most of the practical cases
in carefully designed system.
• RTOS, if not specified otherwise, denotes this class.

8
Real-Time Operating
System
• Operating system is very familiar to everyone.
– Ex; Windows-XP, Linux…
– OS helps people easily exploit the power of the
computer without detailed knowledge of the
hardware through GUI, and multitasking, etc.
• However, in embedded systems:
– There’s no need to give dazzling graphic
interface/performance.
– Must control its task with real-time constraints.
• Car air-bag must be operated in 3 ms after collision.
• When the button in MP3 player is pressed, the menu
must pop up in one second.

9
Technical Pressure
Nielsen’s law:
Bandwidth doubles every 12 months

Embedded SW:
Doubles every 10 months

Complexity

Moore’s law:
IC complexity doubles every 18 months

2000 2010
Source: ST Microelectronics

10
Embedded System

Embedded
System

Core-based Real-Time
System System

Most embedded system targets this area.


11
Where Can Real-Time Systems be Found?

• RT-systems are everywhere:


– plant control
– control of production processes / industrial automation
– railway switching systems
– automotive applications
– flight control systems
– environmental acquisition and monitoring
– telecommunication systems
– robotics
– military systems
– space missions
– household appliances
– virtual / augmented reality

12
Embedded System on Chip
• Today SoC
includes several
modules such as
– MCU, VLIW, DSP
– Memories
– ASICs
– Busing scheme
– Application
Software
– RTOS

13
Real-Time Properties
• Time means being correct
– not only in logical results,
– but also on the time the results are produced
• Real indicates: Reaction to external events
must occur during their evolution.
• Real-time means
– deadline to be met under all (even the worst)
circumstances.

14
Hard/Firm/Soft RT(real
time)
• RT task is called hard
– if missing its deadline may cause
catastrophic consequences on the
environment under control
• RT task is called firm
– if missing its deadline makes the result
useless, but missing does not cause serious
damage
• RT task is called soft
– if meeting its deadline is desirable (e.g. for
performance reasons) but missing does not
cause serious damage
15
Hard/Firm/Soft RT
value value deadline

non-realtime soft

finishing time finishing time

value deadline value deadline

firm hard

finishing time finishing time

16
Examples of Hard/Firm/Soft
RT
Hard RT •sensor/actuator •automotive airbag
•critical system control
•aircraft engine
control
Firm RT •decision support •weather forecast
•value prediction •decisions on stock
exchange order

Soft RT •user interface •communications


•screen display
17
History of RTOS
• Originated as Monitor program, which
– includes Boot loader, Interrupt Service Routine, and
– communicates with external debugging program, and
– Is generally custom-made

• RTOS becomes more and more complex


– To control task in real-time, kernel is essential.
• It controls each task as a thread/process, which interacts with
one another through inter-process communication mechanism.
– Some commercial RTOS also includes:
• Network module such as TCP/IP
• Simple file system implemented on hard-disk or flash memory
• Text-based user interface shell

18
OS Basic: Layer
• Laplante (1997) defines OS by
describing a software hierarchy

User Interface Shell Operating System

File system Executive

Kernel
Inter-process Comm.

Process scheduling Micro-kernel

Thread scheduling Nano-kernel 19


OS Basic: Preemption
• Preemption
– OS can switch to another task
execution even though the current
task has not reached the predefined
time
Old Task point.

– Preemptive
New Task kernel is generally less

stable.

20
OS Basic: Resource
Constraints
• Private resource: dedicated to a particular
process
• Shared resource: to be used by more than
one process
• Exclusive resource: shared resource where
simultaneous access from different processes
is not allowed
• Critical resource: resource that is used under
mutual exclusion constraints. Management
using semaphores (e.g.)

21
How RTOS differs from
general-purpose OS

• In task scheduling,
– RTOS has a preemptive kernel, while in
general-purpose OS (e.g. UNIX), although
there is priority, task switching occurs only
at predefined time boundary.
– RTOS handles only one process at a time
but in multiple threads.
• In memory management,
– RTOS neither requires virtual memory nor
protection mechanism. (Some commercial
RTOS supports these features, though.)

22
Reusable HW and SW parts in
embedded system design
User
Application
Kernel
TCP/IP System
Control
SW

device device device


driver driver driver

IP IP
HW User custom
(standard (computing
block
peripheral) block)

RTOS
Standard parts (Reuse possible)
23
Customizing parts
Agenda
• Overview
– What is Embedded System
– What is RTOS?
• Structure of RTOS
– Priority Scheduling
– Synchronization
• Example: uC/OS
• Debugging Feature
• Market Status
24
Main roles of RTOS
• Task management
– Every task is implemented as a thread for
easy programming and fast
execution.
– Priority is assigned to each task.
• Memory management
• I/O management
– Determines the execution order of tasks,
which is known as Synchronization
• Inter-process Communication
– Message queues
25
RTOS Structure
Algorithm
• System Tables Development

• Dispatcher
Task Management
• Interrupt Service
Routines (ISR) System
Inter-process Comm.
Design RTOS
• System Services Memory Management

I/O Management

System Architecture
Selection I/O Design

26
Operating System Structure:
System Tables
• System Tables:
– Task-Control-Blocks (TCB)
• These hold information necessary to run the tasks.
– Device-Control-Blocks (DCB)
• These hold information necessary for the operating
system to use the I/O devices. Also, each device may
have an additional table or buffer to hold I/O information
– Service-Control-Blocks (SCB)
• These specify the parameters for a request for the
operating system to perform some function.
• E.g. signal is implemented as SCB.
– Asynchronous event processing and exception handling
– It resumes the task blocked by event flags

27
Operating System Structure:
The Dispatcher
• The dispatcher is a program module
that determines which task will run next
after something triggers the system to
switch control to a new task.
• Also called as scheduler

dispatch Running
Block

preemption

Ready Blocked
Wake up 28
by signal
Scheduling algorithm
• Static hard real-time
– All task activations can be pre-calculated off-line.
– At run-time dispatching is performed in a simple way due
to predefined scheduling table
– Very sophisticated off-line algorithm
– System is inflexible to environmental change
• Dynamic hard real-time
– Guarantee must be made on-line each time a new task
enters the system
– Hard to guarantee its correctness.
• Soft real-time
– Priority-based scheduling
– Best effort to perform in average
– Unpredictable

29
Preemptive Priority
Scheduling
t3
priority

t2 t2

t1 t1

time
= preemption = task completion

30
Synchronization
• Roles of synchronization
– Determine the order of executed tasks
– Resource or critical section management
• E.g. I/O must be occupied by only one task in the
specified time.
• Types of synchronization objects
– Semaphores
– Mutexes
– Barrier
– Conditional variables
• Whether exclusion applied or not is based on a
condition.

31
Synchronization

t1 t2
t2 t3
t1 t2
t1 t3
BLOCKED


BLOCKED

BLOCKED


BLOCKED


it
em

t2 t3

(a) Mutex(single token) (b) Semaphore (c) Barrier statement deters


count (multiple=2 Execution until some number
tokens) Of such statements occur.
(Synchronization in narrow sense)

= try to take/has taken/release resource 32


Communication
• Communications
– Mailbox – single messages (Existence of
message in the mailbox allows continuing
the task waiting for it.)
– Queues – multiple messages

t1 t2 t3
t2
M1
t1
BLOCKED M2

it
em

M1
M1 M1
t2 t3
M2

t3
(a) Mailbox (b) Queue 33
Priority Inversion
Too Much
t3 Waiting! t3
priority

t2

t1 t1 t1

time

t3 t1 t3
priority

t2

t1

time
= preemption = block = try to take/has taken/release 34
semaphore
Portability
• Board Support Package (BSP)
– RTOS can be applied to any application
board
• Application board needs to be redesigned when
the target is changed.
– After the information related to the user
application board (ex. Memory map,
interrupt number assignment, frequency of
system timer) is collected, it is put together
in one parameter file called BSP.
– In some general OS, it is called as HAL
(Hardware Abstraction Layer) which includes
processor information.
35
Agenda
• Overview
– What is Embedded System
– What is RTOS?
• Structure of RTOS
– Priority Scheduling
– Synchronization
• Example: uC/OS
• Debugging Feature
• Market Status
36
uC/OS
• Simple real-time kernel
– Source code is open to everyone.
• Supporting features
– System Table
• Task Control Block (TCB)
• Event Control Block (ECB)
– Signal is called as ‘event’ in uC/OS
– Some kind of Service Control Block
• No device driver
– Scheduler
• Manage look up tables to invoke task faster
– Ready table for TCB’s
– Event table for ECB’s

37
Structure of uC/OS
Idle
Task
Conte
xt User User User
task1 task2 task3 …
Switch
Scheduler

updat
priority Ready e TCB TCB TCB …
Table for task1 for task2 for task3

PENDING or
updat READY
priority Event e
ECB ECBlist ECB
Task …
Table for event1for event2for event3
Event list 38
Code example
• Body of MP3 decoder
– MP3 decoding algorithm
– Play/Pause button Min. 3 independent tasks
– Volume up/down
BtnCheck() {
OSMboxPost(BtnPress, PLAY_BTN); /* Signal to Message Box
*/
} Interrupt handler
main() {
… task function
Set_IntrVect(TIMER_IRQ, OSTickClk); priority
Set_IntrVect(IOPORT_IRQ, BtnCheck);

Task1 = OSCreateTask(MP3DecTask, NULL, 10);
Task2 = OSCreateTask(VolCtrlTask, NULL, 20);
Task3 = OSCreateTask(BtnCtrlTask, NULL, 30);
… 39
}
Task management of
uC/OS
• Task Control Block (TCB)
– State of task
• WAITING or READY
– Priority
– Stack
• Each task has an independent stack
• Static stack assignment
– Array variable is given as stack
• Value of registers are saved in private stack while
context switching
• Task Ready Table
– Finding highest priority task for running
– Scheduler does not need to scan whole TCB’s

40
Event management of uC/OS
• Event Control Block (ECB)
– List of tasks waiting for this event
– Event type
• Semaphore/message box/message queue
– Counter (for semaphore)
• Event ready table
– Finding highest priority task waiting for
the event
• A table is attached to each event.

41
Accessing I/O in uC/OS
unsigned int *simple_port = 0x10000;
struct { Pointer-based I/O Access
unsigned char buffer;
union {
unsigned char byte;
struct {
ready : 1; Structure of pointer
empty : 1; - well structured to model complex registers
busy : 1;
unused : 5;
} bit;
} status; Modeling flag in bit-wise access
} *uart = 0x20000;

Task1()
{
if (*simple_port ==1 ) {
*simple_port = 0; User program
}
if (uart->status.bit.ready) { 42
uart->buffer = 0x30;
Agenda
• Overview
– What is Embedded System
– What is RTOS?
• Structure of RTOS
– Priority Scheduling
– Synchronization
• Example: uC/OS
• Debugging Feature
43
Simulation Environment
• RTOS Simulation Model
– Vendor supports simulation model of RTOS.
– The designer programs his/her own modules
in programming language such as C.
– Check validity with event monitor
• Log events with precedence relationship.
• Show the order of executed tasks.
– It can only verify functional behavior.
• No method to handle timing information.

44
Simulation Environment
• Co-simulation Environment
– Connecting Instruction Set Simulator
(ISS) with HDL Simulator.
– Verify the system in cycle-accurate
level.
User Program
HW IP

Bus
ISS IPC BFM
Interface

IPC: InterProcess Communication


BFM: Bus Functional Model 45
Debugging Feature
• Source-level Debugger
– Runs with
• ISS, or
• In-Circuit Emulator(ICE), where the
Debugger controls embedded
processor execution via JTAG port

46
Example: WindRiver Tornado
II
Host Target

Core Tornado Tools Real-Time Embedded Applications

Plug-ins Graphic Connectivity


WindPower Tool Simulation Java Support File System
Environment
WindView ScopePak
Posix Lib. Connectivity
Performance CodeTest Virtual
Pak Coverage Virtual Memory
Codetest CodeTest
Mem Trace
Multiprocessor Support
Visual SlickEdit Look!

SNiFF+ SNiFF+ Pro


ethernet Debug Wind Micro-
serial line Core OS kernel
custom Agent

ICE/JTAG/BDM BSP
Third Party Tools
Wind River Reference Hardware
47
Agenda
• Overview
– What is Embedded System
– What is RTOS?
• Structure of RTOS
– Priority Scheduling
– Synchronization
• Example: uC/OS
• Debugging Feature
• Market Stauts
48
Market Environment
• Many Commercial and Free RTOSs
presents
– WindRiver(VxWork, pSOS), QNX, eCOS…
– Embedded Linux begins to spread
• Today’s commercial RTOS have
– Modular design
• You can select the function which you really want.
• Better to decrease size of required memory
– Many custom modules are prepared
• TCP/IP, SNMP, …
• And they sells…

49
Embedded Market

50
The RTOS Market Share
In-House

Wind River

JMI

QNX

Lynx OS

OS-9

VRTX

0 10 20 30 40 50 60

Source: EE Times & Beacon Technology Partners, LLC Survey, Sept. 2000
51
Conclusion
• Essential part of SoC Design
– No one mention SoC without Embedded Core
– The time in which a system programmer
builds everything on bare system is passed.
• Major jobs of RTOS are:
– Task management
– Event management
– Device management

52

Das könnte Ihnen auch gefallen