Sei sulla pagina 1di 53

Real Time Operating Systems

R R Dhruva Sr. Asst. Professor E. C. E. Dept.

RR Dhruva, CVR College of Engg.

Contents

Introduction to RTOS Tasks Preemption Scheduling Scheduling algorithms

RR Dhruva, CVR College of Engg.

The Challenge
The Rising Software Intensity:

RR Dhruva, CVR College of Engg.

Mobile Terminals
Software > 10X Intensity
2G 4 M bit 30MIPS 3-30MlPS --8-16 bits 10 M Hz 3G 64 M bit 200MIPS 30MIPS 50MIPS 100MIPS 16-32bits 50 M Hz

Memory Radio Channel Speech Codec Voice Control Video Codec CTRL Processor Speed

The Rising Software Intensity: Automobiles

How to meet it...

A more complex software architecture is needed to handle


multiple tasks, coordination, communication, and interrupt handling

an RTOS architecture

What Does Real-Time Mean?

Main difference to other computation: time

time means that correctness of system depends not only on logical results but also on the time the results are produced

real indicates: reaction to external events must occur during their evolution.

system time ( internal time ) has to be measured with same time scale as controlled environment ( external time )

Definition

A real-time Computer system is a computer system in which the correctness of the system behaviour depends not only on the logical results of the computation, but also on the physical instant at which these results are produced. -Kopetz
RR Dhruva, CVR College of Engg.

What is RTOS?

A multitasking operating system intended for real-time applications.

Embedded systems, industrial robots, spacecraft, industrial control and scientific research equipment.

Facilitates the creation of a real-time system Does not guarantee the final result will be real-time; this requires correct development of the software.
RR Dhruva, CVR College of Engg.

RTS: Why use a RTOS?

For many years small embedded RTS have not used a RTOS Profound (but not immediately apparent) effects of using an RTOS - major impact on software:

Dependability productivity maintainability

Significantly simplifies development of medium/large RTS


RR Dhruva, CVR College of Engg.

Real-Time means predictable !


Main difference between real time and nonreal-time : deadline Critical applications: result after deadline not only late but wrong deadline to be met under all (even worst) circumstances real time means predictable

Hard RT vs. Firm vs. Soft RT

RT task is called hard

if missing its deadline may cause catastrophic consequences on the environment under control if missing its deadline makes the result useless, but missing does not cause serious damage if meeting its deadline is desirable (e.g. for performance reasons) but missing does not cause serious damage

RT task is called firm

RT task is called soft

RTOS that is able to handle hard RT tasks is called hard real-time operating system

Hard RT vs. Firm vs. Soft RT

Typical Application Areas

Hard RT systems:

automotive : power-train control, air-bag control, steer by wire, brake by wire aircraft : engine control, aerodynamic control Weather forecast Decisions on stock exchange orders communication systems (voice over IP!) user interaction comfort electronics (body electronics in cars)
RR Dhruva, CVR College of Engg.

Firm RT systems:

Soft RT systems:

Real-Time 'is NOT' Fast

Desirable Features of RealTime Operating Systems


Timeliness OS has to provide kernel mechanisms for


time management handling tasks with explicit time constraints

Design for peak load Predictability Fault tolerance Maintainability

Tasks

Basic SW entity handled by the OS:Process Process = task in our context One processor, concurrent tasks...

CPU has to be assigned to tasks with respect to predefined criterion:scheduling policy implementation of scheduling policy: scheduling algorithm allocation of selected task to CPU: dispatching
RR Dhruva, CVR College of Engg.

Introduction to Scheduling

We observe that processes require alternate use of processor and I/O in a repetitive fashion. Each cycle consist of a CPU burst followed by an I/O burst.

RR Dhruva, CVR College of Engg.

Introduction to Scheduling

In multiprogramming systems, when there is more than one runnable tasks (i.e., ready), the operating system must decide which one to activate. The decision is made by the part of the operating system called the scheduler, using a scheduling algorithm. The scheduler is concerned with deciding policy, not providing a mechanism.

RR Dhruva, CVR College of Engg.

Introduction to Scheduling

In general, a scheduling scheme provides two features:

An algorithm for ordering the use of system resources (CPU) A means of predicting the worst-case behavior of the system when the scheduling algorithm is applied.

RR Dhruva, CVR College of Engg.

Types of Constraints
The following are general types of constraints: Timing constraints

meet your deadline respect pre-requisites access only available resources

Precedence constraints

Resource constraints

RR Dhruva, CVR College of Engg.

Task Scheduling

Three main states of tasks:


active : can potentially execute ready : is waiting for CPU running : is executing on CPU

All ready tasks are kept in ready queue


dispatching scheduling RR Dhruva, CVR College of Engg. termination

activation

Execution

Example for Schedule


Assume three tasks J1, J2, J3 At times t1, t2, t3, t4 the processor performs a context switch
idle J1 (t)
3 2 1

J2

J3

Scheduling obtained by executing three tasks J1, J2, and J3


RR Dhruva, CVR College of Engg.

t1

t2

t3

t4

Preemption

Running task may be interrupted at any point to allow a more important task to gain the processor immediately.
dispatching scheduling preemption termination

activation

Execution

RR Dhruva, CVR College of Engg.

Importance of Preemption

Tasks performing exception handling may need to preempt running tasks to ensure timely reaction Tasks may have different levels of criticalness. This can be mapped to a preemption scheme More efficient schedules can be produced with preemption

RR Dhruva, CVR College of Engg.

Scheduling Goals

All systems

Fairness - giving each process a fair share of the CPU Policy enforcement - seeing that stated policy is carried out Balance - keeping all parts of the system busy Response time - respond to requests quickly Proportionality meet users expectations Meeting deadlines - avoid losing data Predictability avoid quality degradation in multimedia systems

Interactive systems

Real-time systems

RR Dhruva, CVR College of Engg.

Real-Time Scheduling Taxonomy

RR Dhruva, CVR College of Engg.

Basic Notations (1)


i i j
i,j

set of periodic tasks a generic periodic task instance j of task i release time of i,j
i

phase of i (= i,1, i.e. release time of first instance) period of i (= interval between two consecutive activations)

RR Dhruva, CVR College of Engg.

28

Basic Notations (2)


Di relative deadline of i (relative to release time)

di,j

absolute deadline of i,j (di,j = i + (j - 1) Ti + Di)

si,j

start time of i,j (si,j ri,j )

fi,j

finishing time of i,j (fi,j di,j ) RR Dhruva, CVR College of Engg. 29

Feasible and Schedulable Sets of Tasks


Each interval [ti, ti+1) with (t) constant for t[ti, ti+1) is called time slice A preemptive schedule allows a running task to be suspended at any time.

tasks may be executed in disjoint intervals of time

A schedule is called feasible if all tasks can be completed according to a set of specified constraints A set of tasks is called schedulable if there exists at least one algorithm that can produce a feasible schedule
RR Dhruva, CVR College of Engg.

Example of Preemptive Schedule

Parameters to Characterize RT -task Ji

Arrival time ai :

the time Ji becomes ready for execution also called request time or release time, denoted by ri time necessary for execution without interruption
Ci

Computation time Ci:

Ji
t ai Si fi di

Typical parameters of a real-time task

Parameters to Characterize RT -task Ji

Deadline di:

time before which task has to be completed its execution time at which Ji start its execution time at which Ji finishes its execution

Start time Si:

Finishing time fi:

Ci Ji
t ai Si fi di

Typical parameters of a real-time task

Real Time Scheduling

Aperiodic Scheduling

Earliest Deadline First (EDF) Modified EDF Rate Monotonic Priority Assignment (RM) Earliest Deadline First (EDF) Fixed Priority Dynamic Priority
RR Dhruva, CVR College of Engg.

Periodic Scheduling

Servers

Periodic and Aperiodic Tasks

Periodic task i consists of infinite sequence of identical activities, called instances or jobs regularly activated at a constant rate Activation of first instance of i is called phase i

activation time for the kth instance of

i is ai,k= i + (k-1) Ti

Ti is called period of the task

Note: activation time <= start time

Periodic task i can be characterized by Ci, Ti and Di Ci, Ti and Di are constant for each instance. In most cases: Ti = Di Aperiodic task Ji also consists of infinite sequence of identical activities (instances) Their activations are not regular

Periodic and Aperiodic Tasks: Example

Processor Utilization Factor


Given a set of a periodic tasks the processor utilization factor U is the fraction of processor time spent in the execution of the taks set. Ci/Ti is the fraction of processor time spent in executing task i

U=
i= 1

Ci Ti

RR Dhruva, CVR College of Engg.

37

Upper Bound of Processor Utilization Factor


U can be improved by increasing tasks computation times decreasing tasks periods up to a maximum value below which is schedulable and above with is not schedulable Limit depends on task set (particular relations among tasks periods) algorithm used to schedule the tasks Uub(, A) = upper bound of processor utilization factor for a task set under a given algorithm A RR Dhruva, CVR College of Engg. 38

Least Upper Bound of Processor Utilization Factor


U = Uub (, A) => fully utilize the processor. is schedulable using A but any increase of computation time in one of the tasks makes set infeasible.

For given A least upper bound Ulub (A) is the minimum of the utilization factors over all task sets, that fully utilize the processor:

Ulub (A) = min Uub (, A)

RR Dhruva, CVR College of Engg.

39

Schedulability Test
Ulub allows to easily verify the schedulability of a task set: Uub (i) Ulub (A) => i schedulable.

Uub (i) > Ulub (A) => i may be schedulable, if the periods of the tasks are suitable related. Uub (i) > 1 => i is not schedulable

RR Dhruva, CVR College of Engg.

40

Example for Least Upper Bound for U

RR Dhruva, CVR College of Engg.

41

Rate Monotonic Scheduling


More precisely : Rate Monotonic Priority Assignment Priorities are assigned to tasks according to their request rates. Tasks with higher request rates (i.e. shorter periods) get assigned higher priority. Periods constant => RM is fixed-priority assignment RM is intrinsically preemtive: currently executing task is preempted by a newly released task with shorter period.

RR Dhruva, CVR College of Engg.

Rate Monotonic Scheduling: Example

Ulub for n Tasks


For an arbitrary set of periodic tasks, the least upper bound of the processor utilization factor under RM : Ulub = n (21/n - 1) This value decreases with increasing n and converges to Ulub = ln 2 0.69

RR Dhruva, CVR College of Engg.

44

Ulub for n Tasks


n 1 2 3 4 5 Ulub 1.000 0.828 0.780 0.757 O.743 n 6 7 8 9 10 Ulub 0.735 0.729 0.724 0.721 O.718

RR Dhruva, CVR College of Engg.

45

Concluding remarks on RM
RM is optimal among all fixed priority assignment

RM guarantees that an arbitrary set of periodic tasks is schedulable if the total processor utilization U does not exceed the value of 0.69

Ulub = 0.69 is sufficient but not necessary to guarantee the feasibility of a given task set.

RR Dhruva, CVR College of Engg.

46

Earliest Deadline First (EDF)

EDF algorithm:

Dynamic scheduling rule Selects tasks according to their absolute deadlines

Tasks with earlier deadlines will be executed at higher priorities Absolute deadline of periodic task depends on current j-th instance: di,j= i + (j - 1) Ti + Di => EDF is dynamic priority assignment

Intrinsically preemptive Applicable also for aperiodic tasks

RR Dhruva, CVR College of Engg.

EDF Schedulability Analysis


Schedulability of periodic task set handled by EDF can be verified through the processor utilization factor Ulub here is 1 , i.e. 100 % utilization achievable

Theorem A set of periodic tasks is schedulable with EDF if and only if

n i=1

ci
i

RR Dhruva, CVR College of Engg.

48

Example for EDF

RR Dhruva, CVR College of Engg.

Example: EDF vs RM

RR Dhruva, CVR College of Engg.

Survey of RTOS

LynxOS www.lynx.com Microkernel and plug in modules. UNIX compatible. pSOSystem www.windriver.com Iridium satellites. VxWorks www.windriver.com Mars Pathfinder QNX www.qnx.com Suitable for multiprocessors on big (shared memory) machines. Symbian www.symbian.com Mobile phones

RR Dhruva, CVR College of Engg.

Suggested for Further Reading


Response Time Priority Inversion Priority Inheritance Priority Ceiling

RR Dhruva, CVR College of Engg.

Questions Please...

RR Dhruva, CVR College of Engg.

Potrebbero piacerti anche