smarter scheduling (priorities, preemptive priority scheduling, lottery and stride scheduling)

36
cs4414 Fall 2013 David Evans Class 11 Smarter Scheduli ng (Priorit ies)

Upload: david-evans

Post on 05-Dec-2014

1.655 views

Category:

Technology


1 download

DESCRIPTION

University of Virginia cs4414: Operating Systems http://rust-class.org Scheduling Recap Real-Time Scheduling On-Demand vs. Planned Scheduling First Come, First Served Round-Robin Priorities Priority Preemptive Priority Inversion Lottery Scheduling Stride Scheduling For embedded notes, see: http://rust-class.org/class-11-smarter-scheduling.html

TRANSCRIPT

Page 1: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

cs4414 Fall 2013David Evans

Class 11

Smarter Scheduling (Priorities)

Page 2: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

2

Plan for TodayRecap: SchedulingFirst Come, First Served / Round-RobinPrioritiesLottery and Stride SchedulingScheduling in Linux

Page 3: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

3

Wil Thomason

Page 4: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

4

RecapMain Goals of Scheduling

Maximize Resource UseFairness

Switching is ExpensiveFundamental tradeoff between

maximizing usage and fairness

Page 5: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

5

Planned vs. On-DemandPlanned: schedule in advance

Supervisor/developer plans schedule given a priori knowledge about all tasks and

deadlinesOn-Demand: schedule on-the-fly

Supervisor runs periodically and makes decision based on current information

Where is planned used?

Page 6: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

6

Real-Time SystemsHard Real-Time

Missing a deadline is a total system failure.

Soft Real-TimeUndesirable to miss too

many deadlines too badly.

Page 7: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

7

Hard Real-TimeMissing a deadline is a total system failure.

Soft Real-TimeUndesirable to miss too

many deadlines too badly.

Page 8: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

8

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

Page 9: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

9

Planned vs. On-DemandPlanned: schedule in advance

Necessary (at least in part) for hard real time

On-Demand: schedule on-the-flyMost normal systems have unpredictable

tasks with unknown deadlines

Page 10: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

10

What should your courses be?

Page 11: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

11

What should your courses be?Exam 2 will be scheduled later (not next week)Problem Set 3 is due 11:59pm Wednesday, March 5Demos 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)

Page 12: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

12

Scheduling StrategiesFirst Come, First Served (FIFO)

P1 P2 P3

(effectively: non-preemptive multi-processing)

Page 13: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

13

Round-RobinP1 P1 P1P1P2 P2P3 P3P3P3

Time Slice Blocked

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

First Come, First Served (FIFO)P1 P2 P3

(effectively: non-preemptive multi-processing)

Page 14: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

14

ComparisonFirst Come, First Served Round Robin

Page 15: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

15

Which one is my laptop using?

Page 16: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

16

PrioritiesMore 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

Page 17: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

17

High Priority Processes

ps -w -e -o pri,pid,pcpu,vsz,cputime,command | sort -n -r --key=5 | sort --stable -n --key=1

Page 18: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

18

Pre-emptive Priority SchedulingAlways run the highest priority process that is ready to run

Round-robin schedule among equally high, ready to run, highest-priority processes

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

Page 19: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

19

Mars Curiosity (2012)

Page 20: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

20

Mars Pathfinder

(1997)

Page 21: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

21

Pathfinder OS: Pre-emptive PriorityAlways run the highest priority process that is ready to run

Round-robin schedule among equally high, ready to run, highest-priority processes

CPU

Shared Bus

Radio

Camera

Flash MemoryActuators

Page 22: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

22

Priority InversionTask 1 (scheduler) – highest priority (Priority = 1)Task 2 (send data) – (Priority = 4)Task 3 (science analysis) – lowest priority (Priority = 97)

CPU

Shared Bus

Radio

Camera

Flash MemoryActuators

Page 23: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

23

How should we solve priority inversion?

Page 24: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

24

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: 0Holds Bus Lock

Page 25: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

25

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

Page 26: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

26

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

Page 27: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

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 ^ need frame ^ need frame ^ need frame ^

P3 P3 P3

Page 29: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

29

Lottery Scheduling

Page 30: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

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

Page 31: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

31

Priority Pre-Emptive Lottery Scheduling

Page 32: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

32

Page 33: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

33

Page 34: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

34

What is the running time?

Page 35: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

35

What is the running time?

> uname -aLinux 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_maxkernel.pid_max = 32768

Page 36: Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and Stride Scheduling)

36

ChargeStride scheduling works (in real life also)!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)

Problem Set 3 should have high (but not quite hard real-time) priority! (and try to turn off interrupts when you work on it!)