Real Time Operating Systems 1 Period of computer

  • Slides: 82
Download presentation
Real Time Operating Systems 1

Real Time Operating Systems 1

 Period of computer usage can be divided into 3 eras: Mainframe: expensive computers

Period of computer usage can be divided into 3 eras: Mainframe: expensive computers Limited use of real time and embedded applications Personal computers: desktops Limited use of real time and embedded applications Post-PC: portable computer Increased use of real time and embedded applications 2

Reasons for the growth in use of real time systems Reduction in size of

Reasons for the growth in use of real time systems Reduction in size of computer Reduction in cost Improvements in the performance Increased availability and portability 3

What is real time? Those systems in which the correctness of the system depends

What is real time? Those systems in which the correctness of the system depends not only on the logical result of computation, but also on the time at which the results are produced. Real time is a quantitative notion of time Measured using a physical clock system time ( internal time ) has to be measured with same time scale as controlled environment ( external time ) 4

 E. g. chemical plant Whenever temp. reaches certain predefined level, system automatically switches

E. g. chemical plant Whenever temp. reaches certain predefined level, system automatically switches off the heater within some predefined time Logical time deals with qualitative notion of time Expressed using event ordering relations such as before, after, sometimes, precedes, succeeds etc. E. g. : query for availability of book in automated library system 5

Definition A system is called as a Real Time system when we need a

Definition A system is called as a Real Time system when we need a quantitative expression of time to describe the behavior of the system A real-time operating system (RTOS) is an operating system (OS) intended for real-time applications. A real-time operating system offers programmers more control over process priorities. An application's process priority level may exceed that of a system process. Real-time operating systems minimize critical sections of system code, so that the application's interruption is nearly critical. 6

Characteristics of Real Time Operating System Time constraints Every real time task is associated

Characteristics of Real Time Operating System Time constraints Every real time task is associated with some time constraints. One form of this time constraints is deadlines associated with tasks. Other types are delay and duration. It is the responsibility of RTOS to ensure that all tasks meet their respective time constraints. 7

Characteristics of Real Time Operating System (contd. . ) New correctness criterion Correctness implies

Characteristics of Real Time Operating System (contd. . ) New correctness criterion Correctness implies not only logical correctness of the results but also the time at which results are produced is important Logically correct result produced after the deadline would be considered as an incorrect result. 8

Characteristics of Real Time Operating System (contd. . ) Embedded Majority of real time

Characteristics of Real Time Operating System (contd. . ) Embedded Majority of real time systems are embedded in nature. An embedded system is physically embedded in its environment and often controls it. Collect data from the environment Process data Which in turn controls some characteristics of the environment 9

Characteristics of Real Time Operating System (contd. . ) Safety-criticality In traditional non-real time

Characteristics of Real Time Operating System (contd. . ) Safety-criticality In traditional non-real time systems, safety and reliability are different issues But in RTOS, they are highly related A safe system is one that does not cause any damage even it fails 10

Characteristics of Real Time Operating System (contd. . ) A reliable system is one

Characteristics of Real Time Operating System (contd. . ) A reliable system is one that can operate for long durations of time without exhibiting any failures. A safety critical system is required to be highly reliable since any failure of the system can cause extensive damage 11

Characteristics of Real Time Operating System (contd. . ) Concurrency A RTS usually needs

Characteristics of Real Time Operating System (contd. . ) Concurrency A RTS usually needs to respond to several independent events within very short and strict time bounds So they must process data concurrently, otherwise signals may be lost and the system may malfunction 12

Characteristics of Real Time Operating System (contd. . ) Distributed and feedback structure In

Characteristics of Real Time Operating System (contd. . ) Distributed and feedback structure In many real time systems, the different components of the system are naturally distributed across widely spread geographic locations Hence different events of interest arise at different locations These events often have to be handled locally 13

Characteristics of Real Time Operating System (contd. . ) Many real time systems have

Characteristics of Real Time Operating System (contd. . ) Many real time systems have a feedback structure The sensed data about the environment is processed to determine the corrective actions to be taken The results of the processing are used to carry out the corrective actions which in turn again cause a change in the characteristics of the controlled environment 14

Characteristics of Real Time Operating System (contd. . ) Task criticality It is a

Characteristics of Real Time Operating System (contd. . ) Task criticality It is a measure of the cost of failure of a task Determined by examining how critical are the results produced by the task to the proper functioning of the system A RTS may have tasks of different criticalities Hence while designing the systems, criticality of all tasks must be taken into consideration 15

Characteristics of Real Time Operating System (contd. . ) Higher is the criticality, more

Characteristics of Real Time Operating System (contd. . ) Higher is the criticality, more reliable system should be made Also in case of failure of highly critical task, immediate detection and recovery from failure is required 16

Characteristics of Real Time Operating System (contd. . ) Custom hardware A RTS is

Characteristics of Real Time Operating System (contd. . ) Custom hardware A RTS is often implemented on custom hardware that is specifically designed and developed for the purpose 17

Characteristics of Real Time Operating System (contd. . ) Reactive RTS are often reactive

Characteristics of Real Time Operating System (contd. . ) Reactive RTS are often reactive A reactive system is one in which an ongoing interaction between computer and the environment is maintained. In other words, traditional computing system produce output which is a function of input data But RTS enter into an ongoing interactions with their environment 18

Characteristics of Real Time Operating System (contd. . ) In each interaction step, the

Characteristics of Real Time Operating System (contd. . ) In each interaction step, the results computed are used to carry out some actions on the environment The reaction of the environment is sampled and is fed back to the system 19

Characteristics of Real Time Operating System (contd. . ) Stability Under overload conditions, RTS

Characteristics of Real Time Operating System (contd. . ) Stability Under overload conditions, RTS need to continue to meet the deadlines of the most critical tasks though the deadlines of noncritical tasks may not be met 20

Characteristics of Real Time Operating System (contd. . ) Exception handling Many RTS work

Characteristics of Real Time Operating System (contd. . ) Exception handling Many RTS work round the clock and often operate without human operators Taking corrective actions on a failure without human operators is difficult If no corrective action is taken, at least it is desirable that a failure does not result in catastrophic situations 21

RTOS Kernel provides an Abstraction layer that hides from application software the hardware details

RTOS Kernel provides an Abstraction layer that hides from application software the hardware details of the processor / set of processors upon which the application software shall run. Application Software RTOS Hardware 22

RTOS Kernel Functions 23

RTOS Kernel Functions 23

Job, task and timing constraints Unit of work that is schedulable and executed by

Job, task and timing constraints Unit of work that is schedulable and executed by the system is job Set of related jobs which jointly provide some system function is task Release time of a job is the instant of time at which the job becomes available for execution The job can be scheduled and executed at or after its release time whenever its data and control dependency conditions are met We say that jobs have no release time if all the jobs are 24 released when the system begins execution

Job, task and timing constraints (contd. . ) The deadline of a job is

Job, task and timing constraints (contd. . ) The deadline of a job is the instant of time by which its execution is required to be completed We say that the job has no deadline if its deadline is infinity Response time is the length of time from the release time of the job to the instant when it completes 25

Job, task and timing constraints (contd. . ) The maximum allowable response time of

Job, task and timing constraints (contd. . ) The maximum allowable response time of a job is its relative deadline Absolute deadline (deadline)is equal to its release time plus its relative deadline A system computes the control law of each furnace every 100 msec in order to process temperature readings and to control flow of fuel Suppose the system begins computation of first control law computation at time 20 msec 26

Job, task and timing constraints (contd. . ) Computation of control law is done

Job, task and timing constraints (contd. . ) Computation of control law is done periodically hence each computation of control law is a job The release time of job Jk in this job stream is 20+k*100 msec for k=0, 1, … Absolute Deadlines of these jobs are 120 msec, 220 msec and so on. The relative deadlines of these jobs are 100 msec. 27

Job, task and timing constraints (contd. . ) 28

Job, task and timing constraints (contd. . ) 28

Hard and soft timing constraints Timing constraint or deadline is hard if the failure

Hard and soft timing constraints Timing constraint or deadline is hard if the failure to meet it leads to fatal fault Usefulness of a result produced by a hard real time job falls off abruptly and may even become negative when the tardiness of job becomes larger than zero The tardiness of a job measures how late it completes respective to its deadline The timing constraint of a job is hard if the user requires 29 the validation that the system always meet the timing constraint

Hard and soft timing constraints (contd. . ) Timing constraint of a job is

Hard and soft timing constraints (contd. . ) Timing constraint of a job is soft if late completion of a job is undesirable however now serious harm if deadline is missed Usefulness of a soft real time job decreases gradually as the tardiness of the job increases No validation is required for the soft real time jobs, only the demonstration that job meet some statistical constraints is sufficient 30

Utility Function (Task Value Function) Task with a hard deadline Utility Task with a

Utility Function (Task Value Function) Task with a hard deadline Utility Task with a soft deadline 1 0 31 deadline Time

Types of Real-Time Systems Hard real-time system A system where “something very bad” happens

Types of Real-Time Systems Hard real-time system A system where “something very bad” happens if the deadline is not met Examples: control systems for aircraft, nuclear reactors, chemical power plants, jet engines, etc. Soft real-time system A system where the performance is degraded below what is generally considered acceptable if the deadline is missed Example: multimedia system 32

Overview of different classes of real-time scheduling algorithms �clock-driven �weighted round-robin �priority-driven 33

Overview of different classes of real-time scheduling algorithms �clock-driven �weighted round-robin �priority-driven 33

Clock-Driven Scheduling Decisions about what jobs execute at which times are made at specific

Clock-Driven Scheduling Decisions about what jobs execute at which times are made at specific time instants Time instants are chosen before system starts This is achieved using hardware timer Timer is set to expire periodically without intervention of scheduler When the system is initialized, scheduler selects and schedules the job that will execute until next scheduling decision time and then blocks itself waiting for the expiration of timer 34

Clock-Driven Scheduling (contd. . ) When the timer expires, scheduler awakes and repeats these

Clock-Driven Scheduling (contd. . ) When the timer expires, scheduler awakes and repeats these actions. All parameters of hard real-time jobs are fixed and known Schedule is computed off-line and is stored for use in run-time Minimizes scheduling overhead Example: Systems with periodic jobs, e. g. heating furnace controller 35

Weighted Round-Robin extends the basic round-robin algorithm with weights each job has a weight,

Weighted Round-Robin extends the basic round-robin algorithm with weights each job has a weight, which refers to the fraction of processor time allocated for the job a job with a weight w is assigned w time slices each round the length of a round is given by the sum of all weights simple to implement because no need for priority queue 36

Weighted Round-Robin (Contd. . ) algorithm is not suitable to schedule jobs with precedence

Weighted Round-Robin (Contd. . ) algorithm is not suitable to schedule jobs with precedence constraints, since time slices may be wasted due to waiting for completion of a predecessor has been used in for scheduling of real-time traffic in high-speed networks 37

Priority-Driven Scheduling assigns priorities to jobs Resources are never left idle, if there are

Priority-Driven Scheduling assigns priorities to jobs Resources are never left idle, if there are jobs ready (greedy algorithm) Scheduling decisions are locally optimal, but not globally optimal Scheduling decisions are made on events such as releases and completions of jobs (event-driven) i. e. schedule is computed online Jobs ready for execution are placed in one or more queues ordered by priority at each scheduling decision the jobs with the highest priorities are scheduled 38

Priority-Driven Scheduling (contd. . ) Priority driven scheduling algorithms can be classified based on

Priority-Driven Scheduling (contd. . ) Priority driven scheduling algorithms can be classified based on how priorities are assigned to the jobs Fixed priority- priority of each periodic task is fixed relative to other tasks Dynamic priority- assigns different priorities to the individual jobs in each task 39

Strength Priority-Driven Scheduling Priority-driven algorithms have many advantages compared to clock-driven algorithms easy to

Strength Priority-Driven Scheduling Priority-driven algorithms have many advantages compared to clock-driven algorithms easy to implement low run-time overhead information on release times and execution times is not needed a priori in order to decide when to schedule them Priority-driven scheduling better suited for applications with varying timing and resource requirements 40

 Priority driven scheduling algorithms in RTOS: Earliest deadline first (EDF) Latest release time

Priority driven scheduling algorithms in RTOS: Earliest deadline first (EDF) Latest release time (LRT) Least slack time first (LST) or Minimum Laxity First (MLT) 41

Earliest deadline first Dynamic scheduling algo. A way to assign priorities to the jobs

Earliest deadline first Dynamic scheduling algo. A way to assign priorities to the jobs on the basis of their deadlines Each time a new ready task arrives: It is inserted into the queue of ready tasks, sorted by their absolute deadlines Task at head of queue is executed If a newly arrived task is inserted at the head of the queue, the currently executing task is preempted 42

EDF (Contd. . ) It is optimal when used to schedule jobs on a

EDF (Contd. . ) It is optimal when used to schedule jobs on a processor as long as preemption is allowed and jobs do not contend for resources 43

Example of EDF Task A. T. Duration Deadline T 1 0 10 33 T

Example of EDF Task A. T. Duration Deadline T 1 0 10 33 T 2 4 3 28 T 3 5 10 29 T 1 T 2 T 3 44 0 4 7 17 23

Effective release time and deadline Release time and deadlines are sometimes inconsistent with the

Effective release time and deadline Release time and deadlines are sometimes inconsistent with the precedence of jobs Release time of a job may be later than that of its successor but deadline may be earlier than that of its predecessor Hence use effective release time and deadlines J 1 (2, 10) J 2 (0, 7) 45 J 3 (1, 12) J 5 (1, 8) J 4 (4, 9) J 6 (0, 20) J 7 (6, 21)

Effective release time If a job has no predecessor, its effective release time is

Effective release time If a job has no predecessor, its effective release time is equivalent to its own release time If a job has a predecessor, it is the maximum value among given release time and release times of its predecessors 46

Effective release time (contd. . ) J 1 (2, 10) J 3 (1, 12)

Effective release time (contd. . ) J 1 (2, 10) J 3 (1, 12) J 2 (0, 7) J 6 (0, 20) J 7 (6, 21) J 5 (1, 8) J 1 (2, 10) 47 J 4 (4, 9) J 3 (2, 12) J 5 (2, 8) J 4 (4, 9) J 6 (4, 20) J 7 (6, 21)

Effective deadline If a job has no successor, its effective deadline is equivalent to

Effective deadline If a job has no successor, its effective deadline is equivalent to its own deadline If a job has successors, it is the minimum value among given deadline and deadlines of successors 48

Effective deadline (contd. . ) J 1 (2, 10) J 2 (0, 7) J

Effective deadline (contd. . ) J 1 (2, 10) J 2 (0, 7) J 4 (4, 9) J 2 (0, 7) J 3 (2, 8) J 5 (2, 8) J 6 (4, 20) J 7 (6, 21) J 5 (2, 8) J 1 (2, 8) 49 J 3 (2, 12) J 4 (4, 9) J 6 (4, 20) J 7 (6, 21)

Latest release time (LRT) When the goal of scheduling is to meet deadlines, there

Latest release time (LRT) When the goal of scheduling is to meet deadlines, there is no advantage to complete any job sooner than necessary Hence we want to postpone the execution of hard real time jobs to enable soft real time jobs to be completed earlier So we sometimes use Latest release time algorithm (reverse of EDF) 50

LRT (contd. . ) This algo. treats release times as deadlines and deadlines as

LRT (contd. . ) This algo. treats release times as deadlines and deadlines as release time and schedules the job backwards, starting from the latest deadline of all the jobs in priority driven manner to the current time Priorities are based on the release times of jobs. Later the release time, higher is the priority Since it may leave the processor idle when there are jobs ready for execution, LRT is not a priority driven algorithm 51

Example LRT J 1, 3 (0, 6] J 2, 2 (5, 8] J 3,

Example LRT J 1, 3 (0, 6] J 2, 2 (5, 8] J 3, 2 (2, 7] J 1 0 52 1 J 3 4 J 2 6 8

LRT (contd. . ) The latest deadline among all jobs is 8. hence the

LRT (contd. . ) The latest deadline among all jobs is 8. hence the time starts at 8 and goes backward to 0 At time 8, J 2 is ready and is scheduled J 2 completes at 6 and then J 3 is scheduled from 6 to 4 Finally J 1 is scheduled from 4 to 1 53

Least slack time first (LST) Dynamic scheduling algorithm An optimal algorithm for scheduling preemptive

Least slack time first (LST) Dynamic scheduling algorithm An optimal algorithm for scheduling preemptive jobs on one processor At any time t, the slack time (laxity) of a job with deadline d is equals to (d-t-the time required to complete the remaining portion of the job) Assume the previous example: J 1 released at time 0, deadline is 6 and execution time is 3 Hence its slack time is equal to 3 at time 0 54

Least slack time first (LST) (contd. . ) Now suppose that it is preempted

Least slack time first (LST) (contd. . ) Now suppose that it is preempted at time 2 by J 3 which executes from time 2 to 4 During this interval, the slack of J 1 decreases from 3 to 1 (6 -4 -1) LST algorithm assigns priorities to jobs based on their slacks Smaller the slack time, higher is the priority 55

Least slack time first (LST) (contd. . ) While EDF algorithm does not require

Least slack time first (LST) (contd. . ) While EDF algorithm does not require any knowledge of the execution times of jobs, LST algorithm does require this knowledge But the actual execution times of jobs are not known until the job completes , which is the drawback of LST algorithm. It is impossible for us to calculate the actual amount of slack under this circumstance 56

Rate monotonic algorithm for scheduling (RMA) Priority driven scheduling for periodic tasks Each periodic

Rate monotonic algorithm for scheduling (RMA) Priority driven scheduling for periodic tasks Each periodic task denoted by Ti is a sequence of jobs The period Pi of periodic task Ti is the minimum length of all time intervals between release times of consecutive jobs in Ti its execution time ei is the maximum execution time of all the jobs in it. 57

RMA (contd. . ) At all the times, period of execution time of every

RMA (contd. . ) At all the times, period of execution time of every periodic task in the systems are known We refer to the periodic task with phase Φi , period Pi , execution time ei and relative deadline Di by the tuple (Φi , Pi , ei , Di ) E. g. T(1, 10, 3, 6) is a periodic task whose phase is 1, period is 10, execution time is 3 and relative deadline is 6 Phase is also called as release time 58

RMA (contd. . ) First job in this task is released and ready at

RMA (contd. . ) First job in this task is released and ready at time 1 and must be completed by time 7. Second job is ready at time 11 and must be completed by time 17 and so on. Each of these job executes for at most 3 units time. The utilization of this task is 0. 3 Utilization= execution/period 59

RMA (contd. . ) By default phase of each task is 0 and relative

RMA (contd. . ) By default phase of each task is 0 and relative deadline is equal to its period Hence (10, 3) means task with phase=0, period=10, execution time=3 and relative deadline=10 RMA is a fixed priority algorithm which assigns priority to tasks based on their period Shorter the period, higher is the priority. i. e. higher the rate, higher is the priority 60

RMA (contd. . ) Consider a system with 3 tasks: T 1 (4, 1)

RMA (contd. . ) Consider a system with 3 tasks: T 1 (4, 1) T 2 (5, 2) and T 3 (20, 5) T 1 has the shortest period 4 or highest rate, then T 2 and T 3 respectively 61

RMA (contd. . ) Each job of T 1 is placed at the head

RMA (contd. . ) Each job of T 1 is placed at the head of the priority queue and is executed as soon as job is released Jobs of T 2 execute in the background of T 1. Therefore execution of first job of T 2 is delayed until first job of T 1 completes Fourth job of T 2 is preempted at time 16 when fifth job of T 1 is released Similarly T 3 executes in the background of T 1 and T 2 62

RMA (contd. . ) Job of T 3 execute only when there is no

RMA (contd. . ) Job of T 3 execute only when there is no jobs in higher priority tasks ready for execution Till time 18 there is at least one job ready for execution. Hence processor is never idle until that time T 1 T 2 T 3 T 1 T 3 T 2 T 1 T 2 idle T 1 0 63 1 3 4 5 7 8 9 10 12 13 15 16 17 18 20

Types of real time tasks Hard real time task Firm real time task Soft

Types of real time tasks Hard real time task Firm real time task Soft real time task 64

Hard real time task Constrained to produce its results within certain predefined time bounds

Hard real time task Constrained to produce its results within certain predefined time bounds System is considered to have failed whenever any of its hard real time tasks does not produce its required results before the specified time bound. E. g. robot The time bounds usually range from several microseconds to few milliseconds 65

Firm real time tasks Every firm real time task is associated with some predefined

Firm real time tasks Every firm real time task is associated with some predefined deadline before which it is required to produce its results. But unlike a hard real time task, even when a firm real time task does not complete within its deadline, the system does not fail. The late results are merely discarded Firm real time tasks are typically found in multimedia applications Time bound range from a few milliseconds to several hundreds of milliseconds 66

Soft real time tasks They also have time bounds associated with them But unlike

Soft real time tasks They also have time bounds associated with them But unlike hard and firm real time tasks, they are not expressed as absolute values. Instead in terms of average response time required E. g. web browsing Time bounds usually range from a fraction of second to a few seconds 67

Types of real time tasks Based on the way real time tasks recur over

Types of real time tasks Based on the way real time tasks recur over a period of time Periodic Sporadic Aperiodic 68

Periodic task Repeats after a certain fixed time interval The precise time instants at

Periodic task Repeats after a certain fixed time interval The precise time instants at which periodic tasks recur are usually demarcated by clock interrupts Therefore sometimes also referred as clock driven task Fixed time interval after which a task repeats is called the period of that task If Ti is a periodic task, then the time from 0 till the occurrence of the first instance of Ti is denoted by Φi and is called the phase of the task. 69

 Formally a periodic task can be represented by a four tuple (Φi ,

Formally a periodic task can be represented by a four tuple (Φi , pi , ei , di ) where Φi Is the phase of task Pi is the period of task ei Is the worst case execution time di Is the deadline of task 70

Sporadic task Recurs at random instants Task Ti can be represented by 3 tuples

Sporadic task Recurs at random instants Task Ti can be represented by 3 tuples (ei , gi , di ) where ei Is the worst case execution time gi denotes the minimum separation between two consecutive instances of task di Is the relative deadline 71

Sporadic task (contd. . ) the minimum separation gi between two consecutive instances of

Sporadic task (contd. . ) the minimum separation gi between two consecutive instances of task implies that once an instance of a sporadic task occurs, the next instance can not occur before (gi) time units have elapsed. 72

Aperiodic task In many ways similar to sporadic task Can arise at random instants

Aperiodic task In many ways similar to sporadic task Can arise at random instants However, in case of aperiodic tasks, the minimum separation between two instances of tasks can be zero i. e. two or more instances of an aperiodic task can occur at the same time instant Generally soft real time tasks because they can recur in quick succession and therefore it becomes very difficult to meet the deadlines of all instances of aperiodic task 73

Priority inversion Traditional systems employ methods such as semaphores, monitors, locks to achieve the

Priority inversion Traditional systems employ methods such as semaphores, monitors, locks to achieve the mutual exclusion Use of these techniques is inadequate in RTOS It may lead to priority inversion or sometimes more serious unbounded priority inversion 74

 When a lower priority task is already holding a resource, A higher priority

When a lower priority task is already holding a resource, A higher priority task needing the same resource has to wait and can not make progress with its computation Higher priority task will remain blocked until lower priority task releases required non-pre emptable resource 75

 In this situation, higher priority task is said to undergo simple priority inversion

In this situation, higher priority task is said to undergo simple priority inversion on account of the lower priority task Unavoidable when two or more tasks share non-preemptable resources The duration for which task blocks can be made smaller if all tasks are made to restrict themselves to very brief periods of critical section usage 76

Unbounded priority inversion occurs when a higher priority task waits for lower priority task

Unbounded priority inversion occurs when a higher priority task waits for lower priority task to release the resource it needs and In the meanwhile the intermediate priority tasks preempt the lower priority task from CPU usage repeatedly As a result the lower priority task can not complete its usage of the critical resources and the higher priority task waits indefinitely for its required resources to be released 77

78

78

 Consider a real time system with high priority task TH and low priority

Consider a real time system with high priority task TH and low priority task TL Assume both TH and TL need to share a critical resource R Assume that there are several tasks TI 1, TI 2, TI 3… with priorities intermediate between TH and TL and they don’t need R for their computation 79

 Assume that TL starts executing and locks R Soon afterwards TH becomes ready,

Assume that TL starts executing and locks R Soon afterwards TH becomes ready, preempts TL and starts execution Also assume that it needs the same resource R So TH is blocked and TL starts executing again Now TL may be preempted by other intermediate priority tasks which don’t require R 80

 So TH has to wait not only till TL releases the resource but

So TH has to wait not only till TL releases the resource but also till all intermediate priority tasks preempting low priority tasks complete their execution In worst case this time may be infinite 81

Thank You 82

Thank You 82