File

advertisement
Deadline scheduling
This is used for real time systems. The objective of the scheduler is to find a schedule for all the tasks
(there are a fixed set of tasks) so that each meets its deadline. The run time of each task is known in
advance.
Actually it is more complicated.
•
Periodic tasks
•
What if we can't schedule all task so that each meets its deadline (i.e., what should be the
penalty function)?
•
What if the run-time is not constant but has a known probability distribution?
Scheduling Algorithms
1.
FCFS: First-Come-First-Served
The scheduler executes jobs to completion in arrival order. A process does not give up CPU until it either
terminates or performs I/O.
Process
Burst time
Waiting Time
P1
24
0
P2
3
24
P3
3
27
P1
P2
P3
Average waiting time = (0+24+27)/3 = 17.
This algorithm is thus particularly troublesome for time sharing systems, where it is important that each
user get a share of the CPU at regular intervals.
2.
SJF: Shortest-Job-First scheduling
This algorithm associates with each process the length of the process’s next CPU burst. When the CPU is
available, it is assigned to the process that has the smallest next CPU burst.
Process
Burst time
Waiting Time
P1
6
3
P2
8
16
P3
7
9
P4
3
0
P4
P1
P3
P2
Average waiting time = (3+16+9+0)/4 = 7.
Preemptive vs. Non-preemptive SJF scheduler
Preemptive scheduler reruns scheduling decision when process becomes ready. If the new process has
priority over running process, the CPU preempts the running process and executes the new process.
Non-preemptive scheduler only does scheduling decision when running process voluntarily gives up
CPU. In effect, it allows every running process to finish its CPU burst.
3.
Priority Scheduling.
Each process is given a priority, then CPU executes process with highest priority. If multiple processes
with same priority are run able, use some other criteria - typically FCFS. SJF is an example of a prioritybased scheduling algorithm.
P2
Process
Burst time
Priority
Waiting Time
P1
10
3
6
P2
1
1
0
P3
2
4
16
P4
1
5
18
P5
5
2
1
P5
P1
P3
P4
Average waiting time = (6+0+16+18+1)/5 = 8.2.
Priority scheduling can be either preemptive or non-preemptive. A preemptive priority scheduling
algorithm will preempt the CPU if the priority of the newly arrived process is higher than the priority of
the currently running process. A non-preemptive priority scheduling algorithm will simply put the new
process at the head of the ready queue.
•
Assume we have 5 processes P1 (burst time 10, priority 3), P2 (burst time 1, priority 1), P3 (burst
time 2, priority 3), P4 (burst time 1, priority 4), P5 (burst time 5, priority 2). Lower numbers represent
higher priorities. What would a standard priority scheduler do?
•
Big problem with priority scheduling algorithms: starvation or blocking of low-priority processes.
Can use aging to prevent this - make the priority of a process go up the longer it stays runnable but isn't
run.
Solution to this problem of indefinite blockage of low priority processes is aging. Aging is a technique of
gradually increasing the priority of processes that wait in the system for a long time.
4.
Download