Schedulers Operating System Scheduling (h 4., 5. - 5.) Short-Term Which process gets the PU? Fast, since once per 00 ms Long-Term (batch) Which process gets the Ready Queue? Medium-Term (Unix) Which Ready Queue process to memory? Swapping PU-IO urst ycle Preemptive Scheduling add read (I/O Wait) store increment write (I/O Wait) Frequency urst Duration Four times to re-schedule Running to Waiting (I/O wait) Running to Ready (time slice) Waiting to Ready (I/O completion) 4 Termination # optional ==> Preemptive Timing may cause unexpected results updating shared variable kernel saving state Question What Performance riteria Should the Scheduler Seek to Optimize? Ex: PU minimize time spent in queue Others? Scheduling riteria PU utilization (40 to 90) Throughput (processes / hour) Turn-around time 4 Waiting time (in queue) Maximize #, # Minimize #, #4 Response time Self-regulated by users (go home) ounded ==> Variance!
Gantt hart First-ome, First-Served urst Time 0 9 0 vg Wait Time (0 + + 9) / = 5.7 Shortest Job First urst Time 0 0 vg Wait Time (0 + + ) / = Optimal vg Wait Prediction tough Ideas? Priority Scheduling SJF is a special case urst Time Priority 0 9 0 vg Wait Time (0 + + 9) / =. Priority Scheduling riteria? Internal open files memory requirements PU time used - time slice expired (RR) process age - I/O wait completed External $ department sponsoring work process importance super-user (root) - nice Round Robin Fixed time-slice and Preemption urst Time 5 vg = ( + 9 + ) / = 9. FFS? SJF? 9 Round Robin Fun Turn-around time? q = 0 q = q --> 0 urst Time 0 0 0
Rule: 0% within one quantum More Round Robin Fun D vg. Turn-around Time urst Time 6 7 4 5 6 7 Time Quantum Gantt harts: FFS SJF Priority RR (q=) Fun with Scheduling urst Time 0 Priority Performance: Throughput Waiting time Turnaround time More Fun with Scheduling Turn around time: FFS SJF q= PU idle q=0.5 PU idle rrival Time 0.0 0.4.0 urst Time 4 Multi-Level Queues ategories of processes Priority Priority Priority System Interactive atch...... Run all in first, then Starvation! Divide between queues: 70%, 5% Multi-Level Feedback Queues Time slice expensive but want interactive Priority Priority Priority Queue Queue Queue Quantum Quanta 4 Quanta......... onsider process needing 00 quanta, 4,, 6,, 64 = 7 swaps! Favor interactive users Evaluating Scheduling lgorithms With all these possible scheduling algorithms, how to choose one? Ease of implementation Efficiency of implementation / low overhead Performance evaluation (next slide)
Performance Evaluation Methods Deterministic methods / Gantt charts Use more realistic workloads Queueing theory Mathematical techniques Uses probablistic models of jobs / PU utilization Simulation Probabilistic or trace-driven Linux Scheduling Two classes of processes: Real-Time Normal Real-Time: lways run Real-Time above Normal Round-Robin or FIFO Soft not Hard Linux Scheduling Normal: redit-ased process with most credits is selected time-slice then lose a credit (0, then suspend) no runnable process (all suspended), add to every process: credits = credits/ + priority utomatically favors I/O bound processes What is a P? Questions List steps that occur during interrupt Explain how SJF works True or False: FFS is optimal in terms of avg waiting time Most processes are PU bound The shorter the time quantum, the better micro-shell.c? Interrupt Handling Stores program counter (hardware) Loads new program counter (hardware) jump to interrupt service procedure Save P information (assembly) Set up new stack (assembly) Set waiting process to ready () Re-schedule (probably awakened process) () dispatcher in SOS, schedule in Linux If new process, called a context-switch Outline es P Interrupt Handlers Scheduling lgorithms Linux WinNT 4
Windows NT Scheduling asic scheduling unit is a thread Priority based scheduling per thread Preemptive operating system No shortest job first, no quotas Priority ssignment NT kernel uses priority levels is the highest; 0 is system idle thread Realtime priorities: 6 - Dynamic priorities: - 5 Users specify a priority class: realtime (4), high (), normal () and idle (4) and a relative priority: highest (+), above normal (+), normal (0), below normal (-), and lowest (-) to establish the starting priority Threads also have a current priority Quantum Dispatcher Ready List Determines how long a Thread runs once selected Varies based on: NT Workstation or NT Server Intel or lpha hardware Foreground/ackground application threads Dispatcher Ready List 0 9 7 Ready Threads Keeps track of all Ready-to-execute threads Queue of threads assigned to each level How do you think it varies with each? FindReadyThread Locates the highest priority thread that is ready to execute Scans dispatcher ready list Picks front thread in highest priority nonempty queue When is this like round robin? oosting and Decay oost priority Event that wakes blocked thread oosts never exceed priority 5 for dynamic Realtime priorities are not boosted Decay priority by one for each quantum decays only to starting priority (no lower) 5
Starvation Prevention Low priority threads may never execute nti-pu starvation policy thread that has not executed for seconds boost priority to 5 double quantum Decay is swift not gradual after this boost 6