Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPU scheduling 6. Schedulers, CPU Scheduling 6.1. Schedulers

Similar presentations


Presentation on theme: "CPU scheduling 6. Schedulers, CPU Scheduling 6.1. Schedulers"— Presentation transcript:

1 CPU scheduling 6. Schedulers, CPU Scheduling 6.1. Schedulers
Short term, Long term, Medium term schedulers. 6.2. CPU Scheduling CPU- I/O burst cycle CPU scheduler Dispatcher 6.3. Scheduling Criteria 6.4. Scheduling Algorithms First Come First Served. Shortest Job First. Priority Scheduling. Round Robin. Multilevel queues, Multilevel feedback queues. Textbook Silberschatz, Chapter 6

2 Scheduling Criteria CPU utilization (maximize) – (0-100%)
Throughput (maximize) - # of processes that complete their execution per time unit Turnaround time (minimize)– amount of time to execute a particular process (submission completion). Waiting time (minimize) – amount of time a process has been waiting in the ready queue Response time (minimize the average or maximal response time)– amount of time it takes from when a request was submitted until the first response is produced, (not the whole output)

3 Scheduling Algorithms
First-Come, First-Served Shortest-Job-First Shortest Remaining Time First Round Robin Priority Scheduling

4 First-Come, First-Served
This non-preemptive scheduling algorithm follows the first-in, first-out (FIFO) policy. As each process becomes ready, it joins the ready queue – to the tail. When the current running process finishes execution, the oldest process in the ready queue is selected to run next – from the head of queue. Tail Head Ready Queue CPU P3 P2 P1 Head Ready Queue CPU P2 P3 P2 Tail I/O

5 FCFS Waiting Time Process CPU Burst Time (ms) P1 24 P2 3 P3 3 Suppose that the processes arrive at time 0 in the order: P1 , P2 , P3 The Gantt Chart for the CPU processing is: Waiting time for P1 = 0; P2 = 24; P3 = 27 Average waiting time: ( )/3 = 17 P1 P2 P3 24 27 30 Gantt chart - A Gantt Chart is a bar chart that depicts activities as blocks over time. The beginning and end of the block correspond to the beginning and end-date of the activity. A Gantt chart developed as a production control tool in 1917 by Henry L. Gantt, an American engineer. The average waiting time under the FCFS policy is often quite long.

6 FCFS Waiting Time not optimal
Process CPU Burst Time (ms) P1 24 P2 3 P3 3 Suppose that the processes arrive in the order: P2 , P3 , P1 The Gantt chart for the schedule is: Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: ( )/3 = 3 Much better than previous case P1 P3 P2 6 3 30

7 FCFS Convoy Effect Convoy effect - short CPU burst processes behind long process Consider one CPU-bound and many I/O-bound processes Advantages: The code for FCFS scheduling is simple to write and understand. Disadvantages: The average waiting time under the FCFS policy, however, is often quite long. As FCFS is nonpreemptive then once the CPU has been allocated to a process, that process keeps the CPU until it releases the CPU, either by terminating or by requesting I/O. Either the CPU is idle Or I/O devices are idle

8 Shortest Job First (SJF) or Shortest next CPU burst
Associate with each process the length of its next CPU burst Use these lengths to schedule the process with the shortest time SJF is optimal – gives minimum average waiting time for a given set of processes The difficulty is knowing the length of the next CPU request

9 Shortest Job First (SJF) or Shortest next CPU burst Example
Process Arrival Time Burst Time P P P P SJF scheduling chart Average waiting time = ( ) / 4 = 7 P4 P3 P1 3 16 9 P2 24 If we were using the FCFS scheduling scheme, then the average waiting time would be milliseconds. This is better than FCFS But may be not the best one

10 Shortest Job First (SJF) Preemptive - NonPreemptive

11

12 Why 9? Why 1?

13 Prediction of the Length of the Next CPU burst
Can only estimate the length of burst – should be similar to the previous one of the same process Then pick process with shortest predicted next CPU burst Can be done by using the length of previous CPU bursts, using exponential averaging Commonly, α set to ½ τn+1 = αtn + (1- α) τn  =0 n+1 = n Recent history does not count  =1 n+1 =  tn Only the actual last CPU burst counts

14 Prediction of the Length of the Next CPU burst
Figure below shows an exponential average with α = 1/2 and τo = 10.


Download ppt "CPU scheduling 6. Schedulers, CPU Scheduling 6.1. Schedulers"

Similar presentations


Ads by Google