rtos ss

38
REAL TIME OPERATING SYSTEM Sudheesh S Madhav

Upload: sudheesh-s-madhav

Post on 10-May-2015

983 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Rtos ss

REAL TIME OPERATING

SYSTEM

Sudheesh S Madhav

Page 2: Rtos ss

What is Real Time ?

• “ Real time in operating systems:

The ability of the operating system to provide a

required level of service in a bounded response

time.”

Page 3: Rtos ss

WHAT IS RTOS.

• It responds to inputs immediately(Real-Time).

• Here the task is completed within a specified time delay.

• In real life situations like controlling traffic signal or a

nuclear reactor or an aircraft.

• The operating system has to respond quickly.

• Necessary signaling between interrupt routines and task

code is handled by RTOS.

• RTOS can suspend one task code subroutine in the middle

of its processing in order to run another.

Page 4: Rtos ss

What a RTOS is

• Real time computing is equivalent to fast computing.

• Real time systems operate in a static environment

• Real time programming involves assembly coding, priority

interrupt programming, writing device drivers.

Page 5: Rtos ss

SELECTING AN ARCHITECTURE

• Select the simplest architecture that will meet

your response requirements.

• If response requirements not possible, RTOS

can be used.

Page 6: Rtos ss

INTRODUCTION TO RTOS

– A more complex software architecture is needed to handle

multiple tasks, coordination, communication, and interrupt

handling – an RTOS architecture

– Distinction:

• RTOS – OS and embedded software are integrated, ES

starts and activates the OS – both run in the same

address space

• RTOS includes only service routines needed by the ES

application

• Desirable RTOS properties: use less memory,

application programming interface, debugging tools,

support for variety of microprocessors, already-

debugged network drivers

Page 7: Rtos ss

CHARACTERISTICS OF RTOS.

Reliability

Predictability

Performance

Scalability

Consistency

Page 8: Rtos ss

FUNCTIONS OF RTOS

• Task management

• Scheduling

• Resource Allocation

• Interrupt Handling

Page 9: Rtos ss

Task management

• In Real Time Applications the Process is called as Task

which takes execution time and occupies memory.

• Task management is the process of managing tasks

through its life cycle.

Page 10: Rtos ss

TASK STATES

Page 11: Rtos ss

TASK AND TASK STATES

• A task – a simple subroutine

• ES application makes calls to the RTOS functions to start

tasks, passing to the OS, start address, stack pointers, etc. of

the tasks

• Task States:

– Running (Executing task)

– Ready (possibly: waiting, dormant, delayed)

– Blocked (possibly: suspended, pended)

Page 12: Rtos ss

Task States

Suspended

Pended Ready Delayed

Run

Page 13: Rtos ss

Task/Process States

• Each task/Process can belong to one and only one

state

• The Scheduler only operates on the processes in the

Ready state

• There is a single process in the Run/current state at

any time.

• Transitions to and from the Ready queue are affected

as a part of the execution of the RTOS

resource/object services or as a result of timing

events

Page 14: Rtos ss

Typical Task Operations

• creating and deleting tasks,

• controlling task scheduling, and

• obtaining task information.

Page 15: Rtos ss

SCHEDULER– Scheduler – keeps track of the state of each task and

decides which one task should go to running state.

– schedules/shuffles tasks between Running and Ready

states

– Blocking is self-blocking by tasks, and moved to Running

state via other tasks‟ interrupt signaling (when block-factor

is removed/satisfied)

– When a task is unblocked with a higher priority over the

„running‟ task, the scheduler „switches‟ context

immediately (for all pre-emptive RTOSs)

Page 16: Rtos ss

EXAMPLE PROGRAM

Page 17: Rtos ss
Page 18: Rtos ss

Preemptive and Non preemptive

RTOSPreemptive RTOS

Stops low priority task as soon as high

priority task unblocked

Non preemptive RTOS

Takes microprocessor away from the

lower priority task when that task blocks

Page 19: Rtos ss
Page 20: Rtos ss

Tasks and Data

– Each tasks has its won context - not shared, private

registers, stack, etc.

– In addition, several tasks share common data (via

global data declaration; use of „extern‟ in one task to

point to another task that declares the shared data

– Shared data caused the „shared-data problem‟

without solutions discussed in Chp4 or use of

„Reentrancy‟ characterization of functions

Page 21: Rtos ss
Page 22: Rtos ss
Page 23: Rtos ss
Page 24: Rtos ss
Page 25: Rtos ss

Semaphores and Shared Data

• A new tool for atomicity

– Semaphore – a variable/lock/flag used to control access to

shared resource (to avoid shared-data problems in RTOS)

– Protection at the start is via primitive function, called take,

indexed by the semaphore

– Protection at the end is via a primitive function, called

release, also indexed similarly

– Simple semaphores – Binary semaphores are often

adequate for shared data problems in RTOS

Page 26: Rtos ss
Page 27: Rtos ss
Page 28: Rtos ss
Page 29: Rtos ss

RTOS Semaphores & Initializing Semaphores

– Using binary semaphores to solve the „tank monitoring‟

problem

– The nuclear reactor system: The issue of initializing the

semaphore variable in a dedicated task (not in a

„competing‟ task) before initializing the OS – timing of

tasks and priority overrides, which can undermine the

effect of the semaphores

– Solution: Call OSSemInit() before OSInit()

Page 30: Rtos ss
Page 31: Rtos ss
Page 32: Rtos ss
Page 33: Rtos ss

Semaphores and Shared Data

– Reentrancy, Semaphores, Multiple Semaphores, Device

Signaling

– Each shared data (resource/device) requires a separate

semaphore for individual protection, allowing multiple tasks

and data/resources/devices to be shared exclusively, while

allowing efficient implementation and response time

– example of a printer device signaled by a report-buffering

task, via semaphore signaling, on each print of lines

constituting the formatted and buffered report

Page 34: Rtos ss
Page 35: Rtos ss

The initial values of semaphores – when not set properly

or at the wrong place

• The „symmetry‟ of takes and releases – must match or

correspond – each „take‟ must have a corresponding

„release‟ somewhere in the ES application

• „Taking‟ the wrong semaphore unintentionally (issue

with multiple semaphores)

• Holding a semaphore for too long can cause „waiting‟

tasks‟ deadline to be missed

• Priorities could be „inverted‟ and usually solved by

„priority inheritance/promotion

Page 36: Rtos ss
Page 37: Rtos ss

Semaphores and Shared Data

– Variants:

• Binary semaphores – single resource, one-at-a time, alternating in use (also for resources)

• Counting semaphores – multiple instances of resources, increase/decrease of integer semaphore variable

• Mutex – protects data shared while dealing with priority inversion problem

– Summary – Protecting shared data in RTOS

• Disabling/Enabling interrupts (for task code and interrupt routines), faster

• Taking/Releasing semaphores (can‟t use them in interrupt routines), slower, affecting response times of those tasks that need the semaphore

• Disabling task switches (no effect on interrupt routines), holds all other tasks‟ response

Page 38: Rtos ss