CPU Scheduling Chapter 5: CPU Scheduling
Total Page:16
File Type:pdf, Size:1020Kb
Chapter 5: CPU Scheduling Chapter 5: CPU Scheduling n Basic Concepts n Scheduling Criteria n Scheduling Algorithms n Multiple-Processor Scheduling n Real-Time Scheduling n Thread Scheduling n Operating Systems Examples n Java Thread Scheduling n Algorithm Evaluation Operating System Concepts – 7th Edition, Feb 2, 2005 5.2 Silberschatz, Galvin and Gagne ©2005 Project and Teams n Project Proposal and Teams Formation: l Deadline 17th November 2010 to send me the team Operating System Concepts – 7th Edition, Feb 2, 2005 5.3 Silberschatz, Galvin and Gagne ©2005 Assignments n Assignments produced two kinds of work: l Very interesting work l Very interesting work with copy and paste n If you copy and paste you learn nothing! (And you get an F) n Since this is the first time l All those who would take an F for plagiarism, may submit again bu t w ill get a penali zati on of 50% o f the mar ks. l New deadline: 13th of Nov. l Those who did not submit at all will take an F. Operating System Concepts – 7th Edition, Feb 2, 2005 5.4 Silberschatz, Galvin and Gagne ©2005 For honest ones n We should teach you (and you should learn) how to use a template n We should teach how to structure a document l Heading l Paragraphs l Section, subsection l We should teach how to number pages Operating System Concepts – 7th Edition, Feb 2, 2005 5.5 Silberschatz, Galvin and Gagne ©2005 Scheduling n Scheduling is a key concept in computer multitasking and multiprocessing operating system design, and in real-time operating system design. In modern operating systems, there are typically many more processes running than there are CPUs available to run them . n Automated planning and scheduling is a branch of artificial intelligence that concerns the realisation of strategies or action sequences, typ ica lly for execu tion by in te lligen t agen ts, autonomous robots and unmanned vehicles. Unlike classical control and classification problems, the solutions are complex, unknown and have to be discovered and optimised in multidimensional space. n Scheduling as well as game theory are two classical areas in applied mathematics and artificial intelligence of great academic interest and broad practical relevance. Operating System Concepts – 7th Edition, Feb 2, 2005 5.6 Silberschatz, Galvin and Gagne ©2005 Introduction to Scheduling n In a single-processor system, only one process can run at a time; any others must wait until the CPU is free and can be rescheduled. l In a simple computer system, the CPU then just sits idle. All this waiting time is wasted; no useful work is accomplished. n The objective of multiprogramming is to have some process running at all times, to maximize CPU utilization. A process is executed until it must wait, typically for the completion of some I/O request. n With multiprogramming, we try to use this time productively. l Several processes are kept in memory at one time. l When one process has to wait, the operating system takes the CPU away from that process and gives the CPU to another process. This pattern continues. Every time one process has to wait, another process can take over use of the CPU. Operating System Concepts – 7th Edition, Feb 2, 2005 5.7 Silberschatz, Galvin and Gagne ©2005 CPU-I/O Burst Cycle n The success of CPU scheduling depends on an observed property of processes: l Process execution consists of a cycle of CPU execution and I/O wait. l Processes alternate between these two states. Process execution begins with a CPU burst. That is followed by an I/O burst, which is followed by another CPU burst, then another I/O burst, and so on. l Eventually, the final CPU burst ends with a system request to terminate execution Operating System Concepts – 7th Edition, Feb 2, 2005 5.8 Silberschatz, Galvin and Gagne ©2005 Alternating Sequence of CPU And I/O Bursts Operating System Concepts – 7th Edition, Feb 2, 2005 5.9 Silberschatz, Galvin and Gagne ©2005 CPU and I/O Burst n Bursts of CPU usage alternate with periods of I/O wait l a CPU-bound process l an I/O bound process Operating System Concepts – 7th Edition, Feb 2, 2005 5.10 Silberschatz, Galvin and Gagne ©2005 CPU-I/O Burst Cycle n The durations of CPU bursts have been measured extensively. n An I/O-bound program typically has many short CPU bursts. n A CPU-bound program might have a few long CPU bursts. n This distribution can be important in the selection of an appropriate CPU-scheduling algorithm. Operating System Concepts – 7th Edition, Feb 2, 2005 5.11 Silberschatz, Galvin and Gagne ©2005 CPU scheduler n Whenever the CPU becomes idle, the operating system must select one of the processes in the ready queue to be executed. n The selection process is carried out by the short-term scheduler (or CPU scheduler). The scheduler selects a process from the processes in memory that are ready to execute and allocates the CPU to that process. n Note that the readyyq queue is not necessarily a first-in, first-out (()FIFO) queue. n As we shall see when we consider the various scheduling algorithms, a ready queue can be implemented as a FIFO queue, a priority queue , a tree, or simply an unordered linked list. n Conceptually, however, all the processes in the ready queue are lined up waiting for a chance to run on the CPU. n The records in the queues are generally process control blocks (PCBs) of the processes. Operating System Concepts – 7th Edition, Feb 2, 2005 5.12 Silberschatz, Galvin and Gagne ©2005 Recollect from Chap.3 Operating System Concepts – 7th Edition, Feb 2, 2005 5.13 Silberschatz, Galvin and Gagne ©2005 Preemptive scheduling n CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state For example, as the result of an IIO request or an invocation of wait for the termination of one of the child pp)rocesses) 2. Switches from running to ready state For example, when an interrupt occurs 3. Switches from waiting to ready For example, at completion of I/O 4. TitTerminates n For situations 1 and 4, there is no choice in terms of scheduling. A new process (if one exists in the ready queue) must be selected for execution. There is a choice, however, for situations 2 and 3. n Scheduling under 1 and 4 is nonpreemptive n All other scheduling is preemptive Operating System Concepts – 7th Edition, Feb 2, 2005 5.14 Silberschatz, Galvin and Gagne ©2005 Preempt n 1:to acquire (as land) by preemption n 2:to seize upon to the exclusion of others : take for oneself <the movement was then preempted by a lunatic fringe> n 3:to replace with something considered to be of greater value or priority : take precedence over <the program did not appear, having been preempted by a baseball game — Robert MacNeil> n 4:to gain a commanding or preeminent place in n 5:to prevent from happening or taking place : forestall, preclude n From Merriam-Webster Online Dictionary Operating System Concepts – 7th Edition, Feb 2, 2005 5.15 Silberschatz, Galvin and Gagne ©2005 NonNon--preemptivepreemptive scheduling n Under non-preemptive scheduling, once the CPU has been allocated to a process, the process keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state. n This scheduling method was used by Microsoft Windows 3.x; l Windows 95 introduced preemptive scheduling, and all subsequent versions of Windows operating systems have used preemptive scheduling. l The Mac OS X operating system for the Macintosh uses preemptive schedu ling; pre vio us versions of the Macintosh operating sy stem relied on cooperative scheduling. Operating System Concepts – 7th Edition, Feb 2, 2005 5.16 Silberschatz, Galvin and Gagne ©2005 Dispatcher n Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: l switching context l switching to user mode l jumping to the proper location in the user program to restart that program n The dispatcher should be as fast as possible, since it is invoked during every process switch. l The time it takes for the dispatcher to stop one process and start another running is known as the dispatch latency. Operating System Concepts – 7th Edition, Feb 2, 2005 5.17 Silberschatz, Galvin and Gagne ©2005 Chapter 5: CPU Scheduling n Basic Concepts n Scheduling Criteria n Scheduling Algorithms n Multiple-Processor Scheduling n Thread Scheduling n Oppgyerating Systems Exam ples n Java Thread Scheduling n Algorithm Evaluation n Project Proposal and Teams Formation: Deadline 16th November 2009 Operating System Concepts – 7th Edition, Feb 2, 2005 5.18 Silberschatz, Galvin and Gagne ©2005 Scheduling Criteria n Different CPU scheduling algorithms have different properties, and the choice of a particular algorithm may favor one class of processes over another. n In choosing which algorithm to use in a particular situation, we must consider the properties of the various algorithms. l (Analysis for your project) n Many criteria have been suggested for comparing CPU scheduling algorithms. n Which characteristics are used for comparison can make a su bstantial difference in which algorithm is j udged to be best . Operating System Concepts – 7th Edition, Feb 2, 2005 5.19 Silberschatz, Galvin and Gagne ©2005 Scheduling Criteria n CPU utilization l WttkthCPUbWe want to keep the CPU as busy as poss iblCtllCPUible. Conceptually, CPU utilization can range from 0 to 100 percent. In a real system, it should range from 40 percent (for a lightly loaded system) to 90 percent (for a heavily used sys t em ).