1 / 28

Chapter 5 Processor Scheduling

Chapter 5 Processor Scheduling. 5.1 Introduction. Processor (CPU) scheduling is the sharing of the processor(s) among the processes in the ready queue The critical activities are: the ordering of the allocation and de-allocation of the CPU to the various processes and threads, one at a time

wattan
Download Presentation

Chapter 5 Processor Scheduling

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. Chapter 5Processor Scheduling

  2. 5.1 Introduction • Processor (CPU) scheduling is the sharing of the processor(s) among the processes in the ready queue • The critical activities are: • the ordering of the allocation and de-allocation of the CPU to the various processes and threads, one at a time • deciding when to de-allocate and allocate the CPU from a process to another process

  3. Scheduling and Performance These activities must be carried out in such a way as to meet the performance objectives of the system • Scheduling algorithms: FCFS, SJF, RR, SRT

  4. 5.2 Types of Schedulers • Long-term scheduler (memory allocation) • Determines which processes are loaded into memory • Controls the degree of multiprogramming • Medium-term scheduler • Suspends (swaps out) and resumes (swaps in) processes • Short-term scheduler (processor scheduling) • Selects one of the processes that are ready and allocates the CPU to it.

  5. Medium-Term Scheduler The basic idea is that some of the processes can be removed from memory (to disk) and thus reduce the degree of multiprogramming. this is called swapping

  6. 5.3 Processor Scheduling • A CPU scheduling policy defines the order in which processes are selected from the ready queue for CPU processing. • The scheduling mechanism decides when and how to carry out the context switch to the selected process, i.e., the de-allocation of the CPU from the current process and allocation of the CPU to the selected process.

  7. Processor Scheduling (2) • The schedulerselects the next process to execute from among several processes waiting in the ready queue. • The dispatcher allocates the CPU to the selected process at the appropriate time.

  8. Pi CPU Pj CPU Pk CPU … Pi Executable Memory Pj Executable Memory Pk Executable Memory Pi Address Space Pk Address Space Pj Address Space Implementing the Process Abstraction OS interface OSAddress Space CPU ALU Machine Executable Memory Control Unit …

  9. Process Activities Every process that request CPU service, carries out the following sequence of actions: • Join the ready queue and wait for CPU service. • Execute (receive CPU) for the duration of the current CPU burst or for the duration of the time slice (timeout). • Join the I/O queue to wait for I/O service or return to the ready queue to wait for more CPU service. • Terminate and exit if service is completed, i.e., there are no more CPU or I/O bursts. If more service is required, return to the ready queue to wait for more CPU service.

  10. Simple Model for processor Scheduling

  11. 5.3.1 CPU Scheduler • Insertion of processes that request CPU service into the ready queue. This queue is usually a data structure that represents a simple first-in-first-out (FIFO) list, a set of simple lists, or as a priority list. This function is provided by the enqueuer, a component of the scheduler.

  12. Scheduler (2) • The occurrence of a context switch, carried by the context switcher that saves the context of the current process and de-allocates the CPU from that process. • The selection of the next process from the ready queue and loading its context. This can be carried out by the dispatcher, which then allocates the CPU to the newly selected process.

  13. Occurrence of a Context Switch A context switch can occur at any of the following possible times: • The executing process has completed its current CPU burst. This is the normal case in simple batch systems. • The executing process is interrupted by the operating system because its allocated time (time slice) has expired. This is a normal case in time-sharing systems. • The executing process is interrupted by the operating system because a higher priority process has arrived requesting CPU service.

  14. Process Queues The processes that are ready and waiting to execute are kept on a list called the ready queue. A similar list exists for each I/O device, called the device queue.

  15. 5.3.2 Multiple Classes of Processes Single-class system: If the OS treats all processes in the same manner, it is referred as to a single-class system.  fair Multiclass system: A system with different groups of processes, each group is assigned a priority depending on some criteria.

  16. Scheduling with Multiple Queues

  17. Scheduling of Multi-Class Systems • Not Fair – Processes are not treated alike, as preference is given to higher-priority processes • A major problem in multi-class systems is STARVATION • indefinite waiting, one or more low-priority processes may never execute • solution is AGING

  18. 5.4 CPU Scheduling Policies Categories of scheduling policies: • Non-Preemptive -- no interruptions are allowed. A process completes execution of its CPU burst • Preemptive – a process can be interrupted before the process completes its CPU burst

  19. Priorities and Scheduling • Priorities can be used with either preemptive or non-preemptive scheduling. • Depending on the goals of an operating system, one or more of various scheduling policies can be used; each will result in a different system performance.

  20. Criteria for Scheduling Algorithms • CPU utilization • Throughput • Turnaround time • Waiting time • Response time • Fairness

  21. CPU-IO Bursts of Processes An important property of a process is its CPU-IO burst • An I/O bound process has many short CPU burst • A CPU bound process has few long CPU bursts • The OS tries to main maintain a balance of these two types of processes

  22. CPU Scheduling Policies • First-come-first-served (FCFS) • Shortest job first (Shortest process next) • Longest job first • Priority scheduling • Round robin (RR) • Shortest remaining time (SRT) also known as shortest remaining time first (SRTF)

  23. 5.4.1 FCFS Scheduling First come first served (FCFS) scheduling algorithm, a non-preemptive policy • The order of service is the same order of arrivals • Managed with FIFO queue • Simple to understand and implement • Scheduling is FAIR • The performance of this scheme is relatively poor

  24. FCFS Scheduling (cont’d) Example: Five processes arrive at time 0, in the order: P1, P2, P3, P4, P5. Their CPU burst time are shown in the following table. Using FCFS algorithm, find the average turnaround time, average waiting time, throughput, and CPU utilization rate.

  25. FCFS Scheduling (cont’d) Solution: The Gantt chart for FCFS The average waiting time is: (0 + 135 + 237 + 293 + 441)/ 5 = 221.2 msec Throughput: 5 CPU utilization: 100% Turnaround Time (unit: msec): T(p1)=135, T(p2)=135+102=237, T(p3)=135+102+56=293, T(p4)=135+102+56+148=441, T(p5)=135+102+56+148+125=566 The average turnaround time: (135 + 237 + 293 + 441+566) / 5 = 334.4 msec Throughput: 5 CPU utilization: 100%

  26. 5.4.2 SJF (SPN) Scheduling • The scheduler selects the next the process with the shortest CPU burst • Basically a non-preemptive policy • SJF is optimal - gives the minimum average waiting time for a given set of processes.

  27. SJF Scheduling (cont’d) Example: Five processes arrive at time 0, in the order: P1, P2, P3, P4, P5. Their CPU burst time are shown in the following table. Using SJF algorithm, find the average turnaround time, and average waiting time.

  28. Solution: Gantt chart for SJF: Waiting Time: Tw(p3)=0, Tw (p2)=56, Tw (p5) =158, Tw (p1)=283, Tw (p4)=418 Average Waiting Time = (0+56+158+283+418)/5=183 msec P3 P4 P1 P5 P2 Turnaround Time: Ta(p3)=56, Ta (p2)=56+102=158, Ta (p5) =56+102+125=283 Ta (p1)=56+102+125+135=418 Ta (p4)=56+102+125+135+148=566 Average Turnaround Time = (56+158+283+418+566)/5=296 msec

More Related