240-323 os,2000 1 240-323, part ii cpu scheduling department of computer engineering, psuwannarat...

16
240-323 OS,2000 1 240-323, Part II CPU Scheduling epartment of Computer Engineering, PSU Wannarat Suntiamorntu

Upload: tina-godbee

Post on 14-Dec-2015

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

1

240-323, Part II CPU Scheduling

Department of Computer Engineering, PSU Wannarat Suntiamorntut

Page 2: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

2

Department of Computer Engineering, PSU Wannarat Suntiamorntut

Basic Concepts

The basic problem is as follows: How can OS schedule the allocation of CPU cycles to processes in system, to achieve “good performance”?

Scheduling is a fundamental OS function.

Page 3: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

3

Department of Computer Engineering, PSU Wannarat Suntiamorntut

CPU- I/O Burst Cycle

load storeadd store

read from file

store increm entindex

w rite to fi le

load storeadd store

read from file

w ait for I/O

w ait for I/O

w ait for I/O

cpu burst

I/O burst

cpu burst

I/O burst

CPU burst

I/O burst

Page 4: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

4

Department of Computer Engineering, PSU Wannarat Suntiamorntut

Preemptive Scheduling

• process switches from running -> waiting(I/O request, .. )• process switches from running -> ready(interrupt occur)• process switches from waiting -> ready(completion of I/O)• process terminate

Page 5: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

5

Department of Computer Engineering, PSU Wannarat Suntiamorntut

Dispatcher

Module to give control of CPU to process selectedby short-term scheduler. This function involves :

- Switching context- Switching to user mode- Jumping to the proper location in user program to

restart that program

Page 6: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

6

Department of Computer Engineering, PSU Wannarat Suntiamorntut

Scheduling Criteria

• CPU utilization : in a real system, it range from 40 - 90 percents.• Throughput : number of processes that are completed.• Turnaround time : interval from time of submission to completion.• Waiting time : time that a process spends waiting in ready queue.• Response time : time from the submission of a request until the first response.

Page 7: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

7

Department of Computer Engineering, PSU Wannarat Suntiamorntut

Scheduling Algorithms

• First-come, First-served Scheduling (FCFS)mange with FIFO

Process Burst Time P1 24 P2 3 P3 3

P1 P2 P3

0 24 27 30

Average wait time = 17

Page 8: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

8

Department of Computer Engineering, PSU Wannarat Suntiamorntut

FCFS

Process Burst Time P1 24 P2 3 P3 3

0 3 6 30

P3 P2 P1

Average wait time = 3

Page 9: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

9

Department of Computer Engineering, PSU Wannarat Suntiamorntut

Scheduling Algorithm

• Shortest-Job-First Schedulingmange with SJF , minimum average wait time

Process Burst Time P1 6 P2 8 P3 7 P4 3

0 3 9 16 24

P4 P1 P3 P2

Average wait time = 7

Page 10: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

10

Department of Computer Engineering, PSU Wannarat Suntiamorntut

• Shortest-remaining-time-First Schedulingmange with SJF , minimum average wait time

Process Arrival time Burst Time P1 0 8 P2 1 4 P3 2 9 P4 3 5

0 1 5 10 17 26

P1 P2 P4 P1 P3

Average wait time = 6.5

Scheduling Algorithm

Page 11: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

11

Department of Computer Engineering, PSU Wannarat Suntiamorntut

Scheduling Algorithm

• Priority Schedulingscheduling in term of high priority and low.

Process Burst Time Priority P1 10 3 P2 1 1 P3 2 3 P4 1 4 P5 5 2

P2 P5 P1 P3 P40 1 6 16 18 19

Average wait time = 8.2

Page 12: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

12

Department of Computer Engineering, PSU Wannarat Suntiamorntut

Scheduling Algorithm

• Round-Robin Schedulinground-robin (RR), especially for time-sharing.

- time quantum , time slice = small unit of time

Process Burst Time P1 24 P2 3 P3 3

If time quantum = 4

P1 P2 P3 P1 P1 P1 P1 P10 4 7 10 14 18 22 26 30

Average wait time = 5.66

Page 13: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

13

Department of Computer Engineering, PSU Wannarat Suntiamorntut

Scheduling Algorithm

• Multilevel Queue Scheduling

System processHighest priority

Interactive process

Interactive editing process

Bath process

student processlowest priority

Page 14: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

14

Department of Computer Engineering, PSU Wannarat Suntiamorntut

Scheduling Algorithm

• Multilevel Feedback Queue Scheduling

Quantum = 8

Quantum = 16

FCFS

Page 15: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

15

Department of Computer Engineering, PSU Wannarat Suntiamorntut

Scheduling Algorithm

Process Burst Time Priority Arrival time P1 10 3 0 P2 5 1 2 P3 4 3 3 P4 1 4 5 P5 3 2 7

Do the example

Page 16: 240-323 OS,2000 1 240-323, Part II CPU Scheduling Department of Computer Engineering, PSUWannarat Suntiamorntut

240-323 OS,2000

16

Department of Computer Engineering, PSU Wannarat Suntiamorntut

Next Lecture in

Process Synchronization