RTS 2 Part 2

Transcription

RTS 2 Part 2
6/24/2010
Interrupt Management
• Interrupt Handler als Interrupt Service Routine
– Schnellste
Schnellste Bearbeitung
Bearbeitung
– Keine oder nur eingeschränkte Betriebssystemunterstützung
– Je nach HW‐Architektur feste ISR Zuweisung
– Blockiert das Betriebssystem
• Interrupt Handler als Interrupt Task
–
–
–
–
Betriebssystem‐Unterstützung
B
ti b
t
U t tüt
Interrupt‐Kanal ist nach Taskaktivierung schnell wieder frei
Interruptbearbeitung zur Laufzeit austauschbar
Langsame Bearbeitung bedingt durch das Scheduling
Interrupt Priorisierung
• Es stehen, abhängig vom Verwendeten Mikrokontroller unterschiedlich viele Interrupt
Mikrokontroller, unterschiedlich viele Interrupt
Prioritäten zu Verfügung
• Bei dem Einsatz eines Betriebssystems muss dem System Timer ein Interrupt zugewiesen werden.
– Prioritäten unterhalb des System Timers können vom Betriebssystem Scheduler unterbrochen und verwaltet werden.
– Prioritäten oberhalb des System Timers können nicht vom Betriebssystem verwaltet werden. 1
6/24/2010
Ressourcen Management
• Folgende Methoden können (u.A.) zur
V
Verwaltung
lt
d Ressourcen
der
R
eingesetzt
i
tt
werden:
– Binäre Semaphore
• Mutex (Mutual Exclusion)
– Zählende Semaphore
Deadlock Situation
• When tasks are competing for the same set of two or more p
g
resources a deadlock situation may ensure.
– Four conditions are necessary for deadlock:
• Mutual exclusion: Resolved by making resources shareable
• Circular wait: Resolved by strict resource ordering
• Hold and wait: Never allocate more than one resource or allocate all resources at once
• No preemption: Priority inversion
2
6/24/2010
Priority Inversion
•
•
Two tasks J1 and J2 share the same resource Rk (J1 has higher priority than J
has higher priority than J2):
– J2 is activated first and after a while it enters the critical section and locks Rk.
– While J2 is executing the critical section, J1 arrives, it preempts J2 and starts executing
– At time t1, when attempting to enter its critical section, J1 is blocked on Rk, so J2 resumes
– J1 has to wait until t2, when J2 releases the critical section which unlocks Rk.
A priority inversion is said to occur in the d
h
interval [t1, t2] since the highest priority task J1 waits for the execution of the lower priority task J2.
Priority Inversion cont’d
• Medium‐priority tasks delay the execution of J
p
y
y
1
– This could lead to an unbounded priority inversion of J1
3
6/24/2010
Priority Inheritance Protocol (PIP)
• Simple solution to the problem of unbounded
p
p
priority inversion:
p
y
– To modify the priority of those tasks that cause blocking
• When a task Ji blocks one or more higher priority tasks, it temporarily inherits the highest priority of the blocked tasks. This prevents medium priority tasks from preempting Ji.
– The priority inheritance protocol bounds the maximum blocking time of each task
Priority Inheritance Protocol cont’d
• Blocking time computation:
– Bl: Sum of the maximum block‐times D of the tasks relative S
f h
i
bl k i
D f h
k l i
to the current task;
– Bs: Sum of the maximum block‐time D of the Semaphore which is able to block the current task relative to the current task;
– The corresponding minimum of Bl and Bs is the blocking factor of the corresponding task
Bil 
n
 max[ D
j i 1
k
j ,k
: C (S k )  Pi ] n ... number of tasks
m
Bis   max[ D j ,k : C ( S k )  Pi ] m ... number of semaphores
k 1
j i
Bi  min( Bil , Bis )
4
6/24/2010
Priority Inheritance Protocol cont’d
S1(P1)
S2(P1)
S3(P2)
J1
1
2
0
J2
0
9
3
J3
8
7
J4
6
5
B1l  9  8  6  23 B1s  8  9  17
min(B1l , B1s )  17
B2l  8  6  14
B2s  8  7  4  19 min(B2l , B2s )  14
0
B3l  6
B3s  6  5  4  15 min(B3l , B3s )  6
4
B4l  0
B4s  0
min(B4l , B4s )  0
• The Priority Inheritance Protocol does not resolve deadlock situations
Priority Ceiling Protocol (PCP)
•
Extents the Priority Inheritance Protocol:
– A task is not allowed to enter a critical section if there are locked Semaphores that could block it.
• Once a task enters its first critical section, it can never be blocked by lower priority tasks until its completion.
– Each Semaphore is assigned a priority ceiling, equal to the priority of the highest priority task that can lock it.
– A task J is allowed to enter a critical section only if its priority is higher than all priority ceilings of the semaphores currently locked by jobs other than J.
5
6/24/2010
Priority Ceiling Protocol cont’d
• Blocking time computation:
Bi  max{D j ,k | Pj  Pi , C ( S k )  Pi }
j ,k
S1(P1)
S2(P1)
S3(P2)
J1
1
2
0
J2
0
9
3
B2  max(8,6,7,5,4)  8
J3
8
7
0
B3  max((6,5,4)  6
J4
6
5
4
B4  0
B1  max(8,6,9,7,5)  9
PIP versus PCP
• Priority Inheritance Protocol:
– PIP is transparent on the programming level.
PIP is transparent on the programming level
– PIP does not prevent deadlocks
• Priority Ceiling Protocol:
– PCP requires the user to specify the list of resources used by each task in order to compute the ceiling values
– PCP prevents deadlocks
6
6/24/2010
To practice
• Consider three tasks (T1, T2, T3 ‐ having decreased priority) which (
)
share four resources (A, B, C, D).
• Calculate the maximum blocking time for each task using:
– Priority Inheritance Protocol
– Priority Ceiling Protocol
A
B
C
D
T1
3
2
4
6
T2
4
0
6
8
T3
2
1
0
5
7