Scheduling Algorithms
Scheduling Algorithms
Scheduling Algorithms
Types of Scheduling
There are two types of process scheduling policies:
Non Preemptive Scheduling Preemptive Scheduling
Preemptive Scheduling
Preemptive algorithms are driven by the notion of prioritized computation. The process with the highest priority should always be the one currently using the processor. If a process is currently using the processor and a new process with a higher priority enters, the ready list, the process on the processor should be removed and returned to the ready list until it is once again the highest-priority process in the system.
Preemptive Scheduling
context_switch() is called even when the process is running usually done via a timer interrupt or based on priority .
Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time
Dispatcher
Dispatcher module shift the process from on state to another state:
By context switching 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
Queuing Diagram
15
Schedulers
Scheduling is a fundamental O.S. function. Schedulers affect the performance of the system.
Types of Scheduler
Short term Scheduler Medium term Scheduler Long term Scheduler
Schedulers
Short term scheduler: Select a process for execution from the ready queue for CPU allocation. Medium term scheduler (swapper): determine which process to swap in/out of disk to/from memory. Long term scheduler: Determine which processes are admitted into the system or in the ready queue.
Scheduling
Schedulers (Cont.)
Short-term scheduler is invoked very frequently (milliseconds) (must be fast) Long-term scheduler is invoked very infrequently (seconds, minutes) (may be slow)
Schedulers (Cont.)
The long-term scheduler controls the degree of multiprogramming
Nature of process
Processes can be described as either:
I/O-bound process spends more time doing I/O than computations, many short CPU bursts CPU-bound process spends more time doing computations; few very long CPU bursts
Nature of process
Cooperating Process Competitive Process
Cooperating Processes
Independent process cannot affect or be affected by the execution of another process Cooperating process can affect or be affected by the execution of another process Advantages of process cooperation
Information sharing Computation speed-up Modularity Convenience
Competitive Process
Sharing of resources is important.
Deadlock may be occur. Proper Mutual Exclusion is required.
Critical Section
Direct Communication
Processes must name each other explicitly:
send (P, message) send a message to process P receive(Q, message) receive a message from process Q
Indirect Communication
Messages are directed and received from mailboxes (also referred to as ports)
Each mailbox has a unique id Processes can communicate only if they share a mailbox
31
BATCH goals
Can incorrectly influence managers of interactive systems because they used to be good goals ...
Throughput: Maximum job per hour Turnaround time: Minimize the time between submission and termination CPU utilization: Keep the CPU busy all the time
33
34
36
37
38
April 1, 2002
40
Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case.
Burst Time 7 4 1 4
P3 8
P2 12
P4 16
P2
4
P3
5
P2
7
P4
11
P1
16
Priority 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 nonpreemptive
Priority Scheduling
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
Burst Time 53 17 68 24
P1 P3 97 117 P4 P1 P3 P3
Round-robin -- interactive
Length of the quantum?
context switching takes time
51
Multilevel Queue
Ready queue is partitioned into 2 types of separate queues: foreground (interactive) background (batch) Each queue has its own scheduling algorithm
foreground RR background FCFS
Multilevel Queue
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
Multiple-Processor Scheduling
CPU scheduling more complex when multiple CPUs are available Homogeneous processors within a multiprocessor Load sharing Asymmetric multiprocessing only one processor accesses the system data structures, improving the need for data sharing
Multiple-Processor Scheduling
Different rules for different 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 OR can use a master slave arrangement.
Multiple-Processor Scheduling
Master/slave assignment: Kernel functions always run on a particular processor. Other processors execute user processes. Peer assignment: OS can execute on any processor. Each processor does its own scheduling from the pool of available processes.
66
67
69
71
74