0% found this document useful (0 votes)
28 views5 pages

05 CPUScheduling

The document discusses CPU scheduling techniques. It covers basic concepts like CPU bursts and context switching. Scheduling criteria like throughput and waiting time are defined. Specific scheduling algorithms like first-come first-served (FCFS) and shortest-job-first (SJF) are described and compared using examples and Gantt charts.

Uploaded by

NMHH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views5 pages

05 CPUScheduling

The document discusses CPU scheduling techniques. It covers basic concepts like CPU bursts and context switching. Scheduling criteria like throughput and waiting time are defined. Specific scheduling algorithms like first-come first-served (FCFS) and shortest-job-first (SJF) are described and compared using examples and Gantt charts.

Uploaded by

NMHH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CPU Scheduling

Basic Concepts
Scheduling Criteria
Scheduling Algorithms

CPU Scheduling

4.2

1 2

Alternating Sequence of CPU And I/O Bursts


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

4.3 4.4

3 4

CPU Scheduler Dispatcher


Dispatcher module gives control of the CPU to the process
Selects from among the processes in memory that are ready to execute, selected by the short-term scheduler; this involves:
and allocates the CPU to one of them
switching context
CPU scheduling decisions may take place when a process:
switching to user mode
1. Switches from running to waiting state
jumping to the proper location in the user program to restart
2. Switches from running to ready state
that program
3. Switches from waiting to ready Dispatch latency – time it takes for the dispatcher to stop one
4. Terminates process and start another running
Scheduling under 1 and 4 is nonpreemptive
All other scheduling is preemptive

4.5 4.6

5 6

1
Scheduling Criteria Optimization Criteria
CPU utilization – keep the CPU as busy as possible
Max CPU utilization
Throughput – # of processes that complete their execution per
Max throughput
time unit
Min turnaround time
Turnaround time – amount of time to execute a particular
process Min waiting time
Waiting time – amount of time a process has been waiting in the Min response time
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)

4.7 4.8

7 8

First-Come, First-Served (FCFS) Scheduling First-Come, First-Served (FCFS) Scheduling


Processes are executed on first come, first serve basis. FCFS is non-preemptive. The Gantt Chart for the schedule is:
Easy to understand and implement
Poor in performance as average wait time high

P1 P2 P3
Process Burst Time
P1 24 0 24 27 30
P2 3
P3 3
Waiting time for P1 = 0; P2 = 24; P3 = 27
Suppose that the processes arrive in the order: P1 , P2 , P3
Average waiting time: (0 + 24 + 27)/3 = 17

4.9 4.10

9 10

FCFS Scheduling (Cont.) Shortest-Job-First (SJF) Scheduling

Suppose that the processes arrive in the order Associate with each process the length of its next CPU burst. Use these
P2 , P3 , P1 lengths to schedule the process with the shortest time

The Gantt chart for the schedule is: Two schemes:


Non-preemptive – once CPU given to the process it cannot be
P2 P3 P1
preempted until completes its CPU burst
Preemptive – if a new process arrives with CPU burst length less
0 3 6 30 than remaining time of current executing process, preempt. This
scheme is know as the Shortest-Remaining-Time-First (SRTF)
Waiting time for P1 = 6; P2 = 0; P3 = 3 SJF is optimal – gives minimum average waiting time for a given set of
Average waiting time: (6 + 0 + 3)/3 = 3 processes
Much better than previous case
Convoy effect short process behind long process

4.11 4.12

11 12

2
Example of Non-Preemptive SJF Example of Non-Preemptive SJF
Process Arrival Time Burst Time Process Arrival Time Burst Time
Queue Queue
P1 0.0 7 P1 0.0 7
P2 , 4 P2 , 4
P2 2.0 4 P2 2.0 4
P3 4.0 1 P3 , 1 P3 4.0 1 P3 , 1

P4 5.0 4 P4 , 4 P4 5.0 4 P4 , 4
SJF (non-preemptive)

P1 P3 P2 P4

0 3 7 8 12 16
Average waiting time = (0 + 6 + 3 + 7)/4 = 4
Average turnaround time = ( 7 +10 +4 +11)/4 = 8

4.13 4.14

13 14

Example of Preemptive SJF Priority Scheduling


Queue
Process Arrival Time Burst Time A priority number (integer) is associated with each process
P1 , 5
P1 0.0 7 The CPU is allocated to the process with the highest priority (smallest
P2 , 2 integer  highest priority)
P2 2.0 4
P4 , 4 Preemptive
P3 4.0 1
P4 5.0 4 nonpreemptive
SJF is a priority scheduling where priority is the predicted next CPU
burst time
SJF (preemptive) = SRT (Shortest Remaining Time)
Problem  Starvation – low priority processes may never execute

P1 P2 P3 P2 P4 P1 Solution  Aging – as time progresses increase the priority of the


process

0 2 4 5 7 11 16

Average waiting time = (9 + 1 + 0 +2)/4 = 3

4.15 4.16

15 16

Example of RR with Time Quantum = 20


Round Robin (RR)
Queue
Each process gets a small unit of CPU time (time quantum), Process Burst Time P1 , 33
usually 10-100 milliseconds. After this time has elapsed, the
P1 53 P3 , 48
process is preempted and added to the end of the ready queue.
P2 17 P4 , 4
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 P3 68
P1 , 13
chunks of at most q time units at once. No process waits more P4 24
than (n-1)q time units. P3 , 28
Performance P3 , 8
q large  FIFO
q small  q must be large with respect to context switch,
otherwise overhead is too high

4.17 4.18

17 18

3
Example of RR with Time Quantum = 20
Multilevel Queue
Queue

Process Burst Time P1 , 33 Ready queue is partitioned into separate queues:


P1 53 P3 , 48 foreground (interactive)
P2 17 background (batch)
P4 , 4
P3 68 Each queue has its own scheduling algorithm
P1 , 13
P4 24 foreground – RR
P3 , 28
The Gantt chart is: background – FCFS
P3 , 8 Scheduling must be done between the queues
Fixed priority scheduling; (i.e., serve all from foreground then from
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
background). Possibility of starvation.
0 20 37 57 77 97 117 121 134 154 162 Time slice – each queue gets a certain amount of CPU time which it
can schedule amongst its processes
Typically, higher average turnaround than SJF, but better response

4.19 4.20

19 20

Multilevel Queue Scheduling Multilevel Feedback Queue


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

4.21 4.22

21 22

Example of Multilevel Feedback Queue


Multilevel Feedback Queues

Three queues:
Q0 – RR with time quantum 8 milliseconds
Q1 – RR time quantum 16 milliseconds
Q2 – FCFS
Scheduling
A new job enters queue Q0 which is served FCFS. When it gains
CPU, job receives 8 milliseconds. If it does not finish in 8
milliseconds, job is moved to queue Q1.
At Q1 job is again served FCFS and receives 16 additional
milliseconds. If it still does not complete, it is preempted and moved
to queue Q2.

4.23 4.24

23 24

4
Thank you

25

You might also like