Chapter 4 Process Scheduling
Kinds of Scheduling • Non-preemptive scheduling: A process runs to completion when scheduled • Preemptive scheduling: A process may be preempted by the kernel, and another process may be scheduled. Hence a set of processes are processed in an overlapped manner.
Non-preemptive scheduling • Performance criteria: • Throughput • Turnaround times of processes • Weighted turnaround • Change the order in which processes are serviced • Non-preemptive scheduling policies: - First come first served (FCFS) - Shortest request first Q: Which policy will provide better throughput under what conditions?
Preemptive scheduling policies • Performance criteria: • Throughput • Response time to a subrequest • Scheduling policies • Round-robin with time slicing (RR) • Least completed next (LCN) • Shortest time to go (STG): shortest remaining time • Highest response ratio (HRN): defined later
Highest response ratio next (HRN) • Two ways of defining response ratio of a process • Response ratio = Time in the system / service time recd • Response ratio = (Time in the system + execution time)/ service time received We use the first definition in the next slide HRN eliminates the drawbacks of LCN and STG policies. Q: How?
Priority-based scheduling • What should the kernel do if there aren’t any ready processes? • Schedule a dummy process that does nothing • Put the processor to sleep (conserves power!)
Practical scheduling policies • Provide a good balance of response time and overhead • Vary the time slice! • Vary the priority • Provide fair service to processes (Q: How defined?) • In round-robin, all process receive approx similar service. What if one application has 5 processes, while another application has only 1 process?
Multi-level adaptive scheduling • Vary the priority of a process depending on its recent behaviour • If the process uses up its time slice, it must be (more) CPU bound than assumed, so reduce its priority • If a process is starved of CPU attention for some time, increase its priority
Scheduling in Unix • Processes are assigned priorities that are integer values • A larger value implies a lower priority • Priority of a process is varied based on its CPU usage • So as not to have an LCN-like effect (starvation!), the effect of CPU time used is decays with time, hence only recent CPU usage affects priority of a process • Priority of a process = Base priority + nice value + f(CPU time used by the process
Fair-share scheduling using a Unix-like policy • Groups of processes are defined for ensuring fair share of CPU time • Priority of a process depends on the CPU time used by all processes its group • Priority of a process = Base priority + nice value + f(CPU time used by the process) + f(CPU time used by all processes in the same group)
Real time scheduling • Perform scheduling such that each process can meet its deadline • Procedure: • Consider precedences between processes, i.e. which process should complete before which other process • Find the deadline of each application • Use a scheduling policy which ensures that deadlines are met (in a soft real time system, it is adequate to try to meet the deadlines, and succeed most of the time)
Deadlines for processes of previous slide • Total execution time = 25 seconds • If the deadline for the application as a whole is 35 seconds • process P6 has a deadline of 35 seconds • processes P4 and P5 have deadlines of 30 seconds Q: What are the deadlines of other processes?
Feasible schedule • An application has a feasible schedule if there exists at least one sequence in which its processes can be scheduled so that deadlines of all processes are met • Justify the following statement: “If a feasible schedule exists for an application, then earliest deadline first (EDF) scheduling can meet all deadlines.”
Rate Monotonic Scheduling (RMS) • Priority of a process is inversely proportional to its periodicity • Priority-based scheduling is now used Q: Does RMS guarantee that deadlines will be met if an application has a feasible schedule?
Rate Monotonic Scheduling (RMS) • Consider three processes: P1 P2 P3 Time period 10 15 30 Execution time 3 5 9 • What are their priorities? • Does a feasible schedule exist? • Consider summation of (execution time/time period) • Feasible schedule exists if summation is < 1. • Will RMS find a feasible schedule?