1 / 61

CPU Scheduling

CPU Scheduling. G.Anuradha References : Galvin and William Stallings Problems taken from Principles of OS by Naresh Chauhan. Objectives. To introduce CPU scheduling, which is the basis for multiprogrammed operating systems . To describe various CPU-scheduling algorithms .

mahon
Download Presentation

CPU Scheduling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CPU Scheduling G.Anuradha References : Galvin and William Stallings Problems taken from Principles of OS by NareshChauhan

  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.

  4. Frequency for shorter duration is much more than the frequency of longer duration This is the general trend

  5. 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.

  6. Preemptive Scheduling 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 Non Preemptive Scheduling

  7. What are the factors affecting preemptive scheduling? • Cost associated with access to shared data. Cooperative process • Affects the design of os kernel

  8. 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.

  9. 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

  10. 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.

  11. Scheduling Algorithms • First Cum First Served Scheduling(FCFS) • Shortest job First(SJF) • Shortest Remaining Time Next(SRTN) • Round Robin(RR) • Multilevel Queue Scheduling

  12. First Cum First Served (FCFS)

  13. If process come in the order P3, P2, P1 find the average waiting time.

  14. Waiting time for P1=0 Average 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

  15. 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.

  16. Solve Average Waiting time Average Execution time Average Turn Around time Average Response time

  17. Shortest Job First

  18. 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

  19. Solve Average Waiting time Average Execution time Average Turn Around time Average Response time

  20. 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

  21. Shortest Remaining Time First Scheduling P1 P2 P4 P1 P3 17 26 0 1 5 10 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

  22. STF P1 P2 P4 P3 8 0 12 17 26 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

  23. Solve(SJF and SRTF)

  24. Priority Scheduling All process arrive at time t=0 P2 P5 P1 P3 P4 0 1 6 16 18 19

  25. Priority Scheduling All process arrive at time t=0

  26. 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:

  27. 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

  28. Round Robin Scheduling • Designed for time sharing systems • Preemption added to FCFS is Round Robin Scheduling • Ready queue is circular queue

  29. 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.67 Avg ET=3.34 ATAT=8.01

  30. Comparision with FCFS • Compute the same problem using FCFS and comment on the average turnaround time • Reason out the change

  31. 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.

  32. The processes are assumed to have arrived in the order P1,p2,p3,p4,p5 Draw Gantt chart for FCFS, SJF, nonpremptive priority, RR(Time slice=1) TT of each process the above scheduling algos WT of each process for the above scheduling algos Which algo has minimum average waiting time

More Related