SlideShare a Scribd company logo
1 of 41
Plan for Today
• Course Schedule Update
• Norvig Numbers
• Priority Pre-Emptive Scheduling
• Lottery Scheduling
• Stride Scheduling
• What Linux Does (“Completely Fair
Scheduler”)
3 October 2013 University of Virginia cs4414 1
Course Schedule
Original (Syllabus)
PS1: Simple server (10 Sept)
PS2: Shell (24 Sept)
PS3: Web server (10 Oct)
Midterm (10 Oct)
PS4: IceBox (5 Nov)
Project: Open (5 Dec)
Revised
PS1: zhttpto (10 Sept)
PS2: gash (30 Sept + demos)
3 October 2013 University of Virginia cs4414 2
Today is 3 Oct and PS3 is not yet out!
Course Schedule
Original (Syllabus)
PS1: Simple server (10 Sept)
PS2: Shell (24 Sept)
PS3: Web server (10 Oct)
Midterm (10 Oct)
PS4: IceBox (5 Nov)
Project: Open (5 Dec)
Revised
PS1: zhttpto (10 Sept)
PS2: gash (30 Sept + demos)
Midterm (due 14 Oct)
PS3: zhtta (due 28 Oct)
Project: open (due 5 Dec)
3 October 2013 University of Virginia cs4414 3
Note: if you already have a great idea for a project that will be more
worthwhile for you than PS3, you can make a case for doing that
instead of PS3 also.
Oh no…what can we possibly do
with no Problem Set to work on?
3 October 2013 University of Virginia cs4414 4
3 October 2013 University of Virginia cs4414 5
From Class 3…
3 October 2013 University of Virginia cs4414 6
Updating the “Norvig Numbers”
• We don’t just want the numbers, we want programs
that can produce the number.
• Combined efforts and talents of this class should be
able to make a really useful list (and learn a lot)
• Post in Piazza forum with details
– Everyone should contribute something
– Can work in teams of any size (1-60+, but larger teams
should make more interesting contributions)
– Claim and justify a number you will contribute (and then,
start working on the program to do it) – First Come, First
Serve
3 October 2013 University of Virginia cs4414 7
Example
Kernel Timer Interval (Wil Thomason has dibs
on this one!)
Why programmers should care about this
Program that estimates its value
Result for some machine today
3 October 2013 University of Virginia cs4414 8
Another example (also not on Norvig’s list):
Time to Switch Tasks
https://github.com/brson/rust-sched-bench/blob/master/coroutine-call.rs
Scheduling
3 October 2013 University of Virginia cs4414 9
Pre-emptive Priority Scheduling
• Always run the highest priority process that is
ready to run
• Round-robin schedule among equally high,
ready to run, highest-priority processes
3 October 2013 University of Virginia cs4414 10
P 629 P 124Priority 0:
P 528Priority 1:
P 44Priority 2: P 815 P 516
Waiting:
Memory Read P 131
Network Data P 221
Shared Bus P 1209
3 October 2013 University of Virginia cs4414 11
Mars Curiosity (2012)
3 October 2013 University of Virginia cs4414 12
Mars Pathfinder (1997)
Pathfinder OS:
Pre-emptive Priority Scheduling
• Always run the highest priority process that is
ready to run
• Round-robin schedule among equally high,
ready to run, highest-priority processes
3 October 2013 University of Virginia cs4414 13
CPU
SharedBus
Radio
Camera
Flash
MemoryActuators
Priority Inversion
3 October 2013 University of Virginia cs4414 14
Task 1 (scheduler) – highest priority (Priority = 1)
Task 2 (send data) – (Priority = 4)
Task 3 (science analysis) – lowest priority (Priority = 97)
CPU
SharedBus
Radio
Camera
Flash
MemoryActuators
How should we solve
priority inversion?
3 October 2013 University of Virginia cs4414 15
3 October 2013 University of Virginia cs4414 16
Priority 0:
P 528Priority 1:
P 44Priority 2: P 815 P 516
Waiting:
Memory Read P 131
Network Data P 221
Shared Bus P 1209 PRI: 0
Holds Bus Lock
Priority
3 October 2013 University of Virginia cs4414 17
Should my MacBook use a priority pre-emptive scheduler
with priority inheritance?
Kinds of Processes
“Compute-Bound”
3 October 2013 University of Virginia cs4414 18
P1
“I/O-Bound”
P2 wait for disk… P2 wait for network… P2 wait for user…
“Real Time”
P3
need frame ^ need frame ^ need frame ^ need frame ^
P3 P3 P3
3 October 2013 University of Virginia cs4414 19
Carl Waldspurger
Lottery Scheduling
3 October 2013 University of Virginia cs4414 20
Lottery Scheduling
• Each user (process) gets a share of the “tickets”
– e.g., 1000 total tickets, 20 processes each get 50
tickets (or more/less weighted by priority)
• User/process can distribute tickets however it
wants
– Among its own threads, can “loan” to other processes’
threads
• Scheduler: randomly picks a ticket
– Associated thread gets to run for that time slice
3 October 2013 University of Virginia cs4414 21
Silly aside: what does “A/B” mean in English?
Do not use “/” except to mean divide
3 October 2013 University of Virginia cs4414 22
“The University of Virginia is an
equal opportunity/affirmative action
employer.”
On 10/2/13 3:56 PM, [name removed] wrote:
> Mr. Evans,
> The forward slash is commonly used to represent "and" in this context.
“…the accommodation the employee and/or the employee’s
doctor/medical professional believe will enable the employee to
perform the essential functions of the position. The employee
should provide his/her doctor/medical professional with the
definition of a disability…”
Priority Pre-Emptive Lottery Scheduling
3 October 2013 University of Virginia cs4414 23
3 October 2013 University of Virginia cs4414 24
3 October 2013 University of Virginia cs4414 25
3 October 2013 University of Virginia cs4414 26
What is the running time?
> uname -a
Linux power2 3.2.0-49-generic #75-Ubuntu SMP Tue Jun 18 17:39:32
UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
> sysctl kernel.pid_max
kernel.pid_max = 32768
Linux Scheduler before V2.6 (2002)
• Three types of processes:
#define SCHED_OTHER 0
#define SCHED_FIFO 1
#define SCHED_RR 2
• Not pre-emptive: only user-level processes
could be pre-empted
• Select next process according to “goodness”
function
3 October 2013 University of Virginia cs4414 27
Normal user processes
Non-prementable
Real-time round-robin
3 October 2013 University of Virginia cs4414 28
/* linux/kernel/sched.c
* This is the function that decides how desirable a process is.
* You can weigh different processes against each other depending
* on what CPU they've run on lately etc to try to handle cache
* and TLB miss penalties.
*
* Return values:
* -1000: never select this
* 0: out of time, recalculate counters (but it might still
* be
* selected)
* +ve: "goodness" value (the larger, the better)
* +1000: realtime process, select this.
*/
static inline int goodness(struct task_struct * p, int this_cpu, struct
mm_struct *this_mm)
{
int weight;
/*
* Realtime process, select the first one on the
* runqueue (taking priorities within processes
* into account).
*/
if (p->policy != SCHED_OTHER) {
weight = 1000 + p->rt_priority;
goto out;
}
/*
* Give the process a first-approximation goodness value
* according to the number of clock-ticks it has left.
*
* Don't do any other calculations if the time slice is
* over..
*/
weight = p->counter;
if (!weight)
goto out;
#ifdef __SMP__
/* Give a largish advantage to the same processor... */
/* (this is equivalent to penalizing other processors) */
if (p->processor == this_cpu)
weight += PROC_CHANGE_PENALTY;
#endif
/* .. and a slight advantage to the current MM */
if (p->mm == this_mm)
weight += 1;
weight += p->priority;
out:
return weight;
}
/* linux/kernel/sched.c
* This is the function that decides how desirable a process is.
* You can weigh different processes against each other depending
* on what CPU they've run on lately etc to try to handle cache
* and TLB miss penalties.
*
* Return values:
* -1000: never select this
* 0: out of time, recalculate counters (but it might still
* be
* selected)
* +ve: "goodness" value (the larger, the better)
* +1000: realtime process, select this.
*/
static inline int goodness(struct task_struct * p, int this_cpu,
struct mm_struct *this_mm)
{
…
3 October 2013 University of Virginia cs4414 29
static inline int goodness(struct task_struct * p, int this_cpu, struct mm_struct *this_mm)
{
int weight;
/* Realtime process, select the first one on the runqueue (taking priorities into account). */
if (p->policy != SCHED_OTHER) {
weight = 1000 + p->rt_priority;
goto out;
}
/* Give the process a first-approximation goodness value according to the number of clock-
ticks it has left. Don't do any other calculations if the time slice is over.. */
weight = p->counter;
if (!weight)
goto out;
#ifdef __SMP__
/* Give a largish advantage to the same processor... (equivalent to penalizing other
processors) */
if (p->processor == this_cpu)
weight += PROC_CHANGE_PENALTY;
#endif
/* .. and a slight advantage to the current MM (memory segment) */
if (p->mm == this_mm) weight += 1;
weight += p->priority;
out:
return weight;
}
What is the running time of the
Linux 2.2-2.5 Scheduler?
3 October 2013 University of Virginia cs4414 30
3 October 2013 University of Virginia cs4414 31
It was called the “O(n) scheduler”
Linux 2.6 Scheduler (2003-2007)
• 140 different queues (for each processor)
– 0-99 for “real time” processes
– 100-139 for “normal” processes
• Bit vector keeps track of which queues have
ready to run process
• Scheduler picks first process from highest
priority queue with a ready process
– Give it time quantum that scales with priority
3 October 2013 University of Virginia cs4414 32
3 October 2013 University of Virginia cs4414 33
struct runqueue {
struct prioarray *active;
struct prioarray *expired;
struct prioarray arrays[2];
};
struct prioarray
{
int nr_active; /* # Runnable */
unsigned long bitmap[5];
struct list_head queue[140];
};
What is the running time of the
Linux 2.6 Scheduler?
3 October 2013 University of Virginia cs4414 34
3 October 2013 University of Virginia cs4414 35
(Sadly, O(1) scheduler has no Facebook page.)
Linux V2.6.23+ Scheduler
3 October 2013 University of Virginia cs4414 36
3 October 2013 University of Virginia cs4414 37
This is exactly stride scheduling (but with different terminology)!
Rotating Staircase Deadline Scheduler
3 October 2013 University of Virginia cs4414 38
What is the running time of the
Linux 2.6.23+ Scheduler?
Not called the O(log N) scheduler – by Linux 2.6.23 marketing
matters: “Completely Fair Scheduler”
3 October 2013 University of Virginia cs4414 39
What is log2 1 000 000?
Charge
• Claim your “Norvig Number” early!
– No penalty if you decide to switch later
• Stride scheduling works!
– Use it to manage your real life: much smarter than
priority pre-emptive (never finish anything) or
first-come first-served or earliest-deadline-first
– Unless you like to live serendipitously: then you
should use lottery scheduling
3 October 2013 University of Virginia cs4414 40

More Related Content

What's hot

Linux Performance Tools
Linux Performance ToolsLinux Performance Tools
Linux Performance ToolsBrendan Gregg
 
Segmentation Faults, Page Faults, Processes, Threads, and Tasks
Segmentation Faults, Page Faults, Processes, Threads, and TasksSegmentation Faults, Page Faults, Processes, Threads, and Tasks
Segmentation Faults, Page Faults, Processes, Threads, and TasksDavid Evans
 
Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Brendan Gregg
 
Making a Process (Virtualizing Memory)
Making a Process (Virtualizing Memory)Making a Process (Virtualizing Memory)
Making a Process (Virtualizing Memory)David Evans
 
Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBrendan Gregg
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)Brendan Gregg
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debuggingHao-Ran Liu
 
Intro to linux performance analysis
Intro to linux performance analysisIntro to linux performance analysis
Intro to linux performance analysisChris McEniry
 
What the &~#@<!? (Memory Management in Rust)
What the &~#@<!? (Memory Management in Rust)What the &~#@<!? (Memory Management in Rust)
What the &~#@<!? (Memory Management in Rust)David Evans
 
Bpf performance tools chapter 4 bcc
Bpf performance tools chapter 4   bccBpf performance tools chapter 4   bcc
Bpf performance tools chapter 4 bccViller Hsiao
 
Spying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitSpying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitAndrea Righi
 
Java Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsJava Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsBrendan Gregg
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudAndrea Righi
 
Linux monitoring and Troubleshooting for DBA's
Linux monitoring and Troubleshooting for DBA'sLinux monitoring and Troubleshooting for DBA's
Linux monitoring and Troubleshooting for DBA'sMydbops
 
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsTIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsXiaozhe Wang
 
Profiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf ToolsProfiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf ToolsemBO_Conference
 
SSL Failing, Sharing, and Scheduling
SSL Failing, Sharing, and SchedulingSSL Failing, Sharing, and Scheduling
SSL Failing, Sharing, and SchedulingDavid Evans
 

What's hot (20)

The Internet
The InternetThe Internet
The Internet
 
Linux Performance Tools
Linux Performance ToolsLinux Performance Tools
Linux Performance Tools
 
Segmentation Faults, Page Faults, Processes, Threads, and Tasks
Segmentation Faults, Page Faults, Processes, Threads, and TasksSegmentation Faults, Page Faults, Processes, Threads, and Tasks
Segmentation Faults, Page Faults, Processes, Threads, and Tasks
 
Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)
 
Making a Process (Virtualizing Memory)
Making a Process (Virtualizing Memory)Making a Process (Virtualizing Memory)
Making a Process (Virtualizing Memory)
 
Blazing Performance with Flame Graphs
Blazing Performance with Flame GraphsBlazing Performance with Flame Graphs
Blazing Performance with Flame Graphs
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
 
Linux kernel debugging
Linux kernel debuggingLinux kernel debugging
Linux kernel debugging
 
Managing Memory
Managing MemoryManaging Memory
Managing Memory
 
Intro to linux performance analysis
Intro to linux performance analysisIntro to linux performance analysis
Intro to linux performance analysis
 
What the &~#@<!? (Memory Management in Rust)
What the &~#@<!? (Memory Management in Rust)What the &~#@<!? (Memory Management in Rust)
What the &~#@<!? (Memory Management in Rust)
 
Bpf performance tools chapter 4 bcc
Bpf performance tools chapter 4   bccBpf performance tools chapter 4   bcc
Bpf performance tools chapter 4 bcc
 
Spying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitSpying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profit
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Java Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame GraphsJava Performance Analysis on Linux with Flame Graphs
Java Performance Analysis on Linux with Flame Graphs
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloud
 
Linux monitoring and Troubleshooting for DBA's
Linux monitoring and Troubleshooting for DBA'sLinux monitoring and Troubleshooting for DBA's
Linux monitoring and Troubleshooting for DBA's
 
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsTIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
 
Profiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf ToolsProfiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf Tools
 
SSL Failing, Sharing, and Scheduling
SSL Failing, Sharing, and SchedulingSSL Failing, Sharing, and Scheduling
SSL Failing, Sharing, and Scheduling
 

Similar to Smarter Scheduling

Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing ToolsSysdig
 
Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing ToolsBrendan Gregg
 
Window scheduling algorithm
Window scheduling algorithmWindow scheduling algorithm
Window scheduling algorithmBinal Parekh
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2PgTraining
 
When the OS gets in the way
When the OS gets in the wayWhen the OS gets in the way
When the OS gets in the wayMark Price
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling gopi7
 
Operating System 5
Operating System 5Operating System 5
Operating System 5tech2click
 
Cpu scheduling(suresh)
Cpu scheduling(suresh)Cpu scheduling(suresh)
Cpu scheduling(suresh)Nagarajan
 
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...David Evans
 
Priority Scheduling.pptx
Priority Scheduling.pptxPriority Scheduling.pptx
Priority Scheduling.pptxSarupyaDatta1
 
Process management in os
Process management in osProcess management in os
Process management in osMiong Lazaro
 
Operating Systems Third Unit - Fourth Semester - Engineering
Operating Systems Third Unit  - Fourth Semester - EngineeringOperating Systems Third Unit  - Fourth Semester - Engineering
Operating Systems Third Unit - Fourth Semester - EngineeringYogesh Santhan
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.pptKeyreSebre
 
Preemptive process example.pptx
Preemptive process example.pptxPreemptive process example.pptx
Preemptive process example.pptxjamilaltiti1
 
Unit iios process scheduling and synchronization
Unit iios process scheduling and synchronizationUnit iios process scheduling and synchronization
Unit iios process scheduling and synchronizationdonny101
 
Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Nagarajan
 
LoadBalancing .pptx
LoadBalancing .pptxLoadBalancing .pptx
LoadBalancing .pptxalianwarr
 

Similar to Smarter Scheduling (20)

Os2
Os2Os2
Os2
 
Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing Tools
 
Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing Tools
 
Window scheduling algorithm
Window scheduling algorithmWindow scheduling algorithm
Window scheduling algorithm
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2
 
When the OS gets in the way
When the OS gets in the wayWhen the OS gets in the way
When the OS gets in the way
 
Ch05
Ch05Ch05
Ch05
 
cpu sechduling
cpu sechduling cpu sechduling
cpu sechduling
 
Operating System 5
Operating System 5Operating System 5
Operating System 5
 
Cpu scheduling(suresh)
Cpu scheduling(suresh)Cpu scheduling(suresh)
Cpu scheduling(suresh)
 
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...
 
Priority Scheduling.pptx
Priority Scheduling.pptxPriority Scheduling.pptx
Priority Scheduling.pptx
 
Process management in os
Process management in osProcess management in os
Process management in os
 
Operating Systems Third Unit - Fourth Semester - Engineering
Operating Systems Third Unit  - Fourth Semester - EngineeringOperating Systems Third Unit  - Fourth Semester - Engineering
Operating Systems Third Unit - Fourth Semester - Engineering
 
chapter 5 CPU scheduling.ppt
chapter  5 CPU scheduling.pptchapter  5 CPU scheduling.ppt
chapter 5 CPU scheduling.ppt
 
Preemptive process example.pptx
Preemptive process example.pptxPreemptive process example.pptx
Preemptive process example.pptx
 
Cpu Scheduling Galvin
Cpu Scheduling GalvinCpu Scheduling Galvin
Cpu Scheduling Galvin
 
Unit iios process scheduling and synchronization
Unit iios process scheduling and synchronizationUnit iios process scheduling and synchronization
Unit iios process scheduling and synchronization
 
Scheduling algorithm (chammu)
Scheduling algorithm (chammu)Scheduling algorithm (chammu)
Scheduling algorithm (chammu)
 
LoadBalancing .pptx
LoadBalancing .pptxLoadBalancing .pptx
LoadBalancing .pptx
 

More from David Evans

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!David Evans
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksDavid Evans
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeDavid Evans
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in BitcoinDavid Evans
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm ConfirmationsDavid Evans
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting TransactionsDavid Evans
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in ParadiseDavid Evans
 
Mining Economics
Mining EconomicsMining Economics
Mining EconomicsDavid Evans
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More ParanoidDavid Evans
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key SignaturesDavid Evans
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to CryptographyDavid Evans
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?David Evans
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the MassesDavid Evans
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of ReserveDavid Evans
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!David Evans
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinDavid Evans
 

More from David Evans (20)

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero Knowledge
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in Bitcoin
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm Confirmations
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting Transactions
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in Paradise
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
 
Mining Economics
Mining EconomicsMining Economics
Mining Economics
 
Mining
MiningMining
Mining
 
The Blockchain
The BlockchainThe Blockchain
The Blockchain
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key Signatures
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the Masses
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
 
Silk Road
Silk RoadSilk Road
Silk Road
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, Permacoin
 

Recently uploaded

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 

Recently uploaded (20)

Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

Smarter Scheduling

  • 1.
  • 2. Plan for Today • Course Schedule Update • Norvig Numbers • Priority Pre-Emptive Scheduling • Lottery Scheduling • Stride Scheduling • What Linux Does (“Completely Fair Scheduler”) 3 October 2013 University of Virginia cs4414 1
  • 3. Course Schedule Original (Syllabus) PS1: Simple server (10 Sept) PS2: Shell (24 Sept) PS3: Web server (10 Oct) Midterm (10 Oct) PS4: IceBox (5 Nov) Project: Open (5 Dec) Revised PS1: zhttpto (10 Sept) PS2: gash (30 Sept + demos) 3 October 2013 University of Virginia cs4414 2 Today is 3 Oct and PS3 is not yet out!
  • 4. Course Schedule Original (Syllabus) PS1: Simple server (10 Sept) PS2: Shell (24 Sept) PS3: Web server (10 Oct) Midterm (10 Oct) PS4: IceBox (5 Nov) Project: Open (5 Dec) Revised PS1: zhttpto (10 Sept) PS2: gash (30 Sept + demos) Midterm (due 14 Oct) PS3: zhtta (due 28 Oct) Project: open (due 5 Dec) 3 October 2013 University of Virginia cs4414 3 Note: if you already have a great idea for a project that will be more worthwhile for you than PS3, you can make a case for doing that instead of PS3 also.
  • 5. Oh no…what can we possibly do with no Problem Set to work on? 3 October 2013 University of Virginia cs4414 4
  • 6. 3 October 2013 University of Virginia cs4414 5 From Class 3…
  • 7. 3 October 2013 University of Virginia cs4414 6
  • 8. Updating the “Norvig Numbers” • We don’t just want the numbers, we want programs that can produce the number. • Combined efforts and talents of this class should be able to make a really useful list (and learn a lot) • Post in Piazza forum with details – Everyone should contribute something – Can work in teams of any size (1-60+, but larger teams should make more interesting contributions) – Claim and justify a number you will contribute (and then, start working on the program to do it) – First Come, First Serve 3 October 2013 University of Virginia cs4414 7
  • 9. Example Kernel Timer Interval (Wil Thomason has dibs on this one!) Why programmers should care about this Program that estimates its value Result for some machine today 3 October 2013 University of Virginia cs4414 8 Another example (also not on Norvig’s list): Time to Switch Tasks https://github.com/brson/rust-sched-bench/blob/master/coroutine-call.rs
  • 10. Scheduling 3 October 2013 University of Virginia cs4414 9
  • 11. Pre-emptive Priority Scheduling • Always run the highest priority process that is ready to run • Round-robin schedule among equally high, ready to run, highest-priority processes 3 October 2013 University of Virginia cs4414 10 P 629 P 124Priority 0: P 528Priority 1: P 44Priority 2: P 815 P 516 Waiting: Memory Read P 131 Network Data P 221 Shared Bus P 1209
  • 12. 3 October 2013 University of Virginia cs4414 11 Mars Curiosity (2012)
  • 13. 3 October 2013 University of Virginia cs4414 12 Mars Pathfinder (1997)
  • 14. Pathfinder OS: Pre-emptive Priority Scheduling • Always run the highest priority process that is ready to run • Round-robin schedule among equally high, ready to run, highest-priority processes 3 October 2013 University of Virginia cs4414 13 CPU SharedBus Radio Camera Flash MemoryActuators
  • 15. Priority Inversion 3 October 2013 University of Virginia cs4414 14 Task 1 (scheduler) – highest priority (Priority = 1) Task 2 (send data) – (Priority = 4) Task 3 (science analysis) – lowest priority (Priority = 97) CPU SharedBus Radio Camera Flash MemoryActuators
  • 16. How should we solve priority inversion? 3 October 2013 University of Virginia cs4414 15
  • 17. 3 October 2013 University of Virginia cs4414 16 Priority 0: P 528Priority 1: P 44Priority 2: P 815 P 516 Waiting: Memory Read P 131 Network Data P 221 Shared Bus P 1209 PRI: 0 Holds Bus Lock
  • 18. Priority 3 October 2013 University of Virginia cs4414 17 Should my MacBook use a priority pre-emptive scheduler with priority inheritance?
  • 19. Kinds of Processes “Compute-Bound” 3 October 2013 University of Virginia cs4414 18 P1 “I/O-Bound” P2 wait for disk… P2 wait for network… P2 wait for user… “Real Time” P3 need frame ^ need frame ^ need frame ^ need frame ^ P3 P3 P3
  • 20. 3 October 2013 University of Virginia cs4414 19 Carl Waldspurger
  • 21. Lottery Scheduling 3 October 2013 University of Virginia cs4414 20
  • 22. Lottery Scheduling • Each user (process) gets a share of the “tickets” – e.g., 1000 total tickets, 20 processes each get 50 tickets (or more/less weighted by priority) • User/process can distribute tickets however it wants – Among its own threads, can “loan” to other processes’ threads • Scheduler: randomly picks a ticket – Associated thread gets to run for that time slice 3 October 2013 University of Virginia cs4414 21 Silly aside: what does “A/B” mean in English?
  • 23. Do not use “/” except to mean divide 3 October 2013 University of Virginia cs4414 22 “The University of Virginia is an equal opportunity/affirmative action employer.” On 10/2/13 3:56 PM, [name removed] wrote: > Mr. Evans, > The forward slash is commonly used to represent "and" in this context. “…the accommodation the employee and/or the employee’s doctor/medical professional believe will enable the employee to perform the essential functions of the position. The employee should provide his/her doctor/medical professional with the definition of a disability…”
  • 24. Priority Pre-Emptive Lottery Scheduling 3 October 2013 University of Virginia cs4414 23
  • 25. 3 October 2013 University of Virginia cs4414 24
  • 26. 3 October 2013 University of Virginia cs4414 25
  • 27. 3 October 2013 University of Virginia cs4414 26 What is the running time? > uname -a Linux power2 3.2.0-49-generic #75-Ubuntu SMP Tue Jun 18 17:39:32 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux > sysctl kernel.pid_max kernel.pid_max = 32768
  • 28. Linux Scheduler before V2.6 (2002) • Three types of processes: #define SCHED_OTHER 0 #define SCHED_FIFO 1 #define SCHED_RR 2 • Not pre-emptive: only user-level processes could be pre-empted • Select next process according to “goodness” function 3 October 2013 University of Virginia cs4414 27 Normal user processes Non-prementable Real-time round-robin
  • 29. 3 October 2013 University of Virginia cs4414 28 /* linux/kernel/sched.c * This is the function that decides how desirable a process is. * You can weigh different processes against each other depending * on what CPU they've run on lately etc to try to handle cache * and TLB miss penalties. * * Return values: * -1000: never select this * 0: out of time, recalculate counters (but it might still * be * selected) * +ve: "goodness" value (the larger, the better) * +1000: realtime process, select this. */ static inline int goodness(struct task_struct * p, int this_cpu, struct mm_struct *this_mm) { int weight; /* * Realtime process, select the first one on the * runqueue (taking priorities within processes * into account). */ if (p->policy != SCHED_OTHER) { weight = 1000 + p->rt_priority; goto out; } /* * Give the process a first-approximation goodness value * according to the number of clock-ticks it has left. * * Don't do any other calculations if the time slice is * over.. */ weight = p->counter; if (!weight) goto out; #ifdef __SMP__ /* Give a largish advantage to the same processor... */ /* (this is equivalent to penalizing other processors) */ if (p->processor == this_cpu) weight += PROC_CHANGE_PENALTY; #endif /* .. and a slight advantage to the current MM */ if (p->mm == this_mm) weight += 1; weight += p->priority; out: return weight; } /* linux/kernel/sched.c * This is the function that decides how desirable a process is. * You can weigh different processes against each other depending * on what CPU they've run on lately etc to try to handle cache * and TLB miss penalties. * * Return values: * -1000: never select this * 0: out of time, recalculate counters (but it might still * be * selected) * +ve: "goodness" value (the larger, the better) * +1000: realtime process, select this. */ static inline int goodness(struct task_struct * p, int this_cpu, struct mm_struct *this_mm) { …
  • 30. 3 October 2013 University of Virginia cs4414 29 static inline int goodness(struct task_struct * p, int this_cpu, struct mm_struct *this_mm) { int weight; /* Realtime process, select the first one on the runqueue (taking priorities into account). */ if (p->policy != SCHED_OTHER) { weight = 1000 + p->rt_priority; goto out; } /* Give the process a first-approximation goodness value according to the number of clock- ticks it has left. Don't do any other calculations if the time slice is over.. */ weight = p->counter; if (!weight) goto out; #ifdef __SMP__ /* Give a largish advantage to the same processor... (equivalent to penalizing other processors) */ if (p->processor == this_cpu) weight += PROC_CHANGE_PENALTY; #endif /* .. and a slight advantage to the current MM (memory segment) */ if (p->mm == this_mm) weight += 1; weight += p->priority; out: return weight; }
  • 31. What is the running time of the Linux 2.2-2.5 Scheduler? 3 October 2013 University of Virginia cs4414 30
  • 32. 3 October 2013 University of Virginia cs4414 31 It was called the “O(n) scheduler”
  • 33. Linux 2.6 Scheduler (2003-2007) • 140 different queues (for each processor) – 0-99 for “real time” processes – 100-139 for “normal” processes • Bit vector keeps track of which queues have ready to run process • Scheduler picks first process from highest priority queue with a ready process – Give it time quantum that scales with priority 3 October 2013 University of Virginia cs4414 32
  • 34. 3 October 2013 University of Virginia cs4414 33 struct runqueue { struct prioarray *active; struct prioarray *expired; struct prioarray arrays[2]; }; struct prioarray { int nr_active; /* # Runnable */ unsigned long bitmap[5]; struct list_head queue[140]; };
  • 35. What is the running time of the Linux 2.6 Scheduler? 3 October 2013 University of Virginia cs4414 34
  • 36. 3 October 2013 University of Virginia cs4414 35 (Sadly, O(1) scheduler has no Facebook page.)
  • 37. Linux V2.6.23+ Scheduler 3 October 2013 University of Virginia cs4414 36
  • 38. 3 October 2013 University of Virginia cs4414 37 This is exactly stride scheduling (but with different terminology)! Rotating Staircase Deadline Scheduler
  • 39. 3 October 2013 University of Virginia cs4414 38 What is the running time of the Linux 2.6.23+ Scheduler? Not called the O(log N) scheduler – by Linux 2.6.23 marketing matters: “Completely Fair Scheduler”
  • 40. 3 October 2013 University of Virginia cs4414 39 What is log2 1 000 000?
  • 41. Charge • Claim your “Norvig Number” early! – No penalty if you decide to switch later • Stride scheduling works! – Use it to manage your real life: much smarter than priority pre-emptive (never finish anything) or first-come first-served or earliest-deadline-first – Unless you like to live serendipitously: then you should use lottery scheduling 3 October 2013 University of Virginia cs4414 40

Editor's Notes

  1. http://www.linuxjournal.com/article/3910