1 / 85

Understanding Operating Systems Sixth Edition

Understanding Operating Systems Sixth Edition. Chapter 4 Processor Management. Learning Objectives. After completing this chapter, you should be able to describe: The difference between job scheduling and process scheduling, and how they relate

kalin
Télécharger la présentation

Understanding Operating Systems Sixth Edition

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. Understanding Operating Systems Sixth Edition Chapter 4Processor Management

  2. Learning Objectives After completing this chapter, you should be able to describe: • The difference between job scheduling and process scheduling, and how they relate • The advantages and disadvantages of process scheduling algorithms that are preemptive versus those that are nonpreemptive Understanding Operating Systems, Sixth Edition

  3. Learning Objectives (cont’d.) • The goals of process scheduling policies in single-core CPUs • Up to six different process scheduling algorithms • The role of internal interrupts and the tasks performed by the interrupt handler • This chapter is devoted to single processor systems. • Those with multiple processors are discussed in Chapter 6. Understanding Operating Systems, Sixth Edition

  4. Overview • In a simple system, one with a single user and one processor, the process is busy only when it is executing the user’s job • When there are many users: • A multiprogramming environment • There are multiple processes competing to be run by a single CPU • The processor must be allocated to each job in a fair and efficient manner. Understanding Operating Systems, Sixth Edition

  5. Overview • Terms: • Program(job) • An inactive unit such as a file stored on a disk. • Not a process. • To an operating system, a program (job) is a unit ofwork submitted by the user. • Process (task) • An active entity that requires a set of resources, including: • A processor • Special registers • A single instance of a program in execution. Understanding Operating Systems, Sixth Edition

  6. Overview (cont'd.) • Thread • A portion of a process that can run independently. • The Processor (CPU) • Central Processing Unit • That part of the machine that performs calculations and executes the programs. • Multiprogramming: • Requires that the processor be allocated to each job or to each process for a period of time and deallocated at an appropriate moment. • If the processor is deallocated during a program’s execution, it must be done to ensure that it can be restarted later as easily as possible. Understanding Operating Systems, Sixth Edition

  7. Overview (cont'd.) • Interrupt • Call for help • Activates higher-priority program • Context Switch • Saving job processing information when interrupted • (Page 108) • A single processor can be shared by several jobs (processes) if: • The OS has a scheduling policy, as well as a scheduling algorithm, to determine when to stop working on one job and proceed to another. Understanding Operating Systems, Sixth Edition

  8. About Multi-Core Technologies • A dual-core, quad-core, or other multi-core CPU has more than one processor (core) on the computer chip. • Multi-core engineering was driven by the problems caused by nano-sized transistors and their ultra-close placement on a computer chip. • Although chips with millions of transistors that were very close together helped increase system performance, the close proximity of these transistors also increased: • Current leakage • The amount of heat generated by the chip. Understanding Operating Systems, Sixth Edition

  9. Job Scheduling Versus Process Scheduling • One solution was to create a single chip (one piece of silicon) with two or more processor cores. • A single large processor was replaced with: • Two half-sized processors • Four quarter-sized processors. • This design allowed the same sized chip to produce less heat and offered the opportunity to permit multiple calculations to take place at the same time. Understanding Operating Systems, Sixth Edition

  10. Job Scheduling Versus Process Scheduling (cont’d) • The Processor Manager is a composite of two submanagers, the Job Scheduler and the ProcessScheduler • Job Scheduler (High-Level Scheduler) • Each job is initiated by the Job Scheduler based on certain criteria. • Only concerned with selecting jobs from a queue of incoming jobs and placing them in the process queue based on each job’s characteristics. • Goal is to put the jobs in a sequence that will use all of the system’s resources as fully as possible. • Keep most components of the computer system busy most of the time. Understanding Operating Systems, Sixth Edition

  11. Job Scheduling Versus Process Scheduling (cont’d) • Process Scheduler (Low-Level Scheduler) • Once a job is selected for execution, the Process Scheduler determines when each step, or set of steps, is executed. • Also based on certain criteria Understanding Operating Systems, Sixth Edition

  12. Process Scheduler • Most of this chapter is dedicated to the Process Scheduler • After a job has been placed in the READY queue by the Job Scheduler, the Process Scheduler takes over. • The Process Scheduler: • Determines which jobs will get the CPU • When and for how long • Decides when processing should be interrupted; • Determines which queues the job should be moved to during its execution; • Recognizes when a job has concluded and should be terminated. Understanding Operating Systems, Sixth Edition

  13. Process Scheduler (cont'd.) • Is the low-level scheduler that assigns the CPU to execute the processes of those jobs placed in the READY queue by the Job Scheduler. • Becomes a crucial function when the processing of several jobs has to be orchestrated. • To schedule the CPU, the Process Scheduler takes advantage of a common trait among most computer programs: • They alternate between CPU cycles and I/O cycles. Understanding Operating Systems, Sixth Edition

  14. Process Scheduler (cont'd.) • Poisson distribution curve • CPU cycles from I/O-bound and CPU-bound jobs Understanding Operating Systems, Sixth Edition

  15. Process Scheduler (cont'd.) • Although the duration and frequency of CPU cycles vary from program to program, there are some general tendencies that can be exploited when selecting a scheduling system. • The Poisson Distribution Curve: • I/O-Bound jobs have many brief CPU cycles and long I/O cycles; • CPU-Bound jobs have long CPU cycles and shorter I/O cycles. Understanding Operating Systems, Sixth Edition

  16. Process Scheduler (cont'd.) • In a highly interactive environment, there’s a third layer of the Processor Manager: • Middle-level scheduler: • In some cases, especially when the system is overloaded, the Middle-Level Scheduler finds it as advantageous to remove active jobs from memory: • To reduce the degree of multiprogramming; • Allows jobs to be completed faster. • The jobs that are swapped out and eventually swapped back in are managed by the Middle-Level Scheduler. Understanding Operating Systems, Sixth Edition

  17. Process Scheduler (cont'd.) • In a single-user environment, there is no distinction between job and process scheduling • Only one job is active in the system at any given time. • The CPU and all other resources are dedicated to that job, and to each of its processes in turn, until the job is completed. Understanding Operating Systems, Sixth Edition

  18. Job and Process Status • As a jobs movethrough the system, it’s always in one of five states (or at least three): • Job Status (Process Status): • HOLD • READY • WAITING • RUNNING • FINISHED Understanding Operating Systems, Sixth Edition

  19. Job and Process Status (cont'd.) Understanding Operating Systems, Sixth Edition

  20. Job and Process Status (cont'd.) • User submits a job to the system via batch or interactive mode: • When the Job is accepted by the system: • It’s put on HOLD and placed in a queue; • In some systems, the job spooler (disk controller) creates a table with the characteristics of each job in the queue and notes the important features of the job: • An estimate of CPU time; • Priority; • Special I/O devices required; • Maximum memory required. • This table is used by the Job Scheduler to decide which job is to be run next. Understanding Operating Systems, Sixth Edition

  21. Job and Process Status (cont'd.) • From HOLD, the job moves to READY when it’s ready to run but is waiting for the CPU. • RUNNING means that the job is being processed. • WAITING means that the job can’t continue until a specific resource is allocated or an I/O operation has finished. • Upon completion, the job is FINISHED and returned to the user. Understanding Operating Systems, Sixth Edition

  22. Job and Process Status (cont'd.) • The transition from one job or process status to another is initiated by either the Job Scheduler or the Process Scheduler: • The transition from HOLD to READY is initiated by the Job Scheduler according to some predefined policy. • The availability of enough main memory and any requested devices is checked. Understanding Operating Systems, Sixth Edition

  23. Job and Process Status (cont'd.) • The transition from READY to RUNNING is handled by the Process Scheduler according to some predefinedalgorithm: • First-Come, First-Served (FCFS) • Shortest Job Next (SJN) • Priority Scheduling’ • Shortest Remaining Time (SRT) • Round Robin • The transition from RUNNING back to READY is handled by the Process Scheduler according to some predefined time limit or other criterion. • A priority interrupt PS initiates by instruction in job Understanding Operating Systems, Sixth Edition

  24. Job and Process Status (cont'd.) • The transition from RUNNING to WAITING is handled by the Process Scheduler and is initiated by an instruction in the job: • A command to READ, Write, or other I/O request; • Or one that requires a page fetch. • The transition from WAITING to READY is handled by the Process Scheduler and is initiated by a signal from the I/O device manager that the I/O request has been satisfied and the job can continue. • In the case of a page fetch, the page fault handler will signal that the page is now in memory and the process can be placed in the READY queue. Understanding Operating Systems, Sixth Edition

  25. Job and Process Status (cont'd.) • Eventually, the transition from RUNNING to FINISHED is initiated by the Process Scheduler or the Job Scheduler either when: • The job is successfully completed and it ends execution or • The OS indicates that an error has occurred and the job is being terminated prematurely. Understanding Operating Systems, Sixth Edition

  26. Process Control Blocks • Each process in the system is represented by a data structure called a Process Control Block (PCB). Understanding Operating Systems, Sixth Edition

  27. Process Control Blocks (cont’d) • Contains the basic information about the job: • Process Identification; • Process Status; • Process State: • Process Status Word; • Register Contents; • Main Memory; • Resources; • Process Priority; • Accounting. Understanding Operating Systems, Sixth Edition

  28. Process Control Blocks (cont'd.) • Process Control Block (PCB) components • Process identification: • Each job is uniquely identified by the user’s identification and a pointer connecting it to its descriptor; • Supplied by the Job Scheduler when the job first enters the system and is placed on HOLD. • Process status: • Indicates the current status of the job (HOLD, READY, RUNNING,WAITING) and the resources responsible for that status. Understanding Operating Systems, Sixth Edition

  29. Process Control Blocks (cont'd.) • Process Control Block (PCB) components • Process state: • Contains all of the information needed to indicate the current state of the job: • Process Status Word – The current instruction counter and register contents when the job isn’t running but is either on HOLD or is READY or WAITING. If the job is RUNNING, this information is left undefined. • Register Contents – The contents of the register if the job has been interrupted and is waiting to resume processing. Understanding Operating Systems, Sixth Edition

  30. Process Control Blocks (cont'd.) • Main Memory – Pertinent information, including the address where the job is stored and, in the case of virtual memory, the mapping between virtual and physical memory locations. • Resources – Information about all resources allocated to this job. Each resource has an identification field listing its type and a field describing details of its allocation. • Process Priority – Used by systems using a priority scheduling algorithm to select which job will be run next. Understanding Operating Systems, Sixth Edition

  31. Process Control Blocks (cont'd.) • Process Control Block (PCB) components • Accounting: • Contains information used mainly for billing purposes and performance measurement. • It indicates what kind of resources the job used and for how long. • Amount of CPU time used from beginning to end of its execution. • Total time the job was in the system until it exited. • Main storage occupancy – How long the job stayed in memory until it finished execution. • Secondary storage used during execution. • T Understanding Operating Systems, Sixth Edition

  32. Process Control Blocks (cont'd.) • Process Control Block (PCB) components • Accounting: • System programs used. • Number and type of I/O operations, including I/O transmission time, that includes utilization of channels, control units, and devices. • Time spent waiting for I/O completion. • Number of input records read. • Number of output records written. Understanding Operating Systems, Sixth Edition

  33. Process Control Blocks (cont'd.) Understanding Operating Systems, Sixth Edition

  34. PCBs and Queuing • A job’s PCB is created when the Job Scheduler accepts the job and is updated as the job progresses from the beginning to the end of its execution. • Queues use PCBs to track jobs. • The PCB contains all of the data about the job needed by the OS to manage the processing of the job. • As the job moves through the system, its progress is noted in the PCB. Understanding Operating Systems, Sixth Edition

  35. PCBs and Queuing • The PCBs, not the jobs, are linked to form the queues. • The jobs that are WAITING are linked by “reason for waiting” • The PCBs for the jobs in this category are linked into several queues. • These queues need to be managed in an orderly fashion determined by the process schedulingpolicies and algorithms. Understanding Operating Systems, Sixth Edition

  36. PCBs and Queuing (cont'd.) Understanding Operating Systems, Sixth Edition

  37. Process Scheduling Policies • In a multiprogramming environment, there are usually more jobs to be executed than could possibly be run at one time. • Before the OS can schedule them, it needs to resolve three limitations of the system: • There are a finite number of resources (disk drives, printers,tape drives); • Some resources, once they’re allocated, can’t be shared with another job (printers); • Some resources require operator intervention (tape drives). They can’t be reassigned automatically from job to job. Understanding Operating Systems, Sixth Edition

  38. Process Scheduling Policies (cont'd.) • Good process scheduling policy criteria • Maximize throughput: • Run as many jobs aspossible in a given amountof time. • Run only short jobs or jobs without interruptions. • Minimize response time: • Quickly turn aroundinteractive requests. • Run only interactive jobs and letting the batch jobs wait until the interactive load ceases. Understanding Operating Systems, Sixth Edition

  39. Process Scheduling Policies (cont'd.) • Good process scheduling policy criteria (cont’d.) • Minimize turnaround time: • Move entire jobsin and out of system quickly. • Running all batch jobs first because batch jobs can be grouped to run more efficiently than interactive jobs. • Minimize waiting time: • Move job out of the READY queue as quickly as possible. • Reduce the number of users allowed on the system so the CPU would be available immediately whenever a job entered the READY queue. Understanding Operating Systems, Sixth Edition

  40. Process Scheduling Policies (cont'd.) • Good process scheduling policy criteria (cont'd.) • Maximize CPU efficiency: • Keep CPU busy 100 percent of the time. • Run only CPU-bound jobs (not I/O-bound jobs). • Ensure fairness for alljobs • Give every job an equal CPUand I/O time. • Not giving special treatment to any job regardless of its processing characteristics or priority. • Based on this list, if the system favors one type of user then it hurts another or doesn’t efficiently use its resources. The final policy decision rests with the system designer who must determine which criteria are most important for that specific system. Understanding Operating Systems, Sixth Edition

  41. Process Scheduling Policies (cont'd.) • The Job Scheduler selects jobs to ensure that the READY and I/O queues remain balanced. • There are instances when a job claims the CPU for a very long time before issuing an I/O request. • If I/O requests are being satisfied, this extensive use of the CPU will build up READY queue while emptying out the I/O queues. • Creates unacceptable imbalance in the system. Understanding Operating Systems, Sixth Edition

  42. Process Scheduling Policies (cont'd.) • To solve this problem, the Process Scheduler often uses a timing mechanism and periodically interrupts running processes when a predetermined slice of time has expired. • When that happens: • The scheduler suspends all activity on the job currently running and reschedules it into the READY queue. • It will be continued later. Understanding Operating Systems, Sixth Edition

  43. Process Scheduling Policies (cont'd.) • The CPU is now allocated to another job that runs until one of three things happen: • The timer goes off; • The job issues an I/O command; • The job is finished. • The job moves to the READY queue, the WAIT queue, or the FINISHED queue. • A scheduling strategy that interrupts the processing of a job and transfers the CPU to another job is called a preemptive scheduling policy. • Widely used in time-sharing environments. Understanding Operating Systems, Sixth Edition

  44. Process Scheduling Policies (cont'd.) • A scheduling strategy which functions without external interrupts (interrupts external to the job) is a nonpreemptive scheduling policy. • Once a job captures the processor and begins execution, it remains in the RUNNING state uninterrupted until it issues an I/O request or until it is finished. Understanding Operating Systems, Sixth Edition

  45. Process Scheduling Algorithms • The Process Scheduler relies on a process scheduling algorithm, based on specific policy, to allocate the CPU and move jobs through the system. • Early OS used nonpreemptive policies designed to move batch jobs through the system as efficiently as possible. • Most current systems, with their emphasis on interactive use and response time, use an algorithm that takes care of the immediate requests of interactive users. Understanding Operating Systems, Sixth Edition

  46. Process Scheduling Algorithms (cont’d) • Six algorithm types that have been used extensively: • First-come, first-served (FCFS) • A nonpreemptive scheduling algorithm that handles jobs according to their arrival time: • The earlier they arrive, the sooner they’re served. • A very simple algorithm to implement because it uses a FIFO queue. • Fine for most batch systems. • Unacceptable for interactive systems because interactive users expect quick response time. Understanding Operating Systems, Sixth Edition

  47. Process Scheduling Algorithms (cont’d) • With FCFS, as a new job enters the system, its PCB is linked to the end of the READY queue and it is removed from the front of the queue when the processor becomes available, after it has processed all of the jobs before it in the queue. • In a strictly FCFS system, there is no WAIT queues (each job is run to completion). • There may be systems in which control is switched on an I/O request and then the job resumes on I.O completion. • If one job monopolizes the system, the extent of its overall effect on system performance depends on the scheduling policy and whether the job is CPU-bound or I/O-bound. Understanding Operating Systems, Sixth Edition

  48. Process Scheduling Algorithms (cont’d) • While a job with a long CPU cycle is using the CPU, the other jobs in the system are waiting for processing or finishing their I/O requests and joining the READY queue to wait for their turn to use the processor. • If the I/O requests are not being serviced, the I/O queues would remain stable while the READY list grew with new arrivals. • If the job is processing a lengthy I/O cycle, the I/O queues quickly build to overflowing and the CPU could be sitting idle. • This situation is resolved when the I/O-bound job finishes its I/O cycle, the queues start moving again and the system can recover from the bottleneck. Understanding Operating Systems, Sixth Edition

  49. Process Scheduling Algorithms (cont’d) • FCFS is a less attractive algorithm than one that would serve the shortest job first. Understanding Operating Systems, Sixth Edition

  50. First-Come, First-Served (cont'd.) Understanding Operating Systems, Sixth Edition

More Related