Presentation is loading. Please wait.

Presentation is loading. Please wait.

G53SRP: Resource Sharing Issues

Similar presentations


Presentation on theme: "G53SRP: Resource Sharing Issues"— Presentation transcript:

1 G53SRP: Resource Sharing Issues
Real Time Scheduling Resource sharingReal Time Scheduling 29/11/2018 G53SRP: Resource Sharing Issues Chris Greenhalgh School of Computer Science 1 G53SRP G53SRPG53SRP 1

2 Resource sharingReal Time Scheduling
Contents Resource sharing Priority inversion Priority inheritance Priority ceiling emulation RTSJ support Wait-free interactions Summary Book: Wellings ch. 14 (esp & 14.2) 2 G53SRPG53SRP

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 Example of Blocking Process b has higher priority
Process b attempts to lock shared resource Q Process Process a releases lock on Q and is preempted b a 2 4 6 8 10 12 14 16 18 Executing Preempted 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 Example of Priority Inversion
Process Process c attempts to lock shared resource Q c Process c delayed by b which pre-empts a Process a releases lock on Q b a 2 4 6 8 10 12 14 16 18 Executing Preempted 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 Example of Simple Priority Inheritance
Process Process c attempts to lock shared resource Q c Process a inherits priority of c Process a releases lock on Q b a 2 4 6 8 10 12 14 16 18 Executing Preempted Executing with Q locked Blocked

9 Example of Priority Ceiling Emulation
Process Process a has normal priority when not locking Q c b Process a has elevated priority while locking Q a 2 4 6 8 10 12 14 16 18 Executing Preempted 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); Object monitor, }

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


Download ppt "G53SRP: Resource Sharing Issues"

Similar presentations


Ads by Google