Скачать презентацию Scheduling Dispatching 2004 D J Foreman Скачать презентацию Scheduling Dispatching 2004 D J Foreman

adf37e490e9a2c4f3807d9d91db7d985.ppt

  • Количество слайдов: 24

Scheduling & Dispatching © 2004, D. J. Foreman 1 Scheduling & Dispatching © 2004, D. J. Foreman 1

What is What is "Scheduling"? u Managing resources and demands for them Determine next "run-user" ■ Determine resources required ■ Add new "run-user" to "ready" list ■ u All above usually done in kernel mode u "Run-user" ■ Current thread/process that is executing © 2004, D. J. Foreman 2

What is What is "Dispatching"? u Determine user at head of "ready list" u Preempt/wait for current run-user to yield u Save state of current run-user u Load state data for new run-user u Mode switch to new run-user © 2004, D. J. Foreman 3

Questions u How would you design a scheduler that runs in user-mode? What problems Questions u How would you design a scheduler that runs in user-mode? What problems would you have to handle? ■ Why would you want to run it in user-mode? ■ © 2004, D. J. Foreman 4

What is a “job”? u Fixed set of programs (NOT processes) Sort employee records What is a “job”? u Fixed set of programs (NOT processes) Sort employee records ■ Compute wages for each employee ■ Print checks for all employees ■ u Resources statements pre-specified by “job control” Employee DB ■ Payroll DB ■ High-speed printer ■ u Programs © 2004, D. J. Foreman run in strict sequence 5

How is the scheduler invoked? u Voluntary Process/thread blocks itself (“yield”s the CPU) ■ How is the scheduler invoked? u Voluntary Process/thread blocks itself (“yield”s the CPU) ■ Calls scheduler ■ Processes can yield to each other ■ Problems-> greed, errors ■ u Involuntary Pre-emption by interrupt (device/timer) ■ Kernel calls scheduler before/after interrupt is processed, before return to pre-empted user ■ © 2004, D. J. Foreman 6

Policies u Ideally Selectable ■ Changeable ■ u Practically Built into OS ■ Can Policies u Ideally Selectable ■ Changeable ■ u Practically Built into OS ■ Can be changed with versions of OS ■ u Additionally ■ Scheduler can BE the Resource Manager © 2004, D. J. Foreman 7

Control u Interval timer Quantum or slice ■ Fixed or variable ■ u Multiple Control u Interval timer Quantum or slice ■ Fixed or variable ■ u Multiple policies possible in one system Interactive applications • May become compute-bound ■ Batch jobs ■ Deadline production ■ Real-time – process-control systems ■ © 2004, D. J. Foreman 8

Policy implimentation u Mechanism – fixed u Varies by requirements CPU usage ■ Wait Policy implimentation u Mechanism – fixed u Varies by requirements CPU usage ■ Wait time ■ Job completion time ■ u Controls: Fair share ■ Favor long/short jobs ■ Priorities ■ Deadlines ■ © 2004, D. J. Foreman 9

Scheduling Variables P = {pi | 0 i < n}, be a set of Scheduling Variables P = {pi | 0 i < n}, be a set of processes u Let {Pij} = set of threads, j, in Pi u Let S(pi) {running, ready, blocked} u Let t(pi) = required runtime or service time u Let W(pi) = initial wait time u Let TTRnd(pi) = wall clock: endtime – start time (turnaround time) u Batch Throughput rate = 1/(avg TTRnd) u Timesharing response time = W(pi) u Let © 2004, D. J. Foreman 10

Optimizing Schedules u Criteria CPU usage ■ Wait time ■ Deadlines ■ u Methods Optimizing Schedules u Criteria CPU usage ■ Wait time ■ Deadlines ■ u Methods ■ Restrict # of processes pi ■ Pre-determine service time τ(pi) ■ Compute all schedules and choose best © 2004, D. J. Foreman 11

Optimization problems uτ(pi) are estimates u. Schedule-compute time is O(n 2) u. Only an Optimization problems uτ(pi) are estimates u. Schedule-compute time is O(n 2) u. Only an approximation of optimum u. New jobs arrive during processing © 2004, D. J. Foreman 12

Estimating CPU Utilization l = average rate at which processes are placed in the Estimating CPU Utilization l = average rate at which processes are placed in the Ready List= arrival rate (arrivals/sec) m = the average service rate 1/ m = the average service time, t(pi), per process r = expected CPU busy time, computed as: r = arrival rate * avg CPU time each r = l * 1/ m = l / m • Notice: must have l < m (i. e. , r < 1) • What if r approaches 1? © 2004, D. J. Foreman 13

Non-preemptive Schedulers u Using the simplified scheduling model: new->ready-> scheduled-> running->done u Only considers Non-preemptive Schedulers u Using the simplified scheduling model: new->ready-> scheduled-> running->done u Only considers running and ready states u Ignores 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 ■ © 2004, D. J. Foreman 14

Non-preemptive Schedulers u First Come First Served u Shortest Job Next u Priority u Non-preemptive Schedulers u First Come First Served u Shortest Job Next u Priority u Deadline © 2004, D. J. Foreman 15

First Come, First Served u Simple u Ignores service time u Average wait time=simple First Come, First Served u Simple u Ignores service time u Average wait time=simple avg of all W(p) u Predicted W(p)=Wavg u Wavg=Lw/m +. 5/m = (L/m) +1/(2 m) © 2004, D. J. Foreman 16

Shortest Job Next u Minimizes wait time u “Bad” jobs may take excessive time Shortest Job Next u Minimizes wait time u “Bad” jobs may take excessive time u Service times must be known in advance ■ Known for batch systems © 2004, D. J. Foreman 17

Priority u Pre-determined rules required u Low priority jobs may get poor service u Priority u Pre-determined rules required u Low priority jobs may get poor service u Addressable via Age ■ Re-assesment ■ Other resource requirements ■ © 2004, D. J. Foreman 18

Deadline u Based on required finish time u Requires known runtime © 2004, D. Deadline u Based on required finish time u Requires known runtime © 2004, D. J. Foreman 19

Preemptive Scheduling u Almost always by priority u Most common form today u Complex Preemptive Scheduling u Almost always by priority u Most common form today u Complex analysis u Requires interval timer support u Examples: Round Robin (RR) ■ Round Robin with Overhead (RRO) ■ Multi-level queues ■ © 2004, D. J. Foreman 20

Round Robin u Each process gets a fixed time slice to run (Time in Round Robin u Each process gets a fixed time slice to run (Time in Queue) u Fair share u Most common preemptive scheduler today u Optional placement of new processes: queue vs. ring u For n processes, q CPU units, C context Total real time available=n*(q+C) ■ Or q=(T/n)-C ■ u. C is usually ignored, but should not be © 2004, D. J. Foreman 21

RR w/Overhead included u Fixed overhead for C added between slices u Changes average RR w/Overhead included u Fixed overhead for C added between slices u Changes average performance time © 2004, D. J. Foreman 22

Multi-level Queues u More than 1 ready list Interactive ■ Large batch ■ Small Multi-level Queues u More than 1 ready list Interactive ■ Large batch ■ Small batch ■ Compute bound ■ u Top-level queue must clear before next level runs u Within a level use RR, etc © 2004, D. J. Foreman 23

Current systems u Linux u BSD 4. 4 u Win 2 K/NT/XP/7 u See Current systems u Linux u BSD 4. 4 u Win 2 K/NT/XP/7 u See book for descriptions © 2004, D. J. Foreman 24