Operating Systems Scheduling Algorithms (Part 2) Lecture

Document Details

CommodiousAtlanta2949

Uploaded by CommodiousAtlanta2949

Enda Stafford

Tags

operating systems scheduling algorithms computer science computer architecture

Summary

This lecture covers operating system scheduling algorithms, including FCFS, Shortest Process First, Shortest Remaining Time First, and Round Robin, and explains their principles. It also discusses performance metrics.

Full Transcript

Operating Systems Scheduling Algorithms (Part 2) Enda Stafford [email protected] Topics covered Brief revision of the last week topics Scheduling Algorithms  First Come First Served Scheduling Algorithm (FCFS)  Shortest Process First...

Operating Systems Scheduling Algorithms (Part 2) Enda Stafford [email protected] Topics covered Brief revision of the last week topics Scheduling Algorithms  First Come First Served Scheduling Algorithm (FCFS)  Shortest Process First  Shortest Remaining Time First  Round-Robin 5.7 Brief revision Scheduler = a program that handles the decisions on resource allocation and scheduling processes Scheduler is activated when a “scheduling event” occurs.  a resource is requested / is released  a process terminates / is ready to start (new process) Scheduling algorithms – Non pre-emptive vs Pre-emptive  Determines which process should get the CPU to start to run, when another process has finished using the CPU.  => Non pre-emptive scheduling algorithm  Determines when to stop one process, temporarily, and give CPU time to another process.  => Pre-emptive scheduling algorithm 5.7 Brief revision 4 Scheduling Algorithms  Non pre-emptive scheduling algorithms - A process runs until the end of its current CPU burst A) First Come First Served Scheduling Algorithm (FCFS) B) Shortest Process First  Pre-emptive scheduling algorithms - A process runs for a time and can be interrupted by the scheduler C) Shortest Remaining Time First D) Round-Robin 5.7 Brief Revision A) First Come First Served Scheduling Algorithm (FCFS) Each process ready to start is put at the end of a Ready Queue (FIFO principle) A process runs (uses the CPU) until the end of its current CPU burst When the current process finishes, the First-In process in the Ready queue is selected (First Out) to start and use the CPU 5.7 Brief Revision B) Shortest Process First The length of the running time (Burst time) of each process is used to determine which process should start and use the CPU. When the current running process has finished, the process with the shortest running time is selected first, from the Ready Queue A short process jumps ahead of longer processes, regardless of the time when it became ready (no FIFO principle) 5.7 Brief Revision Performance Metrics  Turnaround time  Time from the request to start (arrival time) until process is completed  Response (Waiting) time  Time from the request to start (arrival time) until process starts to run  Initial time spent in the Ready queue  Processor utilisation  Throughput Burst time / Running time / Service time  The amount of time a process needs to be in an active/running state before it completes 5.7 Brief revision 4 Scheduling Algorithms  Non pre-emptive scheduling algorithms  A) First Come First Served Scheduling Algorithm (FCFS)  B) Shortest Process First  Pre-emptive scheduling algorithms  C) Shortest Remaining Time First  D) Round-Robin For algorithm exemplification the following set of processes are considered Process Arrival Time Burst/ Service Request to run Time 1 0 3 2 6 2 4 4 3 6 7 4 8 2 5 5.8 Shortest Remaining Time First Algorithm Principle Similar to the Shortest Process First, except it is a pre-emptive algorithm  A process may be stopped from execution for a period of time The length of the (remaining) execution time of each process is used to determine which goes next. When the algorithm is activated ? The current running process has finished The CPU is available and a process is ready to start When a new process becomes ready to start and its next running (burst) time is shorter than the remaining time of the running process:  the running process will get pre-empted, i.e. it will lose the CPU, and get put in the ready queue 5.8 Shortest Remaining Time First Algorithm Action taken by the algorithm the ready process with the shortest running/remaining time is selected first FIFO principle is NOT applied on the Ready Queue Notes:  It provides the best turnaround time among pre-emptive algorithms  Usually it is difficult to implement  Must estimate process running time 5.8 Shortest Remaining Time First Algorithm Process Arrival Time Service/Burst Time Exemplification 1 0 3 2 2 6 3 4 4 4 6 7 5 8 2 Shortest Remaining Time First 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 P 1A 3 P2 A 1 5 P3 A 4 P4 A 7 P5 A 2 T0 T1 T2 T3 T4 T5 T6 T7 5.8 Shortest Remaining Time First Algorithm Performance Metrics computation for pre-emptive algorithms  Response (waiting) time  Time from the request to run (arrival time) until process starts to run for the first time  In other words……the time the process waits in the ready state before its first transition into the active state  Turnaround time  Time from the request to start (arrival time) until process is completed  In other words……..the amount of time between the moment a process enters the ready queue for the first time and the moment the process exits the running state for the last time 5.8 Shortest Remaining Time First Algorithm Performance Metrics Response Time  P1 = 0 time units Process Arrival Time Burst/ Service Time  P2 = 1 time units 0 3 1  P3 = 0 time units 2 6 2  P4 = 9 time units 4 4  P5 = 0 time units 3 6 7 4 8 2  Avg. RespTime = 5 (0 + 1 + 0 + 9 + 0) / 5 = 10 / 5 = 2.0 5.8 Shortest Remaining Time First Algorithm Performance Metrics Process Arrival Time Burst/ Turnaround = Complete BurstTime – Arrival Time Service Time  P1 = 3 - 0 = 3 time units 0 3 1  P2 = 15 - 2 = 13 time units 2 6 2  P3 = 8 – 4 = 4 time units 4 4 3 6 7  P4 = 22 – 6 = 16 time units 4 8 2  P5 = 10 – 8 = 2 time units 5  Avg. Turnaround = (3 + 13 + 4 + 16 + 2) / 5 = 38 / 5 = 7.6 time units 5.9 Round-Robin Algorithm Principle Assumes that all processes are equally important Uses pre-emption based on clock Each process is assigned an equal time interval, quantum, in which it is allowed to run Each process that wants to run is put at the end of a Process Ready queue (FIFO principle is applied) 5.9 Round-Robin Algorithm When the algorithm is activated ? The current running process has finished The CPU is available The quantum has expired for the current running process Action taken by the algorithm If the running process still needs to run, at the end of its quantum, the CPU is pre-empted and given to another ready process The current process is put in a Ready Queue (at the end of it) and waits for another quantum, if it still needs to run. The oldest process in the Ready Queue (head of queue) is selected as the next process to run (FIFO principle) 5.9 Round-Robin Algorithm Notes:  A quantum = 10 - 100 ms or less  Small quantum:  too many process switches  increases switching overhead  lowers the CPU efficiency  Large quantum:  fewer process switches  increases CPU efficiency  possible poor response time  There is a trade off between the scheduling efficiency and the overhead involved 5.9 Round-Robin Algorithm Process Arrival Time Service Time Exemplification 1 0 3 Quantum = 2 2 2 6 3 4 4 4 6 7 5 8 2 Round-Robin 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 P 1A 2 1 P2 A 2 2 2 P3 A 2 2 P4 A 2 5 P5 A 2 T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 5.9 Round-Robin Algorithm Performance Metrics Response Time  P1 = 0 time units Process Arrival Time Burst/ Service Time  P2 = 0 time units 0 3 1  P3 = 1 time units 2 6 2  P4 = 3 time units 4 4  P5 = 5 time units 3 6 7 4 8 2  Avg. RespTime = 5 (0 + 0 + 1 + 3 + 5) / 5 = 9 / 5 = 1.8 time units 5.9 Round-Robin Algorithm Performance Metrics Process Arrival Time Burst/ Turnaround = Complete BurstTime – Arrival Time Service Time  P1 = 5 - 0 = 5 time units 0 3 1  P2 = 17 - 2 = 15 time units 2 6 2  P3 = 13 – 4 = 9 time units 4 4 3 6 7  P4 = 22 – 6 = 16 time units 4 8 2  P5 = 15 – 8 = 7 time units 5  Avg. Turnaround = (5 + 15 + 9 + 16 + 7) / 5 = 52 / 5 = 10.4 time units 5.10 Exercises Exercise 1 Same set of processes from Tutorial 5 Illustrate how the six processes will run under  Shortest Remaining Time First scheduling algorithm  Round Robin scheduling algorithm Quantum = 3 Compute  Turnaround time  Response time Process Name Arrival Time Burst/ Service time P1 0 4 P2 2 1 P3 3 6 P4 8 2 P5 9 5 P6 12 2 5.10 Exercises Exercise 2 Illustrate how the three processes will run under  Shortest Remaining Time First scheduling algorithm  Round Robin scheduling algorithm  Shortest Remaining Time First  Round Robin, Quantum = 3 Compute  Turnaround time  Response time Process Arrival Time Service/Burst Time 1 0 8 2 2 5 3 3 2 Learning Outcome After this lecture you should have an understanding of the purpose of the scheduler in the typical Operating System. You should be able to  Describe Shortest Remaining Time First and Round Robin algorithms  Exemplify how these two algorithms would run a set of processes

Use Quizgecko on...
Browser
Browser