360 likes | 511 Views
Chapter 2.2 : Scheduling. Objectives. To introduce CPU scheduling, which is the basis for multiprogrammed operating systems To describe various CPU-scheduling algorithms To discuss evaluation criteria for selecting a CPU-scheduling algorithm for a particular system. Scheduling.
E N D
Objectives • To introduce CPU scheduling, which is the basis for multiprogrammed operating systems • To describe various CPU-scheduling algorithms • To discuss evaluation criteria for selecting a CPU-scheduling algorithm for a particular system
Scheduling • scheduling: share CPU among processes • scheduling should: • be fair • all processes must be similarly affected • no indefinite postponement • “aging” as a possible solution • adjust priorities based on waiting time for resource • max. possible number of processes per unit time • reduce response time for interactive users
Scheduling • priorities should be used • not fail even under very heavy load • e.g. accept no new processes to system • e.g. lower quantum
Scheduling Criteria • I/O bound • CPU bound • interactive / batch • importance of quick response • priority • real execution time • time to completion
Scheduling • preemptive x non-preemptive scheduling • preemptive • high cost of context switching • to be effective, there must be a sufficient amount of processes ready to run in memory
Priorities • static x dynamic priorities • static priorities • fixed during execution • easy to implement • not efficient • dynamic priorities • change based on environment changes • harder to implement + more CPU time • enhances response times
Scheduling Techniques
Deadline Scheduling • order processes based on their ending times • useless if process is not completed on time • process must declare all resource requests beforehend • may not be possible • plan resource allocation based on ending times • new resources may become available
FIFO Scheduling • simplest technique • order based on arrival times • non-preemptive • processes with short service times wait unnecessarily because of processes requring long service times • ineffective for interactive processes • response times may be too long • ineffective for I/O bound proceses • I/O ports may be available while the process waits for a CPU bound process to complete FIFO usually used together with other techniques
P1 P2 P3 0 24 27 30 Example: FIFO Scheduling ProcessBurst Time P1 24 P2 3 P3 3 • Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: • Waiting time for P1 = 0; P2 = 24; P3 = 27 • Average waiting time: (0 + 24 + 27)/3 = 17
P2 P3 P1 0 3 6 30 Example: FIFO Scheduling Suppose that the processes arrive in the order: P2 , P3 , P1 • The Gantt chart for the schedule is: • Waiting time for P1 = 6;P2 = 0; P3 = 3 • Average waiting time: (6 + 0 + 3)/3 = 3 • Much better than previous case • Convoy effect - short process behind long process • Consider one CPU-bound and many I/O-bound processes
5 0 10 15 20 A B C D E Example: FIFO Scheduling
ready queue new process end CPU suspend queue Round-Robin Schedulling
Round-Robin Schedulling • FIFO-like • assign CPU to processes for fixed time units in turn • preemptive • quantum = time slice • if not completed within quantum: move to end of queue • effective for interactive processes • has context switching
Round-Robin Schedulling • selection of quantum is critical • has effect on performance of system • short x long • fixed x variable • same x different for each user • if too long quantum becomes FIFO • if too short quantum too much time for context switches • correct quantum sizes different for different types of systems
5 0 10 15 20 A B C D E Example: Round-Robin Scheduling
Shortest-Job-First Scheduling • non-preemptive • order based on shortest time to completion • decreased average waiting times compared to FIFO • better service for short jobs • not suitable for interactive processes • total running time must be known beforehand • user provides estimate • if requires more than estimate, stop process and run later • if jobs repeat, may know running time
P3 P2 P4 P1 3 9 16 24 0 Example of SJF ProcessArTimeBurst Time P10.0 6 P2 2.0 8 P34.0 7 P45.0 3 SJF scheduling chart • Average waiting time = (3 + 16 + 9 + 0) / 4 = 7
5 0 10 15 20 A B C D E Example of SJF
Shortest Time Remaining First Scheduling • preemptive version of previous technique • good performance for time-sharing systems • run process with least time remaining to completion • consider new arrivals too • a running process may be preempted by a new, short process • total running time must be known beforehand • more time wasted • used / remaining time calculations • context switching
P1 P3 P4 P2 P1 0 5 1 10 17 26 Example of STRFS • Now we add the concepts of varying arrival times and preemption to the analysis ProcessAarriArrival TimeTBurst Time P10 8 P2 1 4 P32 9 P43 5 • Preemptive STRFS Gantt Chart • Average waiting time = [(10-1)+(1-1)+(17-2)+5-3)]/4 = 26/4 = 6.5 msec
5 0 10 15 20 A B C D E Example of STRFS
Priority Scheduling • A priority number (integer) is associated with each process • The CPU is allocated to the process with the highest priority (smallest integer highest priority) • Preemptive • Nonpreemptive • SJF is priority scheduling where priority is the inverse of predicted next CPU burst time
P1 P5 P3 P4 P2 0 6 1 16 18 19 Example of Priority Scheduling ProcessA arri Burst TimeTPriority P1 10 3 P2 1 1 P32 4 P41 5 P5 5 2 • Priority scheduling Gantt Chart • Average waiting time = 8.2 msec
Priority Scheduling • Problem Starvation – low priority processes may never execute • Solution Aging – as time progresses increase the priority of the process
Highest Response Ratio Next Scheduling • Nonpreemptive • A solution method to the long jobs in SJF • Dynamic priority is calculated to find next job to execute priority = (burst time + waiting time) / (burst time) ?
level 1 (round-robin) CPU Level 2 (round-robin) Level 3 (round-robin) level n (FIFO) Multilevel Queues Scheduling
Multilevel Queues Scheduling • new process to end of level 1 • round-robin (or any other) within levels • if not completed within quantum, go to end of lower level • limited number of levels • in last level, round-robin instead of FIFO • short, new jobs completed in a short time • in some systems, longer quantum at lower levels
Multilevel Queues Scheduling • processes at higher level queues finished before those in lower levels can be run • a running process may be preempted by a process arriving to a higher level • in some systems stay in same queue for a few rounds • e.g. at lower level queues