Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring...

29
Special Class on Real- Time Systems

Transcript of Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring...

Page 1: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Special Class on Real-Time Systems

Page 2: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Real-time vs. general operating system

• In addition to requiring logical correctness, real-time systems require temporal correctness– Logical correctness: Given an input,

the system must create the correct output

– Temporal correctness: The correct output must be created at the correct time

Page 3: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

• Real-time systems are used in a variety of applications– Safety critical systems

• Airplane autopilot, power plant controllers

– Expensive systems• Satellite controllers, Mars rovers

– Other time critical applications• Radar system, Sensor networks

– Consumer and embedded devices• Cell phones

Real-time applications

Page 4: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

• There are many active areas of research real-time systems– Scheduling algorithms– Schedulability tests– Strategies for reducing power

consumption– Real-time operating systems– Real-time programming languages– Specific real-time applications– Hardware for real-time systems

Aspects of real-time research

Page 5: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Standard real-time system model

• Periodic tasks: A mechanism for executing a job repeatedly at regular time intervals– Example: Taking the temperature and

initiating appropriate response in a power plant controller

• T = (e,p)– e = execution requirement– p = period

Page 6: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Example

• T = (3,5)– This task generates a new job every 5

time units– Each job will require at most 3 time

units to execute– The deadline of each job is equal to

the arrival time of the next job

Page 7: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Task utilization

• Given a periodic task T = (e,p), the utilization of T is e/p– Proportion of processing time this

task will require on average

• Many schedulability tests are based on task utilization

Page 8: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Two common scheduling algorithms

• Earliest Deadline First (EDF)– Jobs with earlier deadlines are given

higher priority

• Rate Monotonic (RM)– Jobs generated by tasks with shorter

periods are given higher priority

Page 9: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Example RM and EDF schedules

Three tasks, T1 = (0.5,3), T2 = (1,4), T3 = (2,6)

T3

T2

T1

T3

T2

T1

RM

EDF

EDF will meet all deadlines if it is possible to do soWe say EDF is optimal on uniprocessors

Page 10: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Utilization-based EDF test

• Given a set of periodic tasksτ = {T1 =(e1,p1), T2=(e2,p2), …,

Tn=(en,pn)}

• Let U = Σ ei/pi be the total utilization of τ

• If U ≤ 1, then τ can be successfully scheduled using preemptive EDF– No jobs will miss their deadlines

Page 11: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Utilization-based RM test

• Given a set of periodic tasksτ = {T1 =(e1,p1), T2=(e2,p2), …, Tn=(en,pn)}

• Let U = Σ ei/pi be the total utilization of τ

• If U ≤ ln 2 (≈ 0.69), then τ can be successfully scheduled using preemptive RM

• Why use RM?– Many real-time operating systems can only

schedule tasks with fixed priority• All jobs generated by the same task must have

the same priority

Page 12: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Shortcomings of periodic task model

• The periodic tasks are assumed to all start at the same time– We can easily add an offset to the

task description T = (o,e,p)

• Not all tasks can have the job’s deadline equal to the task’s period– We can easily add a deadline to the

task description T = (o,e,p,d)

Page 13: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

More serious shortcomings

• The model provided assumes all tasks are independent– Jobs may share resources

• In this case, one job may block another job

– One job may generate data that will be used by another job• In this case, we would want to impose a

precedence constraint on these jobs

Page 14: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Scheduling jobs with dependiencies

• Both blocking and precedence constraints can cause priority inversion and timing anomolies– Priority inversion: A higher priority job

may be forced to wait while a lower priority job executes

– Timing anomolies: Reducing the execution of one job may cause another job finish execution at a later time

Page 15: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Priority inversion

0 2 4 6 8 10 12 14 16 18

J3

J2

J1

= access of single-unit resource R

Page 16: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Timing anomalies

0 2 4 6 8 10 12 14 16 18

J3

J2

J1

When tasks share resources, there may be timing anomalies.

Example: Reducing J3’s critical section from 4 timeunits to 2.5 causes J1 to miss its deadline!

Page 17: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Multiprocessor Scheduling

• Scheduling analysis is much more difficult on multiprocessors

• Many tests can only guarantee feasibility when the utilization is approximately m/2, where m is the number of processors– Things get even more complicated

when there is resource sharing or precedence constraints

Page 18: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Multiprocessor Scheduling

• Hong and Leung used the following example to prove that no online scheduling algorithm can be optimal– J1 = J2 = (0; 2; 4); J3 = (0; 4; 8)– Later arrival times as follows

• J4 = J5 = (2; 2; 4), and • J4 = J 5 = (4; 4; 8).

Page 19: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Example Part 1– J1 = J2 = (0, 2, 4); J3 = (0, 4, 8)– Later arrival times as follows

• J4 = J5 = (2, 2, 4), and • J4‘ = J 5‘ = (4, 4, 8).

0 2 4 6 8 10 12 14 16 18

J3

J2

J1

J5

J4

J3 cannot execute in interval [0,2]

Page 20: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Example Part 2– J1 = J2 = (0, 2, 4); J3 = (0, 4, 8)– Later arrival times as follows

• J4 = J5 = (2, 2, 4), and • J4‘ = J 5‘ = (4, 4, 8).

0 2 4 6 8 10 12 14 16 18

J3

J2

J1

J5

J4

J3 must execute in interval [0,2]

Page 21: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Multiprocessor Scheduling of PTs

• There are optimal online algorithms for scheduling periodic tasks on multiprocessors– Pfair, LLREF, DP-Wrap

• These tasks make decisions to emulate the ideal schedule

Page 22: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

• Ideally, we would execute all tasks at a constant rate – Example T1 = (2,4), T2 = (3,6), and T3 = (6,8)

Ideal (but impractical) schedule

Unfortunately, there are only 2 processors and each can execute only one task at a time!

T3

T2

T1

2 2

1

0 4 8 12

T1 Remaining ExecutionProportion Processor per Task

Page 23: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

• All the optimal scheduling algorithms tracks the ideal schedule– Tasks are guaranteed to have executed at

ideal rate whenever they have a deadline• Hence, all deadlines are met!

Optimal Algorithms for Multiprocs

2

1

0 4 8 12

T1 Remaining Execution Actual and Ideal

CSCI 8740

Page 24: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

DP-Fair Scheduling• A global scheduling algorithm for

periodic tasks with deadlines equal to periods– The global scheduler executes whenever

a job arrives / a deadline occurs• The intervals between scheduling events is

called a time slice

– At the beginning of each slice of length L, the scheduler allocates uiL units of execution to each task Ti

• Every DP-Fair Scheduling algorithm must adhere to 3 “don’t be stupid” rules

Page 25: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Don’t Be Stupid Rules• Rule 1: Execute any job with zero laxity

– Execute right away if at risk of missing a deadline

• Rule 2: Don’t execute any job with zero remaining execution time– Don’t execute if execution time is

completed

• Rule 3: Do not allow processors to idle for more than L(m – U) time units– Do not idle more than system slack allows

Page 26: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

T3T2T1 T4 T5

DP-Wrap: A Simple DP-Fair Alg

T3 T4 T5 T2T1

• T1=(7,2), T2= (10,3), T3= (9,4), T4 = (12,7), T5 = (14,5)

• First time slice is [0,7)• Execution times are 2, 2.1, 3.1, 4.1 and 2.5, resp.

Page 27: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Extensions to the DP-Fair Rules

• DP-Fair can also be used with sporadic tasks and tasks with deadlines not equal to periods– If deadlines are ≥ periods, DP-Fair

algorithms are still optimal– If deadlines are < periods optimality

no longer holds

Page 28: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Other types of real-time systems

• Soft real-time systems– Deadlines may be missed

• Mixed real-time and non-real-time sytems– Real-time and non-real-time jobs

executing in the same system• Want non-real-time jobs to complete as

early as possible without causing real-time jobs to miss deadlines

Page 29: Special Class on Real-Time Systems. Real-time vs. general operating system In addition to requiring logical correctness, real-time systems require temporal.

Why I like researching real-time systems

• Analyzing real-time systems is like solving puzzles– Analysis is visual– Small changes in assumptions can

have large impact in analysis