Scheduling - Hong Kong Polytechnic University
Transcript of Scheduling - Hong Kong Polytechnic University
EEL 602 2
OutlineIntroductionTypes of SchedulingScheduling CriteriaFCFS SchedulingShortest-Job-First SchedulingPriority SchedulingRound Robin SchedulingMultilevel Queue SchedulingMultiprocessor Scheduling
Load BalancingSymmetric Multithreading
Algorithm EvaluationReal Time SchedulingScheduling Examples
Windows XP, 2000Linux
EEL 602 3
Basic PointsProcess Scheduling, Thread Scheduling
Max CPU Utilization → Multiprogramming
CPU Burst ↔ I/O Burst
CPU Burst Distribution
Introduction
EEL 602 5
CPU Scheduling DecisionsRunning → Waiting state
e.g. I/O Request, wait by ParentRunning → Ready state
e.g. InterruptWaiting → Ready state
e.g. Completion of I/OProcess Termination
Nonpreemptive SchedulingPreemptive Scheduling
Associated CostDesign of OS Kernel
Process → Kernel, wait for sys call or I/O completion beforecontext switch
Scheduling Types
EEL 602 6
Scheduling CriteriaCPU Utilization – How busy is the CPU?
Throughput – Number of processes that are completed per unit time
Turnaround Time – How long to execute a process? Submission ↔ Completion
Waiting Time – Sum of periods spent in ready queue
Response Time – Process Request → First response
EEL 602 7
Optimization CriteriaMax CPU utilization
Max throughput
Min turnaround time
Min waiting time
Min response time
Conflicting goals! Requires careful balanceAverage, Min/Max, Variance
EEL 602 8
Process Burst TimeP1 24P2 3P3 3
Arrivals in the order: P1 , P2 , P3 The Gantt Chart for the schedule:
Waiting time → P1 = 0; P2 = 24; P3 = 27Average waiting time → (0 + 24 + 27)/3 = 17
P1 P2 P3
24 27 300
FCFS Scheduling
EEL 602 9
FCFS SchedulingSay, if the processes arrive in the order
P2 , P3 , P1
The Gantt chart for the schedule:
Waiting time → P1 = 6; P2 = 0; P3 = 3Average waiting time → (6 + 0 + 3)/3 = 3, Previously 17 ↑Convoy effect → Short process behind long processNonpreemptive → Problem for time sharing systems
P1P3P2
63 300
EEL 602 10
SJF SchedulingCPU assigned to process with smallest next CPU burst, Tie → FCFS
Shortest-next-CPU-burst algorithm
Major difficultyEstimating the processing time of each job, Predicting the Next!Long running jobs may starve, steady supply of short jobs to CPU
SJF is optimal – minimum average waiting time
EEL 602 11
Process Arrival Time Burst TimeP1 0.0 7P2 2.0 4P3 4.0 1P4 5.0 4
SJF (non-preemptive)
Average waiting time → (0 + 6 + 3 + 7)/4 = 4
SJF Scheduling
P1 P3 P2
73 160
P4
8 12
EEL 602 12
SJF SchedulingProcess Arrival Time Burst Time
P1 0.0 7P2 2.0 4P3 4.0 1P4 5.0 4
SJF (preemptive)
Average waiting time = (9 + 1 + 0 +2)/4 = 3
P1 P3P2
42 110
P4
5 7
P2 P1
16
EEL 602 13
Priority SchedulingA priority number (integer) associated with each process
SJF – A Priority schedulingEqual Priority - FCFS
CPU → Process with the highest priority, High ↔ LowPreemptiveNonpreemptive
Defining PrioritiesInternally, Measurable Quantities
Memory required, time limits, # open files, ratio of avg I/O to CPU burst, etc.
Externally, Outside OSImportance of Process, type/amount of funds, etc.
StarvationLow priority processes may never execute
Solution?Aging
EEL 602 14
Round Robin (RR)Each process gets a small unit of CPU time
Time Quantum (time-slice)usually 10-100 milliseconds
Time elapsed → PreemptedIf not completed → end of the ready queue
RR reduces penalty for short jobs in FCFS
Critical Issue → Length of quantum, qq large → FIFO or FCFSq small → Context switch overhead
EEL 602 15
Process Burst TimeP1 53P2 17P3 68P4 24
The Gantt chart is:
Typically, higher average turnaround than SJF, but better response.
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
0 20 37 57 77 97 117 121 134 154 162
Round Robin (RR)
EEL 602 18
Multilevel QueueReady queue → separate queues
foreground (interactive)background (batch)
Each queue → own scheduling algorithm, e.g.foreground – RRbackground – FCFS
Scheduling must be done between the queuesFixed priority scheduling; (i.e., serve all from foreground then from background), StarvationTime slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR20% to background in FCFS
EEL 602 20
Multilevel Feedback QueueSeparate processes → CPU burst characteristicsProcess moves up ↔ down in queues
Too much time ↓Aging ↑
Key pointsnumber of queuesscheduling algorithms for each queuemethod used to determine when to upgrade a processmethod used to determine when to demote a processmethod used to determine which queue a process will enter when that process needs service
EEL 602 22
Multiple-Processor SchedulingMultiple CPUs → High scheduling complexityHomogeneous Processors
Asymmetric MultiprocessingNo data sharing, System data structures → one processor
Symmetric MultiprocessingSelf Scheduling, Ready queue
Processor AffinitySoft Vs Hard affinity
Load BalancingPush MigrationPull Migration
EEL 602 23
Algorithm EvaluationDeterministic modeling
Takes a particular predetermined workload and defines the performance of each algorithm for that workload
Queueing modelsQueue of network serversLittle’s formula, l = λ × w
λ - Avg arrival rate, w - Avg waiting time, l - Avg queue length
SimulationModel, clockSimulation → modifies system with clock ↑Distribution driven simulationOnly # instances of an event, order?
EEL 602 25
Real-Time SchedulingHard real-time systems
Complete a critical task within a guaranteed timeAdmit or RejectImpossible with SS, VMResource Reservation
Soft real-time computingCritical processes receive priority over less fortunate onesGeneral-purpose systems → Multimedia, GraphicsPriority InversionPriority-inheritance protocol
EEL 602 26
SchedulingPriority-based, preemptive schedulingThread runs → preempted by higher priority thread, terminates, QuDoes not guarantee execution of a real-time thread within time-limit
Thread Priorities32 level priority schemeReal time class → 16-32Variable class → 1-15Memory Management → Thread at 0 priority
Six Classes (Win32 API) – 1 + 5Within each 6 classes – 7 relative prioritiesCurrently selected foreground process → Scheduling Quantum ↑ 3
Example: Windows XP, 2000
EEL 602 28
Example: LinuxScheduling
Increased support for SMP, Scaling with # tasksProcessor affinity, load balancingHigh priority tasks → longer quanta, vice-versaReal time tasks – static prioritiesRest dynamic → nice values ± 5 (interactivity)
Numeric Priorities0-140 level priority schemeReal time → 0-99Nice values → 100-140
C