1
Company
LOGO
Lock-free and Wait-free Slot Scheduling
Algorithms
Pooja Aggarwal Smruti R. Sarangi
Computer Science, IIT Delhi, India
Company
LOGO
2
Outline
Motivation
Related Work
Parallel Slot Scheduler Design
Performance Results
Summary
Company
LOGO
3time
Thread i Thread jHow to schedule
the requests
Real-Time System
t1 t2ti
Company
LOGO
4
Slot Scheduling
Treats time as a discrete quantity
Globally-visible reservation system
Requires advance algorithm for parallel scheduling
Company
LOGO
5
T0 T1 T2 Tn-2 Tn-1 Tn
T1
T1
T1 T2
T2
time
Shared Resource
Reservation System
Company
LOGO
6
Related Work
In 1982 Ousterhout proposed the matrix representation of time-slices and processors to facilitate running jobs simultaneously
The real-time scheduler for the Rialto operating system, based on CPU reservations, bears a great deal of similarity to slot scheduling.
Generic scheduling using locks In 2009 Mhamdi et. al. gave online variants of scheduling
problem for a message passing based system In 2011 Keller et. al. propose an offline version of the algorithm
that has a known task dependence graph.
We propose a novel, parallel, and Linearizable non-blocking slot scheduling algorithms
Company
LOGO
7
Nx1 Problem
N
M
FREE
BUSY
Company
LOGO
8
NxM
Nx1 Problem
N
M
Company
LOGO
9
Time Slots
P3
1xM Problem
T0 T1 T2 T3 T4 Ti Ti+1 Ti+2
P2 P2 P2 P3 P3 P3
Resource can process one
request per slot
Company
LOGO
10
2 2
busy Free
Empty slot
2 4 4
2
time
NxM Problem
Company
LOGO
11
Problems with Locking
× Deadlock – no progress× Priority Inversion – lower-priority process
preempted while holding lock× Convoying – lockholder de-scheduled× Starvation – a process never completes
Company
LOGO
12
Lock-free Algorithm
Optimistic approacha lock-free algorithm can run in four phases:
complete one's own operation assist an obstructing operation (internal helping) abort an obstructing operation and wait
Fast execution when low contention Avoids blocking and priority inversionAvoids deadlock
Company
LOGO
13
Wait-free Algorithm
Per-operation progress guaranteesEvery operation is guaranteed to complete
in a finite number of stepsFaster thread helps the slower threadWait-free = Lock-free + Starvation free
Company
LOGO
14
Basic Helping Mechanism
Each thread is assigned a priority based on the initial timestamp of its request
Shared Data Structure is used to store the requests
Each thread requesting for slots
First chooses a monotonically increasing request ID (reqid)
Announce the request helps all threads with a non-
larger reqid
REQUEST entry per thread
requestId
state
path
threadId
timeSlot
numSlots
9
SOFT
null
1
3
4
10
NEW
null
2
10
4
11
NEW
null
3
7
4
NEED TO HELPAnnouncing the request
Company
LOGO
15
Optimized Helping Criteria Drawback of basic scheme:
Helping even if no starvation even when there is no contention
many threads help same operations large redundant work
Optimization: REQUEST_THRESHOLD HELP_THRESHOLD INTERNAL HELPING
Company
LOGO
16
Parallel Slot Scheduler Design Schedule operation is accomplished in 3 three atomic steps
1. Announce the request concurrent processes realize that there is an operation-in-
progress
2. Temporary Reservation Try to reserve the earliest possible available slots
3. Permanent Reservation finalizing the reserve slots
Company
LOGO
17
FSM of a Request
NEW
SOFT
FORCEHARD
DONE
CANCEL
FAIL
Make temporary reservation
Finished reserving the required slots
Make permanent reservation
POINT of LINEARIZABILITY
POINT of LINEARIZABILITY
Cancelled by other thread or cancelled itself
Could not find empty slot
Company
LOGO
18
Schedule Operation
requestId
state
path
threadId
timeSlot
numSlots
EMPTY
SOFT
9
NEW
null
1
3
4
1
1 1
SOFT
HARD
(3,1)(3,1),(4,2),(5,2)
1
(3,1),(4,2),(5,2),(6,5)
FORCEHARD
POINT of LINEARIZABILITY
1
1 1
1
DONE
10
NEW
null
6
4
3
6 6
SOFT
(4,1),(5,1)
CANCEL
NEW
null
6 6 6
SOFT
(7,5),(8,5),(9,5)
FORCEHARD
6 6 6
DONE
Company
LOGO
19
State Transitions’ of a Slot
Tstamp reqId tid state slotno round
EMPTY
SOFT
HARD
Temporary Reservation
Permanent Reservation
threadId
Company
LOGO
20
Role of Saving Slot
4 4 4 4
2
1 1
2
Already booked
Temporary Reservation
Reserved 4
slots
Reserved 2 slots
Company
LOGO
21
Role of Round
1 1 1
2 2
NEWSOFTCANCEL
2 2
NEWSOFTCANCELNEW
2
SOFT
round is 1round is 2Round is 3
With every cancellation, round
is incrementCAS
Company
LOGO
22
Selecting a Slot
4 4 4 4
6 6
1
2 2
1 1
1
BOOKED
FREE
SOFT, 2
SOFT, 4
Another helper reserved slot
1 1
1
1Another helper Booked the slot
5
7
SOFT,2
Company
LOGO
23
Company
LOGO
24
Issues and Resolutions
ABA issue Time-Stamp
Multiple rollbacks CANCEL-THRESHOLD
Multiple reservations PATH array SHADOW array
Company
LOGO
25
Setup
Two six core 2.66 Ghz Intel Xeon GHz processors
Architecture
Ubuntu Linux 12.10 OS
64 GBRAM
24Threads
Sun’s Java SE Runtime 1.6.0Platform
Company
LOGO
26
Workload
The inter-request distances are truncated normal distributions Box-Muller transform is used to generate the
normal variants Experiment is executed till one of the
thread completes all its iterations Each thread performs 1000 iterations Each experiment is performed 10 times,
and mean values are reported
Company
LOGO
27
Mean time per request (treq)
Lock is 100 times slower
Company
LOGO
28
Work Done
• We run the system till the fastest thread completes κ requests.
• wk = tot requests/(κ ×NUMTHREADS).
Wait-free Work done is around 10 % more
Company
LOGO
29
Sensitivity: Request-threshold
Company
LOGO
30
Summary
First lock-free and wait-free algorithm for four variants of the generic slot scheduling problem
Lock-free is fastest of the three approaches
Wait-freedom incurs an inherent trade-off bounds the completion time of a single operation Total Work done is more
All our algorithms are linearizable Proposed design scheme might be applicable for
other wait-free data structures
Company
LOGO
31
Thank you!Questions?