Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPU Scheduling Basic Concepts. Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor.

Similar presentations


Presentation on theme: "CPU Scheduling Basic Concepts. Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor."— Presentation transcript:

1 CPU Scheduling Basic Concepts

2 Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm Evaluation

3 Objectives To introduce CPU scheduling, which is the basis for multiprogrammed operating systems To describe various CPU-scheduling algorithms To discuss evaluation criteria for selecting a CPU-scheduling algorithm for a particular system

4 Basic Concepts Maximum CPU utilization obtained with multiprogramming CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait CPU burst distribution

5 Histogram of CPU-burst Times

6 CPU-I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait Processes alternate between these two states Each scheduling decision is about which job to give to the CPU for use by its next CPU burst With time slicing, job may be forced to give up CPU before finishing current CPU burst

7 CPU Scheduler Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them CPU scheduling decisions may take place when a process 1.Switches from running to waiting state 2.Switches from running to ready state 3.Switches from waiting to ready 4.Terminates Scheduling under 1 and 4 is nonpreemptive All other scheduling is preemptive

8 Scheduling Managing resource (e.g., CPU) n processes – A schedule is a listing – Number of possible schedules if no interdependencies? Environment – Number of processors involved – Whether preemption is allowed (priorities or time slicing) – Whether a process once active can become blocked (due to I/O, etc…)

9 Scheduling First the easy case – One processor, no preemption, no blocking – n/1 static scheduling problem n processes Know arrival times, processing times

10 Scheduling Given the following information about process P i – Arrival Time a i – Execution Time e i – Due Time d i We can obtain – Completion (finish) Time f i – Turn-around Time t i = (f i – a i ) – Waiting Time w i = (t i – e i ) – Lateness L i = (f i – d i ) – Tardiness T i = max(0, L i )

11 Example ProcessP1P1 P2P2 P3P3 P4P4 P5P5 P6P6 pipi 15255202530 P 4 P 5 P 3 P 1 P 6 P 2 0 20 45 50 65 95 120 titi wiwi P1P1 6550 P2P2 12095 P3P3 5045 P4P4 200 P5P5 4520 P6P6 9565

12 Scheduling Criteria CPU utilization – keep the CPU as busy as possible Throughput – # 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

13 How good is a schedule? Performance Measures Max CPU utilization Max throughput Min turnaround time Min waiting time Min response time

14 First-Come, First-Served (FCFS) Scheduling First-Come, First-Served (FCFS) – Also “First In, First Out” (FIFO) or “Run until done” In early systems, FCFS meant one program scheduled until done (including I/O) Now, means keep CPU until process blocks

15 First-Come, First-Served (FCFS) Scheduling Suppose that the processes arrive in the order: P 1, P 2, P 3. Draw the Gantt Chart for the schedule and compute the average waiting time: 3 ProcessP1P1 P2P2 P3P3 pipi 2433 P1P1 P3P3 P2P2 63300

16 First-Come, First-Served (FCFS) Scheduling Suppose that the processes arrive in the order: P 2, P 3, P 1. Draw the Gantt Chart for the schedule and compute the average waiting time: 17 ProcessP1P1 P2P2 P3P3 pipi 2433 P1P1 P2P2 P3P3 27300

17 First-Come, First-Served (FCFS) Scheduling There is a convoy effect as all the other processes wait for the one big process to get off the CPU – Average waiting time for FCFS is often quite long – What about average turnaround time? Pros and cons – Simple (+) – Short jobs get stuck behind long ones (-) Analogy: getting milk at a supermarket and waiting to pay, always stuck behind carts full of items. Upside: get to read about space aliens!

18 Example of (Shortest Job First) SJF ProcessArrival TimeBurst Time P 1 0.06 P 2 2.08 P 3 4.07 P 4 5.03 SJF scheduling chart Average waiting time = (3 + 16 + 9 + 0) / 4 = 7 P4P4 P3P3 P1P1 3 16 0 9 P2P2 24

19 SJF Scheduling example Sometimes called Shortest Processing Time (SPT) First Draw the Gantt Chart for a SPT schedule and compute the average waiting time and average turnaround time (assume all processes arrive at time 0) ProcessP1P1 P2P2 P3P3 P4P4 P5P5 P6P6 pipi 15255201830

20 Round Robin (RR) Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. Performance –q large  FIFO –q small  q must be large with respect to context switch, otherwise overhead is too high


Download ppt "CPU Scheduling Basic Concepts. Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor."

Similar presentations


Ads by Google