0% found this document useful (0 votes)
5 views

Scheduling Algorithms

Uploaded by

akartar77
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Scheduling Algorithms

Uploaded by

akartar77
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Performance Metric

• Turnaround time: The time at which the job completes minus the
time at which the job arrived in the system:

𝑻𝒕𝒖𝒓𝒏𝒂𝒓𝒐𝒖𝒏𝒅 = 𝑻𝒄𝒐𝒎𝒑𝒍𝒆𝒕𝒊𝒐𝒏 − 𝑻𝒂𝒓𝒓𝒊𝒗𝒂𝒍

• Fairness: Every workload gets an equal share of CPU time

7
1. Each job runs for the same amount of time.
2. All jobs arrive at the same time.
3. Each job runs to completion

First in, First Out (FIFO) 4.


5.
All jobs only use the CPU (i.e., they perform no I/O).
The run-time of each job is known

• First Come, First Served (FCFS)


▪ Very simple and easy to implement
• Example:
▪ Three jobs arrive almost at the same time, Tarrival = 0
▪ Each job runs for 10 seconds.
A B C

0 20 40 60 80 100 120

Time (Second)

8
1. Each job runs for the same amount of time.
2. All jobs arrive at the same time.
3. Each job runs to completion

First in, First Out (FIFO) 4.


5.
All jobs only use the CPU (i.e., they perform no I/O).
The run-time of each job is known

• First Come, First Served (FCFS)


▪ Very simple and easy to implement
• Example:
▪ Three jobs arrive almost at the same time, Tarrival = 0
▪ Each job runs for 10 seconds.
A B C

0 20 40 60 80 100 120

Time (Second)

𝟏𝟎 + 𝟐𝟎 + 𝟑𝟎
𝑨𝒗𝒆𝒓𝒂𝒈𝒆 𝒕𝒖𝒓𝒏𝒂𝒓𝒐𝒖𝒏𝒅 𝒕𝒊𝒎𝒆 = = 𝟐𝟎 𝒔𝒆𝒄
𝟑
9
What is the problem with FIFO – convoy
effect
• Let’s relax assumption 1: Each job no longer runs for the same
amount of time
1. Each job runs for the same amount of time.
2. All jobs arrive at the same time
3. Each job runs to completion
4. All jobs only use the CPU (i.e., they perform no I/O).
5. The run-time of each job is known
• When could FIFO perform poorly in terms of turn around time?
A B C

𝟏𝟎𝟎 + 𝟏𝟏𝟎 + 𝟏𝟐𝟎


𝑨𝒗𝒆𝒓𝒂𝒈𝒆 𝒕𝒖𝒓𝒏𝒂𝒓𝒐𝒖𝒏𝒅 𝒕𝒊𝒎𝒆 = = 𝟏𝟏𝟎 𝒔𝒆𝒄
𝟑
0 20 40 60 80 100 120
10
Time (Second)
1. Each job runs for the same amount of time.
2. All jobs arrive at the same time.
3. Each job runs to completion

Shortest Job First (SJF) 4.


5.
All jobs only use the CPU (i.e., they perform no I/O).
The run-time of each job is known

• Run the shortest job first, then the next shortest, and so on

B C A

0 20 40 60 80 100 120

Time (Second)

𝟏𝟎 + 𝟐𝟎 + 𝟏𝟐𝟎
𝑨𝒗𝒆𝒓𝒂𝒈𝒆 𝒕𝒖𝒓𝒏𝒂𝒓𝒐𝒖𝒏𝒅 𝒕𝒊𝒎𝒆 = = 𝟓𝟎 𝒔𝒆𝒄
𝟑

11
Whats the problem with shortest job first
[B,C arrive]
• Let’s relax assumption 2: Jobs can arrive at
any time. A B C

1. Each job runs for the same amount of time.


2. All jobs arrive at the same time.
3. Each job runs to completion 0 20 40 60 80 100 120
4. All jobs only use the CPU (i.e., they perform no
I/O). Time (Second)
5. The run-time of each job is known
• Example:
▪ A arrives at t=0 and needs to run for 100
seconds.
▪ B and C arrive at t=10 and each need to run for
10 seconds
𝟏𝟎𝟎 + 𝟏𝟏𝟎 − 𝟏𝟎 + (𝟏𝟐𝟎 − 𝟏𝟎)
𝑨𝒗𝒆𝒓𝒂𝒈𝒆 𝒕𝒖𝒓𝒏𝒂𝒓𝒐𝒖𝒏𝒅 𝒕𝒊𝒎𝒆 = = 𝟏𝟎𝟑. 𝟑𝟑 𝒔𝒆𝒄
𝟑
12
Shortest Time-to-Completion First (STFC)
[B,C arrive]
A B C A
• Add preemption to SJF (PSJF)
1. Each job runs for the same amount of
time.
0 20 40 60 80 100 120
2. All jobs arrive at the same time.
3. Each job runs to completion Time (Second)

4. All jobs only use the CPU (i.e., they


perform no I/O).
5. The run-time of each job is known
• A new job enters the system:
▪ Determine remaining time of each job
▪ Schedule the job which has the least time
left
(𝟏𝟐𝟎 − 𝟎) + 𝟐𝟎 − 𝟏𝟎 + (𝟑𝟎 − 𝟏𝟎)
𝑨𝒗𝒆𝒓𝒂𝒈𝒆 𝒕𝒖𝒓𝒏𝒂𝒓𝒐𝒖𝒏𝒅 𝒕𝒊𝒎𝒆 = = 𝟓𝟎 𝒔𝒆𝒄
𝟑
13
Until now…
• Relaxed all assumptions except
1. Each job runs for the same amount of time.
2. All jobs arrive at the same time.
3. Each job runs to completion
4. All jobs only use the CPU (i.e., they perform no I/O).
5. The run-time of each job is known
• STCF is the optimal in such cases: good for computers of 60 and 70s
• Introduction of time-shared machines killed the metric and algos
• Users share machine and demand interactive performance

14
New Metric: Response Time
• The time from when the job arrives to the first time it is scheduled
𝑻𝒓𝒆𝒔𝒑𝒐𝒏𝒔𝒆 = 𝑻𝒇𝒊𝒓𝒔𝒕𝒓𝒖𝒏 − 𝑻𝒂𝒓𝒓𝒊𝒗𝒂𝒍

• Using STCF
▪ A arrives at t=0 and needs to run for 100 seconds.
▪ B and C arrive at t=10 and each need to run for 10 seconds
[B,C arrive]
A B C A

0 20 40 60 80 100 120
15
Time (Second)
Round Robin (RR) Scheduling
• Time slicing Scheduling
▪ Run a job for a time slice and then switch to the next job in the run queue
until the jobs are finished
o Time slice is sometimes called a scheduling quantum

▪ It repeatedly does so until the jobs are finished

▪ The length of a time slice must be a multiple of the timer-interrupt period

16
RR Example
• A, B and C arrive at the same time.
• They each wish to run for 5 seconds

A B C

0 + 5 + 10
𝑇𝑎𝑣𝑒𝑟𝑎𝑔𝑒 𝑟𝑒𝑠𝑝𝑜𝑛𝑠𝑒 = = 5𝑠𝑒𝑐
3
0 5 10 15 20 25 30
Time (Second)

SJF (Bad for Response Time)

17
RR Example A B C

• A, B and C arrive at the same time.


0 5 10 15 20 25 30
• They each wish to run for 5 seconds Time (Second)

SJF (Bad for Response Time)

0 + 5 + 10
𝑇𝑎𝑣𝑒𝑟𝑎𝑔𝑒 𝑟𝑒𝑠𝑝𝑜𝑛𝑠𝑒 = = 5𝑠𝑒𝑐
3
A B CA B CA B CA B CA B C

• Response time of RR with 1s ec


timeslice 5 10 15 20 25 30
0
Time (Second)

RR with a time-slice of 1sec (Good for Response Time)

0+1+2
𝑇𝑎𝑣𝑒𝑟𝑎𝑔𝑒 𝑟𝑒𝑠𝑝𝑜𝑛𝑠𝑒 = = 1𝑠𝑒𝑐
3 18
Timeslice length is important
• The shorter time slice
▪ Better response time
▪ The cost of context switching will dominate overall performance.

• The longer time slice


▪ Amortize the cost of switching
▪ Worse response time

Deciding on the length of the time slice presents


a trade-off to a system designer

19

You might also like