chapter 4: process scheduling dhamdhere: operating systems— a concept-based approach slide no: 1...
Post on 19-Dec-2015
269 views
TRANSCRIPT
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 1Copyright ©2005
Process Scheduling
Chapter 4
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 2Copyright ©2005
A schematic of scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 3Copyright ©2005
Scheduling-related Concepts and Terms
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 4Copyright ©2005
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.
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 5Copyright ©2005
Processes for scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 6Copyright ©2005
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?
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 7Copyright ©2005
Scheduling using FCFS and SRN policies
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 8Copyright ©2005
Performance of FCFS and SRN scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 9Copyright ©2005
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
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 10Copyright ©2005
Round-robin with time slicing (RR)
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 11Copyright ©2005
Least completed next (LCN)
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 12Copyright ©2005
Shortest time to go (STG)
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 13Copyright ©2005
Scheduling using preemptive scheduling policies
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 14Copyright ©2005
Operation of preemptive scheduling policies
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 15Copyright ©2005
Performance of preemptive scheduling policies
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 16Copyright ©2005
Variation of average response time with time slice
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 17Copyright ©2005
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?
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 18Copyright ©2005
Performance of HRN scheduling policy
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 19Copyright ©2005
Long, medium and short-term scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 20Copyright ©2005
Event handling and scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 21Copyright ©2005
Long, medium and short-term scheduling in a time sharing system
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 22Copyright ©2005
Mechanism and policy modules of process scheduler
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 23Copyright ©2005
Simple priority-based scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 24Copyright ©2005
Priority-based scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 25Copyright ©2005
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!)
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 26Copyright ©2005
Round-robin scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 27Copyright ©2005
Ready lists in a time sharing system
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 28Copyright ©2005
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?
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 29Copyright ©2005
Multilevel scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 30Copyright ©2005
Ready lists in a multilevel scheduler
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 31Copyright ©2005
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
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 32Copyright ©2005
Example of multi-level adaptive scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 33Copyright ©2005
Fair share scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 34Copyright ©2005
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
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 35Copyright ©2005
Operation of a Unix-like scheduling policy when process perform I/O
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 36Copyright ©2005
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)
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 37Copyright ©2005
Operation of a fair share scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 38Copyright ©2005
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)
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 39Copyright ©2005
Real time scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 40Copyright ©2005
Process precedence graph (PPG)for a simple real time system
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 41Copyright ©2005
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?
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 42Copyright ©2005
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.”
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 43Copyright ©2005
Performance of Earliest Deadline First Scheduling
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 44Copyright ©2005
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?
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 45Copyright ©2005
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?
Chapter 4: Process Scheduling
Dhamdhere: Operating Systems—A Concept-Based Approach
Slide No: 46Copyright ©2005
Summary of performance analysis