1 / 18

Operating Systems Lecture 15 Scheduling Read Ch 6.1 - 6.3

Operating Systems Lecture 15 Scheduling Read Ch 6.1 - 6.3. 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.

sagira
Download Presentation

Operating Systems Lecture 15 Scheduling Read Ch 6.1 - 6.3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operating SystemsLecture 15 Scheduling Read Ch 6.1 - 6.3 Operating System Concepts

  2. 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). Operating System Concepts

  3. 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? Operating System Concepts

  4. Alternating Sequence of CPU And I/O Bursts Operating System Concepts

  5. Histogram of CPU-burst Times Operating System Concepts

  6. 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. Operating System Concepts

  7. 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. Operating System Concepts

  8. 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. Operating System Concepts

  9. 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) Operating System Concepts

  10. 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) Operating System Concepts

  11. First-Come, First-Served (FCFS) Scheduling P1 P2 P3 0 24 27 30 Process that requests the CPU first is allocated the CPU first. Easily managed with a FIFO queue. Often the average waiting time is long. 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 = ; P2 = ; P3 = • Average waiting time: Operating System Concepts

  12. FCFS Scheduling (Cont.) P2 P3 P1 0 3 6 30 Suppose that the processes arrive in the order P2 , P3 , P1 . • The Gantt chart for the schedule is: • Waiting time for P1 =;P2 = ; P3 = • 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). Operating System Concepts

  13. 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. Operating System Concepts

  14. Example of Non-Preemptive SJF P1 P3 P2 P4 0 3 7 8 12 16 Process Arrival TimeBurst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 • SJF (non-preemptive) • Average waiting time = Operating System Concepts

  15. Example of Preemptive SJF P1 P2 P3 P2 P4 P1 11 16 0 2 4 5 7 Process Arrival TimeBurst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 • SJF (preemptive) • Average waiting time = Operating System Concepts

  16. 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. Operating System Concepts

  17. Prediction of the Length of the Next CPU Burst Operating System Concepts

  18. Examples of Exponential Averaging  =0 n+1 = n Recent history does not count.  =1 n+1 = tn Only the actual last CPU burst counts. If we expand the formula, we get: n+1 =  tn+(1 - )  tn-1+ … +(1 -  )j  tn-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. Operating System Concepts

More Related