CPU Scheduling ( Basic Concepts) Which process will get the CPU when it is available? This is decided by the O.S. and is called CPU scheduling. The part of the O.S. which performs scheduling is called Scheduler. The scheduler selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them. The objective is to maximize CPU utilization in multiprogramming. CPU–I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait.
Alternating Sequence of CPU And I/O Bursts execute CPU Burst I/O Wait I/O Burst execute CPU Burst I/O Wait I/O Burst
Important Definitions Term Description Preemptive Scheduling After allocation the CPU can be taken away from a process. Non Preemptive Scheduling After its allocation the CPU cannot be taken away from a process; process can voluntarily release the CPU. CPU Bound Process A process which heavily uses the CPU and performs a little I/O I/O Bound Process A process performs I/O very frequently Throughput No. of processes that complete their execution per time unit Turnaround time Amount of time to execute a particular process Waiting time Amount of time a process has been waiting in the ready queue Response time Time between submitting a request and getting the first response, not output (in a time-sharing environment)
Optimization Criteria Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time
Scheduling Algorithms First-Come, First-Served (FCFS) Scheduling ( non preemptive) Process CPU Burst (B) (msec) Wait Time (W) W/B P1 25 P2 40 0.625 P3 03 65 21.667 P4 12 68 5.667 This algorithm favors: Longer jobs against the shorter jobs ( W/B is less for longer jobs) CPU bound processes against I/O bound processes
Shortest Job first Scheduling Now the jobs appear as: Process CPU Burst (B) (msec) Wait Time (W) W/B P3 03 P4 12 0.25 P1 25 15 0.65 P2 40 1.00 Now: Longer jobs are not favored against the shorter jobs ( W/B is less for longer jobs) A longer job can face starvation CPU bound processes are still favored against I/O bound processes
Round-Robin (RR) Scheduling (Preemptive) A queue of ready processes is maintained A time quantum q (10-100 msec) is allocated to each process. I f a process does not finish in the allocated time it goes back to the end of the queue (circular queue) If there are n processes, each process gets turn at most after (n-1) q units. Gannt Chart for q = 20 msec CPU CPU … P1 P4 P3 P2 Performance If q is large, this scheme degenerates to FCFS If q is small, more context switches (each process finishes in more turns)