Process &: Cpu Scheduling
Process &: Cpu Scheduling
&
CPU SCHEDULING
CONTEXT SWITCH
Save the state of the old process
Load the saved state for the new process.
Context-switch time is overhead; the system does no useful
work while switching.
Time dependent on hardware support.
CPU Scheduler
Scheduling queues
Ready queue
All processes that are ready and waiting for execution are in
the ready queue.
Usually, a long-term scheduler/job scheduler selects
processes from the job queue to the ready queue.
CPU scheduler/short-term scheduler selects a process from
the ready queue for execution.
Scheduling queues
Device queue
Goal:
CPU utilization
Trivial in a single CPU system
Throughput, turnaround time, wait time,
and response time
Can usually be computed for a given
scenario.
Deterministic modeling
example:
A B C A B C A C A C
Gantt chart: visualize how processes execute.
Time
+
A B C A B C A C A C
Time
A B C A B C A C A C
Time
Preemptive versus
nonpreemptive scheduling
Scheduling Policies
FIFO
Round Robin
Throughput suffers
Context switching cost dominates
Time
Round Robin
turnaround time of C
turnaround time of B
turnaround time of A
A
C
FIFO
Time
Round Robin
+ Shorter response time
+ Fair sharing of CPU
- Not all jobs are preemptable
- Not good for jobs of the same length
-
SJF Illustrated
turnaround time of C
turnaround time of B
turnaround time of A
wait time of C
wait time of B
wait time of A = 0
response time of C
response time of B
response time of A = 0
A
C
Shortest Job First
Time
Some solutions
Priority Scheduling
Time
Time
Time
A B
C
B
Time
A B C
Time
A B C
Time
A B C
Time
A B C
Time
A B C
Time
A B C
Time
A B C
Time