160 likes | 181 Views
Chapter 7 Scheduling : Introduction. Byungjun Kim(bjkim@archi.snu.ac.kr) School of Computer Science and Engineering Seoul National University. CPU scheduler. The CPU scheduler selects from among the processes in memory that are ready to execute and allocates the CPU to one of them.
E N D
Chapter 7Scheduling : Introduction Byungjun Kim(bjkim@archi.snu.ac.kr) School of Computer Science and Engineering Seoul National University
CPU scheduler The CPU scheduler selects from among the processes in memory that are ready to execute and allocates the CPU to one of them
Workload assumption Unrealistic Source : http://en.wikipedia.org/wiki/Workload (Retrieved on 2015/04/27) • Workload • Processes running in the system • Initial assumptions • Each job runs for the same amount of time • All jobs arrive at the same time. • All jobs only use the CPU • The run-time of each job is known • A running job is executed till completion
Scheduling metric 0 20 40 60 80 100 120 140 160 Response time (C) Wait time (D) Turnaround time (B) A B C D • Turnaround time • In general, • Turnaround time means the amount of time taken to fulfill a request • In computing, • Turnaround time is the total time taken between the submission of a program/process/thread/task for execution and the return of the complete output to the customer/user • = - • Performance metric • Another metric • Wait time • The sum of the periods spent waiting on the ready queue • Response time • The time of submission to the time the first response is produced
First In, First Out (FIFO) • First In, First Out (FIFO) • Assigns the CPU based on the order of requests • Non-preemptive • Synonym : First Come, Fist Serve(FCFS) • Pros • It is clearly very simple • Cons • Convoy effect • Short jobs can getstuck behind long jobs
First In, First Out (FIFO) A B C D 0 0 20 20 40 40 60 60 80 80 100 100 120 120 140 140 160 160 A B C D Source : http://therabbitway.com/blog/page/4/ (Retrieved on 2015/04/27) • = ( 10 + 20 + 30 + 40 ) / 4 = 25 • = ( 110 + 120 + 130 + 140) / 4 = 125
Shortest Job First (SJF) B C D A 0 0 20 20 40 40 60 60 80 80 100 100 120 120 140 140 160 160 [ B, C ,D arrive ] A B C D • Shortest Job First (SJF) • It runs the shortest job first, then the next shortest, and so on • Great for short jobs • Small degradation for long jobs • = (10 + 20 + 30 + 140) / 4 = 50 • = (110 + (120 – 20) + (130 – 20) + (140 – 20)) / 4 = 110
Preemptive VS Non-preemptive Source : http://news.naver.com/main/read.nhn?mode=LSD&mid=sec&sid1=103&oid=109&aid=0002126475 (Retrieved on 2015/04/27) • Preemptive scheduling • The currently most eligible job has access to the shared resource • A more eligible job subsequently contends for the resource • The more eligible job preempts the resource • Non-preemptive scheduling • The most eligible job has access to the shared resource until it complete • A more eligible job subsequently contends for the resource • The more eligible job can’t preempt the resource
Shortest Time-to-Completion First (STCF) 0 20 40 60 80 100 120 140 160 [ B, C ,D arrive ] A B C D A Source http://www.leeeisenberg.com/2009/09/14/why-the-express-check-out-line-takes-longer/ (Retrieved on 2015/04/27) • Shortest Time-to-Completion First (STCF) • A preemptive version of SJF • If a job arrives with a shorter time to completion, • STCF preempts the CPU for the new job • Also known as Shortest Remaining Time First (SRTF) • = (140 + (30 – 20) + (40 – 20) + (50 - 20)) / 4 = 50
Shortest Time-to-Completion First (STCF) C arrive B arrive A A B A C A 0 20 40 60 80 100 120 140 160 0 20 40 60 80 100 120 140 160 A B C D • Starvation • Constant arrivals of short jobs can keep long ones from running • New metric • Response time • = - • = (0 + 10 + 20 + 30) / 4 = 15
Round Robin • = (0 + 10 + 20 +30) / 4 = 15 • = (0 + 2 + 4 + 6) /4 = 3 A B C D 10 20 30 40 0 A B C D A B C D A B C D A B C D A B C D 10 20 30 40 0 • Round Robin • Periodically releases the CPU from long-running jobs • Preemptive • Time slice • Scheduling quantum • Interval between timer interrupt • A scheduler that is sensitive to response time
Round Robin • Time slice • If time slice is too long • Scheduling degrades to FIFO • If time slice is too short • Context switching cost dominates • Trade-off • Turnaround time vs Response time
Incorporating I/O • All programs perform I/O • Assumption 3 • When a job initiate an I/O request • It is blocked waiting for I/O completion • The scheduler should schedule another job on the CPU at that time • The scheduler should make a decision when the I/O completes
Incorporating I/O a job • = (90 + 140) / 2 = 115 • = (0 + 90) / 2 = 45 • = (90 + 100) / 2 = 95 • = (0 + 10) / 2 = 5 A A A A 0 20 40 60 80 100 120 140 160 0 20 40 60 80 100 120 140 160 Disk A A A A A B B B B B CPU Allow for overlap a job A A A A Disk A B A B A B A B A B CPU • Example • Jobs A and B, which each need 50ms of CPU time • A runs for 10ms and then issue an I/O request • B simply uses the CPU for 50ms and performs no I/O • STCF scheduler
No more oracle • The OS usually knows very little about the length of each job How can we build an approach that behave like SJF / STCF ?
Summary • Introducing basic idea of scheduling • FIFO • Shortest Job First (SJF) • Shortest Time-to-Completion First (STCF) • Good for Turnaround time • Round Robin • Good for response time