Professional Documents
Culture Documents
CPU Scheduling
Basic Concepts
Scheduling Criteria
Scheduling Algorithms
Multiple-Processor Scheduling
Real-Time Scheduling
Algorithm Evaluation
Basic Concepts
Maximum CPU utilization obtained with
multiprogramming
CPUI/O Burst Cycle Process execution
consists of a cycle of CPU execution and
I/O wait.
CPU burst distribution
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.
Non-Preemptive Scheduling
A scheduling discipline is non preemptive if,
once a process has been given the CPU, the
CPU cannot be taken away from that process.
This scheduling method is used by MS
Windows 3.x
Short jobs are made to wait by longer jobs,
but the treatment of all processes is fairer.
Response time is predictable because
incoming high priority jobs cannot displace
waiting jobs.
OPERATING SYSTEM CONCEPTS
Preemptive Scheduling
A scheduling discipline is preemptive if the
CPU can be taken away from the process.
Windows 95 introduced this scheduling and
all subsequent versions of windows OS have
use preemptive scheduling.
Many processes must be kept in the main
memory so that the next process is normally
ready for the CPU when it becomes available.
Keeping non-running program in main
memory also involves overhead.
OPERATING SYSTEM CONCEPTS
Point to Think
Consider the case of two processes that
share data. While one is updating the
data, it is preempted so that the second
process can run. The second process
then tries to read the data which are in
inconsistent state.
What will be the solution in such
situation?
OPERATING SYSTEM CONCEPTS
Dispatcher
Dispatcher module gives control of the CPU to
the process selected by the short-term
scheduler; this involves:
1. switching context
2. switching to user mode
3. jumping to the proper location in the user program
to restart that program
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, not output (for time-sharing
environment)
OPERATING SYSTEM CONCEPTS
Optimization Criteria
Max CPU utilization
Max throughput
Min turnaround time
Min waiting time
Min response time
Process
Burst Time
P1 24
P2
P3 3
Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:
P1
0
P2
24
P3
27
30
P3
3
P1
6
30
2. Shortest-Job-First (SJR)
Scheduling
P2 2.0
P3 4.0
P4 5.0
SJF (non-preemptive)
P1
0
P3
7
P2
8
P4
12
16
P2 2.0
P3 4.0
P4 5.0
SJF (preemptive)
P1
0
P2
2
P3
4
P2
5
P4
7
P1
11
16
3. Priority Scheduling
A priority number (integer) is associated with each
process
The CPU is allocated to the process with the
highest priority (smallest integer highest priority).
Preemptive (by comparing the priority of incoming
process with the currently running process)
Non-preemptive
P2
20
37
P3
P4
57
P1
77
P3
97 117
P4
P1
P3
P3
5. Multilevel Queue
Scheduling
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.
OPERATING SYSTEM CONCEPTS
7. Multiple-Processor
Scheduling
Real-Time Scheduling
Hard real-time systems required to
complete a critical task within a guaranteed
amount of time.
Soft real-time computing requires that
critical processes receive priority over less
fortunate ones.
Algorithm Evaluation
Deterministic modeling takes a particular
predetermined workload and defines the performance
of each algorithm for that workload.
Queuing models- determining the CPU and I/O burst
n W
n is average queue length
is average arrival rate for new processes in
the queue (i-e 3 processes per second)
And W is the average waiting time in the
queue
OPERATING SYSTEM CONCEPTS