1 / 35

Chapter 5

Chapter 5. CPU Scheduling. CPU Scheduling. Assign processes to be executed by the processor(s). CPU and I/O Burst Cycle. The execution of a process consists of a cycle of CPU execution and I/O wait.

samuru
Télécharger la présentation

Chapter 5

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 5 CPU Scheduling

  2. CPU Scheduling • Assign processes to be executed by the processor(s)

  3. CPU and I/O Burst Cycle • The execution of a process consists of a cycle of CPU execution and I/O wait. • A process begins with a CPU burst, followed by an I/O burst, followed by another CPU burst and so on. The last CPU burst will end will a system request to terminate the execution. • The CPU burst durations vary from process to process and computer to computer.

  4. Histogram of CPU-burst Times

  5. CPU and I/O Bound Process • An I/O bound program has many very short CPU bursts. • A CPU bound program might have a few very long CPU bursts.

  6. Types of Scheduling

  7. Queuing Diagram for scheduling

  8. CPU Scheduler • CPU scheduling decisions may take place when: • The running process changes from running to waiting state. • The running process terminates • A waiting process becomes ready • The current process switches from running to ready stat • Scheduling under 1 and 2 is nonpreemptive. • Once a process is in the running state, it will continue until it terminates or blocks itself. • Scheduling under 3 and 4 is preemptive. • Currently running process may be interrupted and moved to the Ready state by OS.

  9. 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

  10. Ready Process CPU Scheduler and Dispatcher From Other States Process Descriptor Enqueuer Ready List Context Switcher Dispatcher CPU Running Process

  11. What is a Good Scheduler? Criteria • User oriented • Turnaround time: time interval from submission of job until its completion. spent waiting in ready queue. • Waiting time: sum of periods spent waiting in ready queue. • Response time: time interval from submission of job to first response. • Service Time: The amount of time process needs to be in running state (Acquired CPU) before it is completed.

  12. What is a Good Scheduler? Criteria • System oriented • CPU utilization: percentage of time CPU is busy. CPU utilization may range from 0 to 100%. • Throughput: number of jobs completed per time unit. This depends on the average length of the processes.

  13. Goals of Scheduling Algorithms for Different Systems

  14. Scheduling Algorithms • CPU scheduling deals with the problem of deciding which of the processes in the ready queue is to be allocated the CPU. • There are many different CPU scheduling algorithms, which we will discuss now.

  15. First-Come First-Served (FCFS) Scheduling • The process that requests the CPU first is allocated the CPU first. • It is nonpreemptive algorithm. • Can easily be implemented with a FIFO queue. • When a process enters the ready queue, its PCB is linked onto the tail of the queue. • When CPU is free, it is allocated to the process at the head of the queue.

  16. FCSF - Example

  17. FCFS – Advantages and Disadvantages • Advantages • Very simple • Disadvantages • Long average and worst-case waiting times • Poor dynamic behavior (convoy effect - short process behind long process)

  18. Shortest-Job First Scheduling (SJF) • This algorithm associates with each process the length of its next CPU burst. • When the CPU is available, it is assigned the process that has the smallest next CPU burst. • It is a non-preemptive policy.

  19. Shortest Remaining Time First (Preemptive SJF) • Preemptive version of SJF. • If a new process arrives with CPU burst length less than remaining time of current executing process, preempt the currently executing process and allocate the CPU to the new process.

  20. Advantages and Problems with SJF/SRT • Advantages: • Minimizes average waiting times. • Problems: • How to determine length of next CPU burst? • If estimated time for process not correct, the operating system may abort it • Starvation of jobs with long CPU bursts.

  21. Priority Scheduling • A priority (an integer) is associated with each process. • Priorities can be assigned either externally or internally. • The CPU is allocated to the process with the highest priority (smallest integer means highest priority). • Priority scheduling can be: • Preemptive • Nonpreemptive

  22. Priority Scheduling Example

  23. Problem with Priority Scheduling • Starvation or indefinite blocking – low priority processes may never execute. • Solution • Aging – as time progresses increase the priority of the process (Allow a process to change its priority based on its age or execution history)

  24. Round-Robin Scheduling • Each process gets a small unit of CPU time (called time quantum), usually 10-100 milliseconds. • After this time has elapsed, the process is preempted and added to the end of the ready queue. • Ready queue is treated as a circular queue. • CPU scheduler goes around the ready queue, allocating the CPU to each process for a time interval of 1 time quantum. • Ready queue is a FIFO queue of processes.

  25. RR Example

  26. RR With Context Switching Overhead • In RR, context switching overhead should be considered.

  27. RR and Time Quantum • The performance of the RR depends heavily on the size of the time quantum. • If the time quantum is very large, then RR policy is the same as FCFS policy. • If the time quantum is very small then most of the CPU time will be spent on context switching. • Turnaround time also depends on the time quantum • A rule of thumb is that 80% of the CPU bursts should be shorter than the time quantum.

  28. RR and Time Quantum

  29. Multilevel Queue Scheduling

  30. Multilevel Queue Scheduling Example • An OS uses a multilevel queue scheduling algorithm that works as follows. Each process when created is given a type (OS, Interactive and Other). There are three queues Q0, Q1 and Q2 (where Q0 has the highest priority and Q2 the lowest). OS processes are admitted in Q0, interactive in Q1 and all other in Q2. Q0 uses a FCFS scheduling, Q1 RR with time quantum of 5ms and Q2 shortest job first. The scheduler selects the process from Q0. If Q0 if empty then it selects a process from Q1. If both Q0 and Q1 are empty, then it selects a process from Q2. If the CPU is executing a process from a low level queue and a process arrives in a high-level queue, the running process is preemptive and put back in the same queue. A process from Q1 that is preemptive before its time quantum expires will get the priority next time a process is selected from Q1 and will complete its time quantum and then preemptive.

  31. Multilevel Queue Scheduling Example • Show the Gantt chart for the following processes:

  32. Multilevel Feedback Queue Scheduling • A process can move between the various queues; aging can be implemented this way. • Multilevel-feedback-queue scheduler defined by the following parameters: • Number of queues • Scheduling algorithms for each queue • Method used to determine when to upgrade a process • Method used to determine when to demote a process • Method used to determine which queue a process will enter when that process needs service

More Related