160 likes | 174 Views
Learn about the basic concepts of CPU scheduling and various algorithms such as FCFS, SJF, Priority, Round-Robin, Multilevel Queue, and Multilevel Feedback Queue.
E N D
Department of Computer Engineering, PSU Wannarat Suntiamorntut 240-323, Part II CPU Scheduling
Department of Computer Engineering, PSU Wannarat Suntiamorntut Basic Concepts • The basic problem is as follows: How can OS schedule the • allocation of CPU cycles to processes in system, to achieve • “good performance”? • Scheduling is a fundamental OS function.
Department of Computer Engineering, PSU Wannarat Suntiamorntut CPU- I/O Burst Cycle cpu burst I/O burst cpu burst I/O burst CPU burst I/O burst
Department of Computer Engineering, PSU Wannarat Suntiamorntut Preemptive Scheduling • process switches from running -> waiting • (I/O request, .. ) • process switches from running -> ready • (interrupt occur) • process switches from waiting -> ready • (completion of I/O) • process terminate
Department of Computer Engineering, PSU Wannarat Suntiamorntut Dispatcher Module to give control of CPU to process selected by short-term scheduler. This function involves : - Switching context - Switching to user mode - Jumping to the proper location in user program to restart that program
Department of Computer Engineering, PSU Wannarat Suntiamorntut Scheduling Criteria • CPU utilization : in a real system, it range from • 40 - 90 percents. • Throughput : number of processes that are completed. • Turnaround time : interval from time of submission to • completion. • Waiting time : time that a process spends waiting in • ready queue. • Response time : time from the submission of a request • until the first response.
Department of Computer Engineering, PSU Wannarat Suntiamorntut P1 P2 P3 0 24 27 30 Scheduling Algorithms • First-come, First-served Scheduling (FCFS) • mange with FIFO Process Burst Time P1 24 P2 3 P3 3 Average wait time = 17
Department of Computer Engineering, PSU Wannarat Suntiamorntut P3 P2 P1 0 3 6 30 FCFS Process Burst Time P1 24 P2 3 P3 3 Average wait time = 3
Department of Computer Engineering, PSU Wannarat Suntiamorntut P4 P1 P3 P2 0 3 9 16 24 Scheduling Algorithm • Shortest-Job-First Scheduling • mange with SJF , minimum average wait time Process Burst Time P1 6 P2 8 P3 7 P4 3 Average wait time = 7
Department of Computer Engineering, PSU Wannarat Suntiamorntut Scheduling Algorithm • Shortest-remaining-time-First Scheduling • mange with SJF , minimum average wait time Process Arrival time Burst Time P1 0 8 P2 1 4 P3 2 9 P4 3 5 P1 P2 P4 P1 P3 0 1 5 10 17 26 Average wait time = 6.5
Department of Computer Engineering, PSU Wannarat Suntiamorntut P2 P5 P1 P3 P4 0 1 6 16 18 19 Scheduling Algorithm • Priority Scheduling • scheduling in term of high priority and low. Process Burst Time Priority P1 10 3 P2 1 1 P3 2 3 P4 1 4 P5 5 2 Average wait time = 8.2
Department of Computer Engineering, PSU Wannarat Suntiamorntut P1 P2 P3 P1 P1 P1 P1 P1 0 4 7 10 14 18 22 26 30 Scheduling Algorithm • Round-Robin Scheduling • round-robin (RR), especially for time-sharing. • - time quantum , time slice = small unit of time Process Burst Time P1 24 P2 3 P3 3 If time quantum = 4 Average wait time = 5.66
Department of Computer Engineering, PSU Wannarat Suntiamorntut Scheduling Algorithm • Multilevel Queue Scheduling Highest priority System process Interactive process Interactive editing process Bath process student process lowest priority
Department of Computer Engineering, PSU Wannarat Suntiamorntut Quantum = 8 Quantum = 16 FCFS Scheduling Algorithm • Multilevel Feedback Queue Scheduling
Department of Computer Engineering, PSU Wannarat Suntiamorntut Scheduling Algorithm Do the example Process Burst Time Priority Arrival time P1 10 3 0 P2 5 1 2 P3 4 3 3 P4 1 4 5 P5 3 2 7
Department of Computer Engineering, PSU Wannarat Suntiamorntut Next Lecture in Process Synchronization