Professional Documents
Culture Documents
Networks and Operating Systems Chapter 3: Scheduling Last Time
Networks and Operating Systems Chapter 3: Scheduling Last Time
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Last time
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Scheduling is
Scheduling
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Objectives
General:
Fairness
Enforcement of policy
Balance/Utilization
Trade-off between:
scheduler complexity/overhead and
optimality of resulting schedule
2/26/2014
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Batch workloads
Goals:
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Interactive workloads
Wait for external events, and react before the user gets
annoyed
Goals:
Goals:
Deadlines
Guarantees
Predictability (real time fast!)
10
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
11
12
2/26/2014
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
CPU-bound task:
CPU-bound task:
I/O-bound task:
13
14
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Simplifying assumptions
Only one processor
Well relax this (much) later
CPU-bound task:
CPU burst
I/O-bound task:
15
16
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Simplifying assumptions
When to schedule?
When:
1.
2.
3.
4.
17
I/O completes
I/O or timer
18
2/26/2014
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Preemption
Overhead
Non-preemptive scheduling:
Dispatch latency:
Scheduling cost
= 2 x (half context switch) + (scheduling time)
Preemptive scheduling:
Processes dispatched and descheduled without warning
Often on a timer interrupt, page fault, etc.
The most common case in most OSes
Soft-realtime systems are usually preemptive
Hard-realtime systems are often not!
19
20
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
21
22
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Batch-oriented scheduling
23
24
2/26/2014
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
First-come first-served
Simplest algorithm!
Example:
Process
Execu<on
<me
24
But..
A
0
24
C
27
30
25
26
spcl.inf.ethz.ch
@spcl_eth
First-come first-served
spcl.inf.ethz.ch
@spcl_eth
Convoy phenomenon
Short processes back up behind long-running processes
Process
Execu<on
<me
24
Waiting times: 6, 0, 3
Avg.
= (0+3+6)/3 = 3
Much better
But unpredictable !
Generally undesirable
FIFO used for, e.g. memcached
B
0
C
3
A
6
30
28
27
spcl.inf.ethz.ch
@spcl_eth
Optimality
Shortest-Job First
Always run process with
the shortest execution time.
Process
spcl.inf.ethz.ch
@spcl_eth
Execu<on
<me
6
C
D
7
3
Avg. =
1 n 1
( n i ) ti
n i =0
(4t0 + 3t1 + 2t 2 + t3 )
4
29
30
2/26/2014
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
n+1 = tn + (1 ) n
31
32
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Round-robin
Simplest interactive algorithm
Run all runnable tasks for fixed quantum in turn
Advantages:
Its easy to implement
Its easy to understand, and analyze
Higher turnaround time than SJF, but better response
Disadvantages:
Its rarely what you want
Treats all tasks the same
33
34
spcl.inf.ethz.ch
@spcl_eth
Priority
spcl.inf.ethz.ch
@spcl_eth
Priority queues
Priority 100
Priority 4
Priority
Priority 3
Priority 2
Priority 1
Runnable tasks
35
36
2/26/2014
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Multi-level queues
Starvation
Solution: Ageing
Tasks which have waited a long time are gradually increased in priority
Eventually, any starving task ends up with the highest priority
Reset priority when quantum is used up
38
37
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
40
39
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
41
42
2/26/2014
spcl.inf.ethz.ch
@spcl_eth
Resource Containers
spcl.inf.ethz.ch
@spcl_eth
Real Time
43
44
spcl.inf.ethz.ch
@spcl_eth
Real-time scheduling
spcl.inf.ethz.ch
@spcl_eth
45
46
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Rate-monotonic scheduling
Suppose:
m tasks
Ci is the execution time of ith task
Pi is the period of ith task
Ci
i =1
1
Ci
m(2 m 1)
i =1 Pi
47
48
2/26/2014
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Multiprocessor Scheduling
49
50
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Task queue
Core 0
Core 0
Core 1
Core 1
Core 2
Core 2
Core 3
Core 3
But
In practice, each
is more complex
e.g. MFQ
51
52
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
53
54
2/26/2014
spcl.inf.ethz.ch
@spcl_eth
spcl.inf.ethz.ch
@spcl_eth
Multicore scheduling
Littles Law
55
56
10