4. CPU Scheduling - René Doursat

Mar 28, 2006 - Transition diagram of a seven-state model program is on disk ... power-law: large # of short CPU bursts, small # of large bursts. 3/28/2006 ... cooperative scheduling — let a process run until it blocks on I/O ... nuclear plant).
255KB taille 1 téléchargements 60 vues
Principles of Operating Systems CS 446/646

4. CPU Scheduling

René Doursat Department of Computer Science & Engineering University of Nevada, Reno Spring 2006

Principles of Operating Systems CS 446/646 0. Course Presentation 1. Introduction to Operating Systems 2. Processes 3. Memory Management 4. CPU Scheduling 5. Input/Output 6. File System 7. Case Studies

3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

2

Principles of Operating Systems CS 446/646 4. CPU Scheduling a. Concepts of Scheduling b. Scheduling Algorithms c. Queuing Analysis d. Thread Scheduling

3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

3

Principles of Operating Systems CS 446/646 4. CPU Scheduling a. Concepts of Scheduling 9 Three-level scheduling 9 Purpose of CPU scheduling

b. Scheduling Algorithms c. Queuing Analysis d. Thread Scheduling

3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

4

4.a Concepts of Scheduling Three-level scheduling

¾ Medium-term scheduling 9 the decision to add to the number of processes that are partially or fully in main memory (“swapping”) 9 not the same as paging: swapping out means removing all the pages of a process

¾ Short-term scheduling = CPU scheduling 9 the decision as to which available processes in memory are to be executed by the processor (“dispatching”) 3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

5

frequency of intervention

9 the decision to add a program to the pool of processes to be executed: controls the degree of multiprogramming

fine- to coarse-grain time scale

¾ Long-term scheduling (mostly in batch)

4.a Concepts of Scheduling Three-level scheduling

¾ Three-level scheduling

SHORT-TERM

Tanenbaum, A. S. (2001) Modern Operating Systems (2nd Edition).

LONG-TERM

MID-TERM

Three-level scheduling 3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

6

4.a Concepts of Scheduling Three-level scheduling

¾ Reminder: process states

dispatch

admit

Ready

ti v at ac

admit

s

Suspended Ready

nd e p us

e ti v at ac

program is on disk 3/28/2006

event occurs

Blocked

event occurs

Suspended Blocked

Running

release

Exit

timeout

e

New

s

Stallings, W. (2004) Operating Systems: Internals and Design Principles (5th Edition).

event wait program is in memory

nd e p us

Transition diagram of a seven-state model CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

7

4.a Concepts of Scheduling Three-level scheduling

¾ In the O/S, the CPU scheduler decides which “Ready” process to run next (and which “Running” to time out) 9 the discipline it follows is the scheduling algorithm New

Ready

Running

Exit

LONG-TERM Stallings, W. (2004) Operating Systems: Internals and Design Principles (5th Edition).

SHORT-TERM Suspended Ready MID-TERM

program is on disk 3/28/2006

Suspended Blocked

Blocked

program is in memory

Transition diagram of a seven-state model CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

8

4.a Concepts of Scheduling Three-level scheduling

¾ General queuing system for scheduling 9 in most algorithms, queues are not strictly FIFO: rather “pools”

Stallings, W. (2004) Operating Systems: Internals and Design Principles (5th Edition).

Queuing diagram for scheduling 3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

9

4.a Concepts of Scheduling Purpose of CPU scheduling

¾ Why scheduling matters: user service response 9 example: choosing between ƒ a process that updates the screen after the user has closed a window ƒ a process that sends out queued email 9 taking 2 seconds to close the window while sending the email would be unacceptable 9 on the other hand, delaying the email while closing the window would hardly be noticed → schedule wisely to match user’s expectations

3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

10

4.a Concepts of Scheduling Purpose of CPU scheduling

¾ Why scheduling matters: CPU usage 9 switching processes (contexts) is heavy ƒ switch from user mode to kernel mode ƒ CPU state must be saved ƒ process state must be saved ƒ pages and page bits must be saved ƒ MMU must be reloaded with new page table ƒ etc. → to maximize CPU utilization, interleave but at the same time minimize process switches

3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

11

4.a Concepts of Scheduling Purpose of CPU scheduling

¾ Types of process behavior: CPU-I/O burst cycle 9 processes alternate CPU usage with I/O wait ƒ compute-bound processes have long CPU bursts and infrequent I/O ƒ I/O-bound processes have short CPU bursts and frequent I/O

Tanenbaum, A. S. (2001) Modern Operating Systems (2nd Edition).

(a) Compute-bound process vs. (b) I/O-bound process 3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

12

4.a Concepts of Scheduling Purpose of CPU scheduling

¾ Types of process behavior: CPU-I/O burst cycle 9 power-law: large # of short CPU bursts, small # of large bursts

Silberschatz, A., Galvin, P. B. and Gagne. G. (2003) Operating Systems Concepts with Java (6th Edition).

3/28/2006

Typical histogram of CPU-burst times

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

13

4.a Concepts of Scheduling Purpose of CPU scheduling

¾ I/O-bound processes 9 as CPU speeds increase, processes generally tend to become more and more I/O-bound 9 the scheduling of I/O-bound processes will likely become an important subject in the future → basic idea: an I/O-bound process that is “Ready” to run should get the CPU quickly so it can keep the disk busy

3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

14

4.a Concepts of Scheduling Purpose of CPU scheduling

¾ When scheduling decisions must be made 9 when a new process is created — run the child or the parent? 9 when a process exits — who’s next? 9 when an I/O interrupt occurs upon finishing an I/O task — should the waiting process be rescheduled? or let the currently running process continue? or pick another process? etc. 9 when a timeout (clock interrupt) occurs — who’s next?

3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

15

4.a Concepts of Scheduling Purpose of CPU scheduling

¾ Two kinds of CPU-scheduling algorithms 9 cooperative scheduling — let a process run until it blocks on I/O, terminates or voluntarily releases the CPU (system call) Ready

Running

Blocked

9 preemptive scheduling — follow clock interrupts (ex: 50Hz) to forcibly switch processes (demote the “Running” to “Ready”) Ready

Running

Blocked 3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

16

4.a Concepts of Scheduling Purpose of CPU scheduling

¾ Scheduling algorithm goals — all systems (batch & int.) 9 fairness — comparable processes get comparable service 9 compliance to system’s policy — ex: high-priority override low-priority processes (ex: safety control vs. payroll in a nuclear plant) 9 keep system busy — CPU and I/O devices should be utilized fully ƒ if all CPU-bound were run first: fight for CPU, I/O idle ƒ then all I/O-bound were run: fight for I/O, CPU idle → keep a well-balanced mix of CPU-bound and I/O-bound processes, so they can fill in for each other 3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

17

4.a Concepts of Scheduling Purpose of CPU scheduling

¾ Scheduling algorithm goals — batch systems 9 throughput — maximize # of completed jobs per time unit 9 turnaround time (latency) — minimize time between submission and termination of job ƒ high throughput and low turnaround are rarely compatible ƒ for ex: supply of short jobs scheduled in front of long jobs: good throughput, bad turnaround time for long jobs Arrival times

Execution times

#5 arrived

thr

ou gh pu t

#5 executed turnaround time for #5

3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

18

4.a Concepts of Scheduling Purpose of CPU scheduling

¾ Scheduling algorithm goals — interactive systems 9 response time — respond to requests quickly: minimize time between issuing command and getting result ex: a user request to start a new program should take precedence over background work ƒ having interactive requests go first will be perceived as good service 9 proportionality time — meet users’ expectation, even if irrational ƒ ex: 45 seconds to establish a modem connection is perceived as acceptable, yet 45 seconds to hang up is not ƒ whenever possible, take this into account when scheduling ƒ

3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

19

4.a Concepts of Scheduling Purpose of CPU scheduling

¾ Scheduling algorithm goals — summary

Tanenbaum, A. S. (2001) Modern Operating Systems (2nd Edition).

Some goals of CPU scheduling under different circumstances 3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

20

Principles of Operating Systems CS 446/646 4. CPU Scheduling a. Concepts of Scheduling 9 Three-level scheduling 9 Purpose of CPU scheduling

b. Scheduling Algorithms c. Queuing Analysis d. Thread Scheduling

3/28/2006

CS 446/646 - Principles of Operating Systems - 4. CPU Scheduling

21