36
By. Prof.Ruchi Sharma BVCOE NEW DELHI 11/01/22 1

Rtos

Embed Size (px)

DESCRIPTION

A system is said to be Real Time if it is required to complete it’s work & deliver it’s services on time. Example – Flight Control System All tasks in that system must execute on time. Non Example – PC system

Citation preview

Page 1: Rtos

By. Prof.Ruchi SharmaBVCOE

NEW DELHI

04/08/23 1

Page 2: Rtos

04/08/23 2

Fire alarm system: an example

Sensors: microcontroller based

Controllers: ARM based

Central server

Low bandwidth radio links

TCP/IP over radio

Page 3: Rtos

Fire Alarm SystemProblem

Hundreds of sensors, each fitted with Low Range Wireless Sensor information to be logged in a server &

appropriate action initiatedPossible Solution

Collaborative Action Routing

Dynamic – Sensors/controllers may go down Auto Configurable – No/easy human intervention. Less Collision/Link Clogging Less no of intermediate nodes

Fast Response Time Secure

04/08/23 3

Page 4: Rtos

04/08/23 4

Processors MIPS

Microcontrollers ~20ARM7 100-133ARM9 180-250Strong ARM 206Intel Xscale 400Mips4Kcore 400X86

Page 5: Rtos

Real Time SystemA system is said to be Real Time if it is

required to complete it’s work & deliver it’s services on time.

Example – Flight Control SystemAll tasks in that system must execute on time.

Non Example – PC system

04/08/23 5

Page 6: Rtos

Hard and Soft Real Time SystemsHard Real Time System

Failure to meet deadlines is fatalexample : Flight Control System

Soft Real Time SystemLate completion of jobs is undesirable but not

fatal.System performance degrades as more & more

jobs miss deadlinesOnline Databases

Qualitative Definition.

04/08/23 6

Page 7: Rtos

Hard and Soft Real Time Systems(Operational Definition)

Hard Real Time SystemValidation by provably correct procedures or

extensive simulation that the system always meets the timings constraints

Soft Real Time SystemDemonstration of jobs meeting some statistical

constraints suffices.

Example – Multimedia System 25 frames per second on an average

04/08/23 7

Page 8: Rtos

Role of an OS in Real Time SystemsStandalone Applications

Often no OS involvedMicro controller based Embedded Systems

Some Real Time Applications are huge & complexMultiple threadsComplicated Synchronization RequirementsFilesystem / Network / Windowing supportOS primitives reduce the software design time

04/08/23 8

Page 9: Rtos

Features of RTOS’sScheduling.

Resource Allocation.

Interrupt Handling.

Other issues like kernel size.

04/08/23 9

Page 10: Rtos

Scheduling in RTOSMore information about the tasks are

knownNo of tasksResource RequirementsRelease TimeExecution timeDeadlines

Being a more deterministic system better scheduling algorithms can be devised.

04/08/23 10

Page 11: Rtos

Scheduling Algorithms in RTOSClock Driven Scheduling

Weighted Round Robin Scheduling

Priority Scheduling (Greedy / List / Event Driven)

04/08/23 11

Page 12: Rtos

Scheduling Algorithms in RTOS (contd)Clock Driven

All parameters about jobs (release time/ execution time/deadline) known in advance.

Schedule can be computed offline or at some regular time instances.

Minimal runtime overhead.Not suitable for many applications.

04/08/23 12

Page 13: Rtos

Scheduling Algorithms in RTOS (contd)Weighted Round Robin

Jobs scheduled in FIFO mannerTime quantum given to jobs is proportional to

it’s weightExample use : High speed switching network

QOS guarantee.

Not suitable for precedence constrained jobs. Job A can run only after Job B. No point in giving time

quantum to Job B before Job A.

04/08/23 13

Page 14: Rtos

Scheduling Algorithms in RTOS (contd)Priority Scheduling (Greedy/List/Event Driven)

Processor never left idle when there are ready tasks

Processor allocated to processes according to priorities

Priorities static - at design time Dynamic - at runtime

04/08/23 14

Page 15: Rtos

Priority SchedulingEarliest Deadline First (EDF)

Process with earliest deadline given highest priority

Least Slack Time First (LSF)slack = relative deadline – execution left

Rate Monotonic Scheduling (RMS)For periodic tasksTasks priority inversely proportional to it’s

period

04/08/23 15

Page 16: Rtos

Resource Allocation in RTOS Resource Allocation

The issues with scheduling applicable here.Resources can be allocated in

Weighted Round Robin Priority Based

Some resources are non preemptibleExample : semaphores

Priority Inversion if priority scheduling is used

04/08/23 16

Page 17: Rtos

04/08/23 17

Page 18: Rtos

Solutions to Priority Inversion Non Blocking Critical Section

Higher priority Thread may get blocked by unrelated low priority thread

Priority CeilingEach resource has an assigned priorityPriority of thread is the highest of all priorities

of the resources it’s holdingPriority Inheritance

The thread holding a resource inherits the priority of the thread blocked on that resource

04/08/23 18

Page 19: Rtos

Other RTOS issuesInterrupt Latency should be very small

Kernel has to respond to real time eventsInterrupts should be disabled for minimum

possible timeFor embedded applications Kernel Size

should be smallShould fit in ROM

Sophisticated features can be removedNo Virtual MemoryNo Protection

04/08/23 19

Page 20: Rtos

Linux for Real Time ApplicationsScheduling

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 No notion of deadlines

Resource AllocationNo support for handling priority inversion

04/08/23 20

Page 21: Rtos

Interrupt Handling in LinuxInterrupts are disabled in ISR/critical

sections of the kernelNo worst case bound on interrupt latency

avaliableeg: Disk Drivers may disable interrupt for few

hundred millisecondsNot suitable for Real Time Applications

Interrupts may be missed

04/08/23 21

Page 22: Rtos

Other Problems with LinuxProcesses are non preemtible in Kernel Mode

System calls like fork take a lot of timeHigh priority thread might wait for a low

priority thread to complete it’s system callProcesses are heavy weight

Context switch takes several hundred microseconds

04/08/23 22

Page 23: Rtos

Why LinuxCoexistence of Real Time Applications with

non Real Time OnesExample http server

Device Driver BaseStability

04/08/23 23

Page 24: Rtos

RTLinuxReal Time Kernel at the lowest levelLinux Kernel is a low priority thread

Executed only when no real time tasksInterrupts trapped by the Real Time Kernel

and passed onto Linux KernelSoftware emulation to hardware interrupts

Interrupts are queued by RTLinux Software emulation to disable_interrupt()

04/08/23 24

Page 25: Rtos

RTLinux (contd)Real Time Tasks

Statically allocate memoryNo address space protection

Non Real Time Tasks are developed in LinuxCommunication

QueuesShared memory

04/08/23 25

Page 26: Rtos

04/08/23 26

Page 27: Rtos

rtker – Our RTOSMotivation

Our own OS Full grasp over source code – Easily modifiable,

portable

FeaturesModular Design

Isolation of Architecture/CPU dependent and independent code – Easy to Port

Pluggable SchedulerTwo level Interrupt HandlingSmall footprintOskit’s Device Driver Framework

04/08/23 27

Page 28: Rtos

Pluggable SchedulerScheduler - part of the ApplicationKernel interacts with the scheduler through

an API Application developer needs to implement

the scheduler APICan optimize on Data Structures & Algorithms

for implementing the scheduler

04/08/23 28

Page 29: Rtos

rtker – Block Diagram

04/08/23 29

Page 30: Rtos

Two Level Interrupt HandlingTwo level Interrupt Handling

Top Half Interrupt Handler Called Immediately – Kernel never disables interrupts Cannot invoke thread library functions - Race

Conditions

Bottom Half Interrupt Handler Invoked when kernel not in Critical Section Can invoke thread library functions

Very Low Response time (as compared to Linux)

04/08/23 30

Page 31: Rtos

Two Level Interrupt Handling

04/08/23 31

Page 32: Rtos

04/08/23 32

Page 33: Rtos

Other FeaturesFootprint

Small footprint (~50kb) Oskit’s Device Driver Framework

Allows direct porting of existing drivers from Linux.

Example – Ethernet Driver of Linux

04/08/23 33

Page 34: Rtos

Other RTOS’sLynxOS

Microkernel Architecture Kernel provides scheduling/interrupt handling

Additional features through Kernel Plug Ins(KPIs) TCP/IP stack , Filesystem KPI’s are multithreaded

Memory Protection/ Demand Paging OptionalDevelopment and Deployment on the same

host OS support for compilers/debuggers

04/08/23 34

Page 35: Rtos

Other RTOS’s (contd)VxWorks

Monolithic ArchitectureReal Time Posix compliantCross development System

pSOSObject Oriented OS

04/08/23 35

Page 36: Rtos

04/08/23 36

• Interfacing Serial/parallel ports, USB, I2C, PCMCIA, IDE• Communication Serial, Ethernet, Low bandwidth radio, IrDA, 802.11b based devices• User Interface LCD, Keyboard, Touch sensors, Sound, Digital pads, Webcams• Sensors A variety of sensors using fire, temperature, pressure, water level, seismic, sound, vision