You are on page 1of 42

Real Time Operating System

Comparison with conventional OS


GPOS
General purpose OS

RTOS
Realtime OS

Too costly for embedded applications Increased demand on RT functionality


Windows NT, 2K, XP, Solaris, IBM AIX, HPUX Linux Etc

Embedded applications Industrial robots, spacecraft, industrial control, flight control, and scientific research equipment High degree of configurability and extensibility required
Linux? RT Linux VxWorks Windows CE QNX LynxOS RTEMS OS-9

Comparison with conventional OS


RT systems require specific support from OS Conventional OS kernels are inadequate w.r.t. RT requirements

delays)

Multitasking/scheduling
provided through system calls does not take time into account (introduce unbounded

achieved by setting interrupt priority > than process priority increase system reactivity but may cause unbounded delays on process execution even due to unimportant interrupts may cause priority inversion (high priority task blocked by a low priority task)

Interrupt management

Basic IPC and synchronization primitives

No concept of RT clock/deadline
Goal: Minimal Response Time
3

Real-Time Operating Systems


Definition
Systems whose correctness depends on their temporal aspects as well as their functional aspects A system is said to be Real Time if it is required to complete its work & deliver its services on time.
Timeliness on timing constraints (deadlines) Speed/average case performance are less significant. Predictability on timing constraints
4

Performance measure

Key property

Features of Real-Time Operating Systems


Timeliness

OS has to provide mechanisms for

Achieved through proper scheduling algorithms

time management handling tasks with explicit time constraints

Predictability

Core of an RTOS!

to guarantee in advance the deadline satisfaction to notify when deadline cannot be guaranteed Affected by several issues such as

characteristics of the processor (pipelinig, cache, DMA, ...), I/O & interrupts, Synchronization & IPC, Architecture, Memory management, Applications and Scheduling!
5

Features of RTOS: Services


Scheduling Resource Allocation Interrupt handling: Interrupt Latency should be very small For embedded applications Kernel Size should be small Sophisticated features can be removed
Should fit in ROM No Virtual Memory No Protection Kernel has to respond to real time events Interrupts should be disabled for minimum possible time

Fault tolerance HW/SW failures must not cause a crash Design for peak load
All scenarios must be considered

Characteristics of Real Time Operating Systems


Large and complex OR small and embedded
Vary from a few hundred lines of assembler or C to millions of lines of lines of high-level language code Concurrent control of separate system components
Devices operate in parallel in the real-world, hence, better to model this parallelism by concurrent entities in the program

Facilities to interact with special purpose hardware

Need to be able to program devices in a reliable and abstract way

Characteristics of Real Time Operating Systems


Extreme reliability and safety
Embedded systems typically control the environment in which they operate Failure to control can result in loss of life, damage to environment or economic loss We need to be able to predict with confidence the worst case response times for systems Efficiency is important but predictability is essential

Guaranteed response times

In RTS, performance guarantees are:


Task- and/or class centric Often ensured a priori

In conventional systems, performance is:


System oriented and often throughput oriented Post-processing ( wait and see )

Structure of Real time systems

Tasks in RTOS
Job (unit of work) a computation, a file read, a message transmission, etc Attributes Resources required to make progress Timing parameters
Released Execution time Absolute deadline

Relative deadline

10

Tasks in RTOS (2)


Task : a sequence of similar jobs
Periodic task (p,e)
Its jobs repeat regularly Period p = inter-release time (0 < p) Execution time e = maximum execution time (0 < e < p) Utilization U = e/p

10

15

11

Performance measures, estimating program runtimes


Completion ratio / miss ration Maximize total usefulness value (weighted sum) Maximize value of a task Minimize lateness Minimize error (imprecise tasks) Feasibility (all tasks meet their deadlines)

12

Performance metric: Response Time


Response time
Duration from released time to finish time

T1 (4,1) T2 (5,2) T3 (10,2)

5
5

10
10

15
15
13

Performance metric: Response Time


Response time
Duration from released time to finish time
Response Time of T3
T1 (4,1) T2 (5,2) T3 (10,2)

5
5

10
10

15
15
14

Task assignment
Cyclic executive scheduling Cooperative scheduling
scheduler relies on the current process to give up the CPU before it can start the execution of another process

A static priority-driven scheduler can preempt the current process to start a new process. Priorities are set pre-execution

A dynamic priority-driven scheduler can assign, and possibly also redefine, process priorities at run-time.
E.g., Earliest Deadline First (EDF), Least Laxity First (LLF)

E.g., Rate-monotonic scheduling (RMS), Deadline Monotonic scheduling (DM)

15

Scheduling in RTOS : Deadlines


Hard deadline
Disastrous or very serious consequences may occur if the deadline is missed Validation is essential : can all the deadlines be met, even under worst-case scenario? Deterministic guarantees
Ideally, the deadline should be met for maximum performance. The performance degrades in case of deadline misses. Best effort approaches Statistical guarantees

Soft deadline

16

Schedulability
Property indicating whether a real-time system (a set of real-time tasks) can meet their deadlines
(4,1) (5,2) (7,2)

17

Real-Time Scheduling
Determines the order of real-time task executions Static-priority scheduling Dynamic-priority scheduling
(4,1) (5,2) (7,2)

5
5

10
10

15
15
18

RM (Rate Monotonic)
Optimal static-priority scheduling It assigns priority according to period A task with a shorter period has a higher priority Executes a job with the shortest period T1 (4,1) T2 (5,2) T3 (7,2)

5
5

10
10

15
15
19

RM (Rate Monotonic)
Executes a job with the shortest period

T1 (4,1) T2 (5,2) T3 (7,2)

5
5

10
10

15
15
20

RM (Rate Monotonic)
Executes a job with the shortest period
Deadline Miss !
T1 (4,1) T2 (5,2) T3 (7,2)

5
5

10
10

15
15
21

EDF (Earliest Deadline First)


Optimal dynamic priority scheduling A task with a shorter deadline has a higher priority Executes a job with the earliest deadline
T1 (4,1) T2 (5,2) T3 (7,2)

5
5

10
10

15
15
22

EDF (Earliest Deadline First)


Executes a job with the earliest deadline

T1 (4,1) T2 (5,2) T3 (7,2)

5
5

10
10

15
15
23

EDF (Earliest Deadline First)


Executes a job with the earliest deadline

T1 (4,1) T2 (5,2) T3 (7,2)

5
5

10
10

15
15
24

EDF (Earliest Deadline First)


Executes a job with the earliest deadline

T1 (4,1) T2 (5,2) T3 (7,2)

5
5

10
10

15
15
25

EDF (Earliest Deadline First)


Optimal scheduling algorithm
if there is a schedule for a set of real-time tasks, EDF can schedule it.
T1 (4,1) T2 (5,2) T3 (7,2)

5
5

10
10

15
15
26

EDF Overload Conditions


Domino effect during overload conditions
Example: T1(4,3), T2(5,3), T3(6,3), T4(7,3)
Deadline Miss !

T1 0 3

T2

T3 T4 5 6 7

Better schedules :

T1 0 3

T3 5 6 7 0

T1 3

T4 5 6 7
27

RM vs. EDF
Rate Monotonic Simpler implementation, even in systems without explicit support for timing constraints (periods, deadlines) Predictability for the highest priority tasks EDF Full processor utilization Misbehavior during overload conditions

28

Priority(P1) > Priority (P2) P1, P2 share a critical section (CS) P1 must wait until P2 exits CS even if P(P1) > P(P2) Maximum blocking time equals the time needed by P2 to execute its CS In general the blocking time cannot be bounded by CS of the lower priority process
It is a direct consequence of mutual exclusion

29

Priority inversion (2)


Typical characterization of priority inversion
A medium-priority task preempts a lower-priority task which is using a shared resource on which a higher priority task is blocked If the higher-priority task would be otherwise ready to run, but a medium-priority task is currently running instead, a priority inversion is said to occur

30

Priority Inheritance
Basic protocol [Sha 1990] 1.A job J uses its assigned priority, unless it is in its CS and blocks higher priority jobs In which case, J inherits PH, the highest priority of the jobs blocked by J When J exits the CS, it resumes the priority it had at the point of entry into the CS 2.Priority inheritance is transitive Advantage Transparent to scheduler Disadvantage Deadlock possible in the case of bad use of semaphores Chained blocking: if P accesses n resources locked by processes with lower priorities, P must wait for n CS

31

Priority Inheritance (2)

32

Priority Inheritance (3)

Deadlocks

33

Priority Inheritance (4): Chained Blocking


A weakness of the priority inheritance protocol is that it does not prevent chained blocking. Suppose a medium priority thread attempts to take a mutex owned by a low priority thread, but while the low priority thread's priority is elevated to medium by priority inheritance, a high priority thread becomes runnable and attempts to take another mutex already owned by the medium priority thread. The medium priority thread's priority is increased to high, but the high priority thread now must wait for both the low priority thread and the medium priority thread to complete before it can run again. The chain of blocking critical sections can extend to include the critical sections of any threads that might access the same mutex. Not only does this make it much more difficult for the system designer to compute overhead, but since the system designer must compute the worst case overhead, the chained blocking phenomenon may result in a much less efficient system. These blocking factors are added into the computation time for tasks in the RMA analysis, potentially rendering the system unschedulable.

34

Priority Ceiling
In priority ceiling protocol, each resource is assigned a priority ceiling, which is a priority equal to the highest priority of any task which may lock the resource. A task T is allowed to enter a critical section only if its assigned priority is higher than the priority ceilings of all semaphores currently locked by tasks other than T. Task T runs at its assigned priority unless it is in a critical section and blocks higher priority tasks. When a task exits the critical section it resumes the priority it had at the point of entry into the critical section. Prevents Deadlocks and Chained Blocking

35

Priority Ceiling (2)


p0>p1>p2

36

Intertask Communication & Synchronization


These services makes it possible to pass information from one task to another without information ever being damaged. Makes it possible for tasks to coordinate & productively cooperate with each other.
37

Inter-Task communication & Synchronization


The most important communication b/w tasks in an OS is the passing of data from one task to another.

Message Producer Task

Message Receiver Task

If messages are sent more quickly than they can be handled, the OS provides message queues for holding the messages until they can be processed.

38

Message passing in OS
Most General Purpose OS actually copy messages twice as they transfer them from task to task via a message queue. Message Sender Task Message

RAM

Message RAM

Message Receiver Task

39

Message passing in RTOS


In RTOS, the OS copies a pointer to the message, delivers the pointer to the message-receiver task, and then deletes the copy of the pointer with message-sender task.

Message Sender Task Message Message Receiver Task Message

RAM

msg_ptr msg_ptr

RTOS

40

Classification (based on architectures) and applications of various RTOS RTOS for small footprint, mobile and connected
devices
RTOS for complex, hard real-time applications
The real-time features of Windows CE 3.0, a highly modular real-time embedded OS for small footprint, mobile 32-bit intelligent connected devices.

General purpose RTOS in the embedded industry

LynxOS , a POSIX-compatible, multiprocess, multithreaded OS designed for complex real-time applications that require fast and deterministic response.
VxWorks, the most widely adopted RTOS in the embedded industry. VxWorks is a flexible, scalable RTOS with over 1800 APIs and is available on all popular CPU platforms.

41

Classification (based on architectures) and applications of various RTOS RTOS for the Java Platform
Objected-oriented RTOS
pSOSystem is a modular object-oriented operating system. The objects in pSOS include tasks, memory regions, message queues, and semaphores.

The Jbed RTOS package is a real-time capable virtual machine developed for embedded systems and Internet applications under the Java platform.

Real-time features in general purpose OS Research real-time kernels:

Adding real-time features to common general purpose operating systems viz., Windows NT and UNIX.

Real-time kernels such as Spring and Arx are used for ongoing research on RTOS

42

You might also like