0% found this document useful (0 votes)
52 views40 pages

Chapter 03 CPU Scheduling New

This document discusses different CPU scheduling algorithms. It begins by introducing CPU scheduling and describing process behavior and when scheduling decisions need to be made. It then categorizes scheduling algorithms into those used in batch systems, interactive systems, and real-time systems. The goals of different scheduling algorithms are described, including metrics like throughput, turnaround time, response time and meeting deadlines. Specific algorithms discussed include FCFS, SJF, SRTF, Round Robin, and Priority Scheduling.

Uploaded by

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

Chapter 03 CPU Scheduling New

This document discusses different CPU scheduling algorithms. It begins by introducing CPU scheduling and describing process behavior and when scheduling decisions need to be made. It then categorizes scheduling algorithms into those used in batch systems, interactive systems, and real-time systems. The goals of different scheduling algorithms are described, including metrics like throughput, turnaround time, response time and meeting deadlines. Specific algorithms discussed include FCFS, SJF, SRTF, Round Robin, and Priority Scheduling.

Uploaded by

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

Chapter 3: CPU Scheduling

 Introduction to scheduling
 Process behavior
 When to schedule
 Categories of scheduling algorithms
 Scheduling algorithms Goals (Criteria)
 Scheduling Algorithms at a glimpse
Algorithms in Batch systems
Algorithms in interactive systems
Algorithms in Real-time systems
Intro… CPU scheduling
 The aim of pro. Scheduling is to assign processes to be executed
by the processor or processors over time in a way that meets the
system objectives.
 Fundamentally, scheduling is a matter of managing queues to
minimize delays and to optimize performance.
 Scheduling in batch systems was simple.
 But in time sharing - algorithms are becoming more and more
complex.
 Some main frame- use both ways
◦ The scheduler decides whether a batch job or interactive user at
the terminal should go next.
Intro… CPU scheduling …
 CPU was a scarce resources on these machines. Hence,
a good algorithm can make a huge difference.
 But with the advent of personal computer

◦ One processes at a time is not desirable


◦ CPU is a rarely scarce resource – PC are limited by user input and
application type
◦ The situation is different when it comes to high-end networked
workstations and servers. – sending e-mail and closing windows
 The scheduler has to worry about making efficient
use of CPU because switching is expensive.
◦ In some systems memory map must also be saved
◦ Process switch some times invalidates the entire memory
cache
Process Behavior
 CPU bound – long CPU burst
 I/O bound – long I/O burst

Waiting for I/O

 The key factor is CPU burst.


◦ As the CPU gets faster processes tend to get more I/O.
◦ And CPU is improving in much faster way than disks.
When to schedule
 Key issues to make scheduling decisions
◦ When a new process is created
 Child? Parent? Here Long term scheduling/short term scheduling works
◦ When a process exits
 Some other process or a system supplied idle process
◦ When a process blocks for some reason.
 In this case, mostly, medium-term scheduling are used.
◦ When I/O interrupts occurs
 If a hardware provides periodic interrupts, scheduling decision
can be made at each clock interrupts.
◦ Non-Preemptive and preemptive
Categories of scheduling algorithms
 In different environment different algorithms are
implemented
◦ Batch systems
 No user waiting impatiently. Hence, Non-preemptive or long time
run preemptive are acceptable
◦ Interactive systems
 Need preemption
 Most are general purpose – even malicious software can run.
◦ Real-Time systems
 Preemption is, oddly enough, some times not needed
 Run only programs that are needed for further application at hand
Scheduling algorithms Goals
 All systems
◦ Fairness is important
 Comparable processes should get fair share
◦ Enforcing systems policy
 Safety control and payroll applications in a nuclear reactor
◦ Keeping all parts of the computer busy
 I/O bound and CPU- bound can be run together.
Scheduling algorithms Goals…
 Batch systems
◦ Throughput - maximum jobs per hr.
 Throughput = (Number of processes completed) / (Time Unit)
◦ Turn around time – minimize time between submission and
termination
 tat = t(process completed) – t(process submitted)
◦ CPU utilization – keep the CPU busy all the time
 Processor Utilization = (Processor busy time) / (Processor busy
time + Processor idle time)
.
Scheduling algorithms Goals…
 Interactive systems
◦ Response time – respond to request quickly
 rt = t(first response) – t(submission of request)
◦ Waiting Time (wt): for each process Time spent in ready
queue.
◦ Proportionality –meet users expectations
 Real-Time
◦ Meeting deadlines – avoid losing of data
◦ Predictability – avoid quality degradation in multi-media
systems
Scheduling in Batch systems
 FCFS
 SJF/SPN
 Short time remaining next
 Three level scheduling
Example
First Come First Served
 It’s the simplest of all algorithms
 It’s non-preemptive
 A blocked process come to an end of the queue when

it’s ready to be executed


 Easy to understand and to program
 A single linked list keeps track of all ready state

processes
 The greater disadvantage is when executing I/O bound

processes.
First-Come-First-Served (FCFS)

0 5 10 15 20

1
2
3
4
5
FCFS Example with I/O brust

Calculate
1. CPU Utilization
2. throughput
3. Average around time
4. Average Waiting time
5. Average Response time
FCFS example’s answer
Short Job First

 Another non-preemptive and the run time of the


processes are known in advance
 When multiple batch jobs are sitting in a queue with the
same priority, the scheduler runs the shortest job first
◦ Mean Turnaround Time of SJF is better than FCFS in
certain circumstances
Short Job First…
 SJF is only optimal only if all jobs are available
simultaneously.
 Exercise
◦ Consider five jobs whose running time is 2, 4, 1, 1, 1 respectively and
their arrival time is 0, 0, 2, 3, 3 respectively.

◦ Using FCFS the average waiting time is _____.

◦ Running in order of, A, C, D, E,B results in average waiting time of


___.
Short Job first…
0 5 10 15 20

1
2
3
4
5
Shortest Remaining Time Next
 Preemptive version of SJF.

 The scheduler always picks the processes whose remaining


running time is the shortest.

 Again the run time should be known in advance.

 The shortest new job has a great advantage over all processes.
Shortest remaining time first
0 5 10 15 20

1
2
3
4
5
Three Level Scheduling
Scheduling in interactive systems
Scheduling in interactive systems
◦ Round robin scheduling
◦ Priority scheduling
◦ Multiple queuing
◦ Shortest process next
◦ Guaranteed scheduling
Round- Robin scheduling

◦ Processes will be given equal priority


◦ It uses quantum- slice of time
◦ Therefore each process will be given an interval of time
(quanta of time).
 1 quantum, 2 quanta…..
◦ Processes are allowed to run in their given slice of time.
◦ The main issue in round- robin is time taken by context
switching. E.g. 1msec. For process switching and 4msec as a
quanta
Round- Robin…

 It’s better to set one quantum enough amount of time say


100msec to improve the efficiency.
◦ But here what if ten users press the carriage return at the same
time?
 The two main things as a summary
◦ Setting the quantum too short causes to many process switches that
will result in performance degradation.
◦ But setting it too long may cause poor response to short interactive
commands.
Round-Robin (q=1)
0 5 10 15 20

1
2
3
4
5
Round-Robin (q=4)
 DO IT YOURSELF as an exercise!!
Individual Assignment…to be submitted
on date of the next class

Using SJF, SRTF, RR scheduling techniques


Calculate
1. the turn around time
2. throughput
3. CPU Utilization
4. Average Waiting time
5. Average Response time
Priority scheduling
 Each process is assigned a priority. See rs. mntr
 The process with the highest priority is allowed to run.
 This idea is critical in a multi-user environment and also
in a single user with several applications running at a
time.
 Priority will decrease at each clock tick (clock interrupt)
 When the priority level lower from that of the next
highest one, the process switching occurs.
 Plus to the above each priority will be given maximum
allowed quantum of time.
Priority scheduling…
 Unix system has nice which allows the user to
voluntarily reduce its priority level.
 Process priority can be given statically and

dynamically
◦ Statically-Role and privilege assignment in MIS systems
◦ Dynamically- I/O bound processes should be given the highest
priority after waiting for I/O response and asks to run again.
 This avoid unnecessary memory hold time
 A simple algorithm for giving this service is to set the priority to
1/f where f is fraction of the last quantum that the process used.
 For e.g a process that uses 1 msec of its 50 msec quantum then it
will be given priority level tantamount to 50.
priority defining function:

 Following may be used as a Priority (n) = 10 + tnow –


ts(n) – tr(n) – cpu(n)
 where

◦ ts(n) : the time process n is submitted to the system


◦ tr(n) : the time process n entered to the ready queue last time
◦ cpu(n) : next processor burst length of process n
◦ tnow : current time

Priority scheduling….

Process Burst Time Priority


P1 10 3
P2 1 1
P3 2 4
P4 1 5
P5 5 2

N.B. the smallest magnitude is the highest priority level


Priority scheduling….
 It’s often convenient to create priority class and use
round-robin in each classes.
Multiple Queues
 Processes in the highest priority class will run for 1 quantum
and processes in the next highest class will run for 2 quanta
processes in the next class will run for 4 quanta and so on.
◦ Consider how a process that needs100 quanta to continuously run and
finish its computation. It would only need 7 swaps unlike 100 swaps in
pure round- robin.
Multiple Queues….. Priority level
examples
Multiple queues….
 As a processes sank deep and deeper in to the priority
queues it would be run less and less frequently.
◦ This saves the CPU for short and interactive processes.
 A policy of making a process that was decided to run
for a long time to become interactive later.
◦ E.g. copying a file or installing a memory demanding software
Guaranteed Scheduling
 Make real promises to the users about performance and
live up to them.
◦ If n users logged in each will get 1/n of CPU power.
◦ If a user have n processes to run each will get 1/n of the CPU
cycle.
 To make good on the promise. The system must keep
track of how much CPU the process has had since
creation.
◦ i.e. ratio of actual CPU time consumed to CPU entitled.
◦ 0.5, 2.0 ……
◦ The algorithm then runs the process with the lowest ratio.
Real-Time Scheduling
 Hard real-time systems – required to complete a critical task
within a guaranteed amount of time.
◦ Resource reservation – knows how much time it requires and
will be scheduled if it can be guaranteed that amount of time
◦ dedicated to their critical processRequires special purpose
software running on hardware
 Soft real-time computing – requires that critical processes receive
priority over less fortunate ones… ex. Windows task manager
◦ System must have priority scheduling where real time processes
are given the highest priority (no aging to keep priorities
constant)
◦ Dispatch latency must be small – need to be able to preempt
system calls particularly in long, complex calls at safe points
Reading Assignment

 Algorithm evaluation ??
 Scheduling in different OS
windows
Solaris
Unix
Mobile OS
*******End of Chapter 3*************
Your Real Assignment
 Using FCFS, SJF, SRTF, RR scheduling techniques
 Calculate
◦ the turn around time
◦ throughput
◦ CPU Utilization
◦ Average Waiting time
◦ Average Response time
Assume:
1 slice = 1 CPU time
each process will be given 3 slice at a time

You might also like