21

3. CPU Scheduling

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 3. CPU Scheduling
Page 2: 3. CPU Scheduling

3. CPU Scheduling Operating System Concepts with Java – 8th Edition Silberschatz, Galvin and Gagn

Page 3: 3. CPU Scheduling

SPOILER

operating system – CPU Scheduling 3

Page 4: 3. CPU Scheduling

4 operating system – CPU Scheduling

Page 5: 3. CPU Scheduling

Long-short-medium Scheduler Long term Short Term Medium Term

job scheduler CPU scheduler process swapping Scheduler

Slower than short term

Fastest Between two

Control degree of multiprogramming

provides lesser control over degree of Multiprogramming

reduces the degree of multiprogramming

Minimal in time sharing system

Minimal in time sharing system

part of Time sharing systems

selects processes from pool and loads them into memory for execution

selects those processes which are ready to Execute

can re-introduce the process into memory and execution can be continued

5 operating system – CPU Scheduling

Page 6: 3. CPU Scheduling

Dispatcher selects from among the processes in memory that

are ready to execute, and allocates the CPU to one of them

�decide when a process � 1. running to waiting state 2. running to ready state 3. waiting to ready state 4. Terminates

�Scheduling under 1 and 4 is nonpreemptive

�All other scheduling is preemptive

operating system – CPU Scheduling 6

Page 7: 3. CPU Scheduling

Scheduling Factor 1. CPU utilization - keep the CPU as busy as possible must be maximized 2. Throughput - number of processes that complete

their execution per time unit must be maximized 3. �Turnaround time - amount of time to execute a

particular process must be minimized 4. Waiting time - amount of time a process has been

waiting in the ready queue must be minimized 5. �Response time - amount of time it takes from when

a request was submitted until the first response is produced, not output �for timesharing environment�

must be minimized operating system – CPU Scheduling 7

Page 8: 3. CPU Scheduling

SCHEDULING METHOD

▪ FIRST COME FIRST SERVE �FCFS / FIFO�

▪ SORTHEST JOB FIRST �SJF� ▪ PRIORITY BASED ▪ ROUND ROBIN

operating system – CPU Scheduling 8

Page 9: 3. CPU Scheduling

First-Come, First-Served �FCFS� Proces Execute

time Service Time

p1 24 0

p2 3 24

p3 3 27

operating system – CPU Scheduling 9

processes arrive in the order: P1, P2, P3

Waiting time for P1= 0; P2= 24; P3 = 27 �Average waiting time: (0 + 24 + 27)/3 = 17

processes arrive in the order: P2, P3, P1

Waiting time for P1= 6; P2= 0; P3 = 3 �Average waiting time: (6 + 0 + 3)/3 = 3 Conclusion ?

CONVOY EFFECT short process behind long

process

Proces Execute time

Service Time

p1 24 ??

p2 3 ??

p3 3 ??

Page 10: 3. CPU Scheduling

FCFS �another example�

operating system – CPU Scheduling 10

Page 11: 3. CPU Scheduling

Shortest Job First �SJF�

Best approach to minimize waiting time.

Impossible to implement

Processer should know in advance how much time process will take.

operating system – CPU Scheduling 11

Proces Execute time

Service Time

p1 6 3

p2 8 16

p3 7 9

p4 3 0 Average waiting time = (3 + 16 + 9 + 0) / 4 = 7

Page 12: 3. CPU Scheduling

SJF �another example�

operating system – CPU Scheduling 12

Page 13: 3. CPU Scheduling

Priority Scheduling Each process is assigned a priority. Process with highest priority is to be executed first and so on.

Processes with same priority are executed on FCFS

Priority can be decided based on memory requirements, time requirements or any other resource requirement.

operating system – CPU Scheduling 13

Page 14: 3. CPU Scheduling

Round Robin Scheduling Each process is provided a fix time to execute called

quantum Q.

Once a process is executed for given time period. Process is preempted and other

process executes for given time period. �If there are nprocesses in the ready queue and the time quantum is Q, then each process gets 1/nof the CPU time in chunks of at most Q time units at once. No process waits more than �n-1�Q time units.

Performance

Q large -� FIFO

Q small -� overhead is too high

operating system – CPU Scheduling 14

Page 15: 3. CPU Scheduling

RR with Quantum - 4

operating system – CPU Scheduling 15

Proces Execute time

p1 24

p2 3

p3 3

Page 16: 3. CPU Scheduling

Round Robin �another example�

operating system – CPU Scheduling 16

Page 17: 3. CPU Scheduling

Multi Queue Scheduling Multiple queues are maintained for processes.

Each queue can have its own scheduling algorithms.

Priorities are assigned to each queue.

operating system – CPU Scheduling 17

Page 18: 3. CPU Scheduling

Example of Multilevel Three queues� Q0 - RR with Q 8 milliseconds

Q1 - RR with Q 16 milliseconds

Q2 - FCFS

A new job enters queue Q0 which is served FCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1 .

At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2

operating system – CPU Scheduling 18

Page 19: 3. CPU Scheduling

The END . . .

Page 20: 3. CPU Scheduling

References 1. Abraham Silberschatz, Peter Baer Galvin, Greg

Gagne, Operating System Concepts With Java, Wiley

2. Tutorialpoint.com

operating system – CPU Scheduling 20

Page 21: 3. CPU Scheduling

Next Week It is time for

▪ QUIZ - Learn how to calculate scheduling

▪ Practical Hardware TroubleShoot – Install OS on real PC �minimum complete PC

provided by lecturer� – Optional may bring own PC �2 teams 1 complete

PC and extension power cable� in order to gain self experience

operating system – CPU Scheduling 21