Professional Documents
Culture Documents
CPSC 457
CPU scheduling part 2
Fall 2017
Contains slides from Mea Wang, Andrew Tanenbaum and Herbert Bos
1
CPSC 457
Overview
● more CPU scheduling algorithms for interactive systems
○ shortest-process-next, exponential smoothing
○ fair-share
○ priority scheduling
□ multilevel queues
□ multilevel feedback queues
□ lottery
● real-time CPU scheduling
○ rate-monotonic
○ earliest-deadline-first
● thread scheduling
○ user-level
○ kernel-level
2
CPSC 457
CPU scheduling on batch systems
● many ideas from these can be adapted to interactive and even real-time systems
3
CPSC 457
CPU scheduling on interactive systems
4
CPSC 457
Shortest-process-next
● very similar to SJF scheduling
○ uses time-sharing preemption (time slice)
○ ready queue is sorted by a predicted next CPU burst
P = a x B + (1 - a) x P'
where
P is the new prediction, initialized to some value (eg. 0)
P' is the previous prediction
a is a smoothing factor, commonly set to ½
5
CPSC 457
Predicting burst via exponential smoothing
B
P
P = a x B + (1 - a) x P'
actual bursts B:
predicted burst P:
6
CPSC 457
Fair-share scheduling
● a scheduling algorithm that takes into account the (importance of) owners of the processes
● it is used to ensure all users of a system get a 'fair' share of the CPU
● it allocates CPU among users/groups, instead of processes
● solves problems like this:
○ user A runs 10 processes, user B runs a single process
○ user A would get 90% of the CPU, user B only gets 10%
● each user is allocated some fraction of the CPU
○ equal share: with N users, each user gets 1/N of the CPU
○ unequal share: important users get a big chunk of CPU time,
and even more important users get an even bigger chunk of CPU time
● all processes belonging to an owner have to share the owner's CPU share
7
CPSC 457
Fair-share scheduling
● example 1:
○ user 1 has 50% CPU share, and 5 processes: A, B, C, D, E
○ user 2 has 50% CPU share, and 1 process: F
○ possible possible scheduling sequences:
A F B F C F D F E F A F B F C F D F E F A F B F C F D F E F …
A B C D E F F F F F A B C D E F F F F F A B C D E F F F F F …
● example 2:
○ user 1 has 75% CPU share, and 5 processes: A, B, C, D, E
○ user 2 has 25% CPU share, and 1 process: F
○ possible scheduling sequence:
A B C F D E A F B C D F E A B F C D E F A B C F …
A B C D E A B C D E A B C D E F F F F F …
8
CPSC 457
Priority scheduling
9
CPSC 457
Implementing priority scheduling
10
CPSC 457
Multilevel queues
11
CPSC 457
Multilevel queues
12
CPSC 457
Multilevel queues
13
CPSC 457
Multilevel feedback queue scheduling
● similar to multilevel queues
○ multiple queues, each representing a different priority
○ scheduling is done based on queues
○ each process belongs to a queue
● but a process can move between queues (up or down in priority)
○ minimizes the starvation problem, reduces convoy effect *
○ can dynamically react to a job changing from CPU-bound to IO-bound
CPU-bound processes moved to low priority queue, IO-bound to high priority queue
● scheduler defined by
○ number of queues
○ scheduling algorithms for each queue, including different time slices
○ when to move a process between queues *
○ which queue a process will be assigned when the process needs service
14
CPSC 457
Multilevel feedback queue scheduling
Example:
● three queues: Q1, Q2 and Q3
● all three queues use RR scheduling with time-slices of 8ms, 16ms and 32ms
● jobs in Q1 are processed first, then Q2, then Q3
● new jobs added to Q1
● if job in Q1 does not finish in 8ms, Q1 : quantum = 8ms
it is demoted to queue 2
● if job in Q2 does not finish in 16ms,
it is demoted to queue 3 Q2 : quantum = 16ms
18
CPSC 457
Earliest-deadline-first scheduling algorithm (EDF)
19
CPSC 457
EDF example
Event
Task Deadline Burst
time
1 0 30 7
2 1 8 5
3 2 20 11
4 3 5 2
Gantt chart:
1 2 2 4 4 2 2 2 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1
20
CPSC 457
Thread scheduling
User-level threads:
Kernel-level threads:
Operation
Scheduling Algorithms
Environments
• First come, first serve
Batch systems • Shortest job first
• Shortest remaining time next
• Round robin
• Shortest process next
Interactive • Fair share
systems • Lottery
• Multilevel queue
• Multilevel feedback queue
25
CPSC 457
Summary
26
CPSC 457
Review
27
CPSC 457
Questions?
28