Presentation is loading. Please wait.

Presentation is loading. Please wait.

Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.1 Operating System Concepts Operating Systems Lecture 15 Scheduling Read Ch.

Similar presentations


Presentation on theme: "Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.1 Operating System Concepts Operating Systems Lecture 15 Scheduling Read Ch."— Presentation transcript:

1 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.1 Operating System Concepts Operating Systems Lecture 15 Scheduling Read Ch 6.1 - 6.3

2 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.2 Operating System Concepts Recall Schedulers Short term scheduler: Select a process in the ready queue for CPU allocation. Medium term scheduler (swapper): determine which process to swap in/out of disk to/from memory. Long term scheduler: Determine which processes are admitted into the system. Schedulers determine which processes will wait and which will progress. Schedulers affect the performance of the system. Scheduling is a fundamental O.S. function. We will discuss short-term schedulers (CPU allocation).

3 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.3 Operating System Concepts CPU-I/O Burst cycle Process execution consists of a cycles of CPU execution and I/O waiting. A process begins with a CPU burst. When a process waits for I/O, it is called an I/O burst. A process alternates between CPU bursts and I/O bursts. Eventually a CPU burst will end with process termination. The length of CPU bursts vary by process and computer. Typically there are many short bursts and a few long bursts. Question: What length of CPU bursts would an I/O bound process have? Question: What length of CPU bursts would a CPU bound process have?

4 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.4 Operating System Concepts Alternating Sequence of CPU And I/O Bursts

5 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.5 Operating System Concepts Histogram of CPU-burst Times

6 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.6 Operating System Concepts Preemptive vs. Non-preemptive scheduling Non-preemptive scheduling:  Each process completes its full CPU burst cycle before the next process is scheduled.  No time slicing or CPU stealing occurs.  Once a process has control of the CPU, it keeps control until it gives it up (e.g. to wait for I/O or to terminate).  Works OK for batch processing systems, but not suitable for time sharing systems. Preemptive scheduling:  A process may be interrupted during a CPU burst and another process scheduled. (E.g. if the time slice of the first process expires).  More expensive implementation due to process switching.  Used in all time sharing and real time systems.

7 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.7 Operating System Concepts Costs of Preemptive Scheduling Preemptive scheduling leads to some problems that the OS must deal with: Problem 1: inconsistent data:  Suppose process 1 is updating data when preempted by process 2.  Process 2 may then try to read the data, which is in an inconsistent state.  The OS needs mechanisms to coordinate shared data. Problem 2: Kernel preemption:  Suppose the kernel is preempted while updating data (e.g. I/O queues) used by other kernel functions. This could lead to chaos.  UNIX solution: Wait for the system call to complete or have an I/O block take place if in kernel mode.  Problem with UNIX solution: Not good for real time computing.

8 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.8 Operating System Concepts Dispatcher Process scheduling determines the order in which processes execute. Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves:  switching context  switching to user mode  jumping to the proper location in the user program to restart that program Dispatch latency – time it takes for the dispatcher to stop one process and start another running.

9 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.9 Operating System Concepts Scheduling Criteria CPU utilization – keep the CPU as busy as possible Throughput – # 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 – amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)

10 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.10 Operating System Concepts Optimization Criteria The scheduling criteria are optimization problems. We would like to maximize or minimize each. Question: Maximize or Minimize?  CPU utilization:  throughput:  turnaround time:  waiting time:  response time: Can all criteria be optimized simultaneously? Usually try to optimize average times (although sometimes optimize minimum or maximum)

11 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.11 Operating System Concepts First-Come, First-Served (FCFS) Scheduling ProcessBurst Time P 1 24 P2 3 P2 3 P3 3 P3 3 Suppose that the processes arrive in the order: P 1, P 2, P 3 The Gantt Chart for the schedule is: Waiting time for P 1 = ; P 2 = ; P 3 = Average waiting time: P1P1 P2P2 P3P3 2427300 Process that requests the CPU first is allocated the CPU first. Easily managed with a FIFO queue. Often the average waiting time is long.

12 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.12 Operating System Concepts FCFS Scheduling (Cont.) Suppose that the processes arrive in the order P 2, P 3, P 1. The Gantt chart for the schedule is: Waiting time for P 1 = ; P 2 = ; P 3 = Average waiting time: Much better than previous case. Convoy effect: short processes line up behind long process. FCFS is not good for time-sharing systems. (Non- preemptive). P1P1 P3P3 P2P2 63300

13 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.13 Operating System Concepts Shortest-Job-First (SJF) Scheduling Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time. Two schemes:  nonpreemptive – once CPU given to the process it cannot be preempted until completes its CPU burst.  preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF). SJF is optimal – gives minimum average waiting time for a given set of processes.

14 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.14 Operating System Concepts ProcessArrival TimeBurst Time P 1 0.07 P 2 2.04 P 3 4.01 P 4 5.04 SJF (non-preemptive) Average waiting time = Example of Non-Preemptive SJF P1P1 P3P3 P2P2 73160 P4P4 812

15 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.15 Operating System Concepts Example of Preemptive SJF ProcessArrival TimeBurst Time P 1 0.07 P 2 2.04 P 3 4.01 P 4 5.04 SJF (preemptive) Average waiting time = P1P1 P3P3 P2P2 42 11 0 P4P4 57 P2P2 P1P1 16

16 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.16 Operating System Concepts Determining Length of Next CPU Burst Can only estimate the length. Can be done by using the length of previous CPU bursts, using exponential averaging.

17 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.17 Operating System Concepts Prediction of the Length of the Next CPU Burst

18 Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.18 Operating System Concepts Examples of Exponential Averaging  =0  n+1 =  n Recent history does not count.  =1  n+1 = t n Only the actual last CPU burst counts. If we expand the formula, we get:  n+1 =  t n +(1 -  )  t n -1 + … +(1 -  ) j  t n -j + … +(1 -  ) n+1  0 Since both  and (1 -  ) are less than or equal to 1, each successive term has less weight than its predecessor.


Download ppt "Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, 2005 6.1 Operating System Concepts Operating Systems Lecture 15 Scheduling Read Ch."

Similar presentations


Ads by Google