chapter 4: process scheduling dhamdhere: operating systems— a concept-based approach slide no: 1...

46
Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Post on 19-Dec-2015

269 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 1Copyright ©2005

Process Scheduling

Chapter 4

Page 2: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 2Copyright ©2005

A schematic of scheduling

Page 3: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 3Copyright ©2005

Scheduling-related Concepts and Terms

Page 4: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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.

Page 5: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 5Copyright ©2005

Processes for scheduling

Page 6: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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?

Page 7: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 7Copyright ©2005

Scheduling using FCFS and SRN policies

Page 8: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 8Copyright ©2005

Performance of FCFS and SRN scheduling

Page 9: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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

Page 10: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 10Copyright ©2005

Round-robin with time slicing (RR)

Page 11: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 11Copyright ©2005

Least completed next (LCN)

Page 12: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 12Copyright ©2005

Shortest time to go (STG)

Page 13: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 13Copyright ©2005

Scheduling using preemptive scheduling policies

Page 14: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 14Copyright ©2005

Operation of preemptive scheduling policies

Page 15: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 15Copyright ©2005

Performance of preemptive scheduling policies

Page 16: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 16Copyright ©2005

Variation of average response time with time slice

Page 17: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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?

Page 18: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 18Copyright ©2005

Performance of HRN scheduling policy

Page 19: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 19Copyright ©2005

Long, medium and short-term scheduling

Page 20: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 20Copyright ©2005

Event handling and scheduling

Page 21: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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

Page 22: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 22Copyright ©2005

Mechanism and policy modules of process scheduler

Page 23: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 23Copyright ©2005

Simple priority-based scheduling

Page 24: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 24Copyright ©2005

Priority-based scheduling

Page 25: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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!)

Page 26: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 26Copyright ©2005

Round-robin scheduling

Page 27: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 27Copyright ©2005

Ready lists in a time sharing system

Page 28: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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?

Page 29: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 29Copyright ©2005

Multilevel scheduling

Page 30: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 30Copyright ©2005

Ready lists in a multilevel scheduler

Page 31: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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

Page 32: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 32Copyright ©2005

Example of multi-level adaptive scheduling

Page 33: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 33Copyright ©2005

Fair share scheduling

Page 34: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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

Page 35: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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

Page 36: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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)

Page 37: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 37Copyright ©2005

Operation of a fair share scheduling

Page 38: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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)

Page 39: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 39Copyright ©2005

Real time scheduling

Page 40: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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

Page 41: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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?

Page 42: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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.”

Page 43: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 43Copyright ©2005

Performance of Earliest Deadline First Scheduling

Page 44: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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?

Page 45: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

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?

Page 46: Chapter 4: Process Scheduling Dhamdhere: Operating Systems— A Concept-Based Approach Slide No: 1 Copyright ©2005 Process Scheduling Chapter 4

Chapter 4: Process Scheduling

Dhamdhere: Operating Systems—A Concept-Based Approach

Slide No: 46Copyright ©2005

Summary of performance analysis