Anda di halaman 1dari 45

Real Time Operating Systems (RTOS)

Stephen Ferzetti

Types of Operating Systems


An example of a hard real time system is a digital fly-by-wire control system of an aircraft: No lateness is accepted under any circumstances, otherwise the aircraft is not controllable. Useless results if late, if the control system does not respond timely, the result is a hole in the ground. Catastrophic failure, which needs no explanation in the case of an aircraft crash. Cost of missing deadline is infinitely high, the lives of people depend on the correct working of the control system of the aircraft. A soft real-time system can be a vending machine: Rising cost for lateness of results: As it will take longer to treat a customer when the performance of the vending machine is degrading, less customers pay at this machine which results in less profits for the shop owner. Accept lower performance for lateness, it is not catastrophic when deadlines are not met. It will take longer to handle one client with the vending machine. Non real time http://www.omimo.be/encyc/techno/terms/defini/def.htm#HARD

Topics


  

Why are Real Time Operating Systems Important Processes and Threads Scheduling Deadlocks

What makes Operating Systems that are real time so important?


Nuclear Plant Example
Lets say there is a power plant And lets say that the temperature is rising And that there is 10 seconds to cool it down before it is too late But..

Nuclear Plant
Since the plant was running its anti-virus program at the time it missed its window Meltdown

The Main Reasons for Having a RTOS


 

Meeting deadlines Being able to break out of lower priority processes so that more important tasks can be accomplished When you break out of these processes that the data collected remains intact

What is a Process?


A process is an instance of a program running in a computer.

Whatis.com

The Process Model


A process can be broken into 2 parts  Resource grouping Process says what it needs to run  Execution The commands that need to occur for the command to run (handled by threads)

Threads


A thread has a program counter that keeps track of which instruction to execute next. It also has memory to store the variables it is using

Threads and Processes


int main(){

Process
Code Data Child Processes Resource List

int input; cout<<Enter a number:;

Resources
Monitor Keyboard buffer

cin >> input; cout<< you entered:<<input; return 0; }

Process Thread
cout:you entered cin: input
cout: enter a number

Critical region

Process Creation
Processes are created when:  The system is initialized  A process creates another process  The user requests a new process  Initiation of a batch job

System Initialization


There are always processes running in the background so when the system starts these initial processes begin

Process Creates a Process




A process that is running meets a condition that requires another process to run

Real World Example: A policeman is patrolling at night, then he sees something suspicious. He goes to investigate. If there is nothing he continues on his rounds. If there is something wrong he calls for backup and takes action.

The User Requests a Process




The user can start up a new program which will spawn new processes

These programs may be something less important like opening an internet browser, or they may be critical and require immediate response like the triggering of an alarm

Process States
  

Running Ready Blocked

running 1 3 2 ready 4

1. 2. 3. 4.

Process blocks for input Scheduler picks another process Scheduler picks this process Input becomes available

blocked

Running
When a process is running that means that it is accessing the processor and that its code is executing Requirements The process must have all of its devices allocated, and it must not be waiting for any other processes to run

Ready


The ready condition is when the process has all of its resources allocated and it is not waiting on any other processes, and all that it is waiting for is to have processor time

Blocked


A process is blocked when either it is waiting on other processes to complete, or it has not been able to allocate all of the devices that it needs

Process Termination
Ways a process is terminated  Normal exit (voluntary)  Error exit (voluntary)  Fatal error (involuntary)  Killed by another process (involuntary)

Termination Example


Normal Exit The document prints Error Exit The printer is out of paper Fatal Error The computer crashes Killed by another process The User cancels the job

Scheduling


When multiple processes are in the ready state a scheduler is required The scheduler uses a scheduling algorithm to decide which process can enter the critical region

Types of Scheduling Algorithms




Non-preemptive Picks a process to run and will allow it to run forever until it chooses to end Preemptive Allows the process to run, but at anytime it can force the process to move into the ready state and allow another process to run

Deadlocks
Deadlock Condition when no processes will be completed because they cannot get the resources they require
All of these conditions must be true for a deadlock to occur:  Mutual Exclusion resources may only be allocated to one process at a time  Hold and Wait A process may allocate a resource and wait for others  No Preemption A resource may not be forcibly taken away  Circular Wait Processes

Mutual Exclusion


It is important for many resources to be mutually exclusive.

If a printer was not mutually exclusive to one process at a time then if 2 processes were printing at the same time then the output would blend together and be unreadable.

Hold and Wait




When reserving the resources not all of them need to be available at that time The process can hold on to the ones that are available and wait until the others become available

This is important because if a process were to wait to have everything it may never go into the ready state. This is because processes not requiring as much might continually jump in its position.

No Preemption


This means that a resource cannot be forcibly taken away from a process

If preemption for resources was allowed then processes could constantly take away from each other and never get to the processor, or a process that was running and whose time expired might still need that resource

Circular Wait


Circular wait means that processes are holding resources that other processes need

Deadlocks
Total Resources 1 printer 1 CD drive
Process A Holding: Printer Requesting: CD Drive

Process B Holding: CD Drive Requesting: Printer

Neither process is ever completed

Strategies for dealing with deadlocks


  

Ignore the problem Detection and recovery Dynamic avoidance by careful resource allocation Prevention, canceling one of the 4 conditions for deadlocks to occur

Ignoring
 

Ostrich Algorithm Do nothing If you know for a fact that a deadlock will occur very rarely, and the system is not a critical system you may choose to use this strategies This is totally unacceptable for RTOS because reliability is a major issue

Detection and Recovery




Check and see if you are in a deadlock and attempt to get out of it

This means that the program will have to continually check and see if there is a deadlock This wastes too much time

Avoidance


This means that the program will continually check to see whether or not it is in a safe or unsafe condition Unsafe is if it is possible for a deadlock to occur Avoidance is also timely, but not as bad as detection and recovery

Prevention


To prevent a deadlock you must attack one of the conditions for a deadlock to occur

Mutual exclusion Hold and wait + No preemption Circular wait +

Attacking Circular Wait




To attack the circular wait condition we place what resources need to be used in the order that they are used This means that the process cannot obtain any resource that is farther down before getting all the higher ones

Attacking Circular Wait


Process A 1. CD drive 2. Printer 3. Monitor
In this example Process A may not hold onto the monitor until having both the CD drive and the Printer

Attacking Hold and Wait




This is the best strategy when using the real time operating system

The strategy here is requiring the process to hold all that it requires before entering accessing the processor

Attacking Hold and Wait




The reason this works best is because if the process states up front what it needs then there is a list of what each has Therefore if a process needs to be executed immediately then it can kill the processes holding the resources it needs and be run immediately

RTOS For Smart Sensors




 

Smart sensors need to make decisions on their own Their decisions also need to be quick Also it is important that data be preserved

Decision Making


There must be a sense of priority, and there needs to be the ability to break out of processes to make deadlines Since real time systems have a clock specifically so that the system knows what time it is in the world around it is able to keep deadlines

Data Preservation


The systems use threading which can save all the current information even if the program is immediately ended This allows not only the quick response but also all the data at the occurrence to be saved

Some Smart Sensor Topics where RTOS is Essential




Scheduling Communication in Real-Time Sensor Applications


Huan Li, University of Massachusetts, Amherst Prashant Shenoy, University of Massachusetts, Amherst Krithi Ramamritham, Indian Institute of Technology, India

Static Real-Time Data Distribution


Angela Uvarov, University of Rhode Island, Kingston, RI Lisa DiPippo, University of Rhode Island, Kingston, RI Victor Fay-Wolfe, University of Rhode Island, Kingston, RI Kevin Bryan, University of Rhode Island, Kingston, RI Patrick Gadrow, University of Rhode Island, Kingston, RI Timothy Henry, University of Rhode Island, Kingston, RI Matthew Murphy, University of Rhode Island, Kingston, RI Paul R. Work, Raytheon Company, Portsmouth, RI Louis P. DiPalma, Raytheon Company, Portsmouth, RI

Radio-Triggered Wake-Up Capability for Sensor Networks


Lin Gu, University of Virginia John A. Stankovic, University of Virginia

Example


An airplane has many sensors relaying data back to the pilot If something were to go wrong the sensors would need to send an error to the pilot, and take any other action (triggering an extinguisher) However it is almost as important that the sensors are able to record the data at the point of the problem so that the incident can be understood

Homework


Discuss the differences between preemptive and non-preemptive in relation to scheduling Pick a sensor you think would require a real time system and state why you picked it

Questions

References


Modern Operating Systems 2nd edition, Tanenbaum Whatis.com

Special thanks to Hussein for his help

Anda mungkin juga menyukai