1 / 19

G53SRP: Resource Sharing Issues

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.

Download Presentation

G53SRP: Resource Sharing Issues

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. G53SRP: Resource Sharing Issues Chris Greenhalgh School of Computer Science 1

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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)

  11. 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…

  12. Priority Inheritance classes <<abstract>>javax.realtime.MonitorControl extends javax.realtime.PriorityInheritance javax.realtime.PriorityCeilingEmulation

  13. 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); }

  14. PriorityInheritance class package javax.realtime; public class PriorityInheritance extends MonitorControl { // singleton public static PriorityInheritance instance(); }

  15. 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

  16. 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

  17. 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

  18. 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

  19. 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

More Related