SE350: Operating Systems Lecture 8: Scheduling Outline Definitions - - PowerPoint PPT Presentation

se350 operating systems
SMART_READER_LITE
LIVE PREVIEW

SE350: Operating Systems Lecture 8: Scheduling Outline Definitions - - PowerPoint PPT Presentation

SE350: Operating Systems Lecture 8: Scheduling Outline Definitions Response time, throughput, scheduling policy, Uniprocessor policies FCFS, SJF/SRTF, Round Robin, Real-time scheduling Multiprocessor policies


slide-1
SLIDE 1

SE350: Operating Systems

Lecture 8: Scheduling

slide-2
SLIDE 2

Outline

  • Definitions
  • Response time, throughput, scheduling policy, …
  • Uniprocessor policies
  • FCFS, SJF/SRTF, Round Robin, …
  • Real-time scheduling
  • Multiprocessor policies
  • Oblivious scheduling, gang scheduling, …
slide-3
SLIDE 3

Definitions

  • Task
  • User request (e.g., mouse click, web request, shell command, etc.)
  • Workload
  • Set of tasks for system to perform
  • Scheduling algorithm
  • Takes workload as input, decides which tasks to do first
  • Overhead
  • How much extra work is done by scheduler?
  • Preemptive scheduler
  • If we can take resources away from a running task
  • Work-conserving
  • Resources are used whenever there is task to run
  • For non-preemptive schedulers, work-conserving is not always better
  • Only preemptive, work-conserving schedulers to be considered in this lecture!
slide-4
SLIDE 4

Recall: CPU Scheduling

  • Earlier, we talked about life-cycle of threads
  • Threads work their way from ready to running to various waiting queues
  • Question: How does OS decide which thread to dequeue?
  • Obvious queue to worry about is ready queue
  • Others can be scheduled as well, however
  • Scheduling: Deciding which thread gets resource from moment to moment
slide-5
SLIDE 5

Execution Model

  • Programs alternate between bursts of CPU and I/O
  • Use CPU for some period, then do I/O, then use CPU again, etc.
  • CPU scheduling is about choosing thread which gets CPU for its next CPU burst
  • With preemption, thread may be forced to give up CPU before finishing its burst

We Weighted toward small bursts

slide-6
SLIDE 6

CPU Scheduling Assumptions

  • There are many implicit assumptions for CPU scheduling
  • One program per user
  • One thread per program
  • Programs are independent
  • These may not hold in all systems, but they simplify the problem
  • High-level goal is to divide CPU time to optimize some desired properties
slide-7
SLIDE 7

CPU Scheduling Policy Goals/Criteria

  • Minimize average response time
  • Minimize elapsed time to do an operation (or task)
  • Response time is what users see
  • Time to echo a keystroke in editor
  • Time to compile a program
  • Real-time tasks must meet deadlines imposed by “environment”
slide-8
SLIDE 8

CPU Scheduling Policy Goals/Criteria (cont.)

  • Maximize throughput
  • Maximize operations (or tasks) per time unit (e.g., second)
  • Throughput related to response time, but not identical
  • Minimizing response time could lead to more context switching

which will than hurt throughput (more on this later!)

  • Two parts to maximizing throughput
  • Minimize overhead (e.g., context-switching)
  • Efficient use of resources (e.g., CPU, disk, memory, etc.)
slide-9
SLIDE 9

CPU Scheduling Policy Goals/Criteria (cont.)

  • Achieve fairness
  • Share CPU time among users in some equitable way
  • What does equitable mean?
  • Equal share of CPU time?
  • What if some tasks don’t need their full share?
  • Minimize variance in worst case performance?
  • What if some tasks were running when no one else was running?
  • Who are users? Actual users or programs?
  • If A runs one thread and B runs five, B could get five times as much CPU

time on many OS’s

  • Fairness is not minimizing average response time
  • Improving average response time could make system less fair

(more on this later!)

slide-10
SLIDE 10

Outline

  • Definitions
  • Response time, throughput, scheduling policy, …
  • Uniprocessor policies
  • FCFS, SJF/SRTF, Round Robin, …
  • Real-time scheduling
  • Multiprocessor policies
  • Oblivious scheduling, gang scheduling, …
slide-11
SLIDE 11
  • First-Come, First-Served (FCFS)
  • Also “First In, First Out” (FIFO)
  • In early systems, FCFS meant one program

scheduled until done (including its I/O activities)

  • Now, it means that program keeps CPU until the end of its CPU burst
  • Example:

Thread CPU Burst Time T1 24 T2 3 T3 3

  • Suppose threads arrive in order: T1 , T2 , T3

The Gantt Chart for FCFS scheduling is

First-Come, First-Served (FCFS) Scheduling

T1 T2 T3 24 27 30

slide-12
SLIDE 12

FCFS Scheduling (cont.)

  • Example continued:
  • Waiting time for T1 is 0, for T2 is 24, and for T3 is 27
  • Average waiting time is (0 + 24 + 27)/3 = 17
  • Average response time is (24 + 27 + 30)/3 = 27
  • Convoy effect: Short threads get stuck behind long ones
  • At supermarket, you with milk get stuck behind cart full of small items

T1 T2 T3 24 27 30

slide-13
SLIDE 13

FCFS Scheduling (cont.)

  • If threads arrive in order: T2 , T3 , T1, then we have
  • Waiting time for T1 is 6, for T2 is 0, and for T3 is 3
  • Average waiting time is (6 + 0 + 3)/3 = 3
  • Average response time is (3 + 6 + 30)/3 = 13
  • Average waiting time is much better (before it was 17)
  • Average response time is better (before it was 27)
  • Pros and cons of FCFS
  • Simple (+)
  • Short tasks get stuck behind long ones (-)

T1 T3 T2 6 3 30

slide-14
SLIDE 14

Round Robin (RR) Scheduling

  • FCFS is potentially bad for short tasks!
  • Depends on submit order
  • If you are first in line at supermarket with milk,

you don’t care who is behind you, on the other hand…

  • Round Robin
  • Each thread gets small unit of CPU time, called time quantum

(usually 10-100 milliseconds)

  • Once quantum expires, thread is preempted and added to

end of ready queue

  • N threads in ready queue and time quantum is q Þ
  • Each thread gets 1/N of CPU time in chunks of at most q time units
  • No thread waits more than (N-1)q time units

Photo: Pinterest.ca

slide-15
SLIDE 15

Example: RR with Time Quantum of 20

  • Example:

Thread Burst Time T1 53 T2 8 T3 68 T4 24

  • The Gantt chart is
  • Waiting time for

T1 = (68 - 20) + (112 - 88) = 72 T2 = (20 - 0) = 20 T3 = (28 - 0) + (88 - 48) + (125 - 108) = 85 T4 = (48 - 0) + (108 - 68) = 88

  • Average waiting time is (72 + 20 + 85 + 88) / 4 = 66¼
  • Average response time is (125 + 28 + 153 + 112) / 4 = 104½

T1 20 T2 28 T3 48 T4 68 T1 88 T3 108 T4 T1 T3 T3 112 125 145 153

slide-16
SLIDE 16
  • Pros and cons of RR
  • Better for short tasks, Fair (+)
  • Context-switching time adds up for long tasks (-)
  • How does performance change with time quantum?
  • What if it’s too long?
  • Response time suffers!
  • What if it’s too short?
  • Throughput suffers!
  • What if it’s infinite (¥)?
  • RR Þ FCFS
  • Time quantum must be long compared to context switching time,
  • therwise overhead will be too high

Round-Robin Discussion

slide-17
SLIDE 17

Round-Robin Discussion (cont.)

  • Actual choices of time quantum
  • Initially, UNIX time quantum was one second
  • Worked ok when UNIX was used by one or two users
  • What if you use text editor while there are three compilations going on?
  • It takes 3 seconds to echo each keystroke!
  • Need to balance short-task performance and long-task throughput
  • Typical time quantum today is between 10ms – 100ms
  • Typical context-switching overhead is 0.1ms – 1ms
  • Roughly 1% overhead due to context-switching
slide-18
SLIDE 18

FCFS vs. RR

  • Assuming zero-cost context-switching time, is RR always better than FCFS?
  • Suppose there are 10 tasks, each take 100s of CPU time, RR quantum is 1s
  • Completion times

Task # FCFS RR 1 2 … 9 10 991 992 … 999 1000 100 200 … 900 1000

T1 T2 T9 T10 … 100 800 900 1000 200 FCFS … 10 980 990 1000 20 … … … … 999 991 RR

slide-19
SLIDE 19

FCFS vs. RR (cont.)

  • Completion times
  • Both RR and FCFS finish at the same time
  • Average response time is much worse under RR!
  • Bad when all jobs have the same length
  • Also, cache must be shared between all tasks with RR but can be devoted to each

task with FIFO

  • Total time for RR is longer even for zero-cost context switching!

Task # FCFS RR 1 2 … 9 10 991 992 … 999 1000 100 200 … 900 1000

slide-20
SLIDE 20

Earlier Example: RR vs. FCFS, Effect of Different Time Quanta

T2 (8) T4 (24) T1 (53) T3 (68) 8 32 85 153 Best FCFS

Quantum T1 T2 T3 T5 Average Wa Waiting Time Time Best Best FCF CFS 1 5 8 10 10 20 20 Wo Worst FCFS Resp Response

  • nse

Time Time Best Best FCF CFS 1 5 8 10 10 20 20 Wo Worst FCFS

32 85 8 31¼ 85 8 153 32 69½

slide-21
SLIDE 21

Earlier Example: RR vs. FCFS, Effect of Different Time Quanta (cont.)

T2 (8) T4 (24) T1 (53) T3 (68) 68 121 145 153 Worst FCFS

Quantum T1 T2 T3 T5 Average Wa Waiting Time Best Best FCF CFS 1 5 8 10 10 20 20 Wo Worst FCFS Resp Response

  • nse

Time Time Best Best FCF CFS 1 5 8 10 10 20 20 Wo Worst FCFS

32 85 8 31¼ 85 8 153 32 69½ 68 145 121 83½ 121 153 68 145 121¾

slide-22
SLIDE 22

Earlier Example: RR vs. FCFS, Effect of Different Time Quanta (cont.)

Quantum T1 T2 T3 T5 Average Wa Waiting Time Time Best Best FCF CFS 1 5 8 10 10 20 20 Wo Worst FCFS Resp Response

  • nse

Time Time Best Best FCF CFS 1 5 8 10 10 20 20 Wo Worst FCFS

32 85 8 31¼ 85 8 153 32 69½ 68 145 121 83½ 121 153 68 145 121¾

P1 8 56 P2 P3 P4 P1 P3 P4 P1 P3 P4 P1 P3 P1 P3 P3 P3 16 24 32 40 48 64 72 80 88 96 104 112 P1 P3 P1 120 128 133 141149 P3 153

80 8 85 56 57¼ 133 16 153 80 95½ 84 22 85 57 62 137 30 153 81 100½ 82 20 85 58 61¼ 82 10 85 68 61¼ 72 20 85 88 66¼ 135 28 153 82 99½ 135 18 153 92 99½ 125 28 153 112 104½

slide-23
SLIDE 23

Shortest Task First (SJF) Scheduling

  • Could we always mirror best FCFS?
  • Shortest Task First (SJF)
  • Run task that has least amount of computation to do
  • Sometimes called “Shortest Time to Completion First” (STCF)
  • Shortest Remaining Time First (SRTF)
  • Preemptive version of SJF: If task arrives and has shorter time to completion

than remaining time on current task, immediately preempt current task

  • Sometimes called “Shortest Remaining Time to Completion First” (SRTCF)
  • These can be applied to whole program or current CPU burst
  • Key idea: get short tasks out of system
  • Big effect on short tasks, only small effect on long ones
  • Better average response time
slide-24
SLIDE 24

SJF/SRTF Optimality

  • SJF/SRTF minimize average response time! Why?
  • Consider alternative policy P (not SJF/SRTF) that is optimal
  • At some point, P chooses to run task that is not the shortest
  • Keep order of tasks the same, but run the shorter task first
  • This reduces average response time ⇒ contradiction!
slide-25
SLIDE 25

SJF/SRTF Discussion

  • SJF/SRTF are best you can do to minimize average response time
  • Provably optimal (SJF among non-preemptive, SRTF among preemptive)
  • Since SRTF is always at least as good as SJF, we can just focus on SRTF
  • Comparison of SRTF with FCFS
  • What if all tasks are the same length?
  • SRTF ⇒ FCFS (i.e., FCFS is best we can do if all tasks have the same length)
  • What if tasks have varying length?
  • Unlike FCFS, with SRTF, short tasks do not get stuck behind long ones
slide-26
SLIDE 26

Mix of CPU and I/O Bound Tasks: FCFS vs. RR vs. SRTF

  • Example: Suppose there are three tasks
  • A and B are both CPU bound with CPU bursts that last for a week
  • C is I/O bound with iterations of 1ms CPU burst followed by 9ms I/O burst
  • If A or B run by themselves, CPU utilization is 100% and I/O utilization is 0%
  • If C runs by itself, CPU utilization is 10% and I/O utilization is 90%
  • With happens under FCFS scheduling policy?
  • Once A or B get in, keep CPU for two weeks ⇒ poor avg. response time
  • What about RR or SRTF?
  • Easier to see with a timeline

Computation A and B : Computation I/O C :

slide-27
SLIDE 27

Mix of CPU and I/O Bound Tasks: FCFS vs. RR vs. SRTF (cont.)

RR with 40m 40ms time quantum

A B A B

CPU I/O

I/O Utilization: ~11%

RR with 1m 1ms time quantum CPU I/O

C,A,B,A,B,A,B,A,B,A, B

SR SRTF

A

CPU I/O

A A A A A A A A A A A A A A A

I/O Utilization: ~82% I/O Utilization: ~90%

,C,A,B,A,…

slide-28
SLIDE 28

Downsides of SRTF

  • Starvation: Large tasks may never run if short ones keep coming
  • Overhead: Short tasks preempt long ones ⇒ too many context switches
  • Unfair: Large tasks are penalized, there is high variance in response time
  • Impractical: We need to somehow predict future (but how?)
  • Some systems ask users
  • When you submit your task, you have to say how long it will take
  • Users could maliciously misreport length of their task
  • E.g., would it work if a supermarket uses SJF?
  • Customers could game the system: come with one item at a time
  • To prevent cheating, systems may kill tasks if they take too long
  • It’s hard to predict task’s runtime even for non-malicious users
slide-29
SLIDE 29

Predicting Length of Next CPU Burst

  • Adaptive: Dynamically make predictions based on past behavior
  • Works because programs have predictable behavior
  • If program was I/O bound in past, it’ll likely be I/O bound in future
  • If behavior were random, this approach wouldn’t help
  • Example: Use estimator function on previous bursts
  • Let tn-1, tn-2, tn-3, …, t1 be previous CPU burst lengths
  • Estimate next burst tn = f(tn-1, tn-2, tn-3, …)
  • Function f could be any time series estimator (e.g., Kalman filters, etc.)
  • For instance, exponential averaging tn = atn-1+(1-a)tn-1 with (0 < a £ 1)
slide-30
SLIDE 30

Aside: Application Types

  • Can we use past burst times to identify application types?
  • Consider mix of interactive and high-throughput programs
  • How to best schedule them?
  • How to recognize one from the other?
  • Do you trust applications to say that they are “interactive”?
  • Should you schedule the set of applications identically on servers,

workstations, pads, and cellphones?

slide-31
SLIDE 31

Aside: Application Types (cont.)

  • Assumptions encoded into many schedulers
  • Applications that sleep a lot and have short bursts must be interactive
  • Give them high priority
  • Applications that compute a lot must be high-throughput apps
  • Give them lower priority, since they won’t notice intermittent bursts from

interactive applications

  • In general, it is hard to characterize applications
  • What about applications that sleep for a long time, and then compute

for a long time?

  • What about applications that must run under all circumstances
slide-32
SLIDE 32

SRTF Final Notes

  • Bottom line, we can’t really know how long tasks will take
  • However, we can use SRTF as yardstick for measuring other policies
  • Optimal, so we can’t do any better
  • Pros & cons of SRTF
  • Optimal (average response time) (+)
  • Hard to predict future (-)
  • Too many context switches (-)
  • Unfair (-)
slide-33
SLIDE 33

Strict Priority Scheduling

  • Execution plan
  • Always execute highest-priority runnable tasks to completion
  • Each queue can be threaded in RR with some time-quantum
  • Notice any problems?
  • Starvation: Lower priority tasks don’t get to run because higher priority tasks
  • Deadlock: Priority inversion
  • Not strictly a problem with priority scheduling, but happens when low priority

task has lock needed by high-priority task

  • Usually involves third, intermediate priority task that keeps running even though

high-priority task should be running

Priority 3 Priority 2 Priority 1 Priority 0 Task 5 Task 6 Task 1 Task 2 Task 3 Task 7 Task 4

slide-34
SLIDE 34

Strict Priority Scheduling (cont.)

  • How to fix problems?
  • Dynamic priorities – adjust base-level priority up or down

based on heuristics about interactivity, locking, burst behavior, etc…

Priority 3 Priority 2 Priority 1 Priority 0 Task 5 Task 6 Task 1 Task 2 Task 3 Task 7 Task 4

slide-35
SLIDE 35

Scheduling Fairness

  • Strict fixed-priority scheduling between queues is unfair

(run highest, then next, etc.)

  • long running tasks may never get any CPU time
  • In Multics, shut down machine, found 10-year-old task
  • One approach: Give each queue some fraction of CPU
  • What if there are 100 short tasks and only one long task?
  • Like express lanes in a supermarket, sometimes express lanes get so long, get

better service by going into one of other lines

  • Another approach: Increase priority of tasks that don’t get service
  • What is done in some variants of UNIX
  • This is ad hoc; what rate should you increase priorities?
  • And, as system gets overloaded, no task gets CPU time, so everyone increases

in priority Þ Interactive tasks suffer

  • Tradeoff: Fairness is usually gained by hurting average response time!
slide-36
SLIDE 36

Multi-Level Feedback Queue Scheduling

  • Another method for exploiting past behavior (first use in CTSS)
  • Multiple queues, each with different priority
  • Higher priority queues often considered “foreground” tasks
  • Each queue has its own scheduling algorithm
  • E.g. foreground – RR, background – FCFS
  • Sometimes multiple RR priorities with quantum increasing exponentially

(highest:1ms, next: 2ms, next: 4ms, etc.)

  • Adjust each task’s priority as follows (details vary)
  • Task starts in highest priority queue
  • If timeout expires, drop one level
  • If timeout doesn’t expire, push up one level (or to top)

Long-Running compute tasks are demoted to lower priority queues

slide-37
SLIDE 37

Multi-Level Feedback Queue Scheduling (cont.)

  • Result approximates SRTF
  • CPU bound tasks drop like a rock
  • Short-running I/O bound tasks stay near top
  • Scheduling must be done between queues
  • Fixed priority scheduling
  • Serve all from highest priority, then next priority, etc.
  • Time slicing
  • Each queue gets fraction of CPU time
  • E.g., 70% to highest, 20% next, 10% lowest
slide-38
SLIDE 38

Multi-Level Feedback Queue Scheduling (cont.)

  • Countermeasure: user action that foil intent of OS designers
  • For multilevel feedback, put simple I/O’s to keep task’s priority high
  • Example of MIT Othello Contest
  • Cheater put printf’s, ran much faster than competitors!
  • Of course, if everyone did this, wouldn’t work!
slide-39
SLIDE 39

Lottery Scheduling

  • Give each task some number of lottery tickets
  • On each time slice, randomly pick a winning ticket
  • On average, CPU time is proportional to # of tickets given to task
  • How to assign tickets?
  • Give tasks tickets proportional to their priorities
  • To approximate SRTF, give short tasks more and long tasks fewer
  • To avoid starvation, give every task at least one ticket

(everyone makes progress)

  • Compared to strict priority scheduling, lottery scheduling behaves

gracefully as load changes

  • Adding or deleting one task affects all tasks proportionally, independent of

how many tickets each task possesses

slide-40
SLIDE 40

Lottery Scheduling Example

  • Assume short tasks get 10 tickets, long tasks get 1 ticket
  • What if too many short tasks to give reasonable response time?
  • If load average is 100, hard to make progress
  • One approach is to log some users out

# short tasks/ # long tasks % of CPU each short tasks gets % of CPU each long tasks gets 1/1 91% 9% 0/2 N/A 50% 2/0 50% N/A 10/1 9.9% 0.99% 1/10 50% 5%

slide-41
SLIDE 41

Max-Min Fair (MMF) Scheduling

  • Always choose task with lowest accumulated CPU time so far
  • If chosen task doesn’t have CPU burst, schedule second lowest …
  • Break ties randomly if multiple tasks equally have lowest CPU time
  • Goal is to give each task equal share of CPU time
  • With N runnable threads, each thread should get 1/Nth of CPU time
  • At any time t we want to have

Accumulated CPU Time

T1 T2 T3

t/N

slide-42
SLIDE 42

MMF Scheduling (cont.)

  • Strict MMF causes too many context switches
  • It effectively turns to running one instruction of each task
  • Relaxed MMF runs task with lowest accumulated CPU time

for fixed time quantum before choosing next task

  • Notice any problem?
  • Fixed quantum leads to poor response time as # of tasks increases

Accumulated CPU Time

T1 T2 T3

slide-43
SLIDE 43

MMF Scheduling (cont.)

  • Solution: Dynamically change time quantum
  • Target latency: Time interval during which all tasks should run at least once
  • Time quantum = Target latency / N
  • E.g., with 20ms target latency and 4 threads, time quantum is 5ms
  • Notice any problem?
  • With 20ms target latency and 200 threads, time quantum becomes 0.1ms
  • Recall RR: Large context switching overhead if time quantum gets to small
  • Minimum granularity: Minimum length of any time quantum
  • E.g., with target latency 20ms, 1ms minimum granularity, and 200 processes,

time quantum is1ms

slide-44
SLIDE 44

Weighted Max-Min Fair Scheduling

  • What if we want to give more to some and less to others (proportional share)?
  • Key Idea: Assign weight wi to each thread i
  • MMF uses single time quantum for all tasks
  • Weighted MMF uses different time quanta for different tasks
  • E.g., with 20ms target latency, 1ms minimum granularity, and 2 threads: A with

weight 1 and B with weight 4

  • Time quantum for A is 4 ms
  • Time quantum for B is 16 ms

Q = Target latency N

<latexit sha1_base64="Bp7uKwkGRlLTpYf8DBXScxD+og=">ACDHicbVC7SgNBFL3rKxpfUubwQdYhV1RTCNEbKxEwSRCEmR2cjcOzj6YuSuGZcHWxl+xEVTE1g+w8x/8CeJha8LwxzOZeZc/xESUOu+6MjI6NTxQmp4rTM7Nz86WFxbqJUy2wJmIV61OfG1QywhpJUniaOShr7DhX+z39cYlaiPj6IR6CbZD3o1kIAUnS52Vo/ZLmsFmousRXhF2QnXSmOGEkenmeHebW5ZbdwbC/wPsCq9VK+aOw9hAfnZXeWp1YpCFGJBQ3pum5CbUzrkKhXmxlRpMuLjgXWxaGPEQTsbhMnZumU6LIi1PRGxAft9I+OhMb3Qt86Q07n5rfXJ/7RmSkGlnckoSfvRhg8FqWIUs34zrCM1ClI9C7jQ0v6ViXNumyHbX9GW4P2O/BfUN8veVn72Laxdw2DmYRlWIEN8GAHqnAR1ADATdwB4/w5Nw6986z8zK0jDG5bgxzivnwsenwM=</latexit>

Qi = wi × Target latency PN

j=1 wj

<latexit sha1_base64="s2rhlR4NJ97YiUH+ygDrFrFBNhM=">ACKXicbVBNSxBEK1Ro2aTmFGPuTSRQE6bGTHoRVgRgidRcFXY2Qw9vTVra8H3TXq0gzk13jxj3jwYiCiXvMfArmldzeHRH3Q1O9KrqJaWShoLg3puYnHoxPTP7svHq9Zu5t/78wr4pKi2wLQpV6MOEG1QyxzZJUnhYauRZovAgOdkc+genqI0s8j0alNjNeD+XqRScnBT7rd1YsnUWpZoLe+Z4RDJD4wqek93juo/EFCfMxaCubWSqLbH62H91W7XZ/FxHftLQTMYgT0l4V+y1Pry62rK/R7J/a/R71CVBnmJBQ3phMGJXUt1ySFwroRVQZLk54HzuO5tyt07WjS2v2wSk9lhbavZzYSP13wvLMmEGWuM6M05F57A3F57xORela18q8rIanj9K8WoYMPYWE9qFKQGjnChpduViSPuQiMXbsOFED4+SnZX26GK83Puy6NjW8wiy8g/fwEUJYhRZswQ60QcAFXMPuPUuvRvznsYt054wqL8B+8n38AN/Gr/Q=</latexit>
slide-45
SLIDE 45

Weighted MMF Scheduling (cont.)

  • Also track threads’ virtual runtime rather than their true wall-clock runtime
  • Higher weight: Virtual runtime increases more slowly
  • Lower weight: Virtual runtime increases more quickly
  • Linux Completely Fair Scheduler deploys very similar ideas

Actual CPU Time B A 16 4 Virtual CPU Time B A 1 1

slide-46
SLIDE 46

Real-Time Scheduling (RTS)

  • Efficiency is important but predictability is essential
  • We need to predict with confidence worst case response times for systems
  • In RTS, performance guarantees are task and/or class centric and often ensured a priori
  • In conventional systems, performance is system/throughput oriented with post-

threading (… wait and see …)

  • Real-time is about enforcing predictability, and does not equal fast computing!!!
  • Hard real-time
  • Attempt to meet all deadlines
  • EDF (Earliest Deadline First), LLF (Least Laxity First),

RMS (Rate-Monotonic Scheduling), DM (Deadline Monotonic Scheduling)

  • Soft real-time
  • Attempt to meet deadlines with high probability
  • Minimize miss ratio / maximize completion ratio (firm real-time)
  • Important for multimedia applications
  • CBS (Constant Bandwidth Server)
slide-47
SLIDE 47

Real-Time Workload Characteristics

  • Tasks are preemptable, independent with arbitrary arrival (=release) times
  • Tasks have deadlines (D) and known computation times (C)
  • Example Setup:

A1 C1 D1 A2 C2 D2 A3 C3 D3 A4 C4 D4

T1 T2 T3 T4

slide-48
SLIDE 48

Real-Time Workload Characteristics

  • Tasks are preemptable, independent with arbitrary arrival (=release) times
  • Tasks have deadlines (D) and known computation times (C)
  • Example Setup:

Mi Missed De Deadline ne!

A1 D1 A2 D2 A3 D3 A4 D4

T1 T2 T3 T4 Time

slide-49
SLIDE 49

Earliest Deadline First (EDF)

  • Tasks are periodic with period P and computation C in each period: (P

, C)

  • Preemptive priority-based dynamic scheduling
  • Tasks’ (current) priority is based on how close their deadline is
  • Scheduler always schedules active task with closest deadline

5 10 15 T1: (4, 1) T2: (5, 2) T3: (7, 2)

slide-50
SLIDE 50

EDF: Feasibility Testing

  • Even EDF won't work if you have too many tasks
  • For n periodic tasks with computation time Ci and

deadline and period Di, feasible schedule exists if

n

X

i=1

⇣ Ci Di ⌘ ≤ 1

<latexit sha1_base64="st17TGMTLx+7D6ANxutsWcePDu8=">ACFnicbVDLSgMxFM34rPU16tJNsCh1YZlRDdCsQriqoJ9QKcOmThmYyQ5IRyjBf4cYf8CPcuFDErbhz5Ye4MX0stPXAvRzOuZfkHi9iVCrL+jSmpmdm5+YzC9nFpeWVXNtvSrDWGBSwSELRd1DkjDKSUVRxUg9EgQFHiM1r1vq+7VbIiQN+bXqRaQZoDanPsVIack19xwZB25CT+z0JuGpc0rbecXCcl6bJmW59bRc6jEDbNXNWwRoAThJ7RHLFy2/2tdN9KLvmh9MKcRwQrjBDUjZsK1LNBAlFMSNp1okliRDuojZpaMpRQGQzGZyVwm2tKAfCl1cwYH6eyNBgZS9wNOTAVIdOe71xf+8Rqz842ZCeRQrwvHwIT9mUIWwnxFsUGwYj1NEBZU/xXiDtKhKJ1kVodgj58Sar7BfugcHil0zgHQ2TAJtgCeWCDI1AEF6AMKgCDO/AInsGLcW8Ga/G23B0yhjtbIA/MN5/ANkzouY=</latexit>
slide-51
SLIDE 51

How to Evaluate Scheduling Algorithms?

  • Deterministic modeling
  • Take predetermined workload and compute performance of each algorithm
  • Queueing models
  • Mathematical approach for handling stochastic workloads
  • Implementation/Simulation:
  • Build system which allows actual algorithms to be run against actual data –

most flexible/general

slide-52
SLIDE 52

Starvation and Sample Bias

  • Suppose you want to compare scheduling policies
  • Create some infinite sequence of arriving tasks
  • Start measuring
  • Stop at some point
  • Compute ART for finished tasks between start and stop
  • Is this valid or invalid?
  • SJF and FCFS would complete different sets of tasks
  • Their ARTs are not directly comparable
  • E.g., suppose you stopped at any point in FCFS vs. SJF slide
slide-53
SLIDE 53

Solutions for Sample Bias

  • For both systems, measure for long enough that

# of completed tasks >> # of uncompleted tasks

  • Start and stop system in idle periods
  • Idle period: no work to do
  • If algorithms are work-conserving, both will complete the

same set of tasks

slide-54
SLIDE 54

Choosing Right Scheduling Algorithm

I Care About: Then Choose: CPU Throughput FCFS

  • Avg. Response Time

SRTF Approximation I/O Throughput SRTF Approximation Fairness (CPU Time) Linux CFS Fairness – Wait Time to Get CPU Round Robin Meeting Deadlines EDF Favoring Important Tasks Priority

slide-55
SLIDE 55

Outline

  • Definitions
  • Response time, throughput, scheduling policy, …
  • Uniprocessor policies
  • FCFS, SJF/SRTF, Round Robin, …
  • Real-time scheduling
  • Multiprocessor policies
  • Oblivious scheduling, gang scheduling, …
slide-56
SLIDE 56

Multicore Processor Scheduling

  • There could be one ready queue for all cores
  • Notice any problems?
  • Single bottleneck: Contention for ready queue’s lock
  • Limited cache reuse: Lack of data locality as tasks get

scheduled on different cores

  • Solution: each core has its own private ready queue
  • Notice any problems?
  • Load balancing: Some cores might be idle

while tasks pile up on others ready queues

  • One solution: Work stealing
  • Idle cores steal waiting task from busy ones

T4 T3 T2 T1

Core 2 Core 3 Core 1 Core 4

T3 T2 T1 T4 T8 T7 T6 T5

Core 2 Core 3 Core 1 Core 4

slide-57
SLIDE 57

Processor Affinity

  • When task run on core, cache contents of that core stores recent

memory accesses by that task

  • This is referred to as core affinity of tasks
  • Load balancing may affect core affinity as task migrate between cores
  • Performance of migrated task suffers because it loses contents of what it

had in cache of the core it was moved off of

  • Migration is justified only if performance loss is less than waiting time
  • Soft affinity: OS tries to keep tasks on same core, but no guarantees
  • Hard affinity: OS allows tasks to specify set of cores they may run on
slide-58
SLIDE 58

NUMA and CPU Scheduling

  • Uniform memory access (UMA): Cores

experience same, uniform access time to any memory module

  • Non-uniform memory access (NUMA):

Cores access their local memory modules faster than remote memory modules

  • If OS is NUMA-aware, it will assign memory

closes to core that task is running on

Local access

Photos from: http://www.evoventurepartners.com

Remote access

slide-59
SLIDE 59

Scheduling Multithreaded Programs

  • So far, we assumed that there is one thread per program
  • Now, consider scheduling multithreaded programs on multicore processor
  • At any given time, multiple threads from same program could be running
  • Oblivious scheduling: Cores independently schedule threads in their queue
  • Each thread is treated as independent task
  • What happens if one thread gets time-sliced while others are still running?
  • Assuming program uses locks and condition variables, it will still be correct
  • Performance, however, could suffer if threads actually depend on one another

Core 1 Core 2 Core 3

Time

P1.1 P2.3 P3.1 P2.1 P3.2 P2.4 P1.2 P1.3 P2.2

Px.y: thread y in process x

slide-60
SLIDE 60

Problem with Oblivious Scheduling: Bulk Synchronous Delay

  • Data parallelism is common programming design pattern

(e.g., Google MapReduce)

  • Data is split into roughly equal sized chunks
  • Chunks are processed independently on different cores
  • Once all chunks are processed, cores synchronize and communicate their

results to next stage of computation

Photo from cs.calvin.edu

slide-61
SLIDE 61

Problem with Oblivious Scheduling: Bulk Synchronous Delay (cont.)

  • At each step, computation is limited by the slowest task
  • If task is preempted on one core, its work is delayed, stalling all other cores

Photo from cs.calvin.edu

Core 1 Core 2 Core 3

Time Synchronization Synchronization Communication

slide-62
SLIDE 62

Problem with Oblivious Scheduling: Producer-Consumer Delay

  • Producer-consumer design patter is also very common
  • Preempting a thread on one core stalls all others in the chain
  • Some other problems with oblivious scheduling
  • Preempting a thread on the critical path will slow down the entire process
  • Preempting lock holder stalls others until lock holder is re-scheduled

Core 1 Core 2 Core 3

Thread 1 Thread 2 Thread 3

slide-63
SLIDE 63

Gang Scheduling

  • Time is divided into equal intervals
  • Threads from same process are scheduled at beginning of each interval
  • Notice any problems?
  • CPU cycles are waisted when threads have different lengths
  • Some cores remain idle when a process doesn’t have enough tasks for all cores

P1.4 P2.3 P3.1 P2.1 P3.2 P2.4 P1.2 P1.3 P2.2

Core 1 Core 2 Core 3

Time

slide-64
SLIDE 64

Space Sharing

  • Each process is assigned a subset of cores
  • Minimizes processor context switches

T1 T5 T6 T2 T4 T3 T7 Core 1 Core 2 Core 3

Time

Core 4 Core 4 Core 5 T1 T6 T2 T4 T3 T5 T7

Process 1 Process 2

slide-65
SLIDE 65

How Many Cores Does a Process Need?

  • There are overheads
  • E.g., creating extra threads, synchronization, communication
  • Overheads shift the curve down

Number of Processors Performance (Inverse Response Time)

Perfectly Parallel Diminishing Returns Limited Parallelism

slide-66
SLIDE 66

Amdahl’s Law

[G. Amdahl 1967]

  • Architects use it to estimate upper bounds on speedups

Speedup(x) = T1 Tx = T1 (1 − F)T1 + F T1

x

= x x(1 − F) + F

<latexit sha1_base64="imSh03zMRHEJkMcJ1Tt4d09R8=">ACQnicbVBNaxsxEJ1N0yZ13NZNjrmImoJNqNntpc0hYFIwPTrEjkNt42rl2URE+4E0W9Ys+96R/IrX+glx7SEMgph8prF1InDyTevHnDSM9PlDTkuj+dtSfrT59tbD6vbFVfvHxVe719YuJUC+yLWMX61OcGlYywT5IUniYaegrHPgXn+b9wTfURsZRj2YJjkN+FslACk5WmtS+jAgzyo8TxGmaNLJmwQ7YKNBc5L2JV9grKw7u1Q3vXadp2d5C65RiVvzZLYoLXudYlKruy23BHtIvCWptw+rt18BoDupXY6msUhDjEgobszQcxMa51yTFAqLyig1mHBxwc9waGnEQzTjvMygYG+tMmVBrO2JiJXq/Ymch8bMQt86Q07nZrU3Fx/rDVMKPo5zGSUpYSQWi4JUMYrZPFA2lRoFqZklXGhp38rEObdhkI29YkPwVr/8kPTft/Zb7pENow0LbMIuvIEGePAB2vAZutAHAd/hF1zBH+eH89u5dm4W1jVnObMD/8G5+wsT4rIe</latexit><latexit sha1_base64="xID0c1Tbn8/aMShHBgtOGCWxg=">ACQnicbVDLSgMxFM34tr6qLt0ERaiIZcaNuhCKQnGpaFVsS8mkdzQ08yC5I1OG+QM/wk9x4w+48wfcuFARXLkwnSr4OpBw7rncpPjRlJotO17a2BwaHhkdGy8MDE5NT1TnJ071mGsONR4KEN16jINUgRQ4ESTiMFzHclnLid3V7/5BKUFmFwhN0Imj47D4QnOEMjtYpnDYQE08MIoB1HpWQlo9u04SnG06OWk5kryba/1SVnrbpi2Gpfq+Zikn15ElPkltVq1iou2WU7B/1LnE+yVNmZfGMvV9f7reJdox3y2IcAuWRa1x07wmbKFAouISs0Yg0R4x12DnVDA+aDbqZ5BhldNkqbeqEyJ0Caq98nUuZr3fVd4/QZXujfvZ74X68eo7fZTEUQxQgB7y/yYkxpL1AaVso4Ci7hjCuhHkr5RfMhIEm9oIJwfn95b+ktl7eKtsHJowK6WOMLJBFUiIO2SAVskf2SY1wckMeyBN5tm6tR+vFeu1bB6zPmXnyA9b7B+ZJtDw=</latexit><latexit sha1_base64="xID0c1Tbn8/aMShHBgtOGCWxg=">ACQnicbVDLSgMxFM34tr6qLt0ERaiIZcaNuhCKQnGpaFVsS8mkdzQ08yC5I1OG+QM/wk9x4w+48wfcuFARXLkwnSr4OpBw7rncpPjRlJotO17a2BwaHhkdGy8MDE5NT1TnJ071mGsONR4KEN16jINUgRQ4ESTiMFzHclnLid3V7/5BKUFmFwhN0Imj47D4QnOEMjtYpnDYQE08MIoB1HpWQlo9u04SnG06OWk5kryba/1SVnrbpi2Gpfq+Zikn15ElPkltVq1iou2WU7B/1LnE+yVNmZfGMvV9f7reJdox3y2IcAuWRa1x07wmbKFAouISs0Yg0R4x12DnVDA+aDbqZ5BhldNkqbeqEyJ0Caq98nUuZr3fVd4/QZXujfvZ74X68eo7fZTEUQxQgB7y/yYkxpL1AaVso4Ci7hjCuhHkr5RfMhIEm9oIJwfn95b+ktl7eKtsHJowK6WOMLJBFUiIO2SAVskf2SY1wckMeyBN5tm6tR+vFeu1bB6zPmXnyA9b7B+ZJtDw=</latexit>
slide-67
SLIDE 67

Amdahl’s Law (cont.)

[G. Amdahl 1967]

Speedup(x) = T1 Tx = T1 (1 − F)T1 + F T1

x

= x x(1 − F) + F

<latexit sha1_base64="imSh03zMRHEJkMcJ1Tt4d09R8=">ACQnicbVBNaxsxEJ1N0yZ13NZNjrmImoJNqNntpc0hYFIwPTrEjkNt42rl2URE+4E0W9Ys+96R/IrX+glx7SEMgph8prF1InDyTevHnDSM9PlDTkuj+dtSfrT59tbD6vbFVfvHxVe719YuJUC+yLWMX61OcGlYywT5IUniYaegrHPgXn+b9wTfURsZRj2YJjkN+FslACk5WmtS+jAgzyo8TxGmaNLJmwQ7YKNBc5L2JV9grKw7u1Q3vXadp2d5C65RiVvzZLYoLXudYlKruy23BHtIvCWptw+rt18BoDupXY6msUhDjEgobszQcxMa51yTFAqLyig1mHBxwc9waGnEQzTjvMygYG+tMmVBrO2JiJXq/Ymch8bMQt86Q07nZrU3Fx/rDVMKPo5zGSUpYSQWi4JUMYrZPFA2lRoFqZklXGhp38rEObdhkI29YkPwVr/8kPTft/Zb7pENow0LbMIuvIEGePAB2vAZutAHAd/hF1zBH+eH89u5dm4W1jVnObMD/8G5+wsT4rIe</latexit><latexit sha1_base64="xID0c1Tbn8/aMShHBgtOGCWxg=">ACQnicbVDLSgMxFM34tr6qLt0ERaiIZcaNuhCKQnGpaFVsS8mkdzQ08yC5I1OG+QM/wk9x4w+48wfcuFARXLkwnSr4OpBw7rncpPjRlJotO17a2BwaHhkdGy8MDE5NT1TnJ071mGsONR4KEN16jINUgRQ4ESTiMFzHclnLid3V7/5BKUFmFwhN0Imj47D4QnOEMjtYpnDYQE08MIoB1HpWQlo9u04SnG06OWk5kryba/1SVnrbpi2Gpfq+Zikn15ElPkltVq1iou2WU7B/1LnE+yVNmZfGMvV9f7reJdox3y2IcAuWRa1x07wmbKFAouISs0Yg0R4x12DnVDA+aDbqZ5BhldNkqbeqEyJ0Caq98nUuZr3fVd4/QZXujfvZ74X68eo7fZTEUQxQgB7y/yYkxpL1AaVso4Ci7hjCuhHkr5RfMhIEm9oIJwfn95b+ktl7eKtsHJowK6WOMLJBFUiIO2SAVskf2SY1wckMeyBN5tm6tR+vFeu1bB6zPmXnyA9b7B+ZJtDw=</latexit><latexit sha1_base64="xID0c1Tbn8/aMShHBgtOGCWxg=">ACQnicbVDLSgMxFM34tr6qLt0ERaiIZcaNuhCKQnGpaFVsS8mkdzQ08yC5I1OG+QM/wk9x4w+48wfcuFARXLkwnSr4OpBw7rncpPjRlJotO17a2BwaHhkdGy8MDE5NT1TnJ071mGsONR4KEN16jINUgRQ4ESTiMFzHclnLid3V7/5BKUFmFwhN0Imj47D4QnOEMjtYpnDYQE08MIoB1HpWQlo9u04SnG06OWk5kryba/1SVnrbpi2Gpfq+Zikn15ElPkltVq1iou2WU7B/1LnE+yVNmZfGMvV9f7reJdox3y2IcAuWRa1x07wmbKFAouISs0Yg0R4x12DnVDA+aDbqZ5BhldNkqbeqEyJ0Caq98nUuZr3fVd4/QZXujfvZ74X68eo7fZTEUQxQgB7y/yYkxpL1AaVso4Ci7hjCuhHkr5RfMhIEm9oIJwfn95b+ktl7eKtsHJowK6WOMLJBFUiIO2SAVskf2SY1wckMeyBN5tm6tR+vFeu1bB6zPmXnyA9b7B+ZJtDw=</latexit>
slide-68
SLIDE 68

s(x) = x x(1 − F) + F

<latexit sha1_base64="f9zvgM5Q2UJUMFw6UwOFcXKIc=">ACAXicbVDLSgNBEOyNrxhfU+ih8EgJIh14t6UAKB4DGCawLJEmYns8mQ2Qczs5KwBC/+ihcPKl79C2/e/BQnj4MmFjQUVd10d7kRZ1KZ5peRWlhcWl5Jr2bW1jc2t7LbO3cyjAWhNgl5KOoulpSzgNqKU7rkaDYdzmtub3yK/dUyFZGNyqQUQdH3cC5jGClZa2T2Z7xfQJWp6ApOkP0z6eukUjiuDFvZnFk0x0DzxJqSXOnqoPwNANVW9rPZDkns0ARjqVsWGaknAQLxQinw0wzljTCpIc7tKFpgH0qnWT8whAdaWNvFDoChQaq78nEuxLOfBd3elj1ZWz3kj8z2vEyjt3EhZEsaIBmSzyYo5UiEZ5oDYTlCg+0AQTwfStiHSxDkPp1DI6BGv25XlinxYviuaNDqME6RhHw4hDxacQmuoQo2EHiAJ3iBV+PReDbejPdJa8qYzuzCHxgfP08slyY=</latexit><latexit sha1_base64="1dLfmWgM0V+igOTyOMlAIZgrtE=">ACAXicbVDLSsNAFJ34rPUVdSWKDBahRSxJN+pCKRSKywrWFtpQJ9NJO3QyCTMTaQnBjb/ixoWKW/CnR/gfzh9LT1wIXDOfdy7z1uyKhUlvVlzM0vLC4tp1bSq2vrG5vm1vatDCKBSRUHLB1F0nCKCdVRUj9VAQ5LuM1NxeaejX7omQNOA3ahASx0cdTj2KkdJSy9yV2X4OXsCmJxCO+0ncz9on5dxOWmZGStvjQBniT0hmeLlfum7cHBXaZmfzXaAI59whRmSsmFboXJiJBTFjCTpZiRJiHAPdUhDU458Ip149EICj7TShl4gdHEFR+rviRj5Ug58V3f6SHXltDcU/MakfLOnJjyMFKE4/EiL2JQBXCYB2xTQbBiA0QFlTfCnEX6TCUTi2tQ7CnX54l1UL+PG9d6zCKYIwU2AOHIAtscAqK4ApUQBVg8ACewAt4NR6NZ+PNeB+3zhmTmR3wB8bHD0Awl9s=</latexit><latexit sha1_base64="1dLfmWgM0V+igOTyOMlAIZgrtE=">ACAXicbVDLSsNAFJ34rPUVdSWKDBahRSxJN+pCKRSKywrWFtpQJ9NJO3QyCTMTaQnBjb/ixoWKW/CnR/gfzh9LT1wIXDOfdy7z1uyKhUlvVlzM0vLC4tp1bSq2vrG5vm1vatDCKBSRUHLB1F0nCKCdVRUj9VAQ5LuM1NxeaejX7omQNOA3ahASx0cdTj2KkdJSy9yV2X4OXsCmJxCO+0ncz9on5dxOWmZGStvjQBniT0hmeLlfum7cHBXaZmfzXaAI59whRmSsmFboXJiJBTFjCTpZiRJiHAPdUhDU458Ip149EICj7TShl4gdHEFR+rviRj5Ug58V3f6SHXltDcU/MakfLOnJjyMFKE4/EiL2JQBXCYB2xTQbBiA0QFlTfCnEX6TCUTi2tQ7CnX54l1UL+PG9d6zCKYIwU2AOHIAtscAqK4ApUQBVg8ACewAt4NR6NZ+PNeB+3zhmTmR3wB8bHD0Awl9s=</latexit>

What Portion of Code is Parallelizable?

[Allen Karp and Horace Flatt 1990]

  • Expert programmers may not know!
  • Fortunately, we can measure speedup

Set Measure Calculate

  • Fig. criticallyrated.files.wordpress.com

F = ✓ 1 − 1 s(x) ◆ ✓ 1 − 1 x ◆

<latexit sha1_base64="qQhtE3fpWsvIxujU0fqbhIg71I=">ACJnicbZDJSgNBEIZrXGPcoh69NAYhORhmvKgHJSCIxwhGhUwIPZ2epLFnobtGDEOewZfw4lt49iK4IN58FDubaGJBw8/VFdvxdLodG2P62p6ZnZufnMQnZxaXlNbe2fqGjRDFeZGM1JVHNZci5FUKPlVrDgNPMkvevjHr+84UqLKDzHTszrAW2FwheMorEauaMTckhcyX0sODuryhLnW6qC7fFrqtEq43FESU75IfjmAjl7dLdr/IpHCGIl8+utOPAFBp5F7cZsSgIfIJNW65tgx1lOqUDJu1k30Tym7Jq2eM3IkAZc19P+nV2ybZwm8SNlXoik7/6eSGmgdSfwTGdAsa3HWc/8j9US9PfrqQjBHnIBov8RBKMSC80hSKM5QdIyhTwvyVsDY1YaCJNmtCcMZPnhTV3dJByT4zYZRhUBnYhC0ogAN7UIZTqEAVGNzDE7zCm/VgPVv1segdcoazmzAn7K+vgHN5qaN</latexit><latexit sha1_base64="IW7xTh2dAWm/jzJBCq+Se9Ukx08=">ACJnicbZDLSsNAFIYn9VbrLerSzWAR6sKSuFEXloIgLhWMCk0pk+mkHTq5MHMiLSHP0Jdw41vo1o3gBXHng7hw2lrxdmDg5/O4cz5vVhwBZb1auQmJqemZ/Kzhbn5hcUlc3nlTEWJpMyhkYjkhUcUEzxkDnAQ7CKWjASeYOde52DAzy+ZVDwKT6EXs3pAWiH3OSWgrYZOcT72BXMh5K95fqS0NTOUlXqbmau5K02bI4p3sJfvDuGDbNola1h4b/C/hTFaqWvbm7f+8cN8FtRjQJWAhUEKVqthVDPSUSOBUsK7iJYjGhHdJiNS1DEjBVT4d3ZnhDO03sR1K/EPDQ/T6RkCpXuDpzoBAW/1mA/M/VkvA362nPIwTYCEdLfITgSHCg9Bwk0tGQfS0IFRy/VdM20SHATrag7B/n3yX+Fsl/fK1okOo4pGlUdraB2VkI12UBUdoWPkIqu0B16RE/GtXFvPBsvo9ac8Tmzin6U8fYB3YGo2Q=</latexit><latexit sha1_base64="IW7xTh2dAWm/jzJBCq+Se9Ukx08=">ACJnicbZDLSsNAFIYn9VbrLerSzWAR6sKSuFEXloIgLhWMCk0pk+mkHTq5MHMiLSHP0Jdw41vo1o3gBXHng7hw2lrxdmDg5/O4cz5vVhwBZb1auQmJqemZ/Kzhbn5hcUlc3nlTEWJpMyhkYjkhUcUEzxkDnAQ7CKWjASeYOde52DAzy+ZVDwKT6EXs3pAWiH3OSWgrYZOcT72BXMh5K95fqS0NTOUlXqbmau5K02bI4p3sJfvDuGDbNola1h4b/C/hTFaqWvbm7f+8cN8FtRjQJWAhUEKVqthVDPSUSOBUsK7iJYjGhHdJiNS1DEjBVT4d3ZnhDO03sR1K/EPDQ/T6RkCpXuDpzoBAW/1mA/M/VkvA362nPIwTYCEdLfITgSHCg9Bwk0tGQfS0IFRy/VdM20SHATrag7B/n3yX+Fsl/fK1okOo4pGlUdraB2VkI12UBUdoWPkIqu0B16RE/GtXFvPBsvo9ac8Tmzin6U8fYB3YGo2Q=</latexit>

Karp-Flatt Metric

?

slide-69
SLIDE 69

A Final Word On Scheduling

  • When do details of scheduling policy and fairness really matter?
  • When there aren’t enough resources to go around
  • When should you simply buy faster cores?

(Or network link, or expanded highway, or …)

  • Buy it when it will pay for itself in improved response time,

assuming you’re paying for worse response time in reduced productivity, customer angst, etc…

  • Might think you need X fully utilized core, but usually

you will have to buy more than X because response time goes to infinity as utilization approaches100%

  • Interesting implication of this curve
  • Most scheduling algorithms work fine in linear portion of curve, fail otherwise
  • Argues for buying faster resources when hit knee of curve

Utilization Response time

100%

slide-70
SLIDE 70

Summary (1 of 2)

  • First-Come, First-Served (FCFS)
  • Threads are served in the order of their arrival
  • Round-Robin (RR)
  • Give each thread a small amount of CPU time when it executes; cycle

between all ready threads

  • Shortest Task First (SJF) / Shortest Remaining Time First (SRTF):
  • Run whatever task that has the least amount of computation to do/least

remaining amount of computation to do

  • Multi-level Feedback Queue (MFQ)
  • Multiple queues of different priorities and scheduling algorithms
  • Lottery Scheduling
  • Give each thread a priority-dependent number of tickets
slide-71
SLIDE 71

Summary (2 of 2)

  • Max-Min Fair (MMF)
  • Give each task equal share of CPU time
  • Real-Time Scheduling
  • Need to meet a deadline, predictability essential
  • Oblivious Scheduling
  • Each core schedules its own threads
  • Gang Scheduling
  • Schedule tasks from same process at the same time
  • Space Sharing
  • Give each process some number of cores
slide-72
SLIDE 72

Questions?

globaldigitalcitizen.org

slide-73
SLIDE 73

Acknowledgment

  • Slides by courtesy of Anderson, Culler, Stoica,

Silberschatz, Joseph, and Canny