SAE5A OPERATING SYSTEMS SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Topics • CPU Scheduling Basic Concepts CPU-I/O Burst Cycle CPU Scheduler Preemptive Scheduling Dispatcher Scheduling Criteria SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Session Objective • To introduce CPU scheduling, which is the basis for multiprogrammed operating systems SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Learning Outcomes • Upon successful completion of this session, students are expected to have the ability to: – Define, restate, discuss, and explain the policies for scheduling SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Learning Resources • E-Book – Chapter 6 - “Operating System Concepts” by Silberschatz, Galvin, Gagne – 6th Edition SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Methodology • Flipped Class SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Basic Concepts • 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. • In a simple computer system, the CPU then just sits idle. • All this waiting time is wasted; no useful work is accomplished. SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Basic Concepts (Continued..) • With multiprogramming, we try to use this time productively. Several processes are kept in memory at one time. • If one process has to wait, the operating system takes the CPU away from that process and gives the CPU to another process. • Scheduling of this kind is a fundamental operating-system function. • Almost all computer resources including CPU are scheduled before use. SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA CPU–I/O Burst Cycle • Process execution consists of a cycle of CPU execution and I/O wait. • 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. • Eventually, the final CPU burst ends with a system request to terminate execution SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Alternating Sequence of CPU And I/O Bursts SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Duration of CPU bursts • The durations of the CPU bursts vary greatly by process and by computer, but they tend to have a frequency curve similar to that shown in fig. • Curve – Exponential or hyperexponential, with many short CPU bursts, and a few long CPU bursts. • This distribution helps to select an appropriate CPU scheduling algorithm • I/O bound program – have many very short CPU bursts • CPU bound Program – Have a few very long CPU bursts SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Histogram of CPU-burst times SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA CPU Scheduler • Whenever the CPU becomes idle, the operating system must select one of the processes in the ready queue to be executed. • The selection process is carried out by the short-term scheduler, or CPU scheduler. • It selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them. • All process in ready queue waits for a chance to run in the CPU and the records in the queues are PCBs of the processes. • Ready Queue may be implemented as: – – – – FIFO queue Priority queue Tree An unordered linked list SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Preemptive Scheduling • CPU scheduling decisions may take place when a process: 1. When a process switches from the running state to the waiting state (for example, as the result of an I/O request or an invocation of wait() for the termination of a child process). 2. When a process switches from the running state to the ready state (for example, when an interrupt occurs) 3. When a process switches from the waiting state to the ready state (for example, at completion of I/O) 4. When a process terminates SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Preemptive (Continued..) • 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. • When scheduling takes place only under circumstances 1 and 4, we say that the scheduling scheme is nonpreemptive or cooperative. Otherwise, it is preemptive. • Under nonpreemptive 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. SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Dispatcher • 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. SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Scheduling Criteria • CPU utilization – keep the CPU as busy as possible • Throughput – No. 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) SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Optimization Criteria Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA Activity-Quiz • CPU Scheduling - MCQ SAE5A-Operating Systems Prepared by: Ms.N.M.KAVITHA