Resource Access Protocols

17
Resource Access Protocols Resource Access Protocols 張張張張張張張 張張張張張張張張張

description

Resource Access Protocols. 張軒彬助理教授 中興大學資訊科學系. Outline. Priority Inversion Priority Inheritance Protocol. Resource. A resource is any software structure A variable, a memory area, a file, etc. A resource may be shared or private. Exclusive resource - PowerPoint PPT Presentation

Transcript of Resource Access Protocols

Page 1: Resource Access Protocols

Resource Access ProtocolsResource Access Protocols

張軒彬助理教授

中興大學資訊科學系

Page 2: Resource Access Protocols

2嵌入式即時作業系統

OutlineOutline

• Priority Inversion

• Priority Inheritance Protocol

Page 3: Resource Access Protocols

3嵌入式即時作業系統

ResourceResource

• A resource is any software structure– A variable, a memory area, a file, etc.

• A resource may be shared or private.• Exclusive resource

– A shared resource that is protected against concurrent access

• A piece of code executed under mutual exclusion to guarantee exclusive resource accesses is called critical section

Page 4: Resource Access Protocols

4嵌入式即時作業系統

Priority InversionPriority Inversion

• A high-priority job can experience two kinds of blocking– Bounded

• For example, a high-priority job waits for the executions of a low-priority job to acquire a resource

• The blocking time is no longer than that of the critical section where the lower priority job owns the resources

• Necessary to ensure resource consistence

– Unbounded• When a third job preempts the low-priority job during the inversion,

thus delaying the high-priority job even more • Would lead to uncontrolled blocking and cause high-priory job miss its

deadline• Have to be solved

Page 5: Resource Access Protocols

5嵌入式即時作業系統

An Example of Priority Inversion: BoundedAn Example of Priority Inversion: Bounded

normal execution

critical section

J1 blocked

J 1

J 2t1 t2

Example of blocking on an exclusive resource.

Priority of J1 > Priority of J2

Page 6: Resource Access Protocols

6嵌入式即時作業系統

An Example of Priority Inversion: Unbounded An Example of Priority Inversion: Unbounded

An example of priority inversion.

t7t6t5t4t3t2t1t0J 3

J 2

J 1

J 1 blocked

critical sectionnormal execution

J1 and J3 share an exclusive resource

Priority: J1 > J2 > J3

Page 7: Resource Access Protocols

7嵌入式即時作業系統

Priority Inversion (Cont.)Priority Inversion (Cont.)

• Solution– Disallow preemption during the execution of all

critical sections• Only appropriate for very short critical sections because

it may create unnecessary blocking

– Priority Inheritance Protocol

– Priority Ceiling Protocol

Page 8: Resource Access Protocols

8嵌入式即時作業系統

Priority Inheritance ProtocolPriority 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.

Page 9: Resource Access Protocols

9嵌入式即時作業系統

ExampleExample

P3

P3 P1

Example of Priority Inheritance Protocol.

t7t6t5t4t3t2t1t0J 3

J 2

J 1

critical sectionnormal execution Priority: J1 > J2 > J3

J1 and J3 share an exclusive resource

Direct blocking

Push-through blocking

Page 10: Resource Access Protocols

10嵌入式即時作業系統

ExampleExample

• Direct blocking– Occurs when a higher-priority job tries to acquire a resource

already held by a lower-priority job

– Necessary to ensure the consistency of the shared resource

• Push-through blocking – Occurs when a medium-priority job is blocked by a lower-

priority job that has inherited a higher priority from a job it directly blocks

– Necessary to avoid unbounded priority inversion

Page 11: Resource Access Protocols

11嵌入式即時作業系統

Priority Inheritance Protocol (Cont.)Priority Inheritance Protocol (Cont.)

• Unsolved problems– Chained blocking

• The blocking duration for a job can still be substantial because a chain of blocking can be formed

– Deadlock• The protocol does not prevent deadlocks

Page 12: Resource Access Protocols

12嵌入式即時作業系統

Chained BlockingChained Blocking

Example of chained blocking.

aaJ 3

bbJ 2

baJ 1

critical sectionnormal execution Priority: J1 > J2 > J3

J1 and J3 share an exclusive resource aJ1 and J2 share an exclusive resource b

Page 13: Resource Access Protocols

13嵌入式即時作業系統

Chained Blocking (Cont.)Chained Blocking (Cont.)

• From previous slide– J1 is blocked for the duration of two critical sections

• Once to wait J3 to release resource a

• Then to wait J2 to release resource b

– This is called chain blocking

• In the worst case, if J1 accesses n distinct resource that have been locked by n lower-priority jobs– J1 will be blocked for the duration of n critical sections

Page 14: Resource Access Protocols

14嵌入式即時作業系統

DeadlockDeadlock

t5t4t3t2t1

bbJ 2

aJ 1

critical sectionnormal execution

J 1 J 2

wait(S b)

wait(S a)

signal(S b)

signal(S a)

wait(S a)

signal(S b)

wait(S b)

signal(S b)

Example of deadlock.

Blocked on Sb

Blocked on Sa

Page 15: Resource Access Protocols

15嵌入式即時作業系統

Deadlock (Cont.)Deadlock (Cont.)

• Two jobs that use two semaphores in a nested fashion but in reverse order

• J1 is blocked on Sb at time t4. Then, J2 is blocked on Sa at time t5

– Deadlock

Page 16: Resource Access Protocols

16嵌入式即時作業系統

Deadlock (Cont.)Deadlock (Cont.)

• Notably, the deadlock does not depend on the Priority Inheritance Protocol– But is caused by an erroneous use of semaphores

– The deadlock problem can be solved by the mechanisms introduced in the Operating System

• E.g., impose an total ordering on the resource access

Page 17: Resource Access Protocols

17嵌入式即時作業系統

ReferenceReference

• Giorgio C. Buttazzo, “Hard Real-Time Computing Systems: Predictable Scheduling Algorithms and Applications,” Kluwer Academic Publishers, 1997

• Jane W. S. Liu, “Real-Time Systems,” Prentice Hall, 2002