Fast on Average, Predictable in the Worst Case Exploring Real-Time Futexes in LITMUSRT Roy Spliet, Manohar Vanga, Björn Brandenburg, Sven Dziadek IEEE Real-Time Systems Symposium 2014 December 2-5, 2014 Rome, Italy 1 Real-Time Locking API Mutex API kernel_do_lock(); // critical section kernel_do_unlock(); 2 Real-Time Locking API Mutex API No other task is currently holding the lock kernel_do_lock(); // critical section kernel_do_unlock(); No other task is waiting for the lock Operations are typically uncontended at runtime 3 Futexes: Fast Userspace Mutexes A mechanism (API) in the Linux kernel ! • For optimizing the uncontended case of locking protocol implementations ! • Avoid kernel invocation during uncontended operations 4 Futexes: Fast Userspace Mutexes A mechanism (API) in the Linux kernel ! • For optimizing the uncontended case of locking protocol implementations ! • Avoid kernel invocation during uncontended operations Why optimize the uncontended case? ! • Improved throughput for soft real-time workloads ! • Increasing available slack time in the system 5 Real-Time Locking Implementations PRIO_INHERIT! PRIO_PROTECT Classic Priority (Priority (Immediate Multiprocessor Ceiling Protocol! FMLP Inheritance Priority Ceiling PCP (MPCP) (PCP) Protocol) Protocol) Futex Implementation Linux 6 Real-Time Locking Implementations PRIO_INHERIT! PRIO_PROTECT Classic Priority (Priority (Immediate Multiprocessor Ceiling Protocol! FMLP Inheritance Priority Ceiling PCP (MPCP) (PCP) Protocol) Protocol) Futex Implementation Linux LITMUSRT LITMUSRT Real-Time Locking Implementations PRIO_INHERIT! PRIO_PROTECT Classic Priority (Priority (Immediate Multiprocessor Ceiling Protocol! FMLP Inheritance Priority Ceiling PCP (MPCP) (PCP) Protocol) Protocol) Futex Implementation Linux LITMUSRT 8 Real-Time Locking Implementations PRIO_INHERIT! PRIO_PROTECT Classic Priority (Priority (Immediate Multiprocessor Ceiling Protocol! FMLP Inheritance Priority Ceiling PCP (MPCP) (PCP) Protocol) Protocol) Futex Implementation Linux LITMUSRT Choice between futex implementation and better analytical properties 9 Real-Time Locking Implementations PRIO_INHERIT! PRIO_PROTECT Classic Priority (Priority (Immediate Multiprocessor Ceiling Protocol! FMLP Inheritance Priority Ceiling PCP (MPCP) (PCP) Protocol) Protocol) Futex Implementation Linux LITMUSRT Choice between futex implementation and better analytical properties Why is it challenging to have both? 10 Real-Time Locking Implementations PRIO_INHERIT! PRIO_PROTECT Classic Priority (Priority (Immediate Multiprocessor Ceiling Protocol! FMLP Inheritance Priority Ceiling PCP (MPCP) (PCP) Protocol) Protocol) Futex Implementation Reactive Anticipatory 11 Real-Time Locking Protocol Dichotomy Reactive Locking Protocols Anticipatory Locking Protocols React to contention on a lock Anticipate problem scenarios only when it occurs. and take measure to minimize priority-inversion (pi) blocking. 12 Real-Time Locking Protocol Dichotomy Reactive Locking Protocols Anticipatory Locking Protocols React to contention on a lock Anticipate problem scenarios only when it occurs. and take measure to minimize priority-inversion (pi) blocking. Tricky to implement futexes Simple futex implementation without violating semantics 13 Contributions PRIO_INHERIT! PRIO_PROTECT Classic Priority (Priority (Immediate Multiprocessor Ceiling Protocol! FMLP Inheritance Priority Ceiling PCP (MPCP) (PCP) Protocol) Protocol) Futex Implementation 14 Contributions PRIO_INHERIT! PRIO_PROTECT Classic Priority (Priority (Immediate Multiprocessor Ceiling Protocol! FMLP Inheritance Priority Ceiling PCP (MPCP) (PCP) Protocol) Protocol) Futex Implementation Design and implementation of futexes for three anticipatory real-time locking protocols 15 Contributions PRIO_INHERIT! PRIO_PROTECT Classic Priority (Priority (Immediate Multiprocessor Ceiling Protocol! FMLP Inheritance Priority Ceiling PCP (MPCP) (PCP) Protocol) Protocol) Futex Implementation Observed overhead reduction: 92% 85% 84% Design and implementation of futexes for three anticipatory real-time locking protocols 16 Contributions PRIO_INHERIT! PRIO_PROTECT Classic Priority (Priority (Immediate Multiprocessor Ceiling Protocol! FMLP Inheritance Priority Ceiling PCP (MPCP) (PCP) Protocol) Protocol) Futex Implementation Observed overhead reduction: 92% 85% 84% Design and implementation of futexes for three anticipatory real-time locking protocols Method of using page faults to implement futexes 17 Overview of Talk 18 Overview of Talk Challenge Implementation Evaluation 19 Overview of Talk Challenge Implementation Evaluation 20 Futexes — Overview and Intuition The problem with the vanilla approach Mutex API kernel_do_lock(); // critical section kernel_do_unlock(); 21 Futexes — Overview and Intuition The problem with the vanilla approach Kernel invoked on every lock Mutex API and unlock operation kernel_do_lock(); // critical section kernel_do_unlock(); 22 Futexes — Overview and Intuition The problem with the vanilla approach Kernel invoked on every lock Mutex API and unlock operation kernel_do_lock(); // critical section kernel_do_unlock(); Task Task Task Lock State Kernel 23 Futexes — Overview and Intuition Exporting Lock State to Userspace Processes Task Task Task Lock State Kernel Shared lock state between userspace and kernel 24 Futexes — Overview and Intuition Exporting Lock State to Userspace Processes Task Task Task Futex Pseudocode try_to_acquire_lock(lock); Lock State if (lock is contended) Kernel kernel_do_lock(lock); // critical section release_lock(lock); if (there are blocked tasks) kernel_do_unlock(); 25 Futexes — Overview and Intuition Fast-Path for Uncontended Operations Task Task Task Futex Pseudocode try_to_acquire_lock(lock); Lock State if (lock is contended) Kernel kernel_do_lock(lock); // critical section release_lock(lock); if (there are blocked tasks) Fast-path when operation is kernel_do_unlock(); uncontended (kernel not invoked) 26 Futexes — Overview and Intuition Slow-Path for Contended Operations Task Task Task Futex Pseudocode try_to_acquire_lock(lock); Lock State if (lock is contended) Kernel kernel_do_lock(lock); // critical section release_lock(lock); if (there are blocked tasks) Kernel invoked only when lock or kernel_do_unlock(); unlock operation is contended 27 Priority Inheritance Protocol Futexes for reactive locking protocols HI Lock 2 LO Lock 1 Lock 2 … Time 28 Fixed-Priority Scheduling Priority Inheritance Protocol Futexes for reactive locking protocols Uncontended No kernel intervention HI Lock 2 LO Lock 1 Lock 2 … Time 29 Fixed-Priority Scheduling Priority Inheritance Protocol Futexes for reactive locking protocols Contended Kernel intervention needed Uncontended No kernel intervention HI Lock 2 LO Lock 1 Lock 2 … Time 30 Fixed-Priority Scheduling Priority Ceiling Protocol (PCP) • Each lock has a priority ceiling — the highest priority of all tasks that can acquire that lock. • System ceiling — Currently held lock with highest ceiling • A lock may be acquired by a task only if: • Task priority > System Ceiling Priority! • Or the task is holding the system ceiling! • When under pi-blocking, priority inheritance raises priority of lower priority task to that of higher priority task. 31 Priority Ceiling Protocol (PCP) • Each lock has a priority ceiling — the highest priority of all tasks that can acquire that lock. • System ceiling — Currently held lock with highest ceiling • A lock may be acquired by a task only if: • Task priority > System Ceiling Priority! • Or the task is holding the system ceiling! • When under pi-blocking, priority inheritance raises priority of lower priority task to that of higher priority task. 32 Priority Ceiling Protocol (PCP) • Each lock has a priority ceiling — the highest priority of all tasks that can acquire that lock. • System ceiling — Currently held lock with highest ceiling • A lock may be acquired by a task only if: • Task priority > System Ceiling Priority! • Or the task is holding the system ceiling! • When under pi-blocking, priority inheritance raises priority of lower priority task to that of higher priority task. 33 Priority Ceiling Protocol (PCP) • Each lock has a priority ceiling — the highest priority of all tasks that can acquire that lock. • System ceiling — Currently held lock with highest ceiling • A lock may be acquired by a task only if: • Task priority > System Ceiling Priority! • Or the task is holding the system ceiling! • When under contention, priority inheritance (raises priority of lower priority task to that of higher priority task). 34 PCP Futexes — Challenge HI L1 MED L2 LO L1 Time 35 Fixed-Priority Scheduling PCP Futexes — Challenge HI L1 MED L2 LO L1 Time Raises system ceiling prio. to HI Lowers system ceiling prio. to None 36 Fixed-Priority Scheduling PCP Futexes — Challenge Valid acquisition HI L1 MED > System Ceiling Prio. MED L2 LO L1 Time Raises system ceiling prio. to HI Lowers system ceiling prio. to None 37 Fixed-Priority Scheduling PCP Futexes — Challenge HI L1 HI L1 MED L2 MED L2 LO L1 LO L1 Time Time 38 Fixed-Priority Scheduling PCP Futexes — Challenge HI L1 HI L1 MED L2 MED L2 LO L1 LO L1 Time Time Raises system ceiling prio. to HI Preemption Sys. ceiling prio. = HI 39 Fixed-Priority Scheduling PCP Futexes — Challenge L2 free But invalid acquisition HI L1 HI L1 Sys. Ceiling Prio. > MED MED L2 MED L2 LO L1 LO L1 Time Time Raises system ceiling prio. to HI Preemption Sys. ceiling prio. = HI 40 Fixed-Priority Scheduling PCP Futexes — Challenge L2 free But invalid acquisition HI L1 HI L1 Sys.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages83 Page
-
File Size-