processor scheduling
DESCRIPTION
Processor Scheduling. Scheduling is the activity of selecting the next Job / Process / Request to be handled by a Server/CPU. Preemption Scheduling : A request being processed is preempted in order to provide service to other requests in the system. - PowerPoint PPT PresentationTRANSCRIPT
OS/ProcSche/NI2008 1
Processor SchedulingScheduling is the activity of selecting the next Job / Process / Request to be handled by a Server/CPU.Preemption Scheduling: A request being processed is preempted in order to provide service to other requests in the system. It is for providing fair services to all the requests, or servicing the superior request. Non Preemptive Scheduling: A non preemptive scheduling / server always processes a scheduled request / job to completion.
OS/ProcSche/NI2008 2
CPU scheduling criteria CPU Utilization – Percentage of Time that the processor
is busy.
Throughput – how many jobs finished/unit time?• No of processes completed per unit of time.
Turnaround Time – how long from job submission to job termination?
Interval of time between the submission of a process and its completion. Includes actual execution time + time spent waiting for resources, including the processor.
Response Time – how long (on average) does it take to get a “response”?
For an interactive process, this is the time from submission of a request/job until the response begins to be received.
Missed deadlines – were any deadlines missed?
OS/ProcSche/NI2008 3
CPU scheduling criteria
Delay Time / CPU Latency Time: Delay caused in selecting a process for execution
Burst/Service Time: Actual time taken by CPU to completes the process
Weighted Turn around time: Ratio of the turn around time of a job/process to its
own execution requirements. Deadline:
Time by which a job/process must be completed Deadline Overrun:
The amount of time by which the deadline of a job/process is exceeded. It can be both positive or negative.
Schedule Length: The total time taken to complete a set of jobs/processes submitted to a server.
OS/ProcSche/NI2008 4
Scheduler options Priorities
May use priorities to determine who runs next
• Amount of memory, Order of arrival, etc.. Dynamic vs. Static algorithms
• Dynamically alter the priority of the tasks while they are in the system (possibly with feedback)
• Static algorithms typically assign a fixed priority when the job is initially started.
Preemptive vs. Nonpreemptive Preemptive systems allow the task to be
interrupted at any time so that the O.S. can take over again.
OS/ProcSche/NI2008 5
Types of Scheduling Scheduling is split into three
steps/levels/stages Long Term Scheduling / Admission Scheduler
– ( New state / Admit state) to Ready Medium Term Scheduling / Memory Scheduler
– ( Ready / Suspended / Blocked / waiting) Short Term Scheduler / CPU scheduler
– ( Preemptive / Non-Preemptive)– ( Ready to Running State)
OS/ProcSche/NI2008 6
Types of Scheduling Long Term Scheduling:
• When to initiate the processing of a job / process. Which programs are admitted to the system for processing. The others are kept in the input queue until they are selected.
• Allocates necessary resources • Make it ready to send to the Medium Term Scheduler.
Medium Term Scheduler:• MTS keeps track of states of processes admitted for
processing and prepares for execution on the CPU. • It determines which processes should be kept in
memory and which one kept on disk (virtual memory). • The decision to add to the number of processes that
are partially or fully in main memory. • Performs memory swapping in/out.
OS/ProcSche/NI2008 7
Types of Scheduling Short Term Scheduling: The short term scheduler is
invoked whenever an event occurs that may lead to the suspension of the current process or that may provide an opportunity to preempt a currently running process in favor of another. Event are .
• Clock interrupts• I/O interrupts• Operating system calls • Signals
STS picks one process from the list of ready processes for execution on the CPU, and hands it to the Dispatching Mechanism. Dispatching loads the state of the selected process – contents of the PSW and CPU registers – into the CPU and allows the CPU to resume execution of the process.
8
OS/ProcSche/NI2008 9
Scheduling policies / Algorithms First-Come, First Served (FIFO) Shortest Job First (non-preemeptive) Shortest Job First (with preemption)
( Shortest Remaining Time Next ) Highest Response Ratio Next Scheduling Shortest Job Next Deadline Scheduling Priority Scheduling Real-Time Scheduling Round-Robin Scheduling
OS/ProcSche/NI2008 10
Scheduling policies (Preemptive)
Round Robin Scheduling Heavily loaded system Two Queues Multiple Queues Guaranteed Scheduling Lottery Scheduling Fair Share scheduling
OS/ProcSche/NI2008 11
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
OS/ProcSche/NI2008 12
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 13
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
OS/ProcSche/NI2008 14
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
Arrival Times of the Jobs
OS/ProcSche/NI2008 15
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
OS/ProcSche/NI2008 16
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
OS/ProcSche/NI2008 17
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
OS/ProcSche/NI2008 18
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
OS/ProcSche/NI2008 19
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
OS/ProcSche/NI2008 20
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
OS/ProcSche/NI2008 21
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
OS/ProcSche/NI2008 22
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
OS/ProcSche/NI2008 23
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
OS/ProcSche/NI2008 24
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
OS/ProcSche/NI2008 25
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
OS/ProcSche/NI2008 26
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Total time taken,from submission to
completion
OS/ProcSche/NI2008 27
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 0 2 2 6 1 3 4 4 5 4 6 5 7 5 8 2 10
Total time taken,from submission to
completion
OS/ProcSche/NI2008 28
First-Come, First-Served (FIFO) Start jobs in the order they arrive (FIFO queue) Run each job until completion
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 0 3 2 2 6 1 7 3 4 4 5 9 4 6 5 7 12 5 8 2 10 12
Total time taken,from submission to
completion
OS/ProcSche/NI2008 29
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
OS/ProcSche/NI2008 30
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Same Job Mix
OS/ProcSche/NI2008 31
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 32
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 33
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 34
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 35
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 36
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 37
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 38
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 39
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 40
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 41
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 42
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 43
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 0 2 2 6 1 3 4 4 7 4 6 5 9 5 8 2 1
OS/ProcSche/NI2008 44
Shortest Job First Select the job with the shortest (expected) running time Non-Preemptive
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 0 3 2 2 6 1 7 3 4 4 7 11 4 6 5 9 14 5 8 2 1 3
OS/ProcSche/NI2008 45
Shortest Remaining Time Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Same Job Mix
OS/ProcSche/NI2008 46
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 47
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 48
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 49
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 50
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 51
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 52
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 53
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 54
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 55
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 56
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 57
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 58
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 59
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 0 2 2 6 7 3 4 4 0 4 6 5 9 5 8 2 0
OS/ProcSche/NI2008 60
Shortest Remaining Time• Preemptive version of SJF
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 0 3 2 2 6 7 13 3 4 4 0 4 4 6 5 9 14 5 8 2 0 2
5: CPU-Scheduling 61
EXAMPLE DATA:
Process Arrival Service Time Time
1 0 8 2 1 4
3 2 9 4 3 5
0 8 12 21 26
P1 P2 P3 P4
FCFS
Average Turnaround time = ( (8-0) + (12-1) + (21-2) + (26-3) )/4 = 61/4 = 15.25
CPU SCHEDULING
Residence Timeat the CPU
5: CPU-Scheduling 62
Assign each process a priority. Schedule highest priority first. All processes within same priority are FCFS.
Priority may be determined by user or by some default mechanism. The system may determine the priority based on memory requirements, time limits, or other resource usage.
Starvation occurs if a low priority process never runs. Solution: build aging into a variable priority.
Delicate balance between giving favorable response for interactive jobs, but not starving batch jobs.
PRIORITY BASED SCHEDULING:
OS/ProcSche/NI2008 63
Priority scheduling Assign a priority (number) to each process Schedule processes based on their priority Higher priority jobs processes get more CPU
time Managing priorities
Can use “nice” to reduce your priority Can periodically adjust a process’ priority
• Prevents starvation of a lower priority process• Can improve performance of I/O-bound
processes by basing priority on fraction of last quantum used
Priority scheduling
Idea: Each job is assigned a priority Schedule highest priority ready job May be preemptive or non-preemptive Priority may be static or dynamic
Advantages Static priorities work well for real time systems Dynamic priorities work well for general workloads
Disadvantages Low priority jobs can starve How to choose priority of each job?
Goal: Adjust priority of job to match CPU burst
Approximate SCTF by giving short jobs high priority
Highest Response Ratio Next (HRRN)
Non-preemptive, tries to get best average normalized turnaround time
Depends on Response Ratio• W = time spent waiting• S = expected service time• RR = (W + S) / S
Select process with highest RR Feedback
Starts in high-priority queue, moves down in priority as it executes
Lower-priority queues often given longer time slices Can starve long processes
• Move up processes if they wait too long
66
Highest Response Ratio Next (HRRN)
Choose next process with the greatest Response Ratio
( time spent waiting + expected service time)
expected service time
67
Fair-Share Scheduling
User’s application runs as a collection of processes (threads)
User is concerned about the performance of the application
Need to make scheduling decisions based on process sets
68
Traditional UNIX Scheduling
Multilevel feedback using round robin within each of the priority queues
If a running process does not block or complete within 1 second, it is preempted
Priorities are recomputed once per second
Base priority divides all processes into fixed bands of priority levels
Starvation
Effect on Processes
Overhead
Response Tim
e
Throughput
Preemptive
Selection Function
No
Penalizes short and I/O
processes
Minim
um
May be high
Not
Emphasized
No
Max tim
e w
aiting
FCFS
No
Fair
Low
Good for short
processes
Low if quantum
too sm
all
At tim
e quantum
- Round R
obin
Possible
Penalizes Long processes
Can be H
igh
Good for short
processes
High
No
Shortest process
SPN
Possible
Penalizes long processes
Can be H
igh
Good
High
At arrival
Min tim
e left
SRT
No
Good balance
Can be H
igh
Good
High
No
See Notes
HR
RN
Possible
May favor I/O
bound processes
Can be H
igh
Not
emphaisized
Not
emphaisized
At tim
e quantum
See Notes
Feedback
Characteristics of V
arious Scheduling Policies (Table 9.3, page 402)
OS/ProcSche/NI2008 70
Round-Robin Scheduling
Goal: Enable interactivity Limit the amount of CPU that a process can
have at one time.
Time quantum Amount of time the OS gives a process before
intervention The “time slice” Typically: 1 to 100ms
5: CPU-Scheduling 71
ROUND ROBIN: Use a timer to cause an interrupt after a predetermined time.
Preempts if task exceeds it’s quantum. Train of events
DispatchTime slice occurs OR process suspends on eventPut process on some queue and dispatch next
Use numbers in last example to find queueing and residence times. (Use quantum = 4 sec.)
Definitions:– Context Switch Changing the processor from
running one task (or process) to another. Implies changing memory.
– Processor Sharing Use of a small quantum such that each process runs frequently at speed 1/n.
– Reschedule latency How long it takes from when a process requests to run, until it finally gets control of the CPU.
ROUND ROBIN
5: CPU-Scheduling 72
Choosing a time quantum
Too short - inordinate fraction of the time is spent in context switches.
Too long - reschedule latency is too great. If many processes want the CPU, then it's a long time before a particular process can get the CPU. This then acts like FCFS.
Adjust so most processes won't use their slice. As processors have become faster, this is less of an issue.
ROUND ROBIN
OS/ProcSche/NI2008 73
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 74
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 75
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 76
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 77
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 78
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 79
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 80
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 81
Ready List:
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 82
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 83
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 84
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 85
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 86
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 87
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 88
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 89
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 90
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 91
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 92
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 93
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 94
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 95
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 96
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 97
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 98
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
Ready List:
OS/ProcSche/NI2008 99
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Process Time Time 1 0 3 2 2 6 3 4 4 4 6 5 5 8 2
OS/ProcSche/NI2008 100
Round-Robin Scheduling•
0 5 10 15 20
Arrival Processing Turnaround Process Time Time Delay Time 1 0 3 1 4 2 2 6 10 16 3 4 4 9 13 4 6 5 9 14 5 8 2 5 7
OS/ProcSche/NI2008 101
Round-Robin Scheduling
Effectiveness of round-robin depends on The number of jobs, and The size of the time quantum.
Large # of jobs means that the time between scheduling of a single job increases
Slow responses Larger time quantum means that the time
between the scheduling of a single job also increases
Slow responses Smaller time quantum means higher processing
rates but also more overhead!
5: CPU-Scheduling 102
MULTI-LEVEL QUEUES:
Each queue has its scheduling algorithm. Then some other algorithm (perhaps priority
based) arbitrates between queues. Can use feedback to move between queues Method is complex but flexible. For example, could separate system processes,
interactive, batch, favored, unfavored processes
MULTI-LEVEL QUEUES
Multilevel Queue Ready queue is partitioned into separate
queues:foreground (interactive)background (batch)
Each queue has its own scheduling algorithm foreground – RR background – FCFS
Scheduling must be done between the queues Fixed priority scheduling; (i.e., serve all from
foreground then from background). Possibility of starvation.
Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR
20% to background in FCFS
Multilevel Queue Scheduling
Multilevel Feedback Queue
A process can move between the various queues; aging can be implemented this way
Multilevel-feedback-queue scheduler defined by the following parameters:
number of queues scheduling algorithms for each queue method used to determine when to upgrade a
process method used to determine when to demote a
process method used to determine which queue a process
will enter when that process needs service
Example of Multilevel Feedback Queue
Three queues: Q0 – RR with time quantum 8 milliseconds Q1 – RR time quantum 16 milliseconds Q2 – FCFS
Scheduling A new job enters queue Q0 which is served FCFS.
When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1.
At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2.
Multilevel Feedback Queues
OS/ProcSche/NI2008 108
Multi-Level Queue Scheduling
Multiple queues, each with its own priority. Equivalently: each priority has its own ready queue
Within each queue...Round-robin scheduling. Simplist Approach:
A Process’s priority is fixed & unchanging
CPU
High priority
Low priority
OS/ProcSche/NI2008 109
Multi-Level Feedback Queue Scheduling Problem: Fixed priorities are too restrictive
Processes exhibit varying ratios of CPU to I/O times. Dynamic Priorities
Priorities are altered over time, as process behavior changes!
OS/ProcSche/NI2008 110
Multi-Level Feedback Queue Scheduling Problem: Fixed priorities are too restrictive
Processes exhibit varying ratios of CPU to I/O times. Dynamic Priorities
Priorities are altered over time, as process behavior changes!
Issue: When do you change the priority of a process and how often?
OS/ProcSche/NI2008 111
Multi-Level Feedback Queue Scheduling Problem: Fixed priorities are too restrictive
Processes exhibit varying ratios of CPU to I/O times. Dynamic Priorities
Priorities are altered over time, as process behavior changes!
Issue: When do you change the priority of a process and how often?
Solution: Let the amount of CPU used be an indication of how a process is to be handled
Expired time quantum more processing needed Unexpired time quantum less processing needed
Adjusting quantum and frequency vs. adjusting priority?
5: CPU-Scheduling 112
Here’s how the priorities are used in Windows
CPU SCHEDULING Using Priorities
OS/ProcSche/NI2008 113
Multi-Level Feedback Queue Scheduling n priority levels, round-robin scheduling within a
level Quanta increase as priority decreases Jobs are demoted to lower priorities if they do not
complete within the current quantum
CPU
High priority
Low priority
??
OS/ProcSche/NI2008 114
Lottery Scheduling
Scheduler gives each thread some lottery tickets To select the next process to run...
The scheduler randomly selects a lottery number The winning process gets to run
Example Thread A gets 50 tickets Thread B gets 15 tickets Thread C gets 35 tickets There are 100 tickets outstanding.
OS/ProcSche/NI2008 115
Lottery Scheduling
Scheduler gives each thread some lottery tickets. To select the next process to run...
The scheduler randomly selects a lottery number The winning process gets to run
Example Thread A gets 50 tickets 50% of CPUThread B gets 15 tickets 15% of CPUThread C gets 35 tickets 35% of CPUThere are 100 tickets outstanding.
OS/ProcSche/NI2008 116
Lottery Scheduling
Scheduler gives each thread some lottery tickets. To select the next process to run... The scheduler randomly selects a lottery
number The winning process gets to run Example Thread A gets 50 tickets 50% of CPU
Thread B gets 15 tickets 15% of CPUThread C gets 35 tickets 35% of CPUThere are 100 tickets outstanding.• Flexible• Fair• Responsive
5: CPU-Scheduling 117
MULTIPLE PROCESSOR SCHEDULING:
Different rules for homogeneous or heterogeneous processors.
Load sharing in the distribution of work, such that all processors have an equal amount to do.
Each processor can schedule from a common ready queue ( equal machines ) OR can use a master slave arrangement.
Real Time Scheduling:• Hard real-time systems – required to complete a critical task within
a guaranteed amount of time.
• Soft real-time computing – requires that critical processes receive priority over less fortunate ones.
CPU SCHEDULING
OS/ProcSche/NI2008 118
A Brief Look at Real-Time Systems
Assume processes are relatively periodic Fixed amount of work per period (e.g. sensor
systems or multimedia data)
OS/ProcSche/NI2008 119
A Brief Look at Real-Time Systems
Assume processes are relatively periodic Fixed amount of work per period (e.g. sensor
systems or multimedia data) Two “main” types of schedulers... Rate-Monotonic Schedulers
Earliest-Deadline-First Schedulers
OS/ProcSche/NI2008 120
A Brief Look at Real-Time Systems
Assume processes are relatively periodic Fixed amount of work per period (e.g. sensor
systems or multimedia data) Two “main” types of schedulers... Rate-Monotonic Schedulers
Assign a fixed, unchanging priority to each process No dynamic adjustment of priorities
• Less aggressive allocation of processor Earliest-Deadline-First Schedulers
Assign dynamic priorities based upon deadlines
OS/ProcSche/NI2008 121
A Brief Look at Real-Time Systems
Typically real-time systems involve several steps (that aren’t in traditional systems)
Admission control All processes must ask for resources ahead of time. If sufficient resources exist,the job is “admitted” into
the system. Resource allocation
Upon admission... the appropriate resources need to be reserved for
the task. Resource enforcement
Carry out the resource allocations properly
OS/ProcSche/NI2008 122
Rate Monotonic Schedulers
For preemptable, periodic processes (tasks)
Assigns a fixed priority to each task T = The period of the task C = The amount of processing per task period
In RMS scheduling, the question to answer is... What priority should be assigned to a given task?
Process P1T = 1 secondC = 1/2 second / period
OS/ProcSche/NI2008 123
Rate Monotonic Schedulers
P1
P2
OS/ProcSche/NI2008 124
Rate Monotonic Schedulers
P1PRI > P2PRI
P2PRI > P1PRI
P1
P2
OS/ProcSche/NI2008 125
Rate Monotonic Schedulers
P1PRI > P2PRI
P2PRI > P1PRI
P1
P2
The computation for P2 cannot be increased
OS/ProcSche/NI2008 126
Rate Monotonic Schedulers
Assign shortest period tasks to the highest priorities
Admission control is difficult...< 69% There is a standard formula> 69% It may be possible, but need to do more
complex analysis
OS/ProcSche/NI2008 127
Rate Monotonic Schedulers
Assumptions: Processes complete (yield) within their period Independent processes Same CPU requirements per burst Other non-periodic processes have no deadlines Instantaneous preemption with no overhead
OS/ProcSche/NI2008 128
Earliest Deadline First
When processes do not need periodic executionor have constant CPU requirements...
When processes have deadline specifications...
Unlike RMS, EDF uses dynamic priorities (based upon earliest deadline first)(+) 100% processor utilization …?(-) Need to keep track of deadlines
Admission Control Just check to see if 100% processor utilization. Sum the Ci/Ti’s and see if less than or equal to 1 What about overhead?
OS/ProcSche/NI2008 129
Quiz
What are the main tasks of the scheduler? What is the difference between preemptive and non-
preemptive scheduling? What is the advantage of a shorter scheduling
quantum? What is the advantage of a longer scheduling quantum? Why is feedback scheduling useful for interactive jobs? Are these scheduling policies subject to starvation?
Shortest Job First scheduling? Round Robin scheduling? First Come First Served scheduling? Priority scheduling? Earliest Deadline First scheduling?