Sunteți pe pagina 1din 4

Performance Criteria and

Metrics

Process Scheduling (2)  Fairness


 Efficiency: keep resources as busy as possible
 Throughput: # of processes that complete per unit time
 Turnaround Time (also called elapse time)
 amount of time to execute a particular process from the time it’s entered
Indranil Gupta (Indy)  Waiting Time
 amount of time process has been waiting in ready queue
 Response Time
 amount of time from when a request was first submitted until first
response is produced.
 predictability and variance
 Proportionality
 meet users' expectation
Copyright ©: Nahrstedt, Angrave, Abdelzaher, Kravets, Gupta 1  Meeting Deadlines: e.g., multimedia tasks 2

Simple Processor Scheduling


Process Profiles Algorithms
 I/O – Bound
 Does too much I/O to keep CPU busy  Batch systems
 E.g., interactive shell  First Come First Serve (FCFS)
 CPU – Bound  Shortest Job First
 Does too much computation to keep I/O busy
 Interactive Systems
 E.g., a process sorting a million-entry array in RAM
 Round Robin
 Process Mix
 Scheduling should load balance between I/O bound and  Priority Scheduling
CPU-bound processes  …
 Ideal would be to run all equipment (CPU, devices) at
100% utilization
3 4

First Come First Serve (FCFS) FCFS Example


Process Duration Order Arrival Time
 Process that requests the CPU FIRST is allocated the CPU P1 24 1 0
FIRST.
P2 3 2 3
 Also called FIFO
 Preemptive or Non-preemptive? P3 4 3 7
 Used in Batch Systems The final schedule:
 Implementation P1 (24) P2 (3) P3 (4)
 FIFO queues
0 24 27
 A new process enters the tail of the queue
 The scheduler selects next process to run from the head of the queue. P1 waiting time: 0
P2 waiting time: 24-3=21
The average waiting time:
P3 waiting time: 27-7=20 (0+21+20)/3 = 13.67
What if arrival times of P1 and P2 are swapped?
5 6
AWT (average waiting time) = (0+0+20)/3=6.67
Problems with FCFS Why Convoy Effects?

 Non-preemptive  Consider n-1 jobs in system that are I/O bound


and 1 job that is CPU bound.
 Not optimal AWT  I/O bound jobs pass quickly through the ready
 Cannot utilize resources in parallel: queue and suspend themselves waiting for I/O.
 Assume 1 process CPU bounded and many I/O  CPU bound job arrives at head of queue and
bounded processes executes until completion.
 I/O bound jobs re-join ready queue and wait for
 Result: Convoy effect, low CPU and I/O Device
CPU bound job to complete.
utilization
 I/O devices idle until CPU bound job completes.
 When CPU bound job completes, other processes
7 rush to wait on I/O again. CPU becomes idle. 8

Interactive Scheduling Algorithms Round-robin

 One of the oldest, simplest, most commonly used


scheduling algorithms
 Usually preemptive  Select process/thread from ready queue in a
 Time is sliced into quantums (or “quanta”, i.e., time
intervals) round-robin fashion (i.e., take turns)
 Scheduling decision is also made at the beginning of
each quantum Problems:
 Performance Metrics • Does not consider priority
 Average response time • Context switch overhead
 Fairness (or proportional resource allocation)
 Representative algorithms:
 Priority-based
 Round-robin 9 10

Round-robin: Example Choosing the Time Quantum


Process Duration Order Arrival Time  Time quantum too large
P1 3 1 0  FIFO behavior
P2 4 2 0
P3 3 3 0  Poor response time
Suppose time quantum is: 1 unit, P1, P2 & P3 never block  Time quantum too small
P1 P2 P3 P1 P2 P3 P1 P2 P3 P2
 Too many context switches (overheads)
 Inefficient CPU utilization
0 10
P1 waiting time: 4
 Heuristic for choosing time quantum
P2 waiting time: 6 The average waiting time (AWT):  70%-80% of jobs block within time quantum
P3 waiting time: 6 (4+6+6)/3 = 5.33
 Typical time quantum
11  10-100 ms (depends on job priority) 12
Shortest Job First (SJF) Non-preemptive SJF: Example
Process Duration Order Arrival Time
 Schedule the job with the shortest computation time P1 6 1 0
first P2 8 2 0
 Scheduling in Batch Systems P3 7 3 0
P4 3 4 0
 Two types:
P4 (3) P1 (6) P3 (7) P2 (8)
 Non-preemptive
0 3 9 16 24
 Preemptive
 Optimal if all jobs are available simultaneously: P4 waiting time: 0
The total time is: 24
Gives the lowest possible AWT (average waiting P1 waiting time: 3
P3 waiting time: 9 The average waiting time (AWT):
time) among all scheduling algorithms P2 waiting time: 16 (0+3+9+16)/4 = 7
13 14

Comparing to FCFS Preemptive SJF


Process Duration Order Arrival Time  Shortest job runs first.
P1 6 1 0
P2 8 2 0  A job that arrives and is shorter than the
P3 7 3 0
P4 3 4 0
running job will preempt it
Do it yourself
P1 (6) P2 (8) P3 (7) P4 (3)

0 6 14 21 24

The total time is the same.


P1 waiting time: 0
The average waiting time (AWT):
P2 waiting time: 6
P3 waiting time: 14 (0+6+14+21)/4 = 10.25
P4 waiting time: 21 (compare to SJF’s AWT = 7)
15 16

Priority Scheduling
A Problem with Preemptive SJF
 Each job is assigned a priority.
 Starvation  FCFS within each priority level.
 A job may keep getting preempted  Select highest priority job over lower
by shorter ones ones.
 Example  Rationale: higher priority jobs are more
 Process A with elapse time of 1 hour arrives at time 0
mission-critical
 But every 1 minute, a short process with elapse time
of 2 minutes arrives  Example: DVD movie player vs. send email
 Result of SJF: A never gets to run  Problems:
 What’s the difference between starvation  May not give the best AWT
and deadlock? 17
 Starvation of lower priority processes 18
Priority Scheduling: Example Set Priority
(Lower priority number is more preferable)

Process Duration Priority Arrival Time  Every process has a default priority
P1 6 4 0
P2 8 1 0  User can also change a process priority
P3 7 3 0
P4 3 2 0  The nice command to change process’ priority
Do it yourself
P2 (8) P4 (3) P3 (7) P1 (6)

0 8 11 18 24

P2 waiting time: 0
P4 waiting time: 8
The average waiting time (AWT):
P3 waiting time: 11 (0+8+11+18)/4 = 9.25
P1 waiting time: 18 (worse than SJF)
19 20

Set/Get Process Priority Summary

Important Issues to remember:


int getpriority(int which, id_t who);
int setpriority(int which, id_t who, int value);  How to compare different policies?
 What are the pros and cons of each scheduling
policy?

 Next lectures: Synchronization and Semaphores

21 22

S-ar putea să vă placă și