Professional Documents
Culture Documents
Cpu Scheduling: Noopur Dhawan Jntu 27
Cpu Scheduling: Noopur Dhawan Jntu 27
CPU Scheduling
Scheduling the processor among all ready processes The goal is to achieve: High processor utilization High throughput number of processes completed per of unit time Low response time time elapsed from the submission of a request until the first response is produced
Long-term: which process to admit? Medium-term: which process to swap in or out? Short-term: which ready process to execute next?
Optimization Criteria
Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time
Long-Term Scheduling
Determines which programs are admitted to the system for processing Controls the degree of multiprogramming Attempts to keep a balanced mix of processor-bound and I/O-bound processes CPU usage System performance
Medium-Term Scheduling
Makes swapping decisions based on the current degree of multiprogramming Controls which remains resident in memory and which jobs must be swapped out to reduce degree of multiprogramming
Short-Term Scheduling
Selects from among ready processes in memory which one is to execute next The selected process is allocated the CPU It is invoked on events that may lead to choose another process for execution: Clock interrupts I/O interrupts Operating system calls and traps Signals
The selection function determines which ready process is selected next for execution The decision mode specifies the instants in time the selection function is exercised Non preemptive Once a process is in the running state, it will continue until it terminates or blocks for an I/O Preemptive Currently running process may be interrupted and moved to the Ready state by the OS Prevents one process from monopolizing the processor
The dispatcher is the module that gives control of the CPU to the process selected by the short-term scheduler The functions of the dispatcher include: Switching context Switching to user mode Jumping to the location in the user program to restart execution The dispatch latency must be minimal
Processes require alternate use of processor and I/O in a repetitive fashion Each cycle consist of a CPU burst followed by an I/O burst A process terminates on a CPU burst CPU-bound processes have longer CPU bursts than I/O-bound processes
User-oriented criteria Response Time: Elapsed time between the submission of a request and the receipt of a response Turnaround Time: Elapsed time between the submission of a process to its completion System-oriented criteria Processor utilization Throughput: number of process completed per unit time fairness
Scheduling Algorithms
First-Come, First-Served Scheduling Shortest-Job-First Scheduling Also referred to as Shortest Process Next Priority Scheduling Round-Robin Scheduling Multilevel Queue Scheduling Multilevel Feedback Queue Scheduling
Process 1 2 3 4 5
Service time = total processor time needed in one (CPU-I/O) cycle Jobs with long service time are CPU-bound jobs and are referred to as long jobs
Selection function: the process that has been waiting the longest in the ready queue (hence, FCFS) Decision mode: non-preemptive a process runs until it blocks for an I/O
FCFS drawbacks
Favours CPU-bound processes A CPU-bound process monopolizes the processor I/O-bound processes have to wait until completion of CPU-bound process I/O-bound processes may have to wait even after their I/Os are completed (poor device utilization) Better I/O device utilization could be achieved if I/O bound processes had higher priority
Selection function: the process with the shortest expected CPU burst time I/O-bound processes will be selected first Decision mode: non-preemptive The required processing time, i.e., the CPU burst time, must be estimated for each process
Process
Burst Time
P1 15 P2 3 P3 3 Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart (a way to visualize) for the schedule is:
P1
P2
P3
15
18
21
P3 3 6
P1 21
Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case Leads to shortest job first algorithm
SJF Scheduling
Process P1 P2 P3 P4
P4 0
P3
3 7
P1
14
P2 22
Round-Robin
Selection function: same as FCFS Decision mode: preemptive a process is allowed to run until the time slice period (quantum, typically from 10 to 100 ms) has expired a clock interrupt occurs and the running process is put on the ready queue
Preemptive scheduling with dynamic priorities N ready to execute queues with decreasing priorities: P(RQ0) > P(RQ1) > ... > P(RQN) Dispatcher selects a process for execution from RQi only if RQi-1 to RQ0 are empty
New process are placed in RQ0 After the first quantum, they are moved to RQ1 after the first quantum, and to RQ2 after the second quantum, and to RQN after the Nth quantum I/O-bound processes remain in higher priority queues. CPU-bound jobs drift downward. Hence, long jobs may starve