190 likes | 304 Views
This document explores crucial resource sharing issues in real-time systems, focusing on priority inversion, priority inheritance, and priority ceiling emulation. It discusses how locks can lead to blocking scenarios that impact the worst-case response time of higher-priority processes, illustrating concepts with examples. Additionally, it examines wait-free interactions as an alternative to traditional locking mechanisms, providing insights into RTSJ support for dynamic priority management. The information is summarized for practical understanding, referencing key concepts from Wellings' work.
E N D
G53SRP: Resource Sharing Issues Chris Greenhalgh School of Computer Science 1
Contents • Resource sharing • Priority inversion • Priority inheritance • Priority ceiling emulation • RTSJ support • Wait-free interactions • Summary • Book: Wellings ch. 14 (esp. 14.1 & 14.2) 2
Resource sharing • Locking => blocking • lower-priority process locking a resource shared with a higher-priority process delays it • Additional source of interference – delays worst case response time of higher-priority process • By longest time for which lower priority process holds lock for each acquisition in worst case
Process b has higher priority Process b attempts to lock shared resource Q Process a releases lock on Q and is preempted Example of Blocking Process b a 0 2 4 6 8 10 12 14 16 18 Preempted Executing Executing with Q locked Blocked
Priority inversion • But its worse than that: • P3 (lowest priority) holds lock • P1 (highest priority) is blocked waiting for lock • P2 (medium priority) executes • Pre-empts P3 – higher priority • so P1 is further delayed by P2 (no shared resource) as well as P1
Process c attempts to lock shared resource Q Process c delayed by b which pre-empts a Process a releases lock on Q Example of Priority Inversion Process c b a 0 2 4 6 8 10 12 14 16 18 Preempted Executing Executing with Q locked Blocked
Priority inheritance • Dynamically adjusts priority of a process holding a lock: (a) Simple priority inheritance => to maximum priority of all processes currently waiting for lock (b) Priority ceiling emulation => to maximum priority of all processes that ever acquire lock
Process c attempts to lock shared resource Q Process a inherits priority of c Process a releases lock on Q Example of Simple Priority Inheritance Process c b a 0 2 4 6 8 10 12 14 16 18 Preempted Executing Executing with Q locked Blocked
Process a has elevated priority while locking Q Process a has normal priority when not locking Q Example of Priority Ceiling Emulation Process c b a 0 2 4 6 8 10 12 14 16 18 Preempted Executing Executing with Q locked Blocked
Priority inheritance notes • Simple priority inheritance • Prevents priority inversion – limits blocking delay • No additional information required • Priority ceiling emulation • Easier to implement • Requires input from programmer or program analysis to decide in advance what priority to associate with each lock/resource • May reduce worst case blocking compared to simple priority inheritance, but may increase delays in common case (always elevates priority)
Priority inheritance in RTSJ • Simple priority inheritance required by default • Priority ceiling emulation may also be available • In the specification, but optional to implement • NOT implemented in the lab JVM • Specifiable per monitor (i.e. Java object) • With process-wide default • Implemented by MonitorControl and subclasses…
Priority Inheritance classes <<abstract>>javax.realtime.MonitorControl extends javax.realtime.PriorityInheritance javax.realtime.PriorityCeilingEmulation
MonitorControl class package javax.realtime; public abstract class MonitorControl { // default public static MonitorControl getMonitorControl(); public static MonitorControl setMonitorControl( MonitorControl mc); // one monitor public static MonitorControl getMonitorControl( Object monitor); public static MonitorControl setMonitorControl( Object monitor, MonitorControl mc); }
PriorityInheritance class package javax.realtime; public class PriorityInheritance extends MonitorControl { // singleton public static PriorityInheritance instance(); }
PriorityCeilingEmulation class package javax.realtime; public class PriorityCeilingEmulation extends MonitorControl { // instance per priority public PriorityCeilingEmulation instance(int ceiling); public int getCeiling(); // max public static int getMaxCeiling(); } N.B. throws UnsupportedOperationException if not supported by JVM
Examples of use … // actually default anyway… MonitorControl.setMonitorControl( PriorityInheritance.instance()); … MonitorControl.setMonitorControl(sharedObj, PriorityCeilingEmulation.instance(20)); … synchronized(sharedObj) { // will run with priority 20… … } … N.B. it is an error to lock an object with a lower ceiling priority than the thread
Wait-free interactions • An alternative to locks and blocking… • Interactions from a (e.g. high priority) thread fail rather than block • So no risk of delaying the (e.g. high priority) thread • E.g. javax.realtime.WaitFreeReadQueue & WaitFreeWriteQueue • Will block write/read (respectively) if queue full/empty (respectively) • Will not block read/write (respectively) but return null/false (respectively) to indicate failure
Summary (1) • Resource sharing with locks (mutual exclusion) may introduce additional delays due to blocking • Priority inversion can result • Intermediate priority processes pre-empt lower priority processes holding locks needed by higher priority processes • Priority inheritance prevents this => limits blocking time • Simple priority inheritance increases lock-holder’s priority when higher priority processes are waiting for lock • Priority ceiling emulation always increases lock-holder’s priority
Summary (2) • RTSJ requires priority inheritance by default • Others (e.g. priority ceiling emulation) can be specified as default or per-monitor • These are optional in implementation(s) • See MonitorControl • Wait-free interaction can be used to avoid some forms of conflict & blocking • E.g. WaitFreeRead/WriteQueue