Lecture 11: Scheduling

Size: px
Start display at page:

Download "Lecture 11: Scheduling"

Transcription

1 Design & Co-design of Embedded Systems Lecture 11: Scheduling Sharif University of Technology Computer Engineering Dept. Winter-Spring 2008 Mehdi Modarressi

2 Processes and operating systems Dynamic vs. static scheduling Scheduling policies: RMS; EDF. Reference (and slides): Reference (and slides): Wayne Wolf, Computers as Components: Principles of Embedded Computing System Design, Chapter 6 (Processes and Operating Systems), MKP, 2001.

3 Scheduling Scheduling: Given a set of processes and optionally a set of performance constraints, determines a total order in time for invoking processes running on the same PE or use the same system resources. Another important constraint: power consumption

4 Static Scheduling Ordering information known at design time Timing information known at design time Each process is executed according to a fixed schedule. The scheduler computes the best schedule at design time and the schedule does not change at run time.

5 Static Task Scheduling

6 Static Scheduling Ordering and timing information may be unknown until runtime Waiting for external events Cache impact (different memory latencies) Different execution times for an instruction based on input data (in some machines) Conditional instructions (different paths of a branch) Scheduling based on worst-case timing Using dynamic scheduling

7 Dynamic Scheduling An scheduler maintains a pool of processes ready to be executed Selects a ready process based on an scheduling policy

8 Metrics How do we evaluate a scheduling policy: Ability to satisfy all deadlines. CPU utilization---percentage of time devoted to useful work. Scheduling overhead---time required to make scheduling decision.

9 Rate monotonic scheduling RMS (Liu and Layland): widely-used used, analyzable scheduling policy. Analysis is known as Rate Monotonic Analysis (RMA).

10 RMA model All process run on single CPU. Zero context switch time. No data dependencies between processes. Process execution time is constant. Deadline is at end of period. Highest-priority ready process runs.

11 Process parameters T i is computation time of process i; τ i is period of process i. period τ i Pi computation time T i

12 Rate-monotonic analysis Response time: time required to finish process. Critical instant: scheduling state that gives worst response time. Critical instant occurs when all higher-priority processes are ready to execute.

13 Critical instant interfering processes P1 P1 P1 P1 P1 P2 P2 P2 critical instant P3 P4 P3

14 RMS priorities Optimal (fixed) priority assignment: shortest-period process gets highest priority; priority inversely proportional to period; break ties arbitrarily. No fixed-priority scheme does better.

15 RMS example P2 period P2 P1 period P1 P1 P time

16 RMS CPU utilization Utilization for n processes is Σ i T i / τ i As number of tasks approaches infinity, maximum utilization approaches 69%.

17 RMS CPU utilization, cont d. RMS cannot asymptotically guarantee use 100% of CPU, even with zero context switch overhead. Must keep idle cycles available to handle worst-case scenario. However, RMS guarantees all processes will always meet their deadlines.

18 RMS implementation Efficient implementation: scan processes; choose highest-priority active process.

19 Earliest-deadline-first scheduling EDF: dynamic priority scheduling scheme. Process closest to its deadline has highest priority. Requires recalculating processes at every timer interrupt.

20 EDF example P1 P2

21 EDF analysis EDF can use 100% ofcpu CPU. But EDF may miss a deadline.

22 EDF implementation On each timer interrupt: compute time to deadline; choose process closest to deadline. Generally considered too expensive to use in practice.

23 Fixing scheduling problems What if your set of processes is unschedulable? Change deadlines in requirements. Reduce execution times of processes. Get a faster CPU.

24 Priority inversion Priority inversion: low-priority process keeps high-priority process from running. Improper use of system resources can cause scheduling problems: Low-priority process grabs I/O device. High-priority device needs I/O device, but can t get it until low-priority process is done. Can cause deadlock.

25 Solving priority inversion Give priorities to system resources. Have process inherit the priority of a resource that it requests. Low-priority process inherits priority of device if higher.

26 Data dependencies Data dependencies allow us to improve utilization. Restrict combination of processes that can run simultaneously. P1 and P2 can t run simultaneously. P1 P2

27 Context-switching time Non-zero context switch time can push limits of a tight schedule. Hard to calculate effects---depends on order of context switches. In practice, OS context switch overhead is small.

28 What about interrupts? Interrupts take time away from processes. Perform minimum work possible in the interrupt handler. P1 OS intr P2 OS P3

29 Device processing structure Interrupt service routine (ISR) performs minimal I/O. Get register values, put register values. Interrupt service process/thread performs most of device function.

30 Summary Two major scheduling policies RMS EDF Other parameters affecting scheduling Priority inversion Data dependencies Context switching time Interrupts