170 likes | 251 Views
CH 5. CPU Scheduling. 2014-09-29. 5.1 Basic Concepts. CPU Scheduling context switching CPU switching for another process saving old PCB and loading new PCB dispatcher give control of the CPU to the process selected by the CPU scheduler CPU-I/O Burst Cycle
E N D
CH 5. CPU Scheduling 2014-09-29
5.1 Basic Concepts • CPU Scheduling • context switching • CPU switching for another process • saving old PCB and loading new PCB • dispatcher • give control of the CPU to the process selected by the CPU scheduler • CPU-I/O Burst Cycle • Process execution begins with a CPU burst
160 140 120 100 80 60 40 20 0 8 16 24 32 40 burst duration (milliseconds) Histogram of CPU-burst times 5.1 Basic Concepts Load store add store read from file CPU burst I/O burst Wait for I/O CPU burst Store increment index write to file frequency I/O burst Wait for I/O Load store add store read from file CPU burst Wait for I/O I/O burst Alternating sequence of CPU and I/O bursts
5.2 Scheduling Criteria • Performance comparison criteria of CPU scheduling algorithm • CPU utilization : 40% ~ 90% • throughput : finished job # per time unit • turnaround time : waiting time in the Ready Queue • response time : interactive system • preemptive & nonpreemptive Scheduling • context switching : pure overhead (PCB save, load) • Interval timer & interrupting clocking • prevent a monopoly of system • Deadline Scheduling • pay remnant cost for processing in explicit time
5.3 Scheduling Algorithms • FIFO(FCFS) Finish C B A CPU Nonpreemptive Ex) Job Burst Time 1 24 2 3 3 3 If arriving order 1, 2, 3 Job1 Job2 Job3 24 27 30 Average Turnaround Time = (24 + 27 + 30)/3 = 27 Average Waiting Time = (0 + 24 + 27)/3 = 17 ms If arriving order is 2, 3, 1 A.T.T = (3 + 6 + 30) / 3 = 13 A.W.T = (0 + 3 + 6) / 3 = 3
5.3 Scheduling Algorithms • Round Robin Scheduling for Timesharing System Time Quantum of Time Slice (10 ~ 100 msec) Preemptive New job Finish Ex) In the case of jobs in previous example, if time quantum is 4, Average turnaround time is -- J1 J2 J3 J1 J1 · · · · · J1 47 / 3 16 4 7 10 14 30 Average Waiting Time = (4 + 7 + (10 - 4)) / 3 = 17 / 3 = 5.66 ms R.R Scheduling = Preemptive Scheduling Time Quantum : if large FCFS short like processor sharing context switching overhead
5.3 Scheduling Algorithms Process time = 10 Quantum Context switches 12 0 6 1 1 9 0 10 0 10 6 0 1 2 3 4 5 6 7 8 9 10 Showing how a smaller time quantum increases context switching
Process time P1 6 P2 3 P3 1 P4 7 5.3 Scheduling Algorithms Average turnaround time 12.5 12.0 11.5 11.0 10.5 10.0 9.5 9.0 Time quantum 1 2 3 4 5 6 7 Showing how turnaround time varies with the time quantum
J4 J1 J3 J2 0 3 9 16 24 5.3 Scheduling Algorithms • Shortest - Job - First (SJF) • Non preemptive Scheduling • Long - Term Scheduling in Batch system : good. • Short-Term Scheduling : impossible • A.W.T = (3 + 16 + 9 + 0)/4 = 7 ms. • FCFS A.W.T = (0 + 6 + 14 + 21)/4 = 41/4 = 10.25 ms. • AVG Turnaround Time = (3 + 9 + 16 + 24)/4 = 52/4 = 13 ms. Job Burst Time 1 6 2 8 3 7 4 3
5.3 Scheduling Algorithms • Shortest-Remaining-Time-First(SRT) • Transformation of Shortest-Job-First • Preemptive SJF • A.W.T = ((10-1) + (1-1) + (17 -2) + (5-3))/4 = 26/4 = 6.5 ms. • A.T.T = 17 + (5-1) + (26-2) + (10-3) =52/4 = 13 ms. • SJF A.T.T = 14.25 ms. • SJF A.W.T = 5.75 ms. Ex) JobArrive TimeBurst Time 1 0 8 2 1 4 3 2 9 4 3 5 * Assign the Thrasholded Value J1 J2 J4 J1 J3 0 1 5 10 17 26
5.3 Scheduling Algorithms • Priority Scheduling • SJF : Special case of the general priority scheduling. • FCFS : Equal priority. • Major problem : indefinite blocking or starvation. • Solution HRN Ex) JobBurst TimePriority 1 10 3 2 1 1 3 2 3 4 1 4 5 5 2 J2 J5 J1 J3 J4 A.W.T = 8.2 ms A.T.T = 12 ms 0 1 6 16 18 19
5.3 Scheduling Algorithms • HRN(Highest-Response-ratio-Next) : Brinch Hansen • priority = (Waiting Time + Service Time) / Service Time • Nonpreemptive method that apply process service time and total time to wait service
highest priority system processes Interactive processes Interactive editing processes batch processes student processes lowest priority Multilevel Queue scheduling 5.3 Scheduling Algorithms • Multilevel Queue • processes each job classified into queues • ex) classify into Foreground and Background (80% : 20%) • F.G is scheduled by Round Robin algorithm • B.G is scheduled by an FCFS algorithm
quantum = 8 quantum = 16 FCFS Fig 5.7 Multilevel feedback queues 5.3 Scheduling Algorithms • Multilevel Feedback Queue • allow a process to move between queues
5.5 Real-Time Scheduling • Hard real-time • within a guaranteed time • soft real-time • less restrictive
5.6 Algorithm Evaluation • Deterministic modeling Process Burst Time P1 10 P2 1 P3 2 P4 1 P5 5 • maximize CPU utilization • maximize throughput) • Queueing Models • result mathematical formula that estimate the distribution of CPU and I/O bursts. • Simulations
5.6 Algorithm Evaluation FCFS R•R (Quantum=1) S.J.F • Evaluation method • Analytical evaluation • use mathematical analysis by predetermined workload, … • ex) Deterministic modeling • Queuing Model • mathematical formula, arrival rate, service rate • utilization, queue length, wait time • Simulation