Download presentation
Presentation is loading. Please wait.
Published byColleen Summers Modified over 9 years ago
1
CPU Scheduling G.Anuradha References : Galvin and William Stallings Problems taken from Principles of OS by Naresh Chauhan
2
Objectives To introduce CPU scheduling, which is the basis for multiprogrammed operating systems. To describe various CPU-scheduling algorithms. To discuss evaluation criteria for selecting a CPU-scheduling algorithm for a particular system. To examine the scheduling algorithms of several operating systems.
3
Basic concepts-CPU –I/O Burst cycle Why Multi programming? – To Maximize CPU utilization CPU Scheduling is central to OS design For proper CPU scheduling the histogram of CPU-Burst duration is considered.
5
Frequency for shorter duration is much more than the frequency of longer duration This is the general trend
6
Types of Scheduler Long-term Scheduler:-Needed only in the case of batch processing and is absent in multi user time- sharing system. In time-sharing systems the jobs are directly entered into ready queue. Short-term Scheduler:-Invoked whenever there is an interrupt, to select another process for execution. Medium-term Scheduler:- Invoked when there is a need to swap out some blocked processes from memory to secondary storage.
7
Preemptive Scheduling Circumstances when CPU-Scheduling Decisions may take place – Process switches from running state to waiting state (I/O, termination of child process) – Process switches from running to ready state(interrupt) – Process switches from waiting state to ready state(Completion of I/O) – Process terminates Preemptive Scheduling Non Preemptive Scheduling
8
What are the factors affecting preemptive scheduling? Cost associated with access to shared data. Cooperative process Affects the design of os kernel
9
Role of dispatcher Switching context Switching to user mode Jumping to the proper location in the user program to restart the program Dispatch Latency is the time taken to stop one process and start another running process.
10
Scheduling Criteria CPU Utilization Throughput: Number of processes completed per unit time Turnaround time: the interval from the time of submission of a process to the time of completion Turnaround time= waiting time+ execution time
11
Waiting time: sum of periods spend waiting in the ready queue Response time:- time taken to start responding Maximize CPU utilization, Maximize throughput, minimize turnaround time, waiting time and response time.
12
Scheduling Algorithms First Cum First Served Scheduling(FCFS) Shortest job First(SJF) Shortest Remaining Time Next(SRTN) Round Robin(RR) Multilevel Queue Scheduling
13
First Cum First Served (FCFS)
17
If process come in the order P3, P2, P1 find the average waiting time.
18
Waiting time for P1=0Average Execution time=(5+3+2)/3=3.33 Waiting time for P2=5 Waiting time for P3=8 Average Waiting time=(0+5+8)/3=4.33 Average Turn Around time=Average Waiting time + Average Execution time =4.33+3.33 =7.66 Average Response time=(0+5+8)/3=4.33
19
Features of FCFS Average waiting time under FSFS varies if the CPU burst times vary greatly Convey effect is produced because of CPU and IO bound processes FCFS is non preemptive.
20
Solve Average Waiting time Average Execution time Average Turn Around time Average Response time
21
Shortest Job First
25
Average Execution time=(5+3+2)/3=3.33 Average Turn Around Time=3.33+2.33=5.66 Average Response time=(0+2+5)/3=2.33
26
Solve Average Waiting time Average Execution time Average Turn Around time Average Response time
27
Difficulties in SJF algorithm Optimal. The length of the next CPU request is not known in advance The burst time of the next process can be predicted. The predicted value for the next CPU burst is depended on recent information tn and past history SJF can be preemptive or nonpreemptive. Preemptive SJF is called as Shortest remaining time first scheduling
28
Shortest Remaining Time First Scheduling ProcessArrival TimeBurst Time P108 P214 P329 P435 P1P2P4P1P3 01510 1726 WT of P1=(10-1)=9 WT of P2=0 WT of P3=(17-2)=15 WT of P4=(5-3)=2 Average WT=(9+0+15+2)/4=6.5ms Average Execution Time=(8+4+9+5)/5=6.5 ATAT=6.5+6.5=13ms
29
STF ProcessArrival TimeBurst Time P108 P214 P329 P435 P1P2P4P3 0 8 121726 WT for P1=0 WT for P2=(8-1)=7 WT for P3=(17-2)=15 WT for P4=(12-3)=9 Average WT=(0+7+15+9)/4=7.75 ATAT=6.5+7.75=14.25ms
30
Solve(SJF and SRTF) ProcessArrival TimeBurst Time P109 P215 P323 P434
31
Priority Scheduling All process arrive at time t=0 ProcessBurst TimePriority P1103 P211 P324 P415 P552 P2P5P1P4P3 016161819
32
Priority Scheduling ProcessBurst TimePriorityWTTTNormalized TT P11036161.6 P211011 P32416189 P4151819 P552161.2 3.88.2126.36 All process arrive at time t=0
33
Priority Scheduling(PS) Contd… PS can be – Internal: use measurable quantity to compute priority, like time limits, memory requirements, number of open files, etc. – External: Importance of process, type and amount of funds paid for computer use PS can be either – Preemptive: – Non Preemptive:
34
Starvation Why starvation happens? – When low priority job waits indefinitely Solution to starvation is aging – Increasing the priority of processes that wait in the system for long time
35
Round Robin Scheduling Designed for time sharing systems Preemption added to FCFS is Round Robin Scheduling Ready queue is circular queue
47
ProcessBurst time P15 P23 P32 WT for P1=((3-1)+(6-4)+(8-7)=5 ET for P1=5 WT for P2=((1-0)+((4-2)+(7-5)=5 ET for P2=3 WT for P3=(2-0)+(5-3)=4 ET for P3=2 Avg. WT=4.67Avg ET=3.34 ATAT=8.01
48
Comparision with FCFS Compute the same problem using FCFS and comment on the average turnaround time Reason out the change
49
Reasoning of RR RR is heavily depended on time quantum Lesser the time quantum, more the context switches Turnaround time also depends on the size of the time quantum. If time quantum is large enough then RR degenerates to FCFS Thumb rule : 80% of cpu bursts should be shorter than the time quantum.
50
ProcessBTPriority P1103 P211 P323 P414 P552 The processes are assumed to have arrived in the order P1,p2,p3,p4,p5 1.Draw Gantt chart for FCFS, SJF, nonpremptive priority, RR(Time slice=1) 2.TT of each process the above scheduling algos 3.WT of each process for the above scheduling algos 4.Which algo has minimum average waiting time
51
Multilevel queue scheduling Based on foreground(interactive) processes and background (batch) processes multilevel queue scheduling partitions ready queues into several queues. Each queue has its own scheduling algorithm. scheduling among the queues, implemented as fixed-priority preemptive scheduling.
52
Example of multilevel queue scheduling
53
Multilevel Feedback Queue Scheduling Allows a process to move between queues. Uses the concept of aging to prevent starvationaging
54
Parameters of multilevel queue The number of queues The scheduling algorithm for each queue The method used to determine when to upgrade a process to a higher priority queue The method used to determine when to demote a process to a lower priority queue The method used to determine which queue a process will enter when that process needs service
55
Operating System Examples LINUX Windows Solaris
56
LINUX
58
Windows Scheduling Uses priority-based preemptive scheduling 32-level priority scheme is used for scheduling Variable class has priority from 1 to 15 and real time class has priority 16 to 31 Windows API has 6 priority classes – IDLE PRIORITY CLASS – BELOW NORMAL PRIORITY CLASS – NORMAL PRIORITY CLASS – ABOVE NORMAL PRIORITY CLASS – HIGH PRIORITY CLASS – REALTIME PRIORITY CLASS
59
Solaris Scheduling Uses priority based thread scheduling Each thread belongs to one of six classes: Time sharing (TS) (default) Interactive (IA) Real time (RT) System (SYS) Fair share (FSS) Fixed priority (FP)
60
Solaris Scheduling Contd… dynamically alters priorities and assigns time slices of different lengths using a multilevel feedback queue The higher the priority, the smaller the time slice; and the lower the priority, the larger the time slice. Interactive processes have a higher priority; CPU-bound processes, a lower priority.
61
RECAP Types of schedulers Types of scheduling algos Examples of schedulers in different os
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.