32
1 Outline for Today • Objectives: – Linux scheduler – Lottery scheduling

1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

Embed Size (px)

Citation preview

Page 1: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

1

Outline for Today• Objectives:

– Linux scheduler– Lottery scheduling

Page 2: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

2

Linux Scheduling Policy

• Runnable process with highest priority and timeslice remaining runs (SCHED_OTHER policy)– Dynamically calculated priority

• Starts with nice value• Bonus or penalty reflecting whether I/O or compute

bound by tracking sleep time vs. runnable time: – sleep_avg – accumulated during sleep up to

MAX_SLEEP_AVG (10 ms default)– decremented by timer tick while running

Page 3: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

3

Linux Scheduling Policy– Dynamically calculated timeslice

• The higher the dynamic priority, the longer the timeslice:

– Recalculated every round when “expired” and “active” swap

– Exceptions for expired interactive • Go back on active unless there are starving expired tasks

Low priorityless interactive

High prioritymore interactive

10ms 150ms 300ms

Page 4: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

4

.

.

.

.

.

.

Runqueue for O(1) Scheduler

active

expired

priority array

priority array

.

.

.

.

.

.

priority queue

priority queue

priority queue

priority queue

Higher prioritymore I/O300ms

lower prioritymore CPU10ms

Page 5: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

5

.

.

.

.

.

.

Runqueue for O(1) Scheduler

active

expired

priority array

priority array

.

.

.

.

.

.

priority queue

priority queue

priority queue

priority queue

10

Page 6: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

6

.

.

.

.

.

.

Runqueue for O(1) Scheduler

active

expired

priority array

priority array

.

.

.

.

.

.

priority queue

priority queue

priority queue

priority queue

1

0

X

X

Page 7: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

7

Linux Real-time

• No guarantees• SCHED_FIFO

– Static priority, effectively higher than SCHED_OTHER processes*

– No timeslice – it runs until it blocks or yields voluntarily

– RR within same priority level

• SCHED_RR– As above but with a timeslice.

* Although their priority number ranges overlap

Page 8: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

8

Diversion: Synchronization

• Disable Interrupts

• Busywaiting solutions - spinlocks– execute a tight loop if critical section is busy– benefits from specialized atomic (read-mod-

write) instructions

• Blocking synchronization– sleep (enqueued on wait queue) while critical

section is busy.

Page 9: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

9

Support for SMP• Every processor has its

own private runqueue• Locking – spinlock

protects runqueue• Load balancing – pulls

tasks from busiest runqueue into mine.

• Affinity – cpus_allowed bitmask constrains a process to particular set of processors

• load_balance runs from schedule( ) when runqueue is empty or periodically esp. during idle.

• Prefers to pull processes from expired, not cache-hot, high priority, allowed by affinity

P P P P

Memory

$ $ $ $

Symmetric mp

Page 10: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

10

Lottery SchedulingWaldspurger and Weihl (OSDI 94)

Page 11: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

11

Claims

• Goal: responsive control over the relative rates of computation

• Claims:– Support for modular resource management– Generalizable to diverse resources– Efficient implementation of proportional-share

resource management: consumption rates of resources by active computations are proportional to relative shares allocated

Page 12: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

12

Basic Idea

• Resource rights are represented by lottery tickets– abstract, relative (vary dynamically wrt

contention), uniform (handle heterogeneity)– responsiveness: adjusting relative # tickets

gets immediately reflected in next lottery

• At allocation time: hold a lottery;Resource goes to the computation holding the winning ticket.

Page 13: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

13

Fairness

• Expected allocation is proportional to # tickets held - actual allocation becomes closer over time.

• Number of lotteries won by clientE[w] = n p where p = t/T

• Response time (# lotteriesto wait for first win)E[n] = 1/p

w # winst # ticketsT total # tickets n # lotteries

Page 14: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

14

Example List-based Lottery

10 2 5 1 2

T = 20

Random(0, 19) = 15

10 12 17Summing:

Page 15: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

15

Bells and Whistles

• Ticket transfers - objects that can be explicitly passed in messages– Can be used to solve priority inversions

• Ticket inflation– Create more - used among mutually trusting clients to

dynamically adjust ticket allocations

• Currencies - “local” control, exchange rates

• Compensation tickets - to maintain share

– use only f of quantum, ticket inflated by 1/f in next

Page 16: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

16

Kernel Objects

1000base

ticket

amount

currencyC_name

300

Backingtickets

Issued tickets

Activeamount

Currencyname

Page 17: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

17

base

alice bob

task1

task2

task3

thread2 thread3 thread4thread1

3000

200

500

100

100

2000base

1000base

200alice

200 task2

300task2

100task3

100bob100

alice

100task1

0

1 alice =5 base

1 task2=.4 alice =2 base

1 bob =20 base

Page 18: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

18

base

alice bob

task1

task2

task3

thread2 thread3 thread4thread1

3000

300

500

100

100

2000base

1000base

200alice

200 task2

300task2

100task3

100bob100

alice

100task1

100

1 alice =3.33 base

1 task2=.4 alice =1.33 base

1 bob =20 base

Page 19: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

19

Example List-based Lottery

10 task2 2bob 5 task3 1

base

2bob

T = 3000 base

Random(0, 2999) = 1500

Page 20: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

20

Compensation

• A holds 400 base, B holds 400 base

• A runs full 100msec quantum,B yields at 20msec

• B uses 1/5 allotted timeGets 400/(1/5) = 2000 base at each subsequent lottery for the rest of this quantum – a compensation ticket valued at 2000 - 400

Page 21: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

21

Ticket Transfer

• Synchronous RPC between client and server

• create ticket in client’s currency and send to server to fund it’s currency

• on reply, the transfer ticket is destroyed

Page 22: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

22

Control Scenarios

• Dynamic ControlConditionally and dynamically grant ticketsAdaptability

• Resource abstraction barriers supported by currencies. Insulate tasks.

Page 23: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

23

UI

• mktkt, rmtkt, mkcur, rmcur

• fund, unfund

• lstkt, lscur, fundx (shell)

Page 24: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

25

Relative Rate Accuracy

Page 25: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

26

Fairness Over Time

Page 26: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

27

Client-ServerQuery Processing Rates

Page 27: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

28

Controlling Video Rates

Page 28: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

29

Insulation

Page 29: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

30

Other Kinds of Resources• Claim: can be used for any resource where

queuing is used• Control relative waiting times for mutex locks.

– Mutex currency funded out of currencies of waiting threads

– Holder gets inheritance ticket in addition to its own funding, passed on to next holder (resulting from lottery) on release.

• Space sharing - inverse lottery, loser is victim(e.g. in page replacement decision, processor node preemption in MP partitioning)

Page 30: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

31

Lock Funding

Waiting thread

1

lock

1

Waiting thread

1

holding thread

1

t t

bt

Page 31: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

32

Lock Funding

New holding thread

1

lock

1

Waiting thread

1

Old holding thread

1

t

bt

Page 32: 1 Outline for Today Objectives: –Linux scheduler –Lottery scheduling

33

Mutex Waiting Times