UNIX 2 Scheduler
-
Upload
abilash-vakati -
Category
Documents
-
view
221 -
download
0
Transcript of UNIX 2 Scheduler
-
8/11/2019 UNIX 2 Scheduler
1/38
PROCESS
&
CPU SCHEDULING
-
8/11/2019 UNIX 2 Scheduler
2/38
Diagram of Process State
-
8/11/2019 UNIX 2 Scheduler
3/38
-
8/11/2019 UNIX 2 Scheduler
4/38
-
8/11/2019 UNIX 2 Scheduler
5/38
Representation of Process Scheduling
-
8/11/2019 UNIX 2 Scheduler
6/38
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 usefulwork while switching.
Time dependent on hardware support.
-
8/11/2019 UNIX 2 Scheduler
7/38
CPU Scheduler
A CPU scheduler, running in the dispatcher,isresponsible for selecting of the next runningprocess. Based on a particular strategy
When does CPU scheduling happen? A process switches from the running state to waiting state
(e.g. I/O request)
A process switches from the running state to the ready state.
A process switches from waiting state to ready state
(completion of an I/O operation)
A process terminates
-
8/11/2019 UNIX 2 Scheduler
8/38
Scheduling queues
CPU schedulers use various queues in thescheduling process: Job queue: consists of all processes
All jobs (processes), once submitted, are in the job queue.
Some processes cannot be executed (e.g. not in memory). Ready queue
All processes that are ready and waiting for execution are inthe ready queue.
Usually, a long-term scheduler/job scheduler selectsprocesses from the job queue to the ready queue.
CPU scheduler/short-term scheduler selects a process fromthe ready queue for execution.
Simple systems may not have a long-term job scheduler
-
8/11/2019 UNIX 2 Scheduler
9/38
Scheduling queues
Device queue
When a process is blocked in an I/Ooperation, it is usually put in a device queue
(waiting for the device). When the I/O operation is completed, the
process is moved from the device queue tothe ready queue.
-
8/11/2019 UNIX 2 Scheduler
10/38
Performance metrics for CPUscheduling
CPU u ti l izat ion: percentage of the time that CPUis busy.
Throughput: the number of processes completedper unit time
Turnaround t ime: the interval from the time ofsubmission of a process to the time of completion.
Wait t ime: the sum of the periods spent waiting in
the ready queue Response time: the time of submission to the
time the first response is produced
-
8/11/2019 UNIX 2 Scheduler
11/38
Goal of CPU scheduling
Other performance metrics:
fairness: It is important, but harder to definequantitatively.
Goal:
Maximize CPU utilization, Throughput, and
fairness. Minimize turnaround time, waiting time, and
response time.
-
8/11/2019 UNIX 2 Scheduler
12/38
Which metric is used more?
CPU utilization
Trivial in a single CPU system
Throughput, turnaround time, wait time,and response time
Can usually be computed for a givenscenario.
-
8/11/2019 UNIX 2 Scheduler
13/38
Deterministic modelingexample:
Suppose we have processes A, B, and C,submitted at time 0
We want to know the response time, waiting
time, and turnaround time of process A
A B C A B C A C A C Time
response time = 0
+ +wait time
turnaround time
Gantt chart: visualize how processes execute.
-
8/11/2019 UNIX 2 Scheduler
14/38
Deterministic modeling example
Suppose we have processes A, B, and C,submitted at time 0
We want to know the response time, waiting
time, and turnaround time of process B
A B C A B C A C A C Time
response time
+wait time
turnaround time
-
8/11/2019 UNIX 2 Scheduler
15/38
Deterministic modeling example
Suppose we have processes A, B, and C,submitted at time 0
We want to know the response time, waiting
time, and turnaround time of process C
A B C A B C A C A C Time
response time+ ++wait time
turnaround time
-
8/11/2019 UNIX 2 Scheduler
16/38
Preemptive versusnonpreemptive scheduling
Many CPU scheduling algorithms have bothpreemptive and nonpreemptive versions: Preemptive: schedule a new process even when the
current process does not intend to give up the CPU
Non-preemptive: only schedule a new process when thecurrent one does not want CPU any more.
When do we perform non-preemptive scheduling? A process switches from the running state to waiting state
(e.g. I/O request)
A process switches from the running state to the ready state. A process switches from waiting state to ready state
(completion of an I/O operation)
A process terminates
-
8/11/2019 UNIX 2 Scheduler
17/38
Scheduling Policies
FIFO (first in, first out)
Round robin
SJF (shortest job first)
Priority Scheduling
Multilevel feedback queues
Many more...
-
8/11/2019 UNIX 2 Scheduler
18/38
FIFO
FIFO: assigns the CPU based on theorder of requests
Non-preempt ive: A process keeps running
on a CPU until it is blocked or terminated Also known as FCFS (first come, first serve)
- Simple
- Short jobs can get stuck behind long jobs- Turnaround time is not ideal
-
8/11/2019 UNIX 2 Scheduler
19/38
Round Robin
Round Rob in (RR) periodically releasesthe CPU from long-running jobs
Based on timer interrupts so short jobs can get
a fair share of CPU time Pre-emptive: a process can be forced to
leave its running state and replaced byanother running process
Time sl ice: interval between timer interrupts
-
8/11/2019 UNIX 2 Scheduler
20/38
More on Round Robin
If time slice is too long
Scheduling degrades to FIFO
If time slice is too short
Throughput suffers
Context switching cost dominates
-
8/11/2019 UNIX 2 Scheduler
21/38
FIFO vs. Round Robin
With zero-cost context switch, is RRalways better than FIFO?
-
8/11/2019 UNIX 2 Scheduler
22/38
FIFO vs. Round Robin
Suppose we have three jobs of equal length
A B C A B C TimeA B C
turnaround time of A
turnaround time of B
turnaround time of C
Round Robin
A B TimeC
turnaround time of Aturnaround time of B
turnaround time of C
FIFO
-
8/11/2019 UNIX 2 Scheduler
23/38
FIFO vs. Round Robin
Round Robin
+ Shorter response time
+ Fair sharing of CPU
- Not all jobs are preemptable
- Not good for jobs of the same length
- More precisely, not good in terms of the turnaroundtime.
-
8/11/2019 UNIX 2 Scheduler
24/38
Shortest Job First (SJF)
SJFruns whatever job puts the leastdemand on the CPU, also known as STCF(shortest t ime to complet ion f i rs t )
+ Probably optimal in terms of turn-around time .+ Great for short jobs
+ Small degradation for long jobs
-
8/11/2019 UNIX 2 Scheduler
25/38
SJF Illustrated
A B TimeC
turnaround time of A
turnaround time of B
turnaround time of C
Shortest Job First
response time of A = 0
response time of B
response time of C
wait time of A = 0wait time of B
wait time of C
-
8/11/2019 UNIX 2 Scheduler
26/38
Drawbacks of Shortest Job First
- Starvation: constant arrivals of short jobscan keep long ones from running
- There is no way to know the completion
time of jobs (most of the time)
Some solutions
Ask the user, who may not know any better
If a user cheats, the job is killed
-
8/11/2019 UNIX 2 Scheduler
27/38
Priority Scheduling (MultilevelQueues)
Prior i ty schedu l ing: The process withthe highest priority runs first
Priority 0:
Priority 1:
Priority 2:
Assume that low numbers represent high
priority
A
B
C
A B TimeC
Priority Scheduling
-
8/11/2019 UNIX 2 Scheduler
28/38
Multilevel Feedback Queues
Mult i level feedback queuesuse multiplequeues with different priorities
Round robin at each priority level
Run highest priority jobs first Once those finish, run next highest priority, etc
Jobs start in the highest priority queue
If time slice expires, drop the job by one level If time slice does not expire, push the job up
by one level
-
8/11/2019 UNIX 2 Scheduler
29/38
Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
A B C
time = 0
Time
-
8/11/2019 UNIX 2 Scheduler
30/38
-
8/11/2019 UNIX 2 Scheduler
31/38
Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
C
time = 2
A B
A B Time
-
8/11/2019 UNIX 2 Scheduler
32/38
Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
C
time = 3
A B
A B C Time
-
8/11/2019 UNIX 2 Scheduler
33/38
Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
C
time = 3
A B
A B C Time
suppose process A is blocked on an I/O
-
8/11/2019 UNIX 2 Scheduler
34/38
Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
C
time = 3
A
B
A B C Time
suppose process A is blocked on an I/O
-
8/11/2019 UNIX 2 Scheduler
35/38
Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 5
BA B C Time
C
A
suppose process A is returned from an I/O
-
8/11/2019 UNIX 2 Scheduler
36/38
Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 6
BA B C Time
C
A
-
8/11/2019 UNIX 2 Scheduler
37/38
Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 8
BA B C TimeA C
C
-
8/11/2019 UNIX 2 Scheduler
38/38
Multilevel Feedback Queues
Priority 0 (time slice = 1):
Priority 1 (time slice = 2):
Priority 2 (time slice = 4):
time = 9
BA B C TimeA C C