Upload
sequoia-lopez
View
32
Download
4
Embed Size (px)
DESCRIPTION
Operating Systems - Process (CPU) scheduling. Seehwan Yoo MSE.cis.dku. Review. Computer systems ( hw ) Main components : CPU, mem , I/O devices Inter-connect: bus I/O device interaction w/ external world Comm . w/ cpu Interrupt Polling Direct memory access SW in computers - PowerPoint PPT Presentation
Citation preview
Operating Systems- Process (CPU)
schedulingSeehwan YooMSE.cis.dku
Review
• Computer systems (hw)• Main components: CPU, mem,
I/O devices• Inter-connect: bus
• I/O device• interaction w/ external world• Comm. w/ cpu
• Interrupt• Polling
• Direct memory access
• SW in computers• OS kernel, user applications• Dual-mode execution
• For protection• System call – interface to OS
• Process• Abstraction of proces-
sor (CPU) / machine• Execution context• Cf.) program
• Memory layout• Address space
• Process states• State transition
• Time-sharing system• Implementation with
timer interrupt
Process scheduling
• Determine which process to run• Kernel maintains queues
• Data structure!• Ready Q (runq)
• Store processes in ready state• Device Q (ioq)
• Store processes in waiting state (per-device)
• Scheduler picks one of process to run during the next time slot
• How?
Overall picture of schedul-ing
Scheduling
• Diverse policies• Fair-share• First-In-First-Out• Shortest-Job-First
• Good scheduler?• Evaluation criteria
• CPU utilization• Throughput• Turn-around time• Waiting time• Response time
Scheduling Criteria
• CPU utilization – keep the CPU as busy as possible• Throughput – # of processes that complete their ex-
ecution per time unit• Turn-around time – amount of time to complete a
particular process• Waiting time – amount of time a process has been
waiting in the ready queue• Response time – amount of time it takes from when
a request was submitted until the first response is produced, not output (for time-sharing environment)
Anti-break!
• Waiting time of blue-process?• Response time of red-process?• Turn around-time of blue-process at time 3?• Throughput of the system?• CPU utilization?
a b c d e f
First-In, First-Out
• This is not a fair-share scheduler!• First-comer run until it is completed, or
• Until it makes I/O request, or• Until it voluntarily yield CPU
FIFO (FCFS) exampleProcess Burst Time
P1 24
P2 3
P3 3
• Suppose that the processes arrive in the order: P1 , P2 , P3 (at time 0)
• The Gantt Chart for the schedule is:
• Waiting time for P1 = 0; P2 = 24; P3 = 27• Average waiting time: (0 + 24 + 27)/3 = 17
P P P1 2 3
0 24 3027
FIFO (FCFS) another exam-ple!
Suppose that the processes arrive in the order:
P2 , P3 , P1 • The Gantt chart for the schedule is:
• Waiting time for P1 = 6; P2 = 0; P3 = 3• Average waiting time: (6 + 0 + 3)/3 = 3• Much better than previous case• Convoy effect - short process behind long process
• Consider one CPU-bound and many I/O-bound processes
P 1
0 3 6 30
P 2 P 3
Then, How about SJF?
• Take the shortest job at first hand! ProcessArriva l TimeBurst Time
P1 0.0 6
P2 2.0 8
P3 4.0 7
P4 5.0 3
• SJF scheduling chart
• Average waiting time = (3 + 16 + 9 + 0) / 4 = 7
P 3
0 3 24
P 4 P 1
169
P 2
And How about SRTF?- Running scheduler at every time tick
• Take the remaining time job at first hand!• Now we add the concepts of varying arrival times and preemption to
the analysis ProcessA arri Arrival TimeT Burst Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5• SRTF Gantt Chart
• Average waiting time = [(10-1)+(1-1)+(17-2)+5-3)]/4 = 26/4 = 6.5 msec
P 4
0 1 26
P 1 P 2
10
P 3P 1
5 17
Forget about it…
• Only exist in theory• Who knows the shortest job?
• It is the most well-known NP-hard problem• Homework) survey halting problem in the Internet
But, an approximation can be made• From the last execution history
• Commonly, α set to ½
:Define 4.
10 , 3.
burst CPU next the for value predicted 2.
burst CPU of length actual 1.
1n
thn nt
.1 1 nnn t
Like this,
We can put them all to-gether• Or stop it by now;• Break time
Fair-share schedulerRound-robin (RR)• Gives no priority to all process• Pick up one process in an equal probability
• If all the processes have the same time quantum, then all the pro-cesses would utilize CPU time evenly
• Implementation would be…• Randomly pick up a process in the run queue• When time quantum is expired, put it in the retired queue• When there is no process in the run queue, switch run queue with re-
tired queue
• In practice, • Pick the first process in the run queue• Run it until time quantum is expired• When time quantum is expired, put it in the run queue (tail)
RR property & example• Max (worst-case) response time?• Example Process Burst Time
P1 24
P2 3
P3 3 The Gantt chart is:
Typically, higher average turnaround than SJF, but better response q should be large compared to context switch time q usually 10ms to 100ms, context switch < 10 usec
P P P1 1 1
0 18 3026144 7 10 22
P 2 P 3 P 1 P 1 P 1
Priority-based scheduling
• No fair-share scheduler!• Give a priority to a process
• Scheduling according to the priority• Can be fixed• Can be dynamically changed
• Consider low-class citizens!• Low-priority process could be starved• Respect the seniors!
• Apply aging• Increase priority when a process is in the low priority for a long
time
Property of priority sched-uling• Deterministic response time
• Calculate it by hand!
• Used in real-time systems• Rate-monotonic• Earliest-Deadline-First (EDF)
Example of priority sched-uling
ProcessA arri Burst TimeT Priority
P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2
• Priority scheduling Gantt Chart
• Average waiting time = 8.2 msec
1
0 1 19
P 1 P 2
16
P 4P 3
6 18
P
Re-think scheduling!
• Basic ideas• Fair-share• First-in-First-out (FIFO, or queue)• Real-time
• Do the right thing!• Does your application really want?• Compare
• file copy (doing a lot of I/O operation)• Hanoii (scientific application for complex calculation)
Thing to know – when you schedule process• Workload characteristics
• CPU-bound jobs (CPU-intensive)• I/O-bound jobs (I/O-intensive)
• Giving long CPU time for I/O-bound jobs• Giving high priority for CPU-bound jobs• What actually happens in the scheduler is
• Complex• Homework) survey the Linux’s Scheduler
A theory – Little’s Theorem
• n = average queue length• W = average waiting time in queue• λ = average arrival rate into queue• Little’s law – in steady state, processes leaving queue
must equal processes arriving, thus: n = λ x W
• Valid for any scheduling algorithm and arrival distribution
• For example, if on average 7 processes arrive per second, and normally 14 processes in queue, then average wait time per process = 2 seconds
Summary page
• Various schedulers• FIFO, SJF, SRTF, RR, priority-based
• Evaluation criteria• Throughput, …time(s)
• Workload characteristics• I/O or CPU-bound tasks
• Think about the scheduler operation when I/O is involved?