chapter 7 - resource access protocols (critical sections) protocols: no preemptions during critical...
TRANSCRIPT
Chapter 7 - Resource Access Protocols (Critical Sections)
Protocols:
No Preemptions During Critical Sections Once a job enters a critical section, it cannot be preempted until it finishes the critical section
Priority Inheritance Protocol (for static scheduled systems)
A job that is blocking a high priority job that seek the critical section, has its priority elevated to
cause it to finish using the critical section
Priority Ceiling Protocol (for static scheduled system) Jobs are not allowed to enter a critical section if there are jobs that can block it.
Stack Resource Policy (for static or dynamic scheduled systems) A job that needs a resource that is not available, is blocked at the time it attempts to preempt,
instead of at the later time when it would request the resource
Definitions
Resource Types – private, shared, mutually exclusive
Critical Sections – code executed under mutual exclusion: At most one task can be holding the resource at a given time. All other tasks ready to use the resources are “blocked”
Semaphores - Resource Rk Semaphore Sk
A critical section operating on Rk
Begins with a wait(Sk) End with a signal(Sk)
Critical Sections
Implications
Implications of Critical Sections:
Protocols must include max delays due to potential blocking in worst-case computation times when scheduling.
Leads to necessity for very conservative scheduling to guarantee not missing deadlines.
Blocking
Chained Blocking
Priority Inversion
Deadlock
Denying Preemptions during Critical Sections
Denying preemption during execution of a critical section eliminates priority inversion.
Leads to unnecessary blocking (delay) of higher priority tasks.
Priority Inheritance Protocol(applicable for fixed priority scheduling – think Rate Monotonic)
Priority Inheritance Protocol
Priority Inheritance Protocol
Priority Inheritance Protocol
Priority Inheritance Protocol
Some Properties:
Priority Ceiling Protocol
(applicable for fixed priority scheduling – again think Rate Monotonic)
Priority Ceiling Protocol
Priority Ceiling Protocol
Some Properties:
Stack Resource Policy(applicable for fixed or dynamic scheduling – think Rate Monotonic or Earliest Deadline First)
Each task has: A priority pi (assigned either statically or dynamically),
pa > pb means execution of a is more important than b
A preemption level i (assigned statically)
a > b Da < Db (relative deadlines)
Ja can preempt Jb ONLY IF a > b
Preemption levels are static and are used to predict potential blocking in
Stack Resource Policy
Definitions (Current Ceilings):
Current Resource Ceiling (computed as a function of the units of R that are available):
Denotes the number of units of R that are currently available
Denotes the maximum requirement of job J for R
System Ceiling (the maximum of the current ceilings of all of the resources):
smax{CR1 : I= 1,2,…,m)
i.e., the highest preemption level of those jobs that could be blocked on R
i.e., the maximum of the Current Resource Ceilings
Stack Resource Policy
Protocol:
A job is not allowed to preempt until:
its priority is the highest among those jobs ready to run, and
its preemption level is higher than the system ceiling
Stack Resource Policy
Stack Resource Policy Example
Given: (J1 J2 J3) that share (R1 R2 R3) where:
R1 consists of 3 units, R2 of 1, R3 of 3 ,
and
CR1(3) = max 0 = 0
CR1(2) = max { (J3) } = max {1} = 1
CR1(1) = max { (J2), (J3) } = max { 2, 1} = 2
CR1(0) = max { (J1), (J2), (J3) } = max { 3, 2, 1} = 3
= units available, = maximum requirement for the job
Stack Resource Policy ExampleProtocol:
A job is not allowed to preempt until:
its priority is the highest among those jobs ready to run,
its preemption level is higher than the system ceiling
t0 : J3 begins executing and the system ceiling = 0 because all resources are completely available.
When J3 enters its first critical section, it takes the unit of R2 . The ceiling is set to the highest preemption level among the tasks that could
be blocked on R2 ; that is s = 2 = 2.
As a consequence, J2 is blocked by the preemption test and J3 continues to execute.
t1 : When J3 enters its nested critical section, taking all units of R1 , the system ceiling is raised to s = 1 = 3 . This causes J1 to be blocked by the
preemption test.
t2 : As J3 releases R1 , the system ceiling becomes s = 2 = 2 (the highest preemption level among tasks that could be blocked on R2 ; thus J1
preempts J3 and starts executing.
Once J1 is started, it is never blocked during its execution because the condition 1 < s guarantees that all the resources needed by
J1 are available.
As J1 terminates, J3 resumes execution and releases resource R2 .
t3 : As R2 is released, the system ceiling returns to zero and J2 can preempt J3 .
Again, once J2 is started, all the resources it needs are available; thus J2 is never blocked.
Stack Resource PolicyProperties:
The End