SlideShare a Scribd company logo
1 of 29
Download to read offline
Nested Locks in the Lock Implementation:
The Real-Time Read-Write Semaphores on Linux
Daniel B. de Oliveira1,2,3
, Daniel Casini2
, Rômulo S. de Oliveira3
, Tommaso Cucinotta2
, Alessandro Biondi2
, and Giorgio Buttazzo2
Email: bristot@redhat.com, romulo.deoliveira@ufsc.br,
{ daniel.casini,tommaso.cucinotta, alessandro.biondi, giorgio.buttazzo } @santannapisa.it
Real-time Scheduling Open Problems Seminar (RTSOPS 2018)
- Linux is a GPOS with RTOS ambitions
- Preemptive
- FIFO (TLFP) and Deadline (JLFP) schedulers
- User-space locks with PIP & PCP
- PREEMPT-RT improves Linux’s predictability by:
- Making system as preemptive/schedulable as possible
- Bounding priority inversions using PIP on kernel locks
- Max (activation delay?) latency of 150 µs
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux2
Real-time Linux
Due to Linux’s GPOS nature, RT Linux developers are
challenged to provide the predictability required for an
RTOS, while not causing regressions on the general
purpose benchmarks.
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux3
Real-time Linux howevers
- Developers cannot cause performance regressions
- Throughput:
- Two implementations: RT and non RT
- A newer algorithm cannot cause - much - regression compared to the older one
- Predictability:
- Cannot increase the latency
- e.g, cannot disable the preemption for a long period
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux4
In practice it means
As a consequence, the implementation of some well known algorithms, like
read/write semaphores, has been done using approaches that were
exhaustively explored in academic papers.
IOW: it works, but...
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux5
Consequences...
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux6
Read/write semaphores on Linux
Read-side
down_read(&rw_semapore) {
/* enters in the read-side */
}
/*
* Read-side critical section
* Parallel with other readers
* No writers
*/
up_read(&rw_semapore) {
/* leaves the read-side */
}
Write-side
down_write(&rw_semapore) {
/* enters in the write-side */
}
/*
* Write-side critical section
* Exclusive access
*/
up_write(&rw_semapore) {
/* leaves the write-side */
}
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux7
Read/write semaphores on Linux
struct rw_semaphore {
atomic_t readers;
struct rt_mutex rtmutex;
};
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux8
Read/write semaphores on Linux
struct rw_semaphore {
atomic_t readers;
struct rt_mutex rtmutex;
};
struct rt_mutex {
raw_spinlock_t wait_lock;
struct rb_root_cached waiters;
struct task_struct *owner;
int save_state;
};
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux9
Read/write semaphores on Linux
struct rw_semaphore {
atomic_t readers;
struct rt_mutex rtmutex;
};
struct rt_mutex {
raw_spinlock_t wait_lock;
struct rb_root_cached waiters;
struct task_struct *owner;
int save_state;
};
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux10
down_read(rw_sem)
if (++rw_sem->readers > 1)
return /* enter the critical section */
else
rw_sem->readers--
take rw_sem->rtmutex.wait_lock
if (WRITER BIAS is not set) {
rw_sem->readers++
release rw_sem->rtmutex.wait_lock
return /* enter in the critical section */
}
release rw_sem->rtmutex.wait_lock
take rw_sem->rt_mutex
rw_sem->readers++
release the rw_sem->rt_mutex
return /* enter in the critical section */
}
down_write(rw_sem) {
take rw_sem->rtmutex
clear READER BIAS
if (rw_sem->readers != 0)
suspend waiting for the last reader
while(1) {
take sem->rtmutex->wait_lock
if (sem->readers == 0) {
set WRITER BIAS
release rw_sem->rtmutex->wait_lock
return
}
release rw_sem->rtmutex->wait_lock.
suspend waiting for the last reader
}
return
}
Atomic operation
Mutex: ...
Spin lock: ...
Concurrent down operations
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux11
down_read(rw_sem)
if (++rw_sem->readers > 1)
return /* enter the critical section */
else
rw_sem->readers--
take rw_sem->rtmutex.wait_lock
if (WRITER BIAS is not set) {
rw_sem->readers++
release rw_sem->rtmutex.wait_lock
return /* enter in the critical section */
}
release rw_sem->rtmutex.wait_lock
take rw_sem->rt_mutex
rw_sem->readers++
release the rw_sem->rt_mutex
return /* enter in the critical section */
}
down_write(rw_sem) {
take rw_sem->rtmutex
clear READER BIAS
if (rw_sem->readers != 0)
suspend waiting for the last reader
while(1) {
take sem->rtmutex->wait_lock
if (sem->readers == 0) {
set WRITER BIAS
release rw_sem->rtmutex->wait_lock
return
}
release rw_sem->rtmutex->wait_lock.
suspend waiting for the last reader
}
return
}
Atomic operation
Mutex: held
Spin lock: ...
Concurrent down operations
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux12
down_read(rw_sem)
if (++rw_sem->readers > 1)
return /* enter the critical section */
else
rw_sem->readers--
take rw_sem->rtmutex.wait_lock
if (WRITER BIAS is not set) {
rw_sem->readers++
release rw_sem->rtmutex.wait_lock
return /* enter in the critical section */
}
release rw_sem->rtmutex.wait_lock
take rw_sem->rt_mutex
rw_sem->readers++
release the rw_sem->rt_mutex
return /* enter in the critical section */
}
down_write(rw_sem) {
take rw_sem->rtmutex
clear READER BIAS
if (rw_sem->readers != 0)
suspend waiting for the last reader
while(1) {
take sem->rtmutex->wait_lock
if (sem->readers == 0) {
set WRITER BIAS
release rw_sem->rtmutex->wait_lock
return
}
release rw_sem->rtmutex->wait_lock.
suspend waiting for the last reader
}
return
}
Atomic operation
Mutex: held
Spin lock: ...
Concurrent down operations
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux13
down_read(rw_sem)
if (++rw_sem->readers > 1)
return /* enter the critical section */
else
rw_sem->readers--
take rw_sem->rtmutex.wait_lock
if (WRITER BIAS is not set) {
rw_sem->readers++
release rw_sem->rtmutex.wait_lock
return /* enter in the critical section */
}
release rw_sem->rtmutex.wait_lock
take rw_sem->rt_mutex
rw_sem->readers++
release the rw_sem->rt_mutex
return /* enter in the critical section */
}
down_write(rw_sem) {
take rw_sem->rtmutex
clear READER BIAS
if (rw_sem->readers != 0)
suspend waiting for the last reader
while(1) {
take sem->rtmutex->wait_lock
if (sem->readers == 0) {
set WRITER BIAS
release rw_sem->rtmutex->wait_lock
return
}
release rw_sem->rtmutex->wait_lock.
suspend waiting for the last reader
}
return
}
Atomic operation
Mutex: held
Spin lock: ...
Concurrent down operations
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux14
down_read(rw_sem)
if (++rw_sem->readers > 1)
return /* enter the critical section */
else
rw_sem->readers--
take rw_sem->rtmutex.wait_lock
if (WRITER BIAS is not set) {
rw_sem->readers++
release rw_sem->rtmutex.wait_lock
return /* enter in the critical section */
}
release rw_sem->rtmutex.wait_lock
take rw_sem->rt_mutex
rw_sem->readers++
release the rw_sem->rt_mutex
return /* enter in the critical section */
}
down_write(rw_sem) {
take rw_sem->rtmutex
clear READER BIAS
if (rw_sem->readers != 0)
suspend waiting for the last reader
while(1) {
take sem->rtmutex->wait_lock
if (sem->readers == 0) {
set WRITER BIAS
release rw_sem->rtmutex->wait_lock
return
}
release rw_sem->rtmutex->wait_lock.
suspend waiting for the last reader
}
return
}
Mutex: held
Spin lock: ...
Concurrent down operations
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux15
down_read(rw_sem)
if (++rw_sem->readers > 1)
return /* enter the critical section */
else
rw_sem->readers--
take rw_sem->rtmutex.wait_lock
if (WRITER BIAS is not set) {
rw_sem->readers++
release rw_sem->rtmutex.wait_lock
return /* enter in the critical section */
}
release rw_sem->rtmutex.wait_lock
take rw_sem->rt_mutex
rw_sem->readers++
release the rw_sem->rt_mutex
return /* enter in the critical section */
}
down_write(rw_sem) {
take rw_sem->rtmutex
clear READER BIAS
if (rw_sem->readers != 0)
suspend waiting for the last reader
while(1) {
take sem->rtmutex->wait_lock
if (sem->readers == 0) {
set WRITER BIAS
release rw_sem->rtmutex->wait_lock
return
}
release rw_sem->rtmutex->wait_lock.
suspend waiting for the last reader
}
return
}
Concurrent down operations
Mutex: held
Spin lock: block
Mutex: ...
Spin lock: held
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux16
down_read(rw_sem)
if (++rw_sem->readers > 1)
return /* enter the critical section */
else
rw_sem->readers--
take rw_sem->rtmutex.wait_lock
if (WRITER BIAS is not set) {
rw_sem->readers++
release rw_sem->rtmutex.wait_lock
return /* enter in the critical section */
}
release rw_sem->rtmutex.wait_lock
take rw_sem->rt_mutex
rw_sem->readers++
release the rw_sem->rt_mutex
return /* enter in the critical section */
}
down_write(rw_sem) {
take rw_sem->rtmutex
clear READER BIAS
if (rw_sem->readers != 0)
suspend waiting for the last reader
while(1) {
take sem->rtmutex->wait_lock
if (sem->readers == 0) {
set WRITER BIAS
release rw_sem->rtmutex->wait_lock
return
}
release rw_sem->rtmutex->wait_lock.
suspend waiting for the last reader
}
return
}
Concurrent down operations
Mutex: held
Spin lock: block
Mutex: ...
Spin lock: held
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux17
down_read(rw_sem)
if (++rw_sem->readers > 1)
return /* enter the critical section */
else
rw_sem->readers--
take rw_sem->rtmutex.wait_lock
if (WRITER BIAS is not set) {
rw_sem->readers++
release rw_sem->rtmutex.wait_lock
return /* enter in the critical section */
}
release rw_sem->rtmutex.wait_lock
take rw_sem->rt_mutex
rw_sem->readers++
release the rw_sem->rt_mutex
return /* enter in the critical section */
}
down_write(rw_sem) {
take rw_sem->rtmutex
clear READER BIAS
if (rw_sem->readers != 0)
suspend waiting for the last reader
while(1) {
take sem->rtmutex->wait_lock
if (sem->readers == 0) {
set WRITER BIAS
release rw_sem->rtmutex->wait_lock
return
}
release rw_sem->rtmutex->wait_lock.
suspend waiting for the last reader
}
return
}
Concurrent down operations
Mutex: held
Spin lock: block
Mutex: ...
Spin lock: held
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux18
down_read(rw_sem)
if (++rw_sem->readers > 1)
return /* enter the critical section */
else
rw_sem->readers--
take rw_sem->rtmutex.wait_lock
if (WRITER BIAS is not set) {
rw_sem->readers++
release rw_sem->rtmutex.wait_lock
return /* enter in the critical section */
}
release rw_sem->rtmutex.wait_lock
take rw_sem->rt_mutex
rw_sem->readers++
release the rw_sem->rt_mutex
return /* enter in the critical section */
}
down_write(rw_sem) {
take rw_sem->rtmutex
clear READER BIAS
if (rw_sem->readers != 0)
suspend waiting for the last reader
while(1) {
take sem->rtmutex->wait_lock
if (sem->readers == 0) {
set WRITER BIAS
release rw_sem->rtmutex->wait_lock
return
}
release rw_sem->rtmutex->wait_lock.
suspend waiting for the last reader
}
return
}
Concurrent down operations
Mutex: held
Spin lock: block
Mutex: ...
Spin lock: held
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux19
down_read(rw_sem)
if (++rw_sem->readers > 1)
return /* enter the critical section */
else
rw_sem->readers--
take rw_sem->rtmutex.wait_lock
if (WRITER BIAS is not set) {
rw_sem->readers++
release rw_sem->rtmutex.wait_lock
return /* enter in the critical section */
}
release rw_sem->rtmutex.wait_lock
take rw_sem->rt_mutex
rw_sem->readers++
release the rw_sem->rt_mutex
return /* enter in the critical section */
}
down_write(rw_sem) {
take rw_sem->rtmutex
clear READER BIAS
if (rw_sem->readers != 0)
suspend waiting for the last reader
while(1) {
take sem->rtmutex->wait_lock
if (sem->readers == 0) {
set WRITER BIAS
release rw_sem->rtmutex->wait_lock
return
}
release rw_sem->rtmutex->wait_lock.
suspend waiting for the last reader
}
return
}
Concurrent down operations
Mutex: held
Spin lock: held
Mutex: ...
Spin lock: ...
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux20
A task taking a write lock,
With a nested mutex
With a nested spin-lock.
down_write(rw_sem) {
take rw_sem->rtmutex
clear READER BIAS
if (rw_sem->readers != 0)
suspend waiting for the last reader
while(1) {
take sem->rtmutex->wait_lock
if (sem->readers == 0) {
set WRITER BIAS
release rw_sem->rtmutex->wait_lock
return
}
release rw_sem->rtmutex->wait_lock.
suspend waiting for the last reader
}
return
}
Mutex: held
Spin lock: held
Concurrent down operations
Open Issues
1) Implementing in Linux state-of-the-art protocols for
heterogeneous nested locks and developing novel
analysis techniques
- B. C. Ward and J. H. Anderson, “Supporting nested locking in
multiprocessor real-time systems,” in Real-Time Systems (ECRTS), 2012
24th Euromicro Conference on, 2012, pp. 223–232.
- Proposed real-time nested locking protocol (RNLP), with the related asymptotic analysis.
- B. C. Ward and J. H. Anderson, “Fine-grained multiprocessor real-time locking
with improved blocking,” in Proceedings of the 21st International Conference on
Real-Time Networks and Systems, ser. RTNS ’13, 2013.
- Conceived to deal with heterogeneous nested critical sections: Block + Spinning (
short-on-long)
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux23
Shared memory nested critical sections
- C. E. Nemitz, T. Amert, and J. H. Anderson, “Real-time multiprocessor locks with
nesting: Optimizing the common case,” in Proceedings of the 25th
International Conference on Real-Time and Network Systems (RTNS 2017), 2017
- nested read/write spin lock with fast path!
- A. Biondi, A. Weider, and B. Brandenburg, “A blocking bound for nested
fifo spin locks,” in Real-Time Systems Symposium (RTSS), 2016, pp.
291–302.
- Graph abstraction is introduced to derive a fine-grained analysis,
not based on asymptotic bounds for FIFO non-preemptive spin locks.
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux24
Shared memory nested critical sections
- Sleeping:
- Nested blocking (rt mutexes)
- Nested read/write (rw semaphores)
- Busy-wait:
- Nested read/write spin (rw lock)
- Nested spinlock (raw spin lock)
- Fast path is important
- Schedulers: TLFP, JLFP & IRQ/NMI
- Arbitrary affinities
RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux25
Linux’s locking needs
2) The design of specialized analysis techniques
accounting for specific implementations of
complex types of locks (e.g., the aforementioned
read/write lock in Linux).
3) finding more efficient locking protocols, accounting
for both general purpose benchmark performance (i.e.,
average-case behavior, needed by the GPOS nature of
Linux) and predictability.
Questions?
Thanks!

More Related Content

What's hot

Zeromq anatomy & jeromq
Zeromq anatomy & jeromqZeromq anatomy & jeromq
Zeromq anatomy & jeromqDongmin Yu
 
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit Framework
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit FrameworkUnmanned Aerial Vehicles: Exploit Automation with the Metasploit Framework
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit Frameworkegypt
 
Parallel computing in bioinformatics t.seemann - balti bioinformatics - wed...
Parallel computing in bioinformatics   t.seemann - balti bioinformatics - wed...Parallel computing in bioinformatics   t.seemann - balti bioinformatics - wed...
Parallel computing in bioinformatics t.seemann - balti bioinformatics - wed...Torsten Seemann
 
Presentiaon task sheduling first come first serve FCFS
Presentiaon  task sheduling first come first serve FCFSPresentiaon  task sheduling first come first serve FCFS
Presentiaon task sheduling first come first serve FCFSAhmed Salah
 
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...David Evans
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OSharini0810
 
first come first serve scheduling in os
first come first serve scheduling in os first come first serve scheduling in os
first come first serve scheduling in os mikeemukesh
 
Contiki introduction II-from what to how
Contiki introduction II-from what to howContiki introduction II-from what to how
Contiki introduction II-from what to howDingxin Xu
 
grsecurity and PaX
grsecurity and PaXgrsecurity and PaX
grsecurity and PaXKernel TLV
 
An Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux KernelAn Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux KernelSeongJae Park
 
Build reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQBuild reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQRobin Xiao
 
protothread and its usage in contiki OS
protothread and its usage in contiki OSprotothread and its usage in contiki OS
protothread and its usage in contiki OSSalah Amean
 
Non-DIY* Logging
Non-DIY* LoggingNon-DIY* Logging
Non-DIY* LoggingESUG
 
Fun with Network Interfaces
Fun with Network InterfacesFun with Network Interfaces
Fun with Network InterfacesKernel TLV
 
Comparision of scheduling algorithms
Comparision of scheduling algorithmsComparision of scheduling algorithms
Comparision of scheduling algorithmsTanya Makkar
 

What's hot (20)

RCU
RCURCU
RCU
 
Zeromq anatomy & jeromq
Zeromq anatomy & jeromqZeromq anatomy & jeromq
Zeromq anatomy & jeromq
 
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit Framework
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit FrameworkUnmanned Aerial Vehicles: Exploit Automation with the Metasploit Framework
Unmanned Aerial Vehicles: Exploit Automation with the Metasploit Framework
 
Kernel
KernelKernel
Kernel
 
Parallel computing in bioinformatics t.seemann - balti bioinformatics - wed...
Parallel computing in bioinformatics   t.seemann - balti bioinformatics - wed...Parallel computing in bioinformatics   t.seemann - balti bioinformatics - wed...
Parallel computing in bioinformatics t.seemann - balti bioinformatics - wed...
 
Presentiaon task sheduling first come first serve FCFS
Presentiaon  task sheduling first come first serve FCFSPresentiaon  task sheduling first come first serve FCFS
Presentiaon task sheduling first come first serve FCFS
 
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...
Smarter Scheduling (Priorities, Preemptive Priority Scheduling, Lottery and S...
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OS
 
first come first serve scheduling in os
first come first serve scheduling in os first come first serve scheduling in os
first come first serve scheduling in os
 
Contiki introduction II-from what to how
Contiki introduction II-from what to howContiki introduction II-from what to how
Contiki introduction II-from what to how
 
grsecurity and PaX
grsecurity and PaXgrsecurity and PaX
grsecurity and PaX
 
An Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux KernelAn Introduction to the Formalised Memory Model for Linux Kernel
An Introduction to the Formalised Memory Model for Linux Kernel
 
Cp usched 2
Cp usched  2Cp usched  2
Cp usched 2
 
Process scheduling linux
Process scheduling linuxProcess scheduling linux
Process scheduling linux
 
Build reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQBuild reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQ
 
protothread and its usage in contiki OS
protothread and its usage in contiki OSprotothread and its usage in contiki OS
protothread and its usage in contiki OS
 
Non-DIY* Logging
Non-DIY* LoggingNon-DIY* Logging
Non-DIY* Logging
 
Fun with Network Interfaces
Fun with Network InterfacesFun with Network Interfaces
Fun with Network Interfaces
 
Comparision of scheduling algorithms
Comparision of scheduling algorithmsComparision of scheduling algorithms
Comparision of scheduling algorithms
 
Ch05
Ch05Ch05
Ch05
 

Similar to Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linu

Userspace RCU library : what linear multiprocessor scalability means for your...
Userspace RCU library : what linear multiprocessor scalability means for your...Userspace RCU library : what linear multiprocessor scalability means for your...
Userspace RCU library : what linear multiprocessor scalability means for your...Alexey Ivanov
 
exercises-log-management-rsyslog.pdf
exercises-log-management-rsyslog.pdfexercises-log-management-rsyslog.pdf
exercises-log-management-rsyslog.pdfSngB2
 
Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing ToolsSysdig
 
Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing ToolsBrendan Gregg
 
RTOS implementation
RTOS implementationRTOS implementation
RTOS implementationRajan Kumar
 
REAL TIME OPERATING SYSTEM
REAL TIME OPERATING SYSTEMREAL TIME OPERATING SYSTEM
REAL TIME OPERATING SYSTEMprakrutijsh
 
Gluster d thread_synchronization_using_urcu_lca2016
Gluster d thread_synchronization_using_urcu_lca2016Gluster d thread_synchronization_using_urcu_lca2016
Gluster d thread_synchronization_using_urcu_lca2016Gluster.org
 
lxc-namespace.pdf
lxc-namespace.pdflxc-namespace.pdf
lxc-namespace.pdf-
 
Kick-off Project 2: Presentatie Linux
Kick-off Project 2: Presentatie LinuxKick-off Project 2: Presentatie Linux
Kick-off Project 2: Presentatie LinuxPatrick Koning
 
NSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNoSuchCon
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactAlessandro Selli
 

Similar to Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linu (20)

10a log
10a log10a log
10a log
 
Userspace RCU library : what linear multiprocessor scalability means for your...
Userspace RCU library : what linear multiprocessor scalability means for your...Userspace RCU library : what linear multiprocessor scalability means for your...
Userspace RCU library : what linear multiprocessor scalability means for your...
 
exercises-log-management-rsyslog.pdf
exercises-log-management-rsyslog.pdfexercises-log-management-rsyslog.pdf
exercises-log-management-rsyslog.pdf
 
Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing Tools
 
MyShell - English
MyShell - EnglishMyShell - English
MyShell - English
 
Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing Tools
 
freertos-proj.pdf
freertos-proj.pdffreertos-proj.pdf
freertos-proj.pdf
 
RTOS implementation
RTOS implementationRTOS implementation
RTOS implementation
 
REAL TIME OPERATING SYSTEM
REAL TIME OPERATING SYSTEMREAL TIME OPERATING SYSTEM
REAL TIME OPERATING SYSTEM
 
Gluster d thread_synchronization_using_urcu_lca2016
Gluster d thread_synchronization_using_urcu_lca2016Gluster d thread_synchronization_using_urcu_lca2016
Gluster d thread_synchronization_using_urcu_lca2016
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
lxc-namespace.pdf
lxc-namespace.pdflxc-namespace.pdf
lxc-namespace.pdf
 
Making Linux do Hard Real-time
Making Linux do Hard Real-timeMaking Linux do Hard Real-time
Making Linux do Hard Real-time
 
RabbitMQ in Sprayer
RabbitMQ in SprayerRabbitMQ in Sprayer
RabbitMQ in Sprayer
 
netLec5.pdf
netLec5.pdfnetLec5.pdf
netLec5.pdf
 
Kick-off Project 2: Presentatie Linux
Kick-off Project 2: Presentatie LinuxKick-off Project 2: Presentatie Linux
Kick-off Project 2: Presentatie Linux
 
Lamp ppt
Lamp pptLamp ppt
Lamp ppt
 
NSC #2 - Challenge Solution
NSC #2 - Challenge SolutionNSC #2 - Challenge Solution
NSC #2 - Challenge Solution
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compact
 

Recently uploaded

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 

Recently uploaded (20)

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 

Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linu

  • 1. Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux Daniel B. de Oliveira1,2,3 , Daniel Casini2 , Rômulo S. de Oliveira3 , Tommaso Cucinotta2 , Alessandro Biondi2 , and Giorgio Buttazzo2 Email: bristot@redhat.com, romulo.deoliveira@ufsc.br, { daniel.casini,tommaso.cucinotta, alessandro.biondi, giorgio.buttazzo } @santannapisa.it Real-time Scheduling Open Problems Seminar (RTSOPS 2018)
  • 2. - Linux is a GPOS with RTOS ambitions - Preemptive - FIFO (TLFP) and Deadline (JLFP) schedulers - User-space locks with PIP & PCP - PREEMPT-RT improves Linux’s predictability by: - Making system as preemptive/schedulable as possible - Bounding priority inversions using PIP on kernel locks - Max (activation delay?) latency of 150 µs RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux2 Real-time Linux
  • 3. Due to Linux’s GPOS nature, RT Linux developers are challenged to provide the predictability required for an RTOS, while not causing regressions on the general purpose benchmarks. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux3 Real-time Linux howevers
  • 4. - Developers cannot cause performance regressions - Throughput: - Two implementations: RT and non RT - A newer algorithm cannot cause - much - regression compared to the older one - Predictability: - Cannot increase the latency - e.g, cannot disable the preemption for a long period RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux4 In practice it means
  • 5. As a consequence, the implementation of some well known algorithms, like read/write semaphores, has been done using approaches that were exhaustively explored in academic papers. IOW: it works, but... RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux5 Consequences...
  • 6. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux6 Read/write semaphores on Linux Read-side down_read(&rw_semapore) { /* enters in the read-side */ } /* * Read-side critical section * Parallel with other readers * No writers */ up_read(&rw_semapore) { /* leaves the read-side */ } Write-side down_write(&rw_semapore) { /* enters in the write-side */ } /* * Write-side critical section * Exclusive access */ up_write(&rw_semapore) { /* leaves the write-side */ }
  • 7. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux7 Read/write semaphores on Linux struct rw_semaphore { atomic_t readers; struct rt_mutex rtmutex; };
  • 8. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux8 Read/write semaphores on Linux struct rw_semaphore { atomic_t readers; struct rt_mutex rtmutex; }; struct rt_mutex { raw_spinlock_t wait_lock; struct rb_root_cached waiters; struct task_struct *owner; int save_state; };
  • 9. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux9 Read/write semaphores on Linux struct rw_semaphore { atomic_t readers; struct rt_mutex rtmutex; }; struct rt_mutex { raw_spinlock_t wait_lock; struct rb_root_cached waiters; struct task_struct *owner; int save_state; };
  • 10. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux10 down_read(rw_sem) if (++rw_sem->readers > 1) return /* enter the critical section */ else rw_sem->readers-- take rw_sem->rtmutex.wait_lock if (WRITER BIAS is not set) { rw_sem->readers++ release rw_sem->rtmutex.wait_lock return /* enter in the critical section */ } release rw_sem->rtmutex.wait_lock take rw_sem->rt_mutex rw_sem->readers++ release the rw_sem->rt_mutex return /* enter in the critical section */ } down_write(rw_sem) { take rw_sem->rtmutex clear READER BIAS if (rw_sem->readers != 0) suspend waiting for the last reader while(1) { take sem->rtmutex->wait_lock if (sem->readers == 0) { set WRITER BIAS release rw_sem->rtmutex->wait_lock return } release rw_sem->rtmutex->wait_lock. suspend waiting for the last reader } return } Atomic operation Mutex: ... Spin lock: ... Concurrent down operations
  • 11. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux11 down_read(rw_sem) if (++rw_sem->readers > 1) return /* enter the critical section */ else rw_sem->readers-- take rw_sem->rtmutex.wait_lock if (WRITER BIAS is not set) { rw_sem->readers++ release rw_sem->rtmutex.wait_lock return /* enter in the critical section */ } release rw_sem->rtmutex.wait_lock take rw_sem->rt_mutex rw_sem->readers++ release the rw_sem->rt_mutex return /* enter in the critical section */ } down_write(rw_sem) { take rw_sem->rtmutex clear READER BIAS if (rw_sem->readers != 0) suspend waiting for the last reader while(1) { take sem->rtmutex->wait_lock if (sem->readers == 0) { set WRITER BIAS release rw_sem->rtmutex->wait_lock return } release rw_sem->rtmutex->wait_lock. suspend waiting for the last reader } return } Atomic operation Mutex: held Spin lock: ... Concurrent down operations
  • 12. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux12 down_read(rw_sem) if (++rw_sem->readers > 1) return /* enter the critical section */ else rw_sem->readers-- take rw_sem->rtmutex.wait_lock if (WRITER BIAS is not set) { rw_sem->readers++ release rw_sem->rtmutex.wait_lock return /* enter in the critical section */ } release rw_sem->rtmutex.wait_lock take rw_sem->rt_mutex rw_sem->readers++ release the rw_sem->rt_mutex return /* enter in the critical section */ } down_write(rw_sem) { take rw_sem->rtmutex clear READER BIAS if (rw_sem->readers != 0) suspend waiting for the last reader while(1) { take sem->rtmutex->wait_lock if (sem->readers == 0) { set WRITER BIAS release rw_sem->rtmutex->wait_lock return } release rw_sem->rtmutex->wait_lock. suspend waiting for the last reader } return } Atomic operation Mutex: held Spin lock: ... Concurrent down operations
  • 13. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux13 down_read(rw_sem) if (++rw_sem->readers > 1) return /* enter the critical section */ else rw_sem->readers-- take rw_sem->rtmutex.wait_lock if (WRITER BIAS is not set) { rw_sem->readers++ release rw_sem->rtmutex.wait_lock return /* enter in the critical section */ } release rw_sem->rtmutex.wait_lock take rw_sem->rt_mutex rw_sem->readers++ release the rw_sem->rt_mutex return /* enter in the critical section */ } down_write(rw_sem) { take rw_sem->rtmutex clear READER BIAS if (rw_sem->readers != 0) suspend waiting for the last reader while(1) { take sem->rtmutex->wait_lock if (sem->readers == 0) { set WRITER BIAS release rw_sem->rtmutex->wait_lock return } release rw_sem->rtmutex->wait_lock. suspend waiting for the last reader } return } Atomic operation Mutex: held Spin lock: ... Concurrent down operations
  • 14. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux14 down_read(rw_sem) if (++rw_sem->readers > 1) return /* enter the critical section */ else rw_sem->readers-- take rw_sem->rtmutex.wait_lock if (WRITER BIAS is not set) { rw_sem->readers++ release rw_sem->rtmutex.wait_lock return /* enter in the critical section */ } release rw_sem->rtmutex.wait_lock take rw_sem->rt_mutex rw_sem->readers++ release the rw_sem->rt_mutex return /* enter in the critical section */ } down_write(rw_sem) { take rw_sem->rtmutex clear READER BIAS if (rw_sem->readers != 0) suspend waiting for the last reader while(1) { take sem->rtmutex->wait_lock if (sem->readers == 0) { set WRITER BIAS release rw_sem->rtmutex->wait_lock return } release rw_sem->rtmutex->wait_lock. suspend waiting for the last reader } return } Mutex: held Spin lock: ... Concurrent down operations
  • 15. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux15 down_read(rw_sem) if (++rw_sem->readers > 1) return /* enter the critical section */ else rw_sem->readers-- take rw_sem->rtmutex.wait_lock if (WRITER BIAS is not set) { rw_sem->readers++ release rw_sem->rtmutex.wait_lock return /* enter in the critical section */ } release rw_sem->rtmutex.wait_lock take rw_sem->rt_mutex rw_sem->readers++ release the rw_sem->rt_mutex return /* enter in the critical section */ } down_write(rw_sem) { take rw_sem->rtmutex clear READER BIAS if (rw_sem->readers != 0) suspend waiting for the last reader while(1) { take sem->rtmutex->wait_lock if (sem->readers == 0) { set WRITER BIAS release rw_sem->rtmutex->wait_lock return } release rw_sem->rtmutex->wait_lock. suspend waiting for the last reader } return } Concurrent down operations Mutex: held Spin lock: block Mutex: ... Spin lock: held
  • 16. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux16 down_read(rw_sem) if (++rw_sem->readers > 1) return /* enter the critical section */ else rw_sem->readers-- take rw_sem->rtmutex.wait_lock if (WRITER BIAS is not set) { rw_sem->readers++ release rw_sem->rtmutex.wait_lock return /* enter in the critical section */ } release rw_sem->rtmutex.wait_lock take rw_sem->rt_mutex rw_sem->readers++ release the rw_sem->rt_mutex return /* enter in the critical section */ } down_write(rw_sem) { take rw_sem->rtmutex clear READER BIAS if (rw_sem->readers != 0) suspend waiting for the last reader while(1) { take sem->rtmutex->wait_lock if (sem->readers == 0) { set WRITER BIAS release rw_sem->rtmutex->wait_lock return } release rw_sem->rtmutex->wait_lock. suspend waiting for the last reader } return } Concurrent down operations Mutex: held Spin lock: block Mutex: ... Spin lock: held
  • 17. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux17 down_read(rw_sem) if (++rw_sem->readers > 1) return /* enter the critical section */ else rw_sem->readers-- take rw_sem->rtmutex.wait_lock if (WRITER BIAS is not set) { rw_sem->readers++ release rw_sem->rtmutex.wait_lock return /* enter in the critical section */ } release rw_sem->rtmutex.wait_lock take rw_sem->rt_mutex rw_sem->readers++ release the rw_sem->rt_mutex return /* enter in the critical section */ } down_write(rw_sem) { take rw_sem->rtmutex clear READER BIAS if (rw_sem->readers != 0) suspend waiting for the last reader while(1) { take sem->rtmutex->wait_lock if (sem->readers == 0) { set WRITER BIAS release rw_sem->rtmutex->wait_lock return } release rw_sem->rtmutex->wait_lock. suspend waiting for the last reader } return } Concurrent down operations Mutex: held Spin lock: block Mutex: ... Spin lock: held
  • 18. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux18 down_read(rw_sem) if (++rw_sem->readers > 1) return /* enter the critical section */ else rw_sem->readers-- take rw_sem->rtmutex.wait_lock if (WRITER BIAS is not set) { rw_sem->readers++ release rw_sem->rtmutex.wait_lock return /* enter in the critical section */ } release rw_sem->rtmutex.wait_lock take rw_sem->rt_mutex rw_sem->readers++ release the rw_sem->rt_mutex return /* enter in the critical section */ } down_write(rw_sem) { take rw_sem->rtmutex clear READER BIAS if (rw_sem->readers != 0) suspend waiting for the last reader while(1) { take sem->rtmutex->wait_lock if (sem->readers == 0) { set WRITER BIAS release rw_sem->rtmutex->wait_lock return } release rw_sem->rtmutex->wait_lock. suspend waiting for the last reader } return } Concurrent down operations Mutex: held Spin lock: block Mutex: ... Spin lock: held
  • 19. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux19 down_read(rw_sem) if (++rw_sem->readers > 1) return /* enter the critical section */ else rw_sem->readers-- take rw_sem->rtmutex.wait_lock if (WRITER BIAS is not set) { rw_sem->readers++ release rw_sem->rtmutex.wait_lock return /* enter in the critical section */ } release rw_sem->rtmutex.wait_lock take rw_sem->rt_mutex rw_sem->readers++ release the rw_sem->rt_mutex return /* enter in the critical section */ } down_write(rw_sem) { take rw_sem->rtmutex clear READER BIAS if (rw_sem->readers != 0) suspend waiting for the last reader while(1) { take sem->rtmutex->wait_lock if (sem->readers == 0) { set WRITER BIAS release rw_sem->rtmutex->wait_lock return } release rw_sem->rtmutex->wait_lock. suspend waiting for the last reader } return } Concurrent down operations Mutex: held Spin lock: held Mutex: ... Spin lock: ...
  • 20. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux20 A task taking a write lock, With a nested mutex With a nested spin-lock. down_write(rw_sem) { take rw_sem->rtmutex clear READER BIAS if (rw_sem->readers != 0) suspend waiting for the last reader while(1) { take sem->rtmutex->wait_lock if (sem->readers == 0) { set WRITER BIAS release rw_sem->rtmutex->wait_lock return } release rw_sem->rtmutex->wait_lock. suspend waiting for the last reader } return } Mutex: held Spin lock: held Concurrent down operations
  • 22. 1) Implementing in Linux state-of-the-art protocols for heterogeneous nested locks and developing novel analysis techniques
  • 23. - B. C. Ward and J. H. Anderson, “Supporting nested locking in multiprocessor real-time systems,” in Real-Time Systems (ECRTS), 2012 24th Euromicro Conference on, 2012, pp. 223–232. - Proposed real-time nested locking protocol (RNLP), with the related asymptotic analysis. - B. C. Ward and J. H. Anderson, “Fine-grained multiprocessor real-time locking with improved blocking,” in Proceedings of the 21st International Conference on Real-Time Networks and Systems, ser. RTNS ’13, 2013. - Conceived to deal with heterogeneous nested critical sections: Block + Spinning ( short-on-long) RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux23 Shared memory nested critical sections
  • 24. - C. E. Nemitz, T. Amert, and J. H. Anderson, “Real-time multiprocessor locks with nesting: Optimizing the common case,” in Proceedings of the 25th International Conference on Real-Time and Network Systems (RTNS 2017), 2017 - nested read/write spin lock with fast path! - A. Biondi, A. Weider, and B. Brandenburg, “A blocking bound for nested fifo spin locks,” in Real-Time Systems Symposium (RTSS), 2016, pp. 291–302. - Graph abstraction is introduced to derive a fine-grained analysis, not based on asymptotic bounds for FIFO non-preemptive spin locks. RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux24 Shared memory nested critical sections
  • 25. - Sleeping: - Nested blocking (rt mutexes) - Nested read/write (rw semaphores) - Busy-wait: - Nested read/write spin (rw lock) - Nested spinlock (raw spin lock) - Fast path is important - Schedulers: TLFP, JLFP & IRQ/NMI - Arbitrary affinities RTSOPS 2018: Nested Locks in the Lock Implementation: The Real-Time Read-Write Semaphores on Linux25 Linux’s locking needs
  • 26. 2) The design of specialized analysis techniques accounting for specific implementations of complex types of locks (e.g., the aforementioned read/write lock in Linux).
  • 27. 3) finding more efficient locking protocols, accounting for both general purpose benchmark performance (i.e., average-case behavior, needed by the GPOS nature of Linux) and predictability.