Resource Sharing
Resource Sharing
of Real-Time Systems
Resource Sharing
Jan Reineke
normal execution
critical section
J1 is blocked
J1
J2
“Most of the time this combination worked fine. However, very infrequently
it was possible for an interrupt to occur that caused the (medium priority)
communications task to be scheduled during the short interval while the
(high priority) information bus thread was blocked waiting for the (low
priority) meteorological data thread. In this case, the long-running
communications task, having higher priority than the meteorological task,
would prevent it from running, consequently preventing the blocked
information bus task from running. After some time had passed, a
watchdog timer would go off, notice that the data bus task had not been
executed for some time, conclude that something had gone drastically
wrong, and initiate a total system reset.”
Naïve solution for Priority Inversion
No deadlocks. Why?
Basic Idea:
Modify (increase) the priority of those jobs that
cause blocking.
When a job Jj blocks one or more higher-priority
tasks, it temporarily assumes a higher priority.
Methods:
Priority Inheritance Protocol (PIP), for fixed-
priority scheduling
Priority Ceiling Protocol (PCP), for fixed-priority
scheduling
Stack Resource Policy (SRP), for both fixed-
and dynamic-priority scheduling
Priority Inheritance Protocol (PIP)
UnderPIP,
Under PIP,ififthere
there are
are nn lower-priority
lower jobs,
priority jobs , a ahigher-priority
higher-priority
job ca
job
be can befor
blocked blocked
as highforasthe
theduration
durationofofnncritical
criticalsections:
sections.
Chained blocking
PIP: Chained Blocking
Problem 2: chained blocking – many preemptions
V(S1)
P(S1) P(S2) V(S2)
H Task 1
P(S1)
V(S1)
M Task 2
P(S2)
V(S2)
L Task 3
Blocked
Higher-priority task can be blocked Using S1
by each lower-priority task!
Using S2
Task 1 needs M resources may be blocked M times:
many preemptions/much run-time overheads
PIP: Blocking-Time Calculation
C
Beneficial Properties of PCP
PIP PCP
Bounded priority inversion (+) Bounded priority inversion (+)
May deadlock (-) Deadlock-free (+)
Up to n blockings (-) At most one blocking (+)
Easy to implement (+) Not easy to implement (-)
Schedulability Analysis including
Blocking Times
Theorem:
A set of n periodic tasks under PCP can be
scheduled by rate-monotonic scheduling, if