You are on page 1of 163

Priority Inversion

© 2009 Universität Karlsruhe (TH), System Architecture Group 1


Roadmap for Today

 Priority Inversion
 Resource protocols
 Synchronization Mechanisms
 Sg a g
Signaling
 Semaphores
 Monitors

 Synchronization Problems
 Producer / Consumer and
 Reader / Writer

© 2009 Universität Karlsruhe (TH), System Architecture Group 2


Example

P5  5 processes
 process number equals priority
P4  Priority of P5 > priority of P1
 Release and execution times
as shown
P3
 No deadlines (only an example
for later comparison)
P2
 Priority-driven preemptively
P1
scheduled

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 3


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 4


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 5


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 6


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 7


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 8


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 9


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 10


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 11


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 12


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 13


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 14


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 15


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 16


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 17


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 18


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 19


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 20


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 21


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 22


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 23


Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 24


Reality is more complex

 Processes are not usually independent

© 2009 Universität Karlsruhe (TH), System Architecture Group 25


Real-Time Traffic Scheduling

 Two process
streams

 A high priority
& a low priority

© 2009 Universität Karlsruhe (TH), System Architecture Group 26


Problem

 Intersection is a mutually exclusive resource

© 2009 Universität Karlsruhe (TH), System Architecture Group 27


Mutual Exclusion

 Can be solved by
resource access protocols

© 2009 Universität Karlsruhe (TH), System Architecture Group 28


Priorities and Resource
Contention

Main Reference
Pane W. S. Liu “Real-time Systems”, Chapter 8

© 2009 Universität Karlsruhe (TH), System Architecture Group 29


Resources

 Processes require resources in order to


execute. (e.g. locks, ports, memory, …)
 Resource characteristics
 Serially reusable,
 Mutually exclusive
 We ignore resources that
 are infinitely available or exceed demand,
 or can be pre-allocated.

© 2009 Universität Karlsruhe (TH), System Architecture Group 30


Resource Contention Problem

 Priority inversion.
 We need to, at least,
bound the length of P3 3

priority inversion.
 Preferably minimize the P2 2 R1
length of priority inversion.
P1 1
Famous example of priority inversion:

Mars Pathfinder 1997


© 2009 Universität Karlsruhe (TH), System Architecture Group 31
Marth Pathfinder

Mars Path Finder and the famous Mars Rock YOGI

© 2009 Universität Karlsruhe (TH), System Architecture Group 32


Resource Contention Problems

 Timing anomaly
 Deadlock
P2 2

R1

R2
P1 1

© 2009 Universität Karlsruhe (TH), System Architecture Group 33


Resource Contention

Major Assumption

 Single processor system

© 2009 Universität Karlsruhe (TH), System Architecture Group 34


Example with Resources

Our Example + 2 Resources

P5 Resource 1

P4 Resource 2

P3 Nested Critical Section*

P2

P1

0 2 4 6 8 10 12 14 16 18 20
*P2 first needs R1 and then later additionally R2
© 2009 Universität Karlsruhe (TH), System Architecture Group 35
SPD Scheduling

Simple Priority Driven Scheduling

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 36


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 37


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 38


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 39


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 40


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 41


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 42


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 43


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 44


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 45


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 46


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 47


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 48


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 49


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 50


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 51


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 52


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 53


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 54


SPD Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 55


SPD Scheduling

Result

 The most important processes P5 and P4 are


heavily delayed

 P3 is almost not delayed due to its


characteristic,
h t i ti it does
d nott need
d any resource

 Find a better solution

© 2009 Universität Karlsruhe (TH), System Architecture Group 56


Resource Allocation Protocols

4 Resource Allocation Protocols

 Non Preemptive Critical Sections (NPCS)


 Priority Inheritance (PI)
 Priority-Ceiling Protocol (PCP)
 Stacked Priority-Ceiling Protocol (SPCP)
 … and some others
 See text book (Liu)

© 2009 Universität Karlsruhe (TH), System Architecture Group 57


NPCS Scheduling

Nonpreemptive Critical Sections

 As soon as a process holds


a resource it is no longer P3 3 cannot
preemptable* happen at t1

 Prevents deadlock P2 2 R1

 Bounds priority inversion P1 31


Allocate at t0

 Max blocking time is the


maximum execution time of
max prio
the critical sections of all
lower priority processes

*This process gets highest priority in system


© 2009 Universität Karlsruhe (TH), System Architecture Group 58
NPCS Scheduling

Non-Preemptive Critical Sections

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 59


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 60


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 61


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 62


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 63


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 64


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 65


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 66


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 67


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 68


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 69


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 70


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 71


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 72


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 73


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 74


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 75


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 76


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 77


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 78


NPCS Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 79


NPCS Scheduling

Comparison with SPD-Scheduling

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 80


NPCS Scheduling

Analysis: Nonpreemptive Critical


Sections
 Pros
 Simple
 No prior knowledge of resource requirements
needed
 Prevents deadlock
 Cons
 Low priority process blocks high priority process
even when there are no resource conflicts
 Protocol only suitable for trusted software
 Usually implemented by interrupt disabling

 In CS there is no system calls otherwise CPU


wasting in case of a “blocking” system call

© 2009 Universität Karlsruhe (TH), System Architecture Group 81


NPCS Scheduling

Worst-Case Blocking Time

 Longest lower-priority critical section:

bti(rc) = max {cstk}


i+1 ≤k ≤ n

bt = blocking time
cst = critical section time

© 2009 Universität Karlsruhe (TH), System Architecture Group 82


PI Scheduling

Priority Inheritance (PI)

 When a high-priority
process (P3) blocks, the
low-priority process (P1) P3 3

inherits the current priority


of the blocking process
P2 2 R1

P1
13

 PI bounds priority inversion

© 2009 Universität Karlsruhe (TH), System Architecture Group 83


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 84


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 85


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 86


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 87


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 88


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 89


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 90


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2

P1 4

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 91


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2

P1 4

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 92


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5

P1 4

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 93


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5

P1 4 5

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 94


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5

P1 4 5

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 95


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5

P1 4 5 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 96


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5

P1 4 5 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 97


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5

P1 4 5 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 98


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5 2

P1 4 5 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 99


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5 2

P1 4 5 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 100


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5 2

P1 4 5 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 101


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5 2

P1 4 5 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 102


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5 2

P1 4 5 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 103


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5 2

P1 4 5 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 104


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5 2

P1 4 5 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 105


PI Scheduling

Example with Priority Inheritance

P5

P4

P3

P2 5 2

P1 4 5 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 106


PI Scheduling

Comparison with SPD Rule

P5

P4

P3

P2 5 2

P1 4 5 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 107


PI Scheduling

Analysis: Priority Inheritance

 Pros
 Prevents uncontrolled priority inversion.
 Needs no knowledge of resource requirements.

 C
Cons
 Does not prevent deadlock.
 Does not minimise blocking times.
 With chained blocking, worst-case blocking time is
min(n,m) critical sections
 n = number of lower priority processes that can block P
 m = number of resources that can be used to block P
 Some overhead in a release or acquire operation
© 2009 Universität Karlsruhe (TH), System Architecture Group 108
PI Scheduling

Chained Blocking

 4 lower priority processes


 4 potentially conflicting
resources
 Worst-case blocking time
Priority

= 16 units1

1Assume lower priority process


Time allocates its first resource just
before higher priority process runs
© 2009 Universität Karlsruhe (TH), System Architecture Group 109
PCP Scheduling

Priority Ceiling Protocol

 Avoids deadlock by defining an order of


resource acquisition

 Prevents transitive (chained) blocking


 Worst-case blocking time = single critical section

Description how to implement PCP, see:


http://www.awprofessional.com/articles/article.asp?p=30188&seqNum=5&rl=1

© 2009 Universität Karlsruhe (TH), System Architecture Group 110


PCP Scheduling

Priority Ceilings

 Resources required by all processes are


known a priori
 Similar approach as with deadlock avoidance

 Priority ceiling
l off resource Ri is equall to the
h
highest priority of all processes that use Ri

 Priority ceiling of system is highest priority


ceiling of all resources currently in use

© 2009 Universität Karlsruhe (TH), System Architecture Group 111


PCP Scheduling

Priority Ceilings of Our Example

P5 Priority Ceilings of Ri
=5
P4
=4
P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 112


PCP Scheduling

Priority Ceiling Protocol Rules

 Priority inheritance applies as before.


 When a process (P) requests a resource (R)
either:
 If R is allocated  P blocks (+ priority inheritance)
 If R is free,
 If P’s current priority > system’s priority ceiling 

R is allocated to process P
 If P’s current priority ≤ system’s priority ceiling 
P blocks – except if:
 P already holds a resource whose priority ceiling is
equal to the systems priority ceiling

© 2009 Universität Karlsruhe (TH), System Architecture Group 113


PCP Scheduling

Example
max

P5

P4

P3

P2

P1 curr

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 114


PCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 115


PCP Scheduling

Example

P5
curr

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 116


PCP Scheduling

Example

P5

P4

P3

P2 Prio(P2) < CurrSPC  no allocation

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 117


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 … but P1 inherits prio(P2) = 2

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 118


PCP Scheduling

Example

P5

P4

P3

P2

P1 2

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 119


PCP Scheduling

Example

P5

P4

P3

P2

P1 2

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 120


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 121


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 122


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 123


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 124


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 125


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 126


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 127


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 128


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 129


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 130


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 131


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 132


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 133


PCP Scheduling

Example

P5

P4

P3

P2

P1 2 4 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 134


PCP Scheduling

Comparison to Previous Example

P5

P4

P3

P2

P1 2 4 1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 135


PCP Scheduling

Analysis: Priority Ceiling Protocol

 Pros
 Avoids deadlocks
 If a process doesn’t self suspend, a process is
blocked at most once during execution
 Processes cannot be transitively blocked
 minimizes blocking time to the longest lower-priority
conflicting critical section (+ context switches)
 Processes only receive their first resource when all
required resources are not held by lower priority
processes
 Cons
 A priori knowledge of resource needs is required

© 2009 Universität Karlsruhe (TH), System Architecture Group 136


SPCP Scheduling

Stack-Based Priority Ceiling Protocol

 The motivation is to share a single stack


for all processes
 Saves stack space.

 Restriction: processes cannot self-


suspend.

© 2009 Universität Karlsruhe (TH), System Architecture Group 137


SPCP Scheduling

Rules

 Scheduling:
 After a process is released, it is blocked from
starting until its assigned priority is higher than
the current system priority ceiling.
 Unblocked processes are preemptively priority
scheduled according to their assigned priority.

 Resource allocation:
 Whenever a process requests a resource it
receives the resource.

© 2009 Universität Karlsruhe (TH), System Architecture Group 138


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 139


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 140


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 141


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 142


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 143


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 144


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 145


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 146


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 147


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 148


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 149


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 150


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 151


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 152


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 153


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 154


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 155


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 156


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 157


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 158


SPCP Scheduling

Example

P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 159


SPCP Scheduling

Comparison with Priority Ceiling


Protocol
P5

P4

P3

P2

P1

0 2 4 6 8 10 12 14 16 18 20

© 2009 Universität Karlsruhe (TH), System Architecture Group 160


SPCP Scheduling

Analysis: Stack-Based Priority Ceiling

 Pros
 Simple to implement.
 Slightly better worst-case when compared
to normal PCP – two less context switches
switches.
 No priority inheritance needed.

 Cons
 Threads cannot self suspend.

© 2009 Universität Karlsruhe (TH), System Architecture Group 161


Summary

Summary

 4 protocols controlling resource access


in priority driven preemptive systems
 NPCS
 PI
 PCP
 SPCP

© 2009 Universität Karlsruhe (TH), System Architecture Group 162


Summary

Summary

 NPCS and PI do not require a priori


knowledge of resource requirements

 PI neither prevents deadlocks nor avoids


d dl k
deadlocks

 All protocols -except PI- ensure that


processes are blocked at most once*

© 2009 Universität Karlsruhe (TH), System Architecture Group 163

You might also like