SlideShare a Scribd company logo
Smarter
Scheduling
(Priorities)
Plan for Today
Recap: Scheduling
First Come, First Served / Round-Robin
Priorities
Lottery and Stride Scheduling
Scheduling in Linux
1
Wil Thomason

2
Recap
Main Goals of Scheduling
Maximize Resource Use
Fairness
Switching is Expensive
Fundamental tradeoff between
maximizing usage and fairness
3
Planned vs. On-Demand
Planned: schedule in advance
Supervisor/developer plans schedule given
a priori knowledge about all tasks and deadlines
On-Demand: schedule on-the-fly
Supervisor runs periodically and makes
decision based on current information
Where is planned used?

4
Real-Time Systems
Hard Real-Time
Missing a deadline is a
total system failure.

Soft Real-Time
Undesirable to miss too
many deadlines too badly.

5
Hard Real-Time
Missing a deadline is a
total system failure.

Soft Real-Time
Undesirable to miss too
many deadlines too badly.

6
What must programs be able to do
to have guaranteed schedules?

7
Planned vs. On-Demand
Planned: schedule in advance
Necessary (at least in part)
for hard real time
On-Demand: schedule on-the-fly
Most normal systems have unpredictable
tasks with unknown deadlines
8
What should your courses be?

9
What should your courses be?
Exam 2 will be scheduled later (not next week)
Problem Set 3 is due 11:59pm Wednesday, March 5
Demos on Wednesday, Thursday, Friday
No demos after Spring Break barring snow-out
(firm real-time deadline)
But…if you planned a schedule around the previously posted
deadlines, you can stick to them (see me after class)

10
Scheduling Strategies
First Come, First Served (FIFO)
P1

P2

P3

(effectively: non-preemptive multi-processing)

11
First Come, First Served (FIFO)
P2

P1

P3

(effectively: non-preemptive multi-processing)

Round-Robin
P1

P2

Time Slice

P3

P1

P2

P3

P1

P3

P1

P3

Blocked

Each process gets to run for a set time slice, or until it finished or gets blocked.

12
Comparison
First Come, First Served

Round Robin

13
Which one is my laptop using?

14
Priorities
More important processes: “higher priority”
(except Linux inverts priority values!)
Highest priority = 0
gets most preferential treatment
Lowest priority = 99
highest number varies by Linux flavor
15
High Priority Processes
ps -w -e -o pri,pid,pcpu,vsz,cputime,command
| sort -n -r --key=5 | sort --stable -n --key=1

16
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
Priority 0:

P 629

Priority 1:

P 44

Memory Read

P 815

P 516

P 131

Network Data

P 528

Priority 2:

Waiting:

P 124

P 221

Shared Bus

P 1209
17
Mars Curiosity (2012)

18
Mars
Pathfinder
(1997)

19
Pathfinder OS: Pre-emptive Priority
Always run the highest priority process that is
ready to run
Round-robin schedule among equally high, ready to
run, highest-priority processes

Actuators

Shared Bus

CPU

Radio
Camera
Flash
Memory
20
Priority Inversion
Task 1 (scheduler) – highest priority (Priority = 1)
Task 2 (send data) – (Priority = 4)
Task 3 (science analysis) – lowest priority (Priority = 97)

Actuators

Shared Bus

CPU

Radio
Camera
Flash
Memory
21
How should we solve
priority inversion?

22
Waiting:

Priority 0:

Priority 1:

P 44
Holds Bus Lock

P 815

P 516

P 131

Network Data

P 528

Priority 2:

Memory Read

P 221

Shared Bus

P 1209

PRI: 0

23
Should my MacBook use a priority pre-emptive scheduler with priority inheritance?

24
Should my MacBook use a priority pre-emptive scheduler with priority inheritance?

25
Kinds of Processes
“Compute-Bound”
P1

“I/O-Bound”
P2

wait for disk…

P2

wait for network…

P2

wait for user…

“Real Time”
P3
need frame ^

P3
need frame ^

P3
need frame ^

P3
need frame ^
26
Carl Waldspurger
27
Lottery Scheduling

28
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
29
Priority Pre-Emptive

Lottery Scheduling

30
31
32
What is the running time?

33
> 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

What is the running time?

34
Charge
Stride scheduling works (in real life also)!
Much smarter than priority pre-emptive (never finish
anything) or first-come first-served or earliest-deadlinefirst. (Unless you like to live serendipitously: then you
should use lottery scheduling)
Problem Set 3 should have high (but not
quite hard real-time) priority! (and try to
turn off interrupts when you work on it!)
35

More Related Content

What's hot (20)

PPT
Cp usched 2
nidsrajdev
 
PPSX
CPU Scheduling algorithms
Shanu Kumar
 
PPTX
CPU Scheduling Algorithms
Tayba Farooqui
 
PPTX
CPU scheduling algorithms in OS
harini0810
 
PPT
9 cm402.19
myrajendra
 
PDF
5 Process Scheduling
Dr. Loganathan R
 
PDF
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Universitas Pembangunan Panca Budi
 
PPT
first come first serve scheduling in os
mikeemukesh
 
PPTX
scheduling algorithm
nitish sandhawar
 
PPTX
PPT CPU
Arun kumar
 
PPTX
Cpu scheduling
Abhijith Reloaded
 
PDF
Process Scheduling
International Islamic University
 
PPT
cpu scheduling OS
Kiran Kumar Thota
 
PPTX
Scheduling algorithms
Paurav Shah
 
PPTX
Operating system
Lovly Angel
 
PPTX
Scheduling algo(by HJ)
Harshit Jain
 
PDF
Operating Systems 1 (10/12) - Scheduling
Peter Tröger
 
DOCX
Cpu scheduling
marangburu42
 
PPTX
Process scheduling in Light weight weight and Heavy weight processes.
Shreya Kumar
 
PPT
First Come First Serve
Kavya Kapoor
 
Cp usched 2
nidsrajdev
 
CPU Scheduling algorithms
Shanu Kumar
 
CPU Scheduling Algorithms
Tayba Farooqui
 
CPU scheduling algorithms in OS
harini0810
 
9 cm402.19
myrajendra
 
5 Process Scheduling
Dr. Loganathan R
 
Comparison Analysis of CPU Scheduling : FCFS, SJF and Round Robin
Universitas Pembangunan Panca Budi
 
first come first serve scheduling in os
mikeemukesh
 
scheduling algorithm
nitish sandhawar
 
PPT CPU
Arun kumar
 
Cpu scheduling
Abhijith Reloaded
 
cpu scheduling OS
Kiran Kumar Thota
 
Scheduling algorithms
Paurav Shah
 
Operating system
Lovly Angel
 
Scheduling algo(by HJ)
Harshit Jain
 
Operating Systems 1 (10/12) - Scheduling
Peter Tröger
 
Cpu scheduling
marangburu42
 
Process scheduling in Light weight weight and Heavy weight processes.
Shreya Kumar
 
First Come First Serve
Kavya Kapoor
 

Similar to Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling) (20)

PPTX
RTOS for Embedded systems and scheduling mechanisms
manomykv
 
PPTX
UNIPROCESS SCHEDULING.pptx
ansariparveen06
 
PDF
Distributed Operating System_2
Dr Sandeep Kumar Poonia
 
PPTX
Cpu scheduling algorithm on windows
siddhartha pande
 
PPT
Operating System Scheduling
Vishnu Prasad
 
PPTX
Smarter Scheduling
David Evans
 
PPT
Scheduling.ppt with operating system slides
lovepreet33653
 
PDF
Section05 scheduling
Venkatesh Chowdary Nagilla
 
PPTX
Operating Systems
Harshith Meela
 
PDF
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systems
knowdiff
 
PPT
CPU Scheduling
amadayshwan
 
PPT
CPU scheduling in Operating System Explanation
AnitaSofiaKeyser
 
PPT
06-scheduling.ppt including multiple CPUs
ssuserb53446
 
PPT
Planificacion
David Lilue
 
PPTX
Process and CPU Scheduling.pptx it is about Operating system
NishthaShah16
 
PDF
Lect07
Vin Voro
 
PPT
Operating Systems Process Scheduling Algorithms
sathish sak
 
PPT
dataprocess using different technology.ppt
ssuserf6eb9b
 
PPT
Cpu Scheduling Galvin
Sonali Chauhan
 
RTOS for Embedded systems and scheduling mechanisms
manomykv
 
UNIPROCESS SCHEDULING.pptx
ansariparveen06
 
Distributed Operating System_2
Dr Sandeep Kumar Poonia
 
Cpu scheduling algorithm on windows
siddhartha pande
 
Operating System Scheduling
Vishnu Prasad
 
Smarter Scheduling
David Evans
 
Scheduling.ppt with operating system slides
lovepreet33653
 
Section05 scheduling
Venkatesh Chowdary Nagilla
 
Operating Systems
Harshith Meela
 
Sara Afshar: Scheduling and Resource Sharing in Multiprocessor Real-Time Systems
knowdiff
 
CPU Scheduling
amadayshwan
 
CPU scheduling in Operating System Explanation
AnitaSofiaKeyser
 
06-scheduling.ppt including multiple CPUs
ssuserb53446
 
Planificacion
David Lilue
 
Process and CPU Scheduling.pptx it is about Operating system
NishthaShah16
 
Lect07
Vin Voro
 
Operating Systems Process Scheduling Algorithms
sathish sak
 
dataprocess using different technology.ppt
ssuserf6eb9b
 
Cpu Scheduling Galvin
Sonali Chauhan
 
Ad

More from David Evans (20)

PPTX
Cryptocurrency Jeopardy!
David Evans
 
PPTX
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
David Evans
 
PPTX
Hidden Services, Zero Knowledge
David Evans
 
PPTX
Anonymity in Bitcoin
David Evans
 
PPTX
Midterm Confirmations
David Evans
 
PPTX
Scripting Transactions
David Evans
 
PPTX
How to Live in Paradise
David Evans
 
PPTX
Bitcoin Script
David Evans
 
PPTX
Mining Economics
David Evans
 
PPTX
Mining
David Evans
 
PPTX
The Blockchain
David Evans
 
PPTX
Becoming More Paranoid
David Evans
 
PPTX
Asymmetric Key Signatures
David Evans
 
PPTX
Introduction to Cryptography
David Evans
 
PPTX
Class 1: What is Money?
David Evans
 
PPTX
Multi-Party Computation for the Masses
David Evans
 
PPTX
Proof of Reserve
David Evans
 
PPTX
Silk Road
David Evans
 
PPTX
Blooming Sidechains!
David Evans
 
PPTX
Useful Proofs of Work, Permacoin
David Evans
 
Cryptocurrency Jeopardy!
David Evans
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
David Evans
 
Hidden Services, Zero Knowledge
David Evans
 
Anonymity in Bitcoin
David Evans
 
Midterm Confirmations
David Evans
 
Scripting Transactions
David Evans
 
How to Live in Paradise
David Evans
 
Bitcoin Script
David Evans
 
Mining Economics
David Evans
 
Mining
David Evans
 
The Blockchain
David Evans
 
Becoming More Paranoid
David Evans
 
Asymmetric Key Signatures
David Evans
 
Introduction to Cryptography
David Evans
 
Class 1: What is Money?
David Evans
 
Multi-Party Computation for the Masses
David Evans
 
Proof of Reserve
David Evans
 
Silk Road
David Evans
 
Blooming Sidechains!
David Evans
 
Useful Proofs of Work, Permacoin
David Evans
 
Ad

Recently uploaded (20)

PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 

Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

  • 2. Plan for Today Recap: Scheduling First Come, First Served / Round-Robin Priorities Lottery and Stride Scheduling Scheduling in Linux 1
  • 4. Recap Main Goals of Scheduling Maximize Resource Use Fairness Switching is Expensive Fundamental tradeoff between maximizing usage and fairness 3
  • 5. Planned vs. On-Demand Planned: schedule in advance Supervisor/developer plans schedule given a priori knowledge about all tasks and deadlines On-Demand: schedule on-the-fly Supervisor runs periodically and makes decision based on current information Where is planned used? 4
  • 6. Real-Time Systems Hard Real-Time Missing a deadline is a total system failure. Soft Real-Time Undesirable to miss too many deadlines too badly. 5
  • 7. Hard Real-Time Missing a deadline is a total system failure. Soft Real-Time Undesirable to miss too many deadlines too badly. 6
  • 8. What must programs be able to do to have guaranteed schedules? 7
  • 9. Planned vs. On-Demand Planned: schedule in advance Necessary (at least in part) for hard real time On-Demand: schedule on-the-fly Most normal systems have unpredictable tasks with unknown deadlines 8
  • 10. What should your courses be? 9
  • 11. What should your courses be? Exam 2 will be scheduled later (not next week) Problem Set 3 is due 11:59pm Wednesday, March 5 Demos on Wednesday, Thursday, Friday No demos after Spring Break barring snow-out (firm real-time deadline) But…if you planned a schedule around the previously posted deadlines, you can stick to them (see me after class) 10
  • 12. Scheduling Strategies First Come, First Served (FIFO) P1 P2 P3 (effectively: non-preemptive multi-processing) 11
  • 13. First Come, First Served (FIFO) P2 P1 P3 (effectively: non-preemptive multi-processing) Round-Robin P1 P2 Time Slice P3 P1 P2 P3 P1 P3 P1 P3 Blocked Each process gets to run for a set time slice, or until it finished or gets blocked. 12
  • 14. Comparison First Come, First Served Round Robin 13
  • 15. Which one is my laptop using? 14
  • 16. Priorities More important processes: “higher priority” (except Linux inverts priority values!) Highest priority = 0 gets most preferential treatment Lowest priority = 99 highest number varies by Linux flavor 15
  • 17. High Priority Processes ps -w -e -o pri,pid,pcpu,vsz,cputime,command | sort -n -r --key=5 | sort --stable -n --key=1 16
  • 18. 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 Priority 0: P 629 Priority 1: P 44 Memory Read P 815 P 516 P 131 Network Data P 528 Priority 2: Waiting: P 124 P 221 Shared Bus P 1209 17
  • 21. Pathfinder OS: Pre-emptive Priority Always run the highest priority process that is ready to run Round-robin schedule among equally high, ready to run, highest-priority processes Actuators Shared Bus CPU Radio Camera Flash Memory 20
  • 22. Priority Inversion Task 1 (scheduler) – highest priority (Priority = 1) Task 2 (send data) – (Priority = 4) Task 3 (science analysis) – lowest priority (Priority = 97) Actuators Shared Bus CPU Radio Camera Flash Memory 21
  • 23. How should we solve priority inversion? 22
  • 24. Waiting: Priority 0: Priority 1: P 44 Holds Bus Lock P 815 P 516 P 131 Network Data P 528 Priority 2: Memory Read P 221 Shared Bus P 1209 PRI: 0 23
  • 25. Should my MacBook use a priority pre-emptive scheduler with priority inheritance? 24
  • 26. Should my MacBook use a priority pre-emptive scheduler with priority inheritance? 25
  • 27. Kinds of Processes “Compute-Bound” P1 “I/O-Bound” P2 wait for disk… P2 wait for network… P2 wait for user… “Real Time” P3 need frame ^ P3 need frame ^ P3 need frame ^ P3 need frame ^ 26
  • 30. 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 29
  • 32. 31
  • 33. 32
  • 34. What is the running time? 33
  • 35. > 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 What is the running time? 34
  • 36. Charge Stride scheduling works (in real life also)! Much smarter than priority pre-emptive (never finish anything) or first-come first-served or earliest-deadlinefirst. (Unless you like to live serendipitously: then you should use lottery scheduling) Problem Set 3 should have high (but not quite hard real-time) priority! (and try to turn off interrupts when you work on it!) 35