35
Presentation Presentation on on Real Time Operating Systems Real Time Operating Systems

TCIL 18 Real Time Operating Systems

Embed Size (px)

Citation preview

Page 1: TCIL 18 Real Time Operating Systems

Presentation Presentation on on

Real Time Operating SystemsReal Time Operating Systems

Page 2: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 22

ContentsContents

• Real Time System Fundamentals Real Time System Fundamentals

• Real Time Operating System (RTOS)Real Time Operating System (RTOS)

• Linux as RTOSLinux as RTOS

Page 3: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 33

What are Real-time Systems ?What are Real-time Systems ?

• Real-time systemsReal-time systems

Those systems in which the Those systems in which the correctnesscorrectness of the of the system depends system depends not onlynot only on the on the logical resultlogical result of computation, of computation, but alsobut also on the on the timetime at which at which the results are produced.the results are produced.

Page 4: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 44

Types of Real Time SystemsTypes of Real Time Systems

• Based on Hard deadlineBased on Hard deadline: Penalty due to : Penalty due to missing deadline is a higher order of missing deadline is a higher order of magnitude than the Reward in meeting the magnitude than the Reward in meeting the deadline.deadline.

• Based on Soft deadlineBased on Soft deadline: Penalty often equal / : Penalty often equal / lesser magnitude than Reward.lesser magnitude than Reward.

Page 5: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 55

A Sample Real Time System (1)A Sample Real Time System (1)

Page 6: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 66

A Sample Real Time System (2)A Sample Real Time System (2)

• Mission:Mission: Reaching the destination safely. Reaching the destination safely.

• Controlled System: Controlled System: Car.Car.

• Operating environment:Operating environment: Road conditions. Road conditions.

• Controlling SystemControlling System - Human driver:- Human driver: Sensors - Eyes and Ears of the Sensors - Eyes and Ears of the driver. driver. - Computer:- Computer: Sensors - Cameras, Infrared receiver, Sensors - Cameras, Infrared receiver, and Laser telemeter.and Laser telemeter.

Page 7: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 77

A Sample Real Time System (3)A Sample Real Time System (3)

• Controls:Controls: Accelerator, Steering wheel, Break-pedal. Accelerator, Steering wheel, Break-pedal.

• Actuators:Actuators: Wheels, Engines, and Brakes. Wheels, Engines, and Brakes.

• Critical tasks:Critical tasks: Steering and breaking Steering and breaking

• Non-critical tasks:Non-critical tasks: Turning on radio Turning on radio

Page 8: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 88

A Sample Real Time System (4)A Sample Real Time System (4)

• PerformancePerformance is not an absolute one. It measures is not an absolute one. It measures the goodness of the outcome relative to the best the goodness of the outcome relative to the best outcome possible under a given circumstance. outcome possible under a given circumstance.

• Cost of fulfilling the missionCost of fulfilling the mission →→ Efficient solution. Efficient solution.

• Reliability of the driverReliability of the driver →→ Fault-tolerance is a Fault-tolerance is a must. must.

Page 9: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 99

ContentsContents

• Real Time System Fundamentals Real Time System Fundamentals

• Real Time Operating System (RTOS)Real Time Operating System (RTOS)

• Linux as RTOSLinux as RTOS

Page 10: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 1010

RTOS KernelRTOS Kernel• RTOS Kernel provides an Abstraction layer that RTOS Kernel provides an Abstraction layer that

hides from application software the hardware hides from application software the hardware details of the processor / set of processors upon details of the processor / set of processors upon which the application software shall run.which the application software shall run.

Application Software

RTOS

Hardware

Page 11: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 1111

RTOS Kernel FunctionsRTOS Kernel Functions

Page 12: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 1212

Task ManagementTask Management

• Set of services used to allow application software developers Set of services used to allow application software developers to design their software as a number of separate chunks of to design their software as a number of separate chunks of software each handling a distinct topic, a distinct goal, and software each handling a distinct topic, a distinct goal, and sometimes its own real-time deadline. sometimes its own real-time deadline.

• Main service offered is Task Scheduling Main service offered is Task Scheduling – controls the execution of application software tasks controls the execution of application software tasks

– can make them run in a very timely and responsive fashion.can make them run in a very timely and responsive fashion.

Page 13: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 1313

Task SchedulingTask Scheduling

• Non Real -time systems usually use Non-preemptive Non Real -time systems usually use Non-preemptive Scheduling Scheduling – Once a task starts executing, it completes its full executionOnce a task starts executing, it completes its full execution

• Most RTOS perform priority-based preemptive task Most RTOS perform priority-based preemptive task scheduling.scheduling.

• Basic rules for priority based preemptive task schedulingBasic rules for priority based preemptive task scheduling– The Highest Priority Task that is Ready to Run, will be the Task The Highest Priority Task that is Ready to Run, will be the Task

that Must be Running.that Must be Running.

Page 14: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 1414

Priority based Preemptive Task Priority based Preemptive Task Scheduling Scheduling

• Every Task in a software application is assigned a Every Task in a software application is assigned a priority.priority.

• Higher Priority = Higher Need for Quick Response.Higher Priority = Higher Need for Quick Response.

• Follows nested preemption Follows nested preemption

Page 15: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 1515

Nested PreemptionNested Preemption

Timeline for Priority-based Preemptive Scheduling

Page 16: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 1616

Task Switch (1)Task Switch (1)

• Each time the priority-based preemptive scheduler is Each time the priority-based preemptive scheduler is alerted by an External world trigger / Software alerted by an External world trigger / Software trigger it shall go through the following steps that trigger it shall go through the following steps that constitute a constitute a Task SwitchTask Switch::

– Determine whether the currently running task should Determine whether the currently running task should

continue to run. continue to run. – Determine which task should run next.Determine which task should run next.– Save the environment of the task that was stopped (so it Save the environment of the task that was stopped (so it

can continue later).can continue later).– Set up the running environment of the task that will run Set up the running environment of the task that will run

next.next.– Allow the selected task to run.Allow the selected task to run.

Page 17: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 1717

Task Switch (2)Task Switch (2)

• A Non Real time operating system might do task A Non Real time operating system might do task switching only at timer tick times. switching only at timer tick times.

• Even with preemptive schedulers a large array of Even with preemptive schedulers a large array of tasks is searched before a task switch.tasks is searched before a task switch.

• A Real time OS shall use Incrementally arranged A Real time OS shall use Incrementally arranged tables to save on time.tables to save on time.

Page 18: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 1818

Task Switch (3)Task Switch (3)

Task Switching Timing Task Switching Timing

Page 19: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 1919

Intertask Communication & Intertask Communication & Synchronization Synchronization

• These services makes it possible to pass These services makes it possible to pass information from one task to another information from one task to another without information ever being damaged.without information ever being damaged.

• Makes it possible for tasks to coordinate & Makes it possible for tasks to coordinate & productively cooperate with each other. productively cooperate with each other.

Page 20: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 2020

Inter-Task communication & Inter-Task communication & SynchronizationSynchronization

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

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

MessageProducer Task

Message Receiver Task

Page 21: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 2121

Message passing in OSMessage passing in OS

• Most General Purpose OS actually copy messages twice as they Most General Purpose OS actually copy messages twice as they transfer them from task to task via a message queue. transfer them from task to task via a message queue.

Message Sender Task RAM

Message

RAMMessage Receiver

Task

Message

Page 22: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 2222

Message passing in RTOSMessage passing in RTOS• In RTOS, the OS copies a pointer to the message, In RTOS, the OS copies a pointer to the message,

delivers the pointer to the message-receiver task, delivers the pointer to the message-receiver task, and then deletes the copy of the pointer with and then deletes the copy of the pointer with message-sender task.message-sender task.

Message Sender Task

RAM

Message Receiver Task

RTOSmsg_ptr

msg_ptr

Message Message

Page 23: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 2323

DDynamic ynamic MMemory emory AAllocation llocation in General Purpose OSin General Purpose OS

• Non-real-time operating systems offer memory allocation Non-real-time operating systems offer memory allocation services from what is termed a services from what is termed a Heap.Heap.

• Heaps suffer from a phenomenon called Heaps suffer from a phenomenon called External Memory External Memory Fragmentation.Fragmentation.

• Fragmentation problem is solved by Fragmentation problem is solved by Garbage collection / Garbage collection / Defragmentation.Defragmentation.

• Garbage collection algorithms are often wildly non-Garbage collection algorithms are often wildly non-deterministic.deterministic.

Page 24: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 2424

DDynamic ynamic MMemory emory AAllocation llocation in RTOSin RTOS

• RTOS does it by a mechanism known as Pools. RTOS does it by a mechanism known as Pools.

• Pools memory allocation mechanism allows application Pools memory allocation mechanism allows application software to allocate chunks of memory of 4 to 8 different software to allocate chunks of memory of 4 to 8 different buffer sizes per pool.buffer sizes per pool.

• Pools avoid external memory fragmentation, by not Pools avoid external memory fragmentation, by not permitting a buffer that is returned to the pool to be broken permitting a buffer that is returned to the pool to be broken into smaller buffers in the future.into smaller buffers in the future.

• When a buffer is returned the pool, it is put onto a When a buffer is returned the pool, it is put onto a free free buffer listbuffer list of buffers of its own size that are available for of buffers of its own size that are available for future re-use at their original buffer sizefuture re-use at their original buffer size

Page 25: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 2525

ContentsContents

• Real Time System Fundamentals Real Time System Fundamentals

• Real Time Operating System (RTOS)Real Time Operating System (RTOS)

• Linux as RTOSLinux as RTOS

Page 26: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 2626

Dark Side of Linux Dark Side of Linux in Real-Timein Real-Time

• The Linux kernel (< version 2.6) is The Linux kernel (< version 2.6) is neither preemptive neither preemptive nor reentrant nor reentrant by user processes. by user processes.

• Processes are heavy-weightProcesses are heavy-weight: Linux has : Linux has insufficient insufficient resource handlingresource handling. .

• Fair share scheduling algorithm .Fair share scheduling algorithm .

• Unbound amount of CPU time used by Unbound amount of CPU time used by interrupt interrupt handlers handlers under Linux, and these run at a higher priority under Linux, and these run at a higher priority than any user process.than any user process.

Page 27: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 2727

Typical Solutions for LinuxTypical Solutions for Linux

• 3 ways to deal with Linux’ s poor real-time 3 ways to deal with Linux’ s poor real-time performance :performance :

– Ignore Ignore the problem (only for soft real-time).the problem (only for soft real-time).

– Work around Work around and run real-time applications under an and run real-time applications under an RTOS with Linux itself as a separate task. e.g. RT-RTOS with Linux itself as a separate task. e.g. RT-Linux.Linux.

– Adapt Linux Adapt Linux and run a Linux compatible RTOS kernel and run a Linux compatible RTOS kernel instead of the Linux kernel.instead of the Linux kernel.

Page 28: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 2828

Ignore the problem ApproachIgnore the problem Approach

• The most popular approach is to The most popular approach is to ignore the problemignore the problem..

• Mostly works for Mostly works for soft real-time systems.soft real-time systems.

• Design recommendations to reduce latencyDesign recommendations to reduce latency

– If possible, address all real-time response needs directly If possible, address all real-time response needs directly with interrupt service routines.with interrupt service routines.

– Avoid known excessive interrupt-off periods in Linux.Avoid known excessive interrupt-off periods in Linux.

– If a process component is required in the real-time If a process component is required in the real-time control path, then consider aggregate system loading & control path, then consider aggregate system loading & Adapt processesAdapt processes..

Page 29: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 2929

Work Around ApproachWork Around Approach

• Linux kernel runs as a task under a small real-time executive. Linux kernel runs as a task under a small real-time executive.

• Real-time tasks are run directly under the real-time executiveReal-time tasks are run directly under the real-time executive

• Non-real-time tasks are run under Linux.Non-real-time tasks are run under Linux.

• Applications that work on such a system can include machine Applications that work on such a system can include machine control, process control, and instrumentation applications.control, process control, and instrumentation applications.

Page 30: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 3030

Work Around - AdvantagesWork Around - Advantages

• The real-time executive can be small and simple making it The real-time executive can be small and simple making it easier to verify its real-time performance.easier to verify its real-time performance.

• The Linux kernel running non-real-time tasks is "standard" The Linux kernel running non-real-time tasks is "standard" Linux so it is compatible with other Linux distributions and Linux so it is compatible with other Linux distributions and can easily be updated.can easily be updated.

• Supports hard real-time applications.Supports hard real-time applications.

Page 31: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 3131

Work Around - DisadvantagesWork Around - Disadvantages

• Not applicable if real-time part of the software is large / Not applicable if real-time part of the software is large / not easily separated from the code that needs a Linux not easily separated from the code that needs a Linux environment environment

• Tasks running under the real-time executive do not have Tasks running under the real-time executive do not have access to the Linux facilities, device drivers, etc.access to the Linux facilities, device drivers, etc.

• Tasks running under the Linux kernel and can access the Tasks running under the Linux kernel and can access the facilities are not real-time. facilities are not real-time.

• Programmers tend to increase the number of facilities in Programmers tend to increase the number of facilities in the real-time kernel until the real-time executive replicates the real-time kernel until the real-time executive replicates facilities of Linux.facilities of Linux.

Page 32: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 3232

Adapt LinuxAdapt Linux

• The original Linux kernel is The original Linux kernel is replaced with a compatible replaced with a compatible kernel kernel with hard real-time performance characteristics.with hard real-time performance characteristics.

• The kernel is only a small part of a whole operating system. If The kernel is only a small part of a whole operating system. If just the Linux kernel is replaced and the libraries, utilities, and just the Linux kernel is replaced and the libraries, utilities, and file structure remain the same.file structure remain the same.

• The real-time kernel must support all the facilities of a Linux The real-time kernel must support all the facilities of a Linux kernel while still remaining fully preemptive and reentrant.kernel while still remaining fully preemptive and reentrant.

Page 33: TCIL 18 Real Time Operating Systems

(c) Telecommunications Consultants India Limited(c) Telecommunications Consultants India Limited 3333

Adapt Linux Approach Adapt Linux Approach Advantages & DisadvantagesAdvantages & Disadvantages

• Advantages:Advantages:– No limits on the size and complexity of the real-time No limits on the size and complexity of the real-time

application code.application code.– Third party software not originally envisioned for real-Third party software not originally envisioned for real-

time use can be invoked by real-time tasks time use can be invoked by real-time tasks – With the same programming interfaces, programmers With the same programming interfaces, programmers

who understand Linux would already be experts in the who understand Linux would already be experts in the real-time environment.real-time environment.

• Disadvantages:Disadvantages:– With modified Linux you are NOT sure of full With modified Linux you are NOT sure of full

compatibility with standard Linux applicationcompatibility with standard Linux application

Page 34: TCIL 18 Real Time Operating Systems

Any Questions?Any Questions?

Page 35: TCIL 18 Real Time Operating Systems

Thank YouThank You !!