scheduling & dispatching
DESCRIPTION
Scheduling & Dispatching. What is "Scheduling"?. Managing resources and demands for them Determine next "run-user" Determine resources required Add new "run-user" to "ready" list All above usually done in kernel mode "Run-user" Current thread/process that is executing. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/1.jpg)
© 2004, D. J. Foreman 1
Scheduling & Dispatching
![Page 2: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/2.jpg)
© 2004, D. J. Foreman 2
What is "Scheduling"?Managing resources and demands for them
■ Determine next "run-user" ■ Determine resources required■ Add new "run-user" to "ready" list
All above usually done in kernel mode"Run-user"
■ Current thread/process that is executing
![Page 3: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/3.jpg)
© 2004, D. J. Foreman 3
What is "Dispatching"?Determine user at head of "ready list"Preempt/wait for current run-user to yieldSave state of current run-userLoad state data for new run-userContext switch to new run-user
![Page 4: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/4.jpg)
© 2004, D. J. Foreman 4
QuestionsHow would you plan a scheduler that runs
in user-mode?■ What problems would you have to handle?■ Why would you want to run it in user-mode?
![Page 5: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/5.jpg)
© 2004, D. J. Foreman 5
What is a “job”?Fixed set of programs (NOT processes)
■ Sort employee records■ Compute wages for each employee■ Print checks for all employees
Resources pre-specified by “job control” statements■ Employee DB■ Payroll DB■ High-speed printer
Programs run in strict sequence
![Page 6: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/6.jpg)
© 2004, D. J. Foreman 6
How is the scheduler invoked?Voluntary
■ Process/thread blocks itself (“yield”s the CPU)■ Calls scheduler■ Processes can yield to each other■ Problems-> greed, errors
Involuntary ■ Pre-emption by interrupt (device/timer)■ Kernel calls scheduler before/after interrupt is
processed, before return to pre-empted user
![Page 7: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/7.jpg)
© 2004, D. J. Foreman 7
PoliciesIdeally
■ Selectable■ Changeable
Practically■ Built into OS■ Can be changed with versions of OS
Additionally■ Scheduler can BE the Resource Manager
![Page 8: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/8.jpg)
© 2004, D. J. Foreman 8
Control Interval timer
■ Quantum or slice■ Fixed or variable
Multiple policies possible in one system■ Interactive users
• May become compute-bound
■ Batch users■ Deadline production■ Real-time – process-control systems
![Page 9: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/9.jpg)
© 2004, D. J. Foreman 9
Policy implimentationMechanism – fixedVaries by requirements
■ CPU usage■ Wait time■ Job completion time
Controls:■ Fair share■ Favor long/short jobs■ Priorities■ Deadlines
![Page 10: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/10.jpg)
© 2004, D. J. Foreman 10
Scheduling Variables Let P = {pi | 0 i < n}, be a set of processes
Let {Pij} = set of threads, j, in Pi
Let S(pi) {running, ready, blocked}
Let (pi) = required runtime or service time
Let W(pi) = initial wait time
Let TTRnd(pi) = wall clock: endtime – start time (turnaround time)
Batch Throughput rate = 1/(avg TTRnd)
Timesharing response time = W(pi)
![Page 11: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/11.jpg)
© 2004, D. J. Foreman 11
Optimizing SchedulesCriteria
■ CPU usage■ Wait time■ Deadlines
Methods ■ Restrict # of processes pi
■ Pre-determine service time τ(pi) ■ Compute all schedules and choose best
![Page 12: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/12.jpg)
© 2004, D. J. Foreman 12
Optimization problems
τ(pi) are estimates
Schedule-compute time is O(n2)Only an approximation of optimumNew jobs arrive during processing
![Page 13: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/13.jpg)
© 2004, D. J. Foreman 13
Estimating CPU Utilization = average rate at which processes are placed in the Ready List= arrival rate (arrivals/sec)
= the average service rate 1/ = the average service time, (pi), per process
= expected CPU busy time, computed as: = arrival rate * avg CPU time each = * 1/ = /
• Notice: must have < (i.e., < 1)• What if approaches 1?
![Page 14: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/14.jpg)
© 2004, D. J. Foreman 14
Non-preemptive SchedulersUsing the simplified scheduling model:
new->ready-> scheduled-> running->doneOnly considers running and ready statesIgnores time in blocked state:
■ New process created when it becomes ready■ Process is destroyed when it is blocked■ Only looking at “small phases” of a process
![Page 15: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/15.jpg)
© 2004, D. J. Foreman 15
Non-Preemptive Schedulers
First Come First ServedShortest Job NextPriorityDeadline
![Page 16: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/16.jpg)
© 2004, D. J. Foreman 16
First Come, First ServedSimpleIgnores service timeAverage wait time=simple avg of all W(p)
Predicted W(p)=Wavg
Wavg=Lw/+ .5/= (L/) +1/(2)
![Page 17: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/17.jpg)
© 2004, D. J. Foreman 17
Shortest Job NextMinimizes wait time“Bad” jobs may take excessive timeService times must be known in advance
■ Known for batch systems
![Page 18: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/18.jpg)
© 2004, D. J. Foreman 18
PriorityPre-determined rules requiredLow priority jobs may get poor serviceAddressable via
■ Age■ Re-assesment■ Other resource requirements
![Page 19: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/19.jpg)
© 2004, D. J. Foreman 19
DeadlineBased on required finish timeRequires known runtime
![Page 20: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/20.jpg)
© 2004, D. J. Foreman 20
Preemptive SchedulingAlmost always by priorityMost common form todayComplex analysisRequires interval timer supportExamples:
■ Round Robin (RR)■ Round Robin with Overhead (RRO)■ Multi-level queues
![Page 21: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/21.jpg)
© 2004, D. J. Foreman 21
Round RobinEach process gets a fixed time slice to run
(Time in Queue)Fair shareMost common preemptive scheduler todayOptional placement of new processes:
queue vs. ringFor n processes, q CPU units, C context
■ Total real time available=n*(q+C)■ Or q=(T/n)-C
C is usually ignored, but should not be
![Page 22: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/22.jpg)
© 2004, D. J. Foreman 22
RR w/Overhead icludedFixed overhead for C added between
slicesChanges average performance time
![Page 23: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/23.jpg)
© 2004, D. J. Foreman 23
Multi-level QueuesMore than 1 ready list
■ Interactive■ Large batch■ Small batch■ Compute bound
Top-level queue must clear before next level runs
Within a level use RR, etc
![Page 24: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/24.jpg)
© 2004, D. J. Foreman 24
Current systemsLinuxBSD 4.4Win 2K/NT/XPSee book for descriptions
![Page 25: Scheduling & Dispatching](https://reader036.vdocuments.mx/reader036/viewer/2022070401/56813696550346895d9e234e/html5/thumbnails/25.jpg)
© 2004, D. J. Foreman 25
Midterm