3Resource A resource is any software structure A variable, a memory area, a file, etc.A resource may be shared or private.Exclusive resourceA shared resource that is protected against concurrent accessA piece of code executed under mutual exclusion to guarantee exclusive resource accesses is called critical sectionA resource is any software structure, for example, a data structure, a variable, man memory area or a file.A resource may be shared or private. If shared, it may also be protected against concurrent accesses, which is called exclusive resource.
4Priority InversionA high-priority job can experience two kinds of blockingBoundedFor example, a high-priority job waits for the executions of a low-priority job to acquire a resourceThe blocking time is no longer than that of the critical section where the lower priority job owns the resourcesNecessary to ensure resource consistenceUnboundedWhen a third job preempts the low-priority job during the inversion, thus delaying the high-priority job even moreWould lead to uncontrolled blocking and cause high-priory job miss its deadlineHave to be solved
5An Example of Priority Inversion: Bounded normal executioncritical sectionJ1 blockedJ 1J 2t1t2Example of blocking on an exclusive resource.Priority of J1 > Priority of J2J1 has a higher priority than J2.J2 start its execution first and then enter a critical section. During the execution of its critical section, J1 is activated and preempts J2 since it has a higher priority than J2. However, when J1 want to enter its critical section to access the exclusive shared resource, it is blocked since the source is currently hold by J2.As a result, J2 resume again. After it finish its execution in the critical section, the exclusive shared resource is unlocked and J1 change from block state to the ready time. Thus, J1 preempt J2 and enter its critical section.
6An Example of Priority Inversion: Unbounded normal executionPriority: J1 > J2 > J3critical sectionJ1 and J3 share an exclusive resourceJ 1 blockedJ 1Three tasks J1, J2 and J3 have decreasing priority. Besides, J1 and J3 share an exclusive resource.At first, J3 start execution and enter its critical section. During the execution of its critical section, J1 is activated and preempts J3. However, when J1 want to enter its critical section to access the exclusive shared resource, it is blocked since the resource is currently hold by J3. Thus, J1 is blocked and J3 resumes execution.At time t4, J2 becomes ready and preempt J2. After it finish execution, J3 resume again. At time t6, J3 finish execution and finally J1 is ready and enter its critical section.Thus, in the interval [t3, t6], a priority inversion is occurred. Note that, the maximum blocking time that J1 may experience is undetermined, which would lead to uncontrolled blocking time and miss its deadline.J 2J 3t0t1t2t3t4t5t6t7An example of priority inversion.
7Priority Inversion (Cont.) SolutionDisallow preemption during the execution of all critical sectionsOnly appropriate for very short critical sections because it may create unnecessary blockingPriority Inheritance ProtocolPriority Ceiling ProtocolThere are some approaches to solve the priority inversion problem.First, we may disallow preemption during the execution of all critical section. However, this would result in unnecessary blocking since a higher-priority task that does not want to enter its critical section will also be blocked.The other approaches are priority inheritance protocol and priority ceiling protocol.
8Priority Inheritance Protocol When a job Ti is blocked by a lower priority job Tk, Ti transmits its priority to the Tk.In general, a job inherits the highest priority of the jobs blocked by it.Priority inheritance is transitive;If J3 blocks J2, and J2 blocks J1, then J3 inherits the priority of J1 via J2.Priority inheritance protocol: modify the priority of host task that cause blocking.
9Example Example of Priority Inheritance Protocol. normal execution Priority: J1 > J2 > J3critical sectionJ1 and J3 share an exclusive resourceDirect blockingJ 1Push-through blockingJ 2At time t3, which is called direct blocking, J1 want to enter its critical section but is blocked. J3 inheritance J1’s prioirty.At time t4, which is called push-through blocking, J2 becomes ready, but however, is blocked.J 3t0t1t2t3t4t5t6t7P1P3P3Example of Priority Inheritance Protocol.
10Example Direct blocking Push-through blocking Occurs when a higher-priority job tries to acquire a resource already held by a lower-priority jobNecessary to ensure the consistency of the shared resourcePush-through blockingOccurs when a medium-priority job is blocked by a lower-priority job that has inherited a higher priority from a job it directly blocksNecessary to avoid unbounded priority inversion
11Priority Inheritance Protocol (Cont.) Unsolved problemsChained blockingThe blocking duration for a job can still be substantial because a chain of blocking can be formedDeadlockThe protocol does not prevent deadlocksHowever, the priority inheritance protocol may suffer from chained blocking and deadlock.
12Example of chained blocking. normal executionPriority: J1 > J2 > J3J1 and J3 share an exclusive resource acritical sectionJ1 and J2 share an exclusive resource bJ 1abJ 2bbJ1 have to wait for both J2 and J3 to release the shared resources a and b.J 3aaExample of chained blocking.
13Chained Blocking (Cont.) From previous slideJ1 is blocked for the duration of two critical sectionsOnce to wait J3 to release resource aThen to wait J2 to release resource bThis is called chain blockingIn the worst case, if J1 accesses n distinct resource that have been locked by n lower-priority jobsJ1 will be blocked for the duration of n critical sections
14Deadlock normal execution critical section J 1 a J 2 b b Blocked on Sbwait(S a)wait(S b)J 1await(S b)wait(S a)Blocked on SaJ 2Two jobs that use two semaphores in a nested fashion but in reverse order.As shown in the figure, J1 is blocked at t4. Then, J2 is blocked in t5. As a result, a deadlock is occurred.bbsignal(S b)signal(S b)t1t2t3t4t5signal(S a)signal(S b)Example of deadlock.
15Deadlock (Cont.)Two jobs that use two semaphores in a nested fashion but in reverse orderJ1 is blocked on Sb at time t4. Then, J2 is blocked on Sa at time t5Deadlock
16Deadlock (Cont.)Notably, the deadlock does not depend on the Priority Inheritance ProtocolBut is caused by an erroneous use of semaphoresThe deadlock problem can be solved by the mechanisms introduced in the Operating SystemE.g., impose an total ordering on the resource accessBoth the chained blocking and deadlock are be solved by the Protocol Ceiling Protocol. However, we skip it in our course.
17ReferenceGiorgio C. Buttazzo, “Hard Real-Time Computing Systems: Predictable Scheduling Algorithms and Applications,” Kluwer Academic Publishers, 1997Jane W. S. Liu, “Real-Time Systems,” Prentice Hall, 2002