Chapter 5: Process Scheduling
-
Upload
whoopi-colon -
Category
Documents
-
view
24 -
download
5
description
Transcript of Chapter 5: Process Scheduling
5.2 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Basic ConceptsBasic Concepts
CPU scheduling is the basic of multiprogramming OS.
Scheduling is a fundamental OS function.
Almost all computer resources are scheduled before use.
The CPU is one of the primary computer resources.
By switching the CPU among processes, the OS can make the computer more productive.
Thus its scheduling is central to OS design
5.3 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
CPU-I/O Burst Cycle CPU-I/O Burst Cycle
CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait
Processes alternate between these two states.
Process execution begins with a CPU burst.
That is followed by an I/O burst, then another CPU burst, then another I/O burst and so on.
5.4 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
CPU-I/O Burst CycleCPU-I/O Burst Cycle
Finally, the last CPU burst will end with a system request to terminate execution , rather than with another I/O burst.
This distribution can help us select an appropriate CPU-scheduling algorithm.
5.5 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Alternating Sequence of CPU And I/O BurstsAlternating Sequence of CPU And I/O Bursts
5.6 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
CPU-I/O Burst CycleCPU-I/O Burst Cycle
The duration of these CPU burst have been extensively measured.
In measured in histogram the curve is generally characterized as exponential or hyper exponential with many short CPU bursts, and a few long CPU bursts.
5.7 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Histogram of CPU-burst TimesHistogram of CPU-burst Times
5.8 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
CPU SchedulerCPU Scheduler
Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them
CPU scheduling decisions may take place when a process:
1.Switches from running to waiting state
2. Switches from running to terminates state
3. Switches from running to ready state
3.Switches from waiting to ready state
5.9 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Preemptive versus Non-preemptive Preemptive versus Non-preemptive SchedulingScheduling
Non-Preemptive scheduling : Scheduling takes place only under first
two of the above cases. Here, one process is selected to execute.
Then, it is allowed to run until it voluntarily enter into the wait state (case 1) or gets terminate (case 2).
Simple, but its not efficient. doesn’t require timer or clock interrupt.
5.10 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Preemptive versus Non-preemptive Preemptive versus Non-preemptive SchedulingScheduling
Preemptive scheduling :
Scheduling takes place only under any of the above cases.
Here, one process is selected to execute. Then, it is allowed to run only for some maximum time duration. After the time duration, another process is selected to execute.
Very efficient, but complex.
require timer or clock interrupt.
5.11 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
DispatcherDispatcher
Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this function involves:
switching context
switching to user mode
jumping to the proper location in the user program to restart that program
Dispatch latency – time it takes for the dispatcher to stop one process and start another running
5.12 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Scheduling CriteriaScheduling Criteria
Various scheduling algorithms are available.
They work based on different criteria to select a process.
To compare the performance of different scheduling algorithms, various performance criteria are decided.
5.13 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Scheduling CriteriaScheduling Criteria
They are as given below : CPU utilization :
It is an average fraction of time during which CPU is busy.
It ranges form 0 to 100 percent. In a real system, it should be between 40 to 90 percent.
CPU should remain as busy as possible, or CPU utilization should remain as high as possible.
5.14 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Scheduling CriteriaScheduling Criteria
Throughput : Number of processes completed per time unit is
called throughput. For long process, this rate may be 1 hour; for
short transactions, throughput might be 10 processes per second.
Turnaround time : Time required to complete execution of a process
is called turn-around time. It specifies that how long it takes to complete a
process execution. Turnaround time=process finish time-process
arrival time.
5.15 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Scheduling CriteriaScheduling Criteria
Waiting time : It is total time duration spent by a
process waiting in ‘Ready’ queue. Waiting time=turnaround time-actual
execution time. Scheduling algorithm affects the time
that a process spends waiting in the ‘Ready’ queue.
5.16 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Scheduling CriteriaScheduling Criteria
Response time : It is time between issuing a
command/request and getting output/result.
It is more important in interactive system.
User requests should be served as quickly as possible.
Here, user requests are given more priority compared to background system processes.
5.17 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Optimization CriteriaOptimization Criteria
Max CPU utilization
Max throughput
Min turnaround time
Min waiting time
Min response time
5.18 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Scheduling AlgorithmsScheduling Algorithms
There are four different algorithms are described bellow :
First-Come, First-Served (FCFS) Scheduling
Shortest-Job-First (SJF) Scheduling
Priority Scheduling
Round-Robin Scheduling
5.19 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
First-Come, First-Served (FCFS) SchedulingFirst-Come, First-Served (FCFS) Scheduling
Selection criteria : The process that requests first is served
first. It means that processes are served in the exact order as they come.
Decision Mode: Non-Preemptive: once a process is
selected, it runs until it blocks for an I/O or some event, or it terminates.
5.20 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
First-Come, First-Served (FCFS) SchedulingFirst-Come, First-Served (FCFS) Scheduling
Implementation:
This strategy can be easily implemented by using FIFO queue.
FIFO means first in first out. When first process enters the system, it starts its execution.
All other processes are appended in a queue. When CPU becomes free, a process from the first position in a queue is selected to run.
5.21 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
First-Come, First-Served (FCFS) SchedulingFirst-Come, First-Served (FCFS) Scheduling
Example:
Consider the following set of four processes. Their arrival time and time required to complete the execution are given in following table.
Consider all time values in milliseconds.
5.22 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
First-Come, First-Served (FCFS) SchedulingFirst-Come, First-Served (FCFS) Scheduling
Process Arrival Time Time required for
Completion
(Burst time)
P0 0 10
P1 1 6
P2 3 2
P3 5 4
5.23 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
First-Come, First-Served (FCFS) SchedulingFirst-Come, First-Served (FCFS) Scheduling
Gantt Chart:
Average Turnaround Time:(10+15+15+17)/4=57/4=14.25 ms
Average Waiting Time:(0+9+13+13)/4=35/4=8.75 ms
0 10 16 18 2218 221816 221810 16 22180 10 16 2218
P0 P1 P2 P3
5.24 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
First-Come, First-Served (FCFS) SchedulingFirst-Come, First-Served (FCFS) Scheduling
Initially only process P0 is present and it is allowed to run.
But, when P0 completes, all other processes are present.
So, next process P1 from ready queue is selected and allowed to run till it completes.
This procedure is repeated till all processes complete their execution.
5.25 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
First-Come, First-Served (FCFS) SchedulingFirst-Come, First-Served (FCFS) Scheduling
Advantages:
Simple, Fair
Easy to understand, easy to implement
Disadvantages:
Not efficient. Average waiting time is too high.
CPU utilization may be too low. Consider a CPU-bound process running with many I/O bound process.
5.26 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJR) SchedulingShortest-Job-First (SJR) Scheduling
Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time
Two schemes:
Non-Preemptive – once CPU given to the process it cannot be preempted until completes its CPU burst
5.27 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) Scheduling
Preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF)
SJF is optimal – gives minimum average waiting time for a given set of processes
5.28 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) SchedulingNon-preemptiveNon-preemptive
Selection Criteria:
The process that requires shortest time to complete execution, is served first.
Decision Mode:
Non-preemptive: Once a process is selected, it runs until it blocks for an I/O or some event, or it terminates.
5.29 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) SchedulingNon-preemptiveNon-preemptive
Implementation:
This strategy can be implemented by using sorted FIFO queue.
All processes in a queue are sorted in ascending order based on their required CPU burst.
When CPU becomes free, a process from the first position in queue is selected to run.
5.30 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) SchedulingNon-preemptiveNon-preemptive
Example:
Consider the following set of four processes. Their arrival time and time required to complete the execution are given in following table.
Consider all time values in milliseconds.
5.31 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) SchedulingNon-preemptiveNon-preemptive
Process Arrival Time Time required for
Completion
(Burst time)
P0 0 10
P1 1 6
P2 3 2
P3 5 4
5.32 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) SchedulingNon-preemptiveNon-preemptive
Gantt Chart:
Average Turnaround Time:
(10+21+9+11)/4=51/4=12.75 ms Average Waiting Time:
(0+15+7+7)/4=29/4=7.25 ms
0 10 12 2216
P0 P2 P3 P1
5.33 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) SchedulingNon-preemptiveNon-preemptive
Initially only process P0 is present and it is allowed to run.
But, when P0 completes, all other processes are present.
So, process with shortest CPU burst P2 is selected and allowed to run till it completes.
Whenever more than one process is available, such type of decision is taken.
This procedure is repeated till all process complete their execution.
5.34 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) SchedulingNon-preemptiveNon-preemptive
Advantages:
Less waiting time.
Good response for short processes
Disadvantages:
It is difficult to estimate time required to complete execution.
Starvation is possible for long process. Long process may wait for ever.
5.35 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) SchedulingPreemptivePreemptive
Selection Criteria:
The process, whose remaining run time is shortest, is served first.
This is a preemptive version of SJF scheduling
Decision Mode:
Preemptive: when a new process arrives, it total time is compared to the current process remaining time.
5.36 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) Scheduling Shortest-Job-First (SJF) Scheduling PreemptivePreemptive
If the new job needs less time to finish than the current process, the current process is suspended and new job started.
Implementation: This strategy can be implemented by using
sorted FIFO queue. All processes in a queue are sorted in
ascending order based on their remaining run time.
When CPU becomes free, a process from the first position in queue is selected to run.
5.37 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) SchedulingPreemptivePreemptive
Example:
Consider the following set of four processes. Their arrival time and time required to complete the execution are given in following table.
Consider all time values in milliseconds.
5.38 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) SchedulingPreemptivePreemptive
Process Arrival Time Time required for
Completion
(Burst time)
P0 0 10
P1 1 6
P2 3 2
P3 5 4
5.39 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) SchedulingPreemptivePreemptive
Gantt Chart:
Average Turnaround Time:
(22+8+2+8)/4=40/4=10.00 ms Average Waiting Time:
(12+2+0+4)/4=18/4=4.5 ms
0 3 5 2213
P0 P2 P1 P3P0 P1 P0
91
P1 P2P1 P2P1 P2P1 P2P1 P0P2 P0P2
5.40 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) SchedulingPreemptivePreemptive
Initially only process P0 is present and it is allowed to run.
But, when P1 comes, it has shortest remaining run time.
So, P0 is preempted and P1 is allowed to run.
Whenever new process comes or current process blocks, such type of decision is taken.
This procedure is repeated till all process complete their execution.
5.41 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Shortest-Job-First (SJF) SchedulingShortest-Job-First (SJF) SchedulingPreemptivePreemptive
Advantages:
Less waiting time.
Good response for short processes
Disadvantages:
Starvation is possible for long process. Long process may wait for ever.
Context switch overhead is there.
5.42 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority SchedulingPriority Scheduling A priority number (integer) is associated with each process
The CPU is allocated to the process with the highest priority (smallest integer highest priority)
Preemptive
Non-Preemptive
SJF is a priority scheduling where priority is the predicted next CPU burst time
Problem Starvation – low priority processes may never execute
Solution Aging – as time progresses increase the priority of the process
5.43 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based SchedulingPriority Based SchedulingNon-PreemptiveNon-Preemptive
Selection Criteria:
The process, the has highest priority is served first.
Decision Mode:
Non-preemptive: Once a process is selected, it runs until it blocks for an I/O or some event, or it terminates.
5.44 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based SchedulingPriority Based Scheduling Non-Non-PreemptivePreemptive
Implementation: This strategy can be implemented by using
sorted FIFO queue. All processes in a queue are sorted based
on their priority with highest priority process at front end.
When CPU becomes free, a process from the first position in queue is selected to run.
5.45 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based Scheduling Priority Based Scheduling Non-PreemptiveNon-Preemptive
Example:
Consider the following set of four processes. Their arrival time and time required to complete the execution and priorities are given in following table.
Consider all time values in milliseconds and small value for priority means higher priority of a process.
5.46 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based Scheduling Priority Based Scheduling Non-PreemptiveNon-Preemptive
Process Arrival Time
Time required for
Completion
(Burst time)
Priority
P0 0 10 5
P1 1 6 4
P2 3 2 2
P3 5 4 0
5.47 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based Scheduling Priority Based Scheduling Non-PreemptiveNon-Preemptive
Gantt Chart:
Average Turnaround Time:
(10+21+13+9)/4=53/4=13.25 ms Average Waiting Time:
(0+15+11+5)/4=31/4=7.75 ms
0 2216
P3 P2 P1
1410
P0
5.48 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based Scheduling Priority Based Scheduling Non-PreemptiveNon-Preemptive
Initially only process P0 is present and it is allowed to run.
But, when P0 completes, all other processes are present.
So, process with highest priority P3 selected and allowed to run till it completes.
Whenever more than one process is available, such type of decision is taken.
This procedure is repeated till all processes complete their execution.
5.49 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based Scheduling Priority Based Scheduling Non-PreemptiveNon-Preemptive
Advantages:
Priority is considered. Critical processes can get better response time.
Disadvantages:
Starvation is possible for low priority processes. It can be overcome by using technique called ‘Aging’.
Aging : gradually increases the priority of processes that wait in the system for a long time.
5.50 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based SchedulingPriority Based SchedulingPreemptivePreemptive
Selection Criteria:
The process, the has highest priority is served first.
Decision Mode:
Preemptive: When a new process arrives, its priority is compared to the current process priority.
If the new job has higher priority than the current process, the current process is suspended and the new job started.
5.51 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based SchedulingPriority Based Scheduling PreemptivePreemptive
Implementation: This strategy can be implemented by using
sorted FIFO queue. All processes in a queue are sorted based
on their priority with highest priority process at front end.
When CPU becomes free, a process from the first position in queue is selected to run.
5.52 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based Scheduling Priority Based Scheduling PreemptivePreemptive
Example:
Consider the following set of four processes. Their arrival time and time required to complete the execution and priorities are given in following table.
Consider all time values in milliseconds and small value for priority means higher priority of a process.
5.53 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based Scheduling Priority Based Scheduling PreemptivePreemptive
Process Arrival Time
Time required for
Completion
(Burst time)
Priority
P0 0 10 5
P1 1 6 4
P2 3 2 2
P3 5 4 0
5.54 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based Scheduling Priority Based Scheduling PreemptivePreemptive
Gantt Chart:
Average Turnaround Time:
(22+12+2+4)/4=40/4=10.00 ms Average Waiting Time:
(12+6+0+0)/4=18/4=4.5 ms
0 221391
P0P2P1P0 P1 P1
3 5
5.55 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based Scheduling Priority Based Scheduling PreemptivePreemptive
Initially only process P0 is present and it is allowed to run.
But, P1 comes, it has higher priority.
So, P0 is preempted and P1 is allowed to run.
This procedure is repeated till all processes complete their execution.
5.56 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Priority Based Scheduling Priority Based Scheduling PreemptivePreemptive
Advantages:
Priority is considered. Critical processes can get better response time.
Disadvantages:
Starvation is possible for low priority processes. It can be overcome by using technique called ‘Aging’.
Aging : gradually increases the priority of processes that wait in the system for a long time.
Context switch overhead is there.
5.57 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Round Robin (RR)Round Robin (RR)
Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.
If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units.
5.58 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Round Robin (RR)Round Robin (RR)
Selection Criteria:
The Process that requests first is serves first.
It means that Process are served in the exact order as they come.
The selection criteria are same as that of FCFS scheduling.
5.59 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Round Robin (RR)Round Robin (RR)
Decision Mode: Non-Preemptive/Preemptive : Each
selected process is assigned a time interval, called time quantum or time slice.
Process is allowed to run only for this time interval.
Here, one of two things is possible : First, process needs CPU burst less than time quantum.
5.60 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Round Robin (RR)Round Robin (RR)
In this case, process will voluntarily release CPU burst less than to the end of the queue.
Second, process needs CPU burst longer than time quantum.
In this case, process will be running at the end of time quantum.
Now, it will be preempted and moved to the end of the queue.
CPU will be allocated to another process. Here, length of time quantum is critical to
determine.
5.61 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Round Robin (RR)Round Robin (RR)
Implementation: This strategy can be implemented by using
sorted FIFO queue. When new Process, or process releases
CPU, or process is preempted, it is moved to the end of the queue.
When CPU becomes free, a process from the first position in queue is selected to run.
5.62 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Round Robin (RR)Round Robin (RR)
Example: (Non-Preemptive)
Consider the following set of four processes.
Their burst time are given in following table.
all time values are in milliseconds.
Consider that time quantum is of 4 millisecond.
5.63 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Round Robin (RR)Round Robin (RR)
Process Burst
Time
P0 24
P1 3
P2 3
5.64 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Round Robin (RR)Round Robin (RR)
Gantt Chart:
Average Turnaround Time:
(30+7+10)/3=47/3=15.66 ms Average Waiting Time:
(6+4+7)/3=17/3=5.56 ms
0 30264
P1 P1
14 18
P1 P3P2P2 P3 P1 P1 P1 P1 P1P1
7 10 22
5.65 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Round Robin (RR)Round Robin (RR)
When we use a time quantum of 4 ms, then process P1 gets the first 4 ms.
Since, it requires another 20 ms, it is preempted after the first time quantum, and the CPU is given to the next process in the queue, process P2.
Since, process P2 does not need 4 ms, it quits before its time quantum expires.
The CPU is the given to the next process, process P3.
Once each process has received 1 time quantum, the CPU is returned to process P1 for an additional time quantum.
5.66 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Round Robin (RR)Round Robin (RR)
Advantages:
One of the oldest, simplest, fairest and most widely used algorithms.
Disadvantages:
Context switch overhead is there.
Determination of time quantum is too critical. If it is too short, it causes frequent context switches and lowers CPU efficiency. If it is too long it causes poor responses for short interactive processes.
5.67 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Time Quantum and Context Switch TimeTime Quantum and Context Switch Time
5.68 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Multilevel Queue SchedulingMultilevel Queue Scheduling
Ready queue is partitioned into separate queues:
foreground (interactive)background (batch)
Each queue has its own scheduling algorithm
foreground – RR
background – FCFS
5.69 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Multilevel Queue SchedulingMultilevel Queue Scheduling
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
5.70 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Multilevel Queue SchedulingMultilevel Queue Scheduling
5.71 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Multilevel Feedback Queue SchedulingMultilevel Feedback Queue Scheduling
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
5.72 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Multilevel Feedback Queue SchedulingMultilevel Feedback Queue Scheduling
method used to determine when to demote a process
method used to determine which queue a process will enter when that process needs service
5.73 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Example of Multilevel Feedback QueueExample of Multilevel Feedback Queue
Three queues:
Q0 – RR with time quantum 8 milliseconds
Q1 – RR time quantum 16 milliseconds
Q2 – FCFS
5.74 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Example of Multilevel Feedback QueueExample of Multilevel Feedback Queue
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.
5.75 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Multilevel Feedback QueuesMultilevel Feedback Queues
5.76 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Multiple-Processor SchedulingMultiple-Processor Scheduling
CPU scheduling more complex when multiple CPUs are available
Homogeneous (Identical) processors within a Multiprocessor.
If several identical processors are available, then Load sharing can occur.
It would be possible to provide a separate queue for each processor.
Asymmetric multiprocessing – only one processor accesses the system data structures, alleviating the need for data sharing.
5.77 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Real-Time SchedulingReal-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
5.78 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Thread SchedulingThread Scheduling
Local Scheduling – How the threads library decides which thread to put onto an available lightweight process(LWP).
Global Scheduling – How the kernel decides which kernel thread to run next.
5.79 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Java Thread SchedulingJava Thread Scheduling
JVM Uses a Preemptive, Priority-Based Scheduling Algorithm
FIFO Queue is Used if There Are Multiple Threads With the Same Priority
5.80 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Java Thread Scheduling (cont)Java Thread Scheduling (cont)
JVM Schedules a Thread to Run When
1. The Currently Running Thread Exits the Runnable State
2. A Higher Priority Thread Enters the Runnable State
5.81 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Operating System ExamplesOperating System Examples
Solaris scheduling
Windows XP scheduling
Linux scheduling
5.82 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Solaris 2 SchedulingSolaris 2 Scheduling
Solaris 2 uses priority-based process scheduling.
It has four classes of scheduling, which are in order of priority real time, system, time sharing and interactive.
Each class includes different priorities and scheduling algorithms.
5.83 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Solaris 2 SchedulingSolaris 2 Scheduling
Time sharing class:
The scheduling policy for this class to dynamically alters priorities and assign time slices of different lengths using a multilevel feedback queue.
Interactive class :
This class uses the same scheduling policy as the time-sharing class, but it gives windowing application a higher priority for better performance.
5.84 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Solaris 2 SchedulingSolaris 2 Scheduling
System class:
Solaris 2 uses the system class to run kernel processes,.
Once established, the priority of a system process does not change.
The system class reserved for kernel use.
The scheduling policy for the system class does not time-slice.
5.85 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Solaris 2 SchedulingSolaris 2 Scheduling
Real time class:
This class is given the highest priority to run among all classes.
So a real time process will run before a process in any other class.
5.86 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Solaris 2 SchedulingSolaris 2 Scheduling
5.87 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Windows XP SchedulingWindows XP Scheduling
Windows XP schedules threads using a priority-based, preemptive scheduling algorithm.
The thread selected to run by the dispatcher will run until it is preempted by a higher-priority thread until it terminates, until its time quantum ends or until it calls a blocking system call, such as for I/O.
The dispatcher uses a 32-level priority scheme to determine the order of thread execution.
5.88 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Windows XP SchedulingWindows XP Scheduling
Priorities are divided into two classes: the variable class contains threads having priorities from 1 to 15.
And the real time class contains thread with priorities ranging from 16 to 31.
There is also thread running at priority 0 that is used for memory management.
5.89 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Windows XP SchedulingWindows XP Scheduling
There is a relationship between the numeric priority of the windows XP kernel and the win32 API.
In next slide figure to shown the values of each priority class appear in the top row.
The left column contains the values for the different relative priorities.
For example , if the relative priority of a thread in the ABOVE_NORMAL_PRIORITY_CLASS is NORMAL, the numeric priority of that thread is 10.
5.90 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Windows XP PrioritiesWindows XP Priorities
5.91 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Linux SchedulingLinux Scheduling
Linux provides two separate process-scheduling algorithms. Time-sharing real-time
5.92 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Linux SchedulingLinux Scheduling
Time-sharing :
Linux uses a prioritized, credit-based algorithm.
Each process possesses a certain number of scheduling credits, when a new task must be chosen to run, the process with the most credits is selected.
Every time that a time interrupt occurs, the currently running process loses one credit, when its credits reaches zero , it is suspended and another process is chosen.
5.93 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Linux SchedulingLinux Scheduling
real-time :
Linux’s real-time scheduling is soft-rather than hard- real time.
The scheduler offers strict guarantees about the relative priorities of real-time processes, but the kernel does not offer any guarantees about how quickly a real time process will be scheduled once that process becomes runble.
5.94 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Linux SchedulingLinux Scheduling
Real-time Soft real-time Posix.1b compliant – two classes
FCFS and RRHighest priority process always runs
first
5.95 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Algorithm EvaluationAlgorithm Evaluation
Deterministic modeling
takes a particular predetermined workload and defines the performance of each algorithm for that workload
Queuing models
Queuing analysis can useful in comparing scheduling algorithms but it also has limitations.
The mathematics of complicated algorithms or distribution can be difficult to work with.
5.96 Silberschatz, Galvin and Gagne ©2005Operating System Concepts
Algorithm EvaluationAlgorithm Evaluation
So that they will be able to compute an answer, queuing models are often only an approximation of real system.
Implementation
The only completely accurate way to evaluate a scheduling algorithm is to code it, put it in the operating system and see how it works.
This approach puts the actual algorithm in the real system for evaluation under real operating condition.