Transcript

1

Real-Time Operating Systems

Praveen Varma

www.carrertime.in

2

Contents

– Introduction– Characteristic of RTOS– Real-Time task scheduling

• Clock-driven• Event-driven

– Scheduling of real-time task on a uniprocessor• Rate Monotonic Analysis (RMA)• Earliest Deadline First (EDF)• Scheduling with limited priority levels

– Features of RTOS– Commercial real-time operating systems

• RT Linux, PSOS, VRTX, WinCE

3

Real Time System

• A system is said to be Real Time if it is required to complete it’s work & deliver it’s services on time.

4

Types of RTS:

• Hard real-time System: – Breaking the limit is always seen as a fundamental

failure– Nuclear Power Plant Controller– Flight Control System

• Soft real-time System:– Breaking the time limit is unwanted, but is not

immediately critical– web sites and services– Satellite-based applications

5

• Firm Real-Time Systems– If a deadline is missed occasionally, the system does

not fail– The results produced by a task after the deadline are

rejected– Video Conferencing

– Satellite Based Tracking

of enemy movementUtility

D Time

6

Real Time OS

Hardware

Standard OS

RT Applications

RT extension

Applications

7

Characteristic of RTOS

• Time constraints• Correctness criterion (not only logical but also

time)• Safety-Critically (safety + reliability)

• Task Criticality (cost of failure of task)

• Custom Hardware• Reactive• Stability• Exception Handling

8

OS Real-Time Extensions

• Extension of an OS by real-time components

• Cooperation between RT- and non-RT parts

• Advantages: rich functionality

• Disadvantage: – Computing and memory resources

• Example: RT-Linux, Solaris, Windows NT

9

Components of a RTOS

• Process (task) management– Scheduler– Synchronization mechanism

• Interprocess communication (IPC)• Semaphores

• Memory management• Interrupt service mechanism• I/O management• Hardware abstraction layer• Development Environments• Board Support Packages (BSP)

10

Real-Time Task Scheduling

• Scheduling of tasks is the primary means by which the operating system meets task deadlines.

• So, scheduling is an important problem.• Lot of work has been done in developing

appropriate schedulers for real-time tasks– Scheduling on uniprocessors– Scheduling on multiprocessors and distributed

systems

11

Real Time Task Scheduling

1.Clock Driven:- Table-driven & Cyclic

2. Event Driven:- Simple Priority Based

- Rate Monotonic Analysis (RMA)

- Earliest Deadline First (EDF)

3. Hybrid:- Round-robin

12

Clock-driven Scheduling

• Table-driven scheduling• Decision regarding which job to run next is made

at specific time instants– Timers are used to trigger the decision point– The job-list along with information regarding

which task to be run for how long are stored in a table

13

Clock-driven Scheduling

Task Start time Stop timeT1 100T2 101 150T3 151 225T4 226 300

14

Clock-Driven Scheduling

• The scheduler develops a permanent schedule for a period (P1,P2,...,Pn) and stores in a table.

• Round robin scheduling is an example of clock-driven scheduling

• Clock-driven schedulers are – Simple: used in low cost applications

– Efficient: very little runtime overhead

– Inflexible: Very difficult to accommodate dynamically changing task set or task characteristics.

15

Priority-based Schedulers

• These are also called event-driven schedulers– Scheduling decisions are made when certain events

occur• Tasks becoming ready• Tasks completing execution

• These are called preemptive schedulers– When a higher priority task becomes ready it

preempts the executing lower priority task

• These are greedy schedulers: – They never keep the processor idle if a task is ready.

16

Priority-based Schedulers

• Static priority schedulers:– The task priorities once assigned by the

programmers, do not change during runtime– RMA (Rate Monotonic Algorithm) is the optimal static

priority scheduling algorithm

• Dynamic priority– The task priorities can change during runtime based

on the relative urgency of completion of tasks

– EDF (Earliest Deadline First) is the optimal uniprocessor scheduling algorithm

17

Priority-based Schedulers

• First let us consider the simplest scenario:– Uni-processor– Independent tasks

• Tasks do not share resources • There is no precedence ordering among the tasks

18

Priority-based Scheduling

• Independent tasks executed on a uniprocessor – Two algorithms pretty much summarise the

important results in this scenario

• EDF (Earliest Deadline First)• RMA (Rate Monotonic Analysis )

19

EDF

• EDF is the optimal uniprocessor scheduling algorithm– If EDF cannot feasibly schedule a set of tasks, there

exists no other scheduling algorithms to do that.

• Can schedule both periodic and aperiodic tasks• Schedulability check:

– Sum of utilization due to tasks is less than one.

20

EDF

• EDF is – Simple– Optimal

• But, is rarely used– No commercially available operating system

directly supports EDF scheduling– Let us examine the disadvantages of EDF

21

Disadvantages of EDF

• Transient overload handling– EDF has very poor, overload handling

capability– When a low-criticality task becomes delayed it

can make even the most critical task miss its deadline

– In fact, it is extremely difficult to predict which task would miss its deadline when a task takes more time

22

Disadvantages of EDF

• Runtime efficiency– EDF is not very efficient– Inorder to implement EDF the tasks need to

be maintained sorted in a priority queue based on their deadline

– The complexity of maintaining a priority queue is (log n), where n is the number of tasks

23

Rate Monotonic Algorithm

• The priority of a task is proportional to its rate of occurrence.

– The higher is the rate (or lower is the period) of a task, the higher is its priority.

Rate

Priority

24

RMA

• RMA has been shown to be the optimal uniprocessor static priority scheduling algorithm

– If RMA cannot schedule a set of periodic tasks, no other scheduling algorithm can.

25

Hybrid Schedulers

• Time-Sliced Round-Robin Scheduling:- Are very commonly used in traditional OS.

- Is a preemptive scheduling method.

- Here ready tasks are held in a circular queue.

- once a task is taken from queue then it runs for a time slice & if does not complete then it inserted back in to the queue.

- Here all tasks are equal with identical time slice.

It can be extended by putting larger time slice to the higher priority tasks.

26

Resource sharing

• So far, the only resource that we considered is CPU.

• However, tasks may need to share resources such as files, memory, data structures.– These are nonpreemptable resources– Called critical sections in the operating

systems literature

27

Critical Sections

• The traditional operating system solution to share critical sections– Is through the use of semaphores.

• However, in real-time systems this solution does not work well, it gives rise to:– Priority inversion– Unbounded priority inversion

28

Features of RTOS

• Clock and Timer Support- most important issue- hard real time application support timer service with resolution of few microseconds.

• Real-Time Priority Levels- it must support static (or real-time) priority level.- where traditional OS dynamically changes the

priority levels of tasks to maximize the system throughput.

29

Features of RTOS

• Fast Task Preemption– When a high priority task arrives, an low priority task

should preempt.– the waiting time of the high priority task to start

execution is expressed as task preemption time.

• Predictable and Fast Interrupt Latency- interrupt latency is the time delay between the occurrence of an interrupt and the running of the corresponding Interrupt Service Routing (ISR).- upper bound on interrupt latency must be bounded

30

Features of RTOS

• Support for Resource sharing Among Real Time Tasks

- the resource to be shared between the real time task using Priority Ceiling Protocol (PCP)

• Requirements on Memory Management

- real time OS requires to provide virtual memory support for heavy real time tasks.

- embedded real time OS usually don't support virtual memory

31

Features of RTOS

• Support for Asynchronous I/O- asynchronous I/O means non-blocking I/O.

- where as traditional read() or write() system call performs synchronous I/O.

- in asynchronous I/O, system call will return immediately once the I/O request has been passed down to the hardware or queued in the OS, typically before the physical I/O

operation has even begun.

32

Commercial Real-Time Operating Systems

• Criteria for comparing RTOS:– Scheduling policy supported– Memory locking and other support– Timers– Interrupt handling– File system support– Device interfacing

• Embedded systems have small memories– The operating system size is important– Obviously, OS with large footprint cannot be used in

embedded applications– Power saving features are desirable

33

Other RTOS issues

• Interrupt Latency should be very small– Kernel has to respond to real time events– Interrupts should be disabled for minimum

possible time

• For embedded applications Kernel Size should be small– Should fit in ROM

• Sophisticated features can be removed– No Virtual Memory

34

Linux for Real Time Applications

• Scheduling– Priority Driven Approach

• Optimize average case response time

– Interactive Processes Given Highest Priority• Aim to reduce response times of processes

– Real Time Processes• Processes with high priority

35

RT Linux

• RT kernel intercepts and attends to all interrupts– If an interrupt is to cause a RT task to run, the

RT kernel preempts Linux (if Linux is running that time) and lets the RT task run

Hard-ware

RT Kernel

Linux

36

References:

1. Real-Time Systems Theory and Practice Rajib Mall

2. Real-Time Systems, Jane W.S. Liu

3. Real-Time Operating System, Frank Kolnick

37

questions

38

top related