Lock free shared data
-
Upload
davide-faconti -
Category
Technology
-
view
619 -
download
0
Transcript of Lock free shared data
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Lock-Free Data Exchange for Real-TimeApplications
Peter Soetens
Flander’s Mechatronics Technology CentreLeuven
25 Feb 2006Free and Open Source Developers Meeting
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Outline
1 IntroductionAbout You and MeApplication Domain
2 Lock-Free ExplainedThe Good ’Ol DaysA New Kind of Computer Science
3 Lock-Free PerformanceTime determinismAlgorithm Overhead
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
Outline
1 IntroductionAbout You and MeApplication Domain
2 Lock-Free ExplainedThe Good ’Ol DaysA New Kind of Computer Science
3 Lock-Free PerformanceTime determinismAlgorithm Overhead
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
What You Will Learn.
What lock-free data exchange offers.
When to use it.
Why it is better.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
What I Will Offer.
Give an introduction to lock-free algorithms for non-experts.
Show an experimental comparison between traditionallocks and lock-free algorithms.
Provide good leads for lock-free application and kerneldevelopment.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
What I Assume About You.
You. . .
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
What I Assume About You.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
What I Assume About You.
You. . .
know what multi-threaded applications are.
care about real-time or embedded application design.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
Outline
1 IntroductionAbout You and MeApplication Domain
2 Lock-Free ExplainedThe Good ’Ol DaysA New Kind of Computer Science
3 Lock-Free PerformanceTime determinismAlgorithm Overhead
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
Definitions
An algorithm is lock-free if. . .
it does not ’block’ threads
every step taken achieves global progress.
it allows individual threads to starve (loop forever) butdenies livelock.
Redefinition (2003): “Obstruction Free”
Real-Time
A term to denote execution time determinism of an action orsequence of actions in response to an event. This means thatthe action always completes (and/or starts) within a boundedtime interval.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
When to Use Lock-Free Algorithms
Lock-Free is especially useful for
multi-threaded or -process applications
blob data- or pointer-exchangeOS kernels and applications
Real-Time (time determinism)Embedded (simple scheduler)
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
When to Use Lock-Free Algorithms
Lock-Free is especially useful for
multi-threaded or -process applications
blob data- or pointer-exchangeOS kernels and applications
Real-Time (time determinism)Embedded (simple scheduler)
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
What Lock-Free Requires
Lock-Free requiresProcessor support
A Compare-And-Swap (CAS, CMPXCH) orLoad-Linked/Store-Conditional (LL/SC) processorinstruction orAtomic increment/decrement and test.
Architecture supportA piece of physically Shared Memory.
An algorithmFortunately, they all look the same.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
What Lock-Free Requires
Lock-Free requiresProcessor support
A Compare-And-Swap (CAS, CMPXCH) orLoad-Linked/Store-Conditional (LL/SC) processorinstruction orAtomic increment/decrement and test.
Architecture supportA piece of physically Shared Memory.
An algorithmFortunately, they all look the same.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
What Lock-Free Requires
Lock-Free requiresProcessor support
A Compare-And-Swap (CAS, CMPXCH) orLoad-Linked/Store-Conditional (LL/SC) processorinstruction orAtomic increment/decrement and test.
Architecture supportA piece of physically Shared Memory.
An algorithmFortunately, they all look the same.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
What Lock-Free Does Not Require
Lock-Free does not require
OS support
Scheduler support
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
About You and MeApplication Domain
Example Uses
Common uses are:From Orocos.org:
FIFO/LIFO data buffers(Single) linked listsPointer queuesShared data
From Boost.org (0.33.0)Smart pointers
. . . in many readers/many writers environments
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Outline
1 IntroductionAbout You and MeApplication Domain
2 Lock-Free ExplainedThe Good ’Ol DaysA New Kind of Computer Science
3 Lock-Free PerformanceTime determinismAlgorithm Overhead
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
The Example Application
D
Shared DataReaderThread
WriterThread
’Thread’ : May be an interrupt, thread, process,...
’Data’ : Modifyable in a single (composite) transaction.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Unprotected Access
D
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Unprotected Access
D
UnrestrictedAccess
Corrupted Data
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
D
The Lock
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
D
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
D
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
D
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
D
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
D
ZZzzz...
A worst case scenario. . .
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
D
ZZzzz...
A worst case scenario. . .
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
D
ZZzzz...
A worst case scenario. . .
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
D
ZZzzz...
A worst case scenario. . .
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
D
Is this scalable ?
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
D
Which thread has the lowest priority ?
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
DLowest
Priority !
Which thread has the lowest priority ?
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
DLowest
Priority !
Pre−emptingthreads
always havehigher
priority !
Which thread has the lowest priority ?
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
DLowest
Priority !
Which thread has the lowest priority ?
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Using Locks
D
LowestPriority !
Which thread has the lowest priority ?
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Based Reader-Writer Summary
Effect on priorities ?A higher priority means a worse delay
Best case access time ?Grab the lock, modify, release lock (Taccess)
Worst case access time ?= 2 ∗ Taccess using priority inheritance or∞ without priority inheritance (priority inversions)
Memory requirements ?= sizeof (D) + sizeof (Lock) + sizeof (SchedAlgorithms)
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Based Reader-Writer Summary
- Effect on priorities ?A higher priority means a worse delay
Best case access time ?Grab the lock, modify, release lock (Taccess)
Worst case access time ?= 2 ∗ Taccess using priority inheritance or∞ without priority inheritance (priority inversions)
Memory requirements ?= sizeof (D) + sizeof (Lock) + sizeof (SchedAlgorithms)
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Based Reader-Writer Summary
- Effect on priorities ?A higher priority means a worse delay
- Best case access time ?Grab the lock, modify, release lock (Taccess)
Worst case access time ?= 2 ∗ Taccess using priority inheritance or∞ without priority inheritance (priority inversions)
Memory requirements ?= sizeof (D) + sizeof (Lock) + sizeof (SchedAlgorithms)
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Based Reader-Writer Summary
- Effect on priorities ?A higher priority means a worse delay
- Best case access time ?Grab the lock, modify, release lock (Taccess)
- Worst case access time ?= 2 ∗ Taccess using priority inheritance or∞ without priority inheritance (priority inversions)
Memory requirements ?= sizeof (D) + sizeof (Lock) + sizeof (SchedAlgorithms)
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Based Reader-Writer Summary
- Effect on priorities ?A higher priority means a worse delay
- Best case access time ?Grab the lock, modify, release lock (Taccess)
- Worst case access time ?= 2 ∗ Taccess using priority inheritance or∞ without priority inheritance (priority inversions)
+ Memory requirements ?= sizeof (D) + sizeof (Lock) + sizeof (SchedAlgorithms)
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Based Reader-Writer Summary
- Effect on priorities ?A higher priority means a worse delay
- Best case access time ?Grab the lock, modify, release lock (Taccess)
- Worst case access time ?= 2 ∗ Taccess using priority inheritance or∞ without priority inheritance (priority inversions)
+ Memory requirements ?= sizeof (D) + sizeof (Lock) + sizeof (SchedAlgorithms)
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Let’s get rid of locks!
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Outline
1 IntroductionAbout You and MeApplication Domain
2 Lock-Free ExplainedThe Good ’Ol DaysA New Kind of Computer Science
3 Lock-Free PerformanceTime determinismAlgorithm Overhead
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 1 Writer
D
SharedData
2 ReaderThreads
1 WriterThread
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 1 Writer
DD D
Mark most recent
Read most recent
Pre-allocate data blocks to avoid run-time allocation (notreal-time). No heap required.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 1 Writer
DD D
Write...modify
Yep, that’s RCU (Read-Copy-Update) for you experts.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 1 Writer
DD D
Done!
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 1 Writer
DD D
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 1 Writer
DD D
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 1 Writer
DD D
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 1 Writer
DD D
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 1 Writer
DD DD
Mark Writer
Reader Reader
modify
Worst case number of required data blocks = 2 + RFor a single writer - many readers setup.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Free Single Writer Summary
Effect on priorities ?None
Best case access time ?Writer: TFindpointer + TModify + TPointercopy
Reader: TRead
Worst case access time ?Writer: TFindpointer + TModify + TPointercopy
Reader: TRead
Memory requirements ?= sizeof (D) ∗ (2 + R)
Did I use CAS ?No
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Free Single Writer Summary
+ Effect on priorities ?None
Best case access time ?Writer: TFindpointer + TModify + TPointercopy
Reader: TRead
Worst case access time ?Writer: TFindpointer + TModify + TPointercopy
Reader: TRead
Memory requirements ?= sizeof (D) ∗ (2 + R)
Did I use CAS ?No
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Free Single Writer Summary
+ Effect on priorities ?None
+ Best case access time ?Writer: TFindpointer + TModify + TPointercopy
Reader: TRead
Worst case access time ?Writer: TFindpointer + TModify + TPointercopy
Reader: TRead
Memory requirements ?= sizeof (D) ∗ (2 + R)
Did I use CAS ?No
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Free Single Writer Summary
+ Effect on priorities ?None
+ Best case access time ?Writer: TFindpointer + TModify + TPointercopy
Reader: TRead
+ Worst case access time ?Writer: TFindpointer + TModify + TPointercopy
Reader: TRead
Memory requirements ?= sizeof (D) ∗ (2 + R)
Did I use CAS ?No
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Free Single Writer Summary
+ Effect on priorities ?None
+ Best case access time ?Writer: TFindpointer + TModify + TPointercopy
Reader: TRead
+ Worst case access time ?Writer: TFindpointer + TModify + TPointercopy
Reader: TRead
- Memory requirements ?= sizeof (D) ∗ (2 + R)
Did I use CAS ?No
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Free Single Writer Summary
+ Effect on priorities ?None
+ Best case access time ?Writer: TFindpointer + TModify + TPointercopy
Reader: TRead
+ Worst case access time ?Writer: TFindpointer + TModify + TPointercopy
Reader: TRead
- Memory requirements ?= sizeof (D) ∗ (2 + R)
Did I use CAS ?No
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 2 Writers
D
SharedData
2 ReaderThreads
2 WriterThreads
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 2 Writers
DD D
Which one is most recent ?
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 2 Writers
DD D
Writer 1modify
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 2 Writers
DD D
Writer 1 Writer 2modify
Higherpriority
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 2 Writers
DD D
Writer 1 Writer 2modify
Compare−and−Swap:
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 2 Writers
DD D
Writer 1modify
Done!
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 2 Writers
DD D
Writer 1modify
CASFails !
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 2 Writers
DD D
Writer 1 modifyagain!
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 2 Writers
DD D
Done!
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Away with Locks: 2 Writers
DD D
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Free Multiple Writer Summary
Effect on priorities ?Highest priority wins!
Best case access time ?= TFindpointer + TModify + TPointercopy
Always the case for the highest priority thread.
Worst case access time ?= WHigherPriority ∗ TBestcase
Depends on the number of higher priority writers.
Memory requirements ?= sizeof (D) ∗ (2 ∗W + R)
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Free Multiple Writer Summary
+ Effect on priorities ?Highest priority wins!
Best case access time ?= TFindpointer + TModify + TPointercopy
Always the case for the highest priority thread.
Worst case access time ?= WHigherPriority ∗ TBestcase
Depends on the number of higher priority writers.
Memory requirements ?= sizeof (D) ∗ (2 ∗W + R)
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Free Multiple Writer Summary
+ Effect on priorities ?Highest priority wins!
+ Best case access time ?= TFindpointer + TModify + TPointercopy
Always the case for the highest priority thread.
Worst case access time ?= WHigherPriority ∗ TBestcase
Depends on the number of higher priority writers.
Memory requirements ?= sizeof (D) ∗ (2 ∗W + R)
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Free Multiple Writer Summary
+ Effect on priorities ?Highest priority wins!
+ Best case access time ?= TFindpointer + TModify + TPointercopy
Always the case for the highest priority thread.
+ Worst case access time ?= WHigherPriority ∗ TBestcase
Depends on the number of higher priority writers.
Memory requirements ?= sizeof (D) ∗ (2 ∗W + R)
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
The Good ’Ol DaysA New Kind of Computer Science
Lock-Free Multiple Writer Summary
+ Effect on priorities ?Highest priority wins!
+ Best case access time ?= TFindpointer + TModify + TPointercopy
Always the case for the highest priority thread.
+ Worst case access time ?= WHigherPriority ∗ TBestcase
Depends on the number of higher priority writers.
- Memory requirements ?= sizeof (D) ∗ (2 ∗W + R)
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Outline
1 IntroductionAbout You and MeApplication Domain
2 Lock-Free ExplainedThe Good ’Ol DaysA New Kind of Computer Science
3 Lock-Free PerformanceTime determinismAlgorithm Overhead
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Recap: Definition
Real-Time
A term to denote execution time determinism of an action orsequence of actions in response to an event. This means thatthe action always completes (and/or starts) within a boundedtime interval.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Going Real-Time
Given one of these Real-Time schedulers:
Rate Monotonic Scheduler (RMS)
Deadline Monotonic Scheduler (DMS)
Earliest Deadline First Scheduler (EDFS)
The following properties are always true for any lock-freealgorithm:
The highest priority writer thread has best case accesstime.
The other writer threads have bounded access time.
Any reader has always best case access time.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Going Real-Time
Given one of these Real-Time schedulers:
Rate Monotonic Scheduler (RMS)
Deadline Monotonic Scheduler (DMS)
Earliest Deadline First Scheduler (EDFS)
The following properties are always true for any lock-freealgorithm:
The highest priority writer thread has best case accesstime.
The other writer threads have bounded access time.
Any reader has always best case access time.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Going Real-Time
Given one of these Real-Time schedulers:
Rate Monotonic Scheduler (RMS)
Deadline Monotonic Scheduler (DMS)
Earliest Deadline First Scheduler (EDFS)
The following properties are always true for any lock-freealgorithm:
The highest priority writer thread has best case accesstime.
The other writer threads have bounded access time.
Any reader has always best case access time.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Going Real-Time
Given one of these Real-Time schedulers:
Rate Monotonic Scheduler (RMS)
Deadline Monotonic Scheduler (DMS)
Earliest Deadline First Scheduler (EDFS)
The following properties are always true for any lock-freealgorithm:
The highest priority writer thread has best case accesstime.
The other writer threads have bounded access time.
Any reader has always best case access time.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Real-Time Validation Experiment
Real-time Machine ControllerPentium III 750MHz, 128MB RAM(this is vastly oversized for our purpose, but allowedon-target data capturing)
Software
Linux 2.4.18 with RTAI/LXRT 3.0 Patch
Orocos configured for LXRT
Many readers / many writers test applications
Both FIFO buffers and shared data exchange
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Real-Time Validation: Data Flow
Concurr ent
NRT
Sma ll
NRT
RT500Hz
RT1Hz
RT2KHz
RT500Hz
RT1KHz
NRT
RT500Hz
RT1Hz
RT2KHz
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Real-Time Validation: No Communication
0.1
1
10
100
1000
10000
100000
1e+06
1e-05 1e-04 0.001 0.01
Occ
uren
ces
Latency time ( s ). Bucket size: 5 us
1ms/0.5ms5ms/1ms
0.1
1
10
100
1000
10000
100000
1e+06
1e-05 1e-04 0.001 0.01
Occ
uren
ces
Latency time ( s ). Bucket size: 5 us
0.5ms/0.1ms1ms/0.2ms2ms/0.3ms
Executionlatencies
For a small (2 RTthreads) andconcurrent (3 RTthreads)application.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Real-Time Validation: Data Exchange
0.1
1
10
100
1000
10000
100000
1e+06
1e-06 1e-05 1e-04 0.001 0.01 0.1
Occ
uren
ces
Latency time ( s ). Bucket size: 5 us
1ms/0.5ms
0.1
1
10
100
1000
10000
100000
1e+06
1e-06 1e-05 1e-04 0.001 0.01 0.1
Occ
uren
ces
Latency time ( s ). Bucket size: 5 us
1ms/0.5ms
Small application, high priority thread.
Communicationlatencies
Lock based (top)and lock free(bottom).
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Real-Time Validation: Data Exchange
0.1
1
10
100
1000
10000
100000
1e-06 1e-05 1e-04 0.001 0.01 0.1
Occ
uren
ces
Latency time ( s ). Bucket size: 5 us
5ms/0.5ms
0.1
1
10
100
1000
10000
100000
1e-06 1e-05 1e-04 0.001 0.01 0.1
Occ
uren
ces
Latency time ( s ). Bucket size: 5 us
5ms/0.5ms
Small application, low priority thread.
Communicationlatencies
Lock based (top)and lock-free(bottom).
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Real-Time Validation: Data Exchange
0.1
1
10
100
1000
10000
100000
1e-06 1e-05 1e-04 0.001 0.01 0.1
Occ
uren
ces
Latency time ( s ). Bucket size: 5 us
0.5ms/0.1ms
0.1
1
10
100
1000
10000
100000
1e-06 1e-05 1e-04 0.001 0.01 0.1
Occ
uren
ces
Latency time ( s ). Bucket size: 5 us
0.5ms/0.1ms
Concurrent application, high priority thread.
Communicationlatencies
Lock based (top)and lock free(bottom).
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Real-Time Validation: Data Exchange
0.1
1
10
100
1000
10000
100000
1e-06 1e-05 1e-04 0.001 0.01 0.1
Occ
uren
ces
Latency time ( s ). Bucket size: 5 us
1ms/0.2ms
0.1
1
10
100
1000
10000
100000
1e+06
1e-06 1e-05 1e-04 0.001 0.01 0.1
Occ
uren
ces
Latency time ( s ). Bucket size: 5 us
1ms/0.2ms
Concurrent application, medium priority thread.
Communicationlatencies
Lock based (top)and lock free(bottom).
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Real-Time Validation: Data Exchange
0.1
1
10
100
1000
10000
100000
1e-06 1e-05 1e-04 0.001 0.01 0.1
Occ
uren
ces
Latency time ( s ). Bucket size: 5 us
2ms/0.3ms
0.1
1
10
100
1000
10000
100000
1e-06 1e-05 1e-04 0.001 0.01 0.1
Occ
uren
ces
Latency time ( s ). Bucket size: 5 us
2ms/0.3ms
Concurrent application, medium priority thread.
Communicationlatencies
Lock based (top)and lock free(bottom).
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Real-Time Validation: Conclusions
Small Applications
Lock-free performs on average better
Lock-free performs worst case better
Concurrent Applications
Lock-free performs on average better
Lock-free performs worst case better
Lock-free prevents dead-line failures
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Outline
1 IntroductionAbout You and MeApplication Domain
2 Lock-Free ExplainedThe Good ’Ol DaysA New Kind of Computer Science
3 Lock-Free PerformanceTime determinismAlgorithm Overhead
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Memory Overhead
Memory consumption increases linearly
OK for most real-time andembedded applications, number ofthreads is well known.
Worse, if not catastrophic, for OSkernels, number of threads isunknown.
Reference counted memory
Both readers and writers need toreference count data blocks.
Requires ’atomic’ processorinstructions.
DD D
Reference counted
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Overhead for Readers
Increase reference count
Since a data block may not be freedbefore all readers are done readingit, a reference countingimplementation is required.Analogous to RCU
Detect moved ’Most Recent’ pointer.If a reader ’locks’ the data block butdetects that the refcount is one, itmust retry, since the block may be inre-use already.
DD D
Reference counted
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Overhead for Writers
Find an empty data block
Possibly race against other writers
Increase reference count
Copy and update the data
Large data blocks will reduceperformance
Retry if necessary (W > 1)
In case source data block changed,startover with the copy-update fromthe new data block.
DD D
Reference counted
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Exception: Lock-free Pointer Queues
Best case access time ?= TFindpointer + TPointercopy
Always the case for the highest priority thread.
Worst case access time ?= WHigherPriority ∗ TBestcase
Depends on the number of higher priority writers.
Memory requirements ?= sizeof (D) ∗ Nqueue
⇒ Best of both worlds ! Independent of number of threads.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Exception: Lock-free Pointer Queues
+ Best case access time ?= TFindpointer + TPointercopy
Always the case for the highest priority thread.
Worst case access time ?= WHigherPriority ∗ TBestcase
Depends on the number of higher priority writers.
Memory requirements ?= sizeof (D) ∗ Nqueue
⇒ Best of both worlds ! Independent of number of threads.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Exception: Lock-free Pointer Queues
+ Best case access time ?= TFindpointer + TPointercopy
Always the case for the highest priority thread.
+ Worst case access time ?= WHigherPriority ∗ TBestcase
Depends on the number of higher priority writers.
Memory requirements ?= sizeof (D) ∗ Nqueue
⇒ Best of both worlds ! Independent of number of threads.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Time determinismAlgorithm Overhead
Exception: Lock-free Pointer Queues
+ Best case access time ?= TFindpointer + TPointercopy
Always the case for the highest priority thread.
+ Worst case access time ?= WHigherPriority ∗ TBestcase
Depends on the number of higher priority writers.
+ Memory requirements ?= sizeof (D) ∗ Nqueue
⇒ Best of both worlds ! Independent of number of threads.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Summary
Lock-Free algorithms are a drastic improvement forreal-time applications
Lock-Free algorithms don’t require any schedulerintervention.
But be aware of memory requirements.
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
Thank you for your attention !
Peter Soetens Lock-Free Data Exchange
IntroductionLock-Free Explained
Lock-Free PerformanceSummary
References
http://www.orocos.org
Anderson, J., S. Ramamurthy, and K. Jeffay (1995).Real-time com- puting with lock-free shared objects.Proceedings of the 16th IEEE Real-Time SystemsSymposium.
Herlihy, M. (1991). Wait-free synchronization. ACM Trans.Program. Lang. Syst. 13 (1), 124-149.
Herlihy, M., V. Luchangco, and M. Moir (2003).Obstruction-free synchronization: Double-ended queuesas an example. In 03: Proceedings of the 23rdInternational Conference on Dis- tributed ComputingSystems, Washington, DC, USA, pp. 522. IEEE ComputerSociety.
Peter Soetens Lock-Free Data Exchange