slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
CSE 522 Real-Time Scheduling (3) PowerPoint Presentation
Download Presentation
CSE 522 Real-Time Scheduling (3)

Loading in 2 Seconds...

play fullscreen
1 / 36

CSE 522 Real-Time Scheduling (3) - PowerPoint PPT Presentation


  • 65 Views
  • Uploaded on

CSE 522 Real-Time Scheduling (3) . Computer Science & Engineering Department Arizona State University Tempe, AZ 85287 Dr. Yann -Hang Lee yhlee@asu.edu (480) 727-7507.  1 :{…P(S1)…V(S1)…}  3 :{…P(S1)…V(S1)…}. Attempt to lock S1 (blocked). S1 locked. S1 unlocked.  2(M).  1(H).

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'CSE 522 Real-Time Scheduling (3)' - makya


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

CSE 522 Real-Time Scheduling (3)

Computer Science & Engineering DepartmentArizona State University Tempe, AZ 85287

Dr. Yann-Hang Leeyhlee@asu.edu(480) 727-7507

priority inversion in synchronization

1 :{…P(S1)…V(S1)…}

3 :{…P(S1)…V(S1)…}

Attempt to lock S1 (blocked)

S1 locked

S1 unlocked

2(M)

1(H)

Blocked

S1 unlocked

S1 locked

3(L)

Time

Priority Inversion in Synchronization
priority inversion
Priority Inversion
  • Delay to a task’s execution caused by interference from lower priority tasks is known as priority inversion
  • Priority inversion is modeled by blocking time
  • Identifying and evaluating the effect of sources of priority inversion is important in schedulability analysis
  • Sources of priority Inversion
    • Synchronization and mutual exclusion
    • Non-preemtable regions of code
    • FIFO (first-in-first-out) queues
accounting for priority inversion
Accounting for Priority Inversion
  • Recall that task schedulability is affected by
    • preemption: two types of preemption
      • can occur several times per period
      • can occur once per period
    • execution: once per period
    • blocking: at most once per period for each request to a source
  • The schedulability formulas are modified to add a “blocking” or “priority inversion” term to account for inversion effects
ub test with blocking

H1 Preemption(can hit once)

Blocking

Hn Preemption(can hit n times)

Execution

UB Test with Blocking
  • Include blocking while calculating effective utilization for each tasks:
rt test with blocking
RT Test with Blocking
  • Blocking is also included in the RT test
  • Perform test as before, including blocking effect
example considering blocking

100 msec

200 msec

300 msec

1

25 msec

50 msec

100 msec

Data Structure

10 msec

30 msec

2

3

Example: Considering Blocking
  • Consider the following example

Periodic tasks

What is the worst case blocking effect (priority inversion) experienced by each task ?

example adding blocking
Example: Adding Blocking
  • Task 2 does not use the data structure. Task 2 does experiences no priority inversion
  • Task 1 shares the data structure with 3 . Task 1 could have to wait for 3 to complete its critical section. But worse, if 2 preempts while 1 is waiting for the data structure, 1 could have to wait for 2’s entire computation.
  • This is the resulting table
ub test for example
UB Test for Example
  • UB test with blocking:

Not schedulable

with additional RT test, 3is shown to be schedulable

synchronization protocols
Synchronization Protocols
  • No preemption
  • Basic priority inheritance
  • Highest locker’s priority
  • Priority ceiling
  • Each protocol prevents unbounded priority inversion.
nonpreemption protocol
Nonpreemption Protocol

2:{…P(S1)…V(S1)…}

4:{…P(S1)…V(S1)…}

ready

blocked

1(H)

ready

2

ready

3

S1 locked

S1 unlocked

4(L)

Time

advantages and disadvantages
Advantages and Disadvantages
  • Advantages:
    • Simplicity
    • Use with fixed-priority and dynamic-priority systems
    • No priori knowledge about resource requirement by each task
    • Good when all critical sections are short
  • Disadvantages:
    • Every task can be blocked by every lower priority task, even when there is no resource sharing between the tasks.
    • Blocking time: max(csi)
basic inheritance protocol bip
Basic Inheritance Protocol (BIP)

2:{…P(S1)…V(S1)…}

4:{…P(S1)…V(S1)…}

ready

1(H)

attempts to

lock S1

S1 locked

S1 unlocked

ready

2

blocked

ready

3

S1 locked

S1 unlocked

4(L)

inherits the priority of 2

after 2 is blocked

some notations
Some Notations
  • Jiis the i-th job in Task T.
  • i = Assigned priority of Job Ji
  • i(t) = current priority of Ji
  • If the decision to change the priority of Job Ji is made at t = t1 then
    • i(t1-) = priority at and immediately before,
    • i(t1+) = priority immediately after the priority change
  •  = nonexistent priority, lower than the lowest priority
terminology and assumptions
Terminology and Assumptions
  • At time t1, job Ji requests resource Rk.
  • Rk Jl: Resource Rk is held by Job Jl
  • Ji Rk: Job Jiis blocked waiting for resourceRkto be released (Ji Rk Jl)
  • Scheduling Rules:
    • Ready Jobs scheduled on processors preemptively in a priority driven manner according to their current priorities, i(t).
    • At job release time the priority is equal to its assigned priority
      • if Ji is release at t = t’, then i(t’) = i
  • Resource allocation:
    • If a resource is free then it is allocated when requested
    • if not free then the request is denied and the requesting job is blocked
priority inheritance rules
Priority Inheritance Rules
  • Scheduling Rule: same as the assumptions
  • Allocation Rule:same as the assumptions
  • Priority-Inheritance Rule:
    • if Ji  Rk Jl and l(t1-) = priority of Jl at t = t1
    • then l(t1+) = i(t1)
    • until Jlreleases Rk at t2when l(t2+) = l(t1-)
  • L. Sha, R. Rajkumar, J. Lehoczky, “Priority Inheritance Protocols: An Approach to Real-Time Synchronization”, IEEE Transactions on Computers, Vol. 39, No. 9, pp. 1175-1185, 1990
properties of priority inheritance
Properties of Priority Inheritance
  • For each resource (semaphore), a list of blocked tasks must be stored in a priority queue.
  • A task (job) ti uses its assigned priority, and uses (inherits) the highest dynamic priority of all the tasks it blocks when it is in its critical section and blocks some higher priority tasks.
  • Priority inheritance is transitive; that is, if tasktiblocks tjand tj blocks tk, then ti can inherit the priority of tk.
  • When tasktireleases a resource, which priority it should use?
  • Chained blocking if requesting multiple resources (nested mutex requests)
  • Direct blocking and indirect (inheritance) blocking (when the lower priority task inherits the higher priority task’s priority).
implementation issues of bip
Implementation Issues of BIP

PI semaphore and basic semaphore

Priority is changed when acquiring and releasing a lock

When release a lock, can the priority be restore to the one before acquiring?

Need to maintain a list of PI semaphores locked by a task

  • when holding multiple locks and release one
  • when a PI semaphore is deleted
  • when a task waiting for a PI semaphore quits the waiting (due to timeout)
  • when the priority of a task waiting for a PI semaphore is changed

Note that for each semaphore, a queue for all waiting tasks

example of chained blocking bip
Example Of Chained Blocking (BIP)

1:{…P(S1)…P(S2)…V(S2)…V(S1)…}

2:{…P(S1)…V(S1)…}

3:{…P(S2)…V(S2)…}

Attempts to lock S1(blocked)

Attempts to lock S2(blocked)

B

B

1(H)

B

S1 locked

S1 unlocked

2(M)

S2 unlocked

S2 locked

3(L)

deadlock using bip
Deadlock: Using BIP

1 :{…P(S1)…P(S2)…V(S2)…V(S1)..}

2 :{…P(S2)…P(S1)…V(S1)…V(S2)..}

Attempts to lock

S2 (blocked)

Locks S1

1 (H)

B

Attempts to lock S1 (blocked)

S2 locked

2 (M)

blocking time under bip
Blocking Time Under BIP
  • Example

T1 = {.. P(A) .3. P(B) .2. V(B) .1. V(A) ..}

T2 = {.. P(C) .2. V(C) ..}

T3 = {.. P(A) .1. P(B) .2. V(B) .2. V(A) .. }

T4 = {.. P(A) .1. P(C) .1. P(B) .3. V(B) .1. V(C) .1. V(A).. }

priority ceiling protocol pcp
Priority Ceiling Protocol (PCP)

2:{…P(S1)…V(S1)…}

 3:{…P(S2)…V(S2)…}

4:{…P(S1)…V(S1)…}

1(H)

attempts to lock S1

ready

S1 locked

S1 unlocked

B

2

attempts to lock S2

S2 locked

ready

3

blocked by ceiling

S1 unlocked

S1 locked

4(L)

basic priority ceiling rules 1
Basic Priority Ceiling Rules (1)
  • (R) = priority ceiling of resource R – the highest priority of the tasks that request R
  • S(t) = system priority ceiling -- the highest priority ceiling of the resources that are in use at time t
  • Scheduling Rule: same as the assumptions
  • Allocation Rule:
    • if Ji  Rk Jl at t = t1then block Ji (no change)
    • Rk free at t1,
      • if i(t1) > S(t1), then Rk Ji
      • else (i.e. i(t1)  S(t1) )

if for some Rx Ji and (Rx) = S(t1), then Rk Ji

[ Ji holds a resource Rx whose priority ceiling is S(t1) ]

      • else deny and block (Ji  Rk)
basic priority ceiling rules 2
Basic Priority Ceiling Rules (2)
  • Priority-Inheritance Rule:
    • if Ji  Rk at t = t1and is blocked by Jl (and l(t1-) = priority of Jl)
      • eitherRk  Jl, (Jl holds the resource Rk)

or Jl Rx and (Rx) = S(t1)  i(t1)

    • then l(t1+) = i(t1) (inherited priority)
    • until Jlreleases all Rxwith (Rx)  i(t1), l(t2+) = l(t1-) at t = t2.
blocking in pcp
Blocking in PCP
  • A task TH can be blocked by a lower-priority task TL in three ways:
    • directly, i.e.
    • when TL inherits a priority higher than the priority pH of TH.
    • When TH requests a resource the priority ceiling of resources held by TL is equal to or higher than pH:

TH

X

TL

allocated to

request for

T  TH

X

TL

(p > pH)

Y

TL

X

TH

(pHPX)

blocked at most once pcp
Blocked At Most Once (PCP)

1:{…P(S1)…P(S2)…V(S2)…V(S1)…}

2:{…P(S1)…V(S1)…}

3:{…P(S2)…V(S2)…}

S2 locked

S2 unlocked

S1 locked

S1 unlocked

attempts to lock S1(blocked)

1(H)

B

attempts to lock S1(blocked)

S1 unlocked

S1 locked

2(M)

S2 unlocked

S2 locked

3(L)

deadlock avoidance using pcp
Deadlock Avoidance: Using PCP

1 :{…P(S1)…P(S2)…V(S2)…V(S1)..}

2 :{…P(S2)…P(S1)…V(S1)…V(S2)..}

Locks S2

Unlocks S2

Attempts to lock S1 (blocked)

Locks S1

Unlocks S1

1 (H)

C

Locks S1

Unlocks S1

Unlocks S2

Locks S2

2 (M)

stack sharing
Stack Sharing
  • Sharing of the stack among tasks eliminates stack space fragmentation and so allows for memory savings:
  • However:
    • Once job is preempted, it can only resume when it returns to be on top of stack.
    • Otherwise, it may cause a deadlock.
    • Stack becomes a resource that allows for “one-way preemption”.

T1

T1

Ti

Ti

Tn

Tn

no stack sharing

stack sharing

stack based priority ceiling protocol
Stack-Based Priority Ceiling Protocol
  • To avoid deadlocks: Once execution begins, make sure that job is not blocked due to resource access
    • allow preemption only if the priority is higher than the ceiling of the resources in use
  • Update Current Ceiling in the usual manner
    • If no resource allocated, S(t) = 
  • Scheduling Rule:
    • Ji released and blocked until i(t) > S(t)
    • When not blocked jobs are scheduled in the usual manner.
  • Allocation Rule:
    • Allocate when requested
stack based pcp cont
Stack-Based PCP (cont)
  • The Stack-Based Priority-Ceiling Protocol is deadlock-free:
    • When a job begins to execute, all the resources it will ever need are free.
    • Otherwise, S(t) would be higher or equal to the priority of the job.
    • Whenever a job is preempted, all the resources needed by the preempting job are free.
    • The preempting job can complete, and the preempted job can resume.
  • Worst-case blocking time of Stack-Based Protocol is the same as for Basic Priority Ceiling Protocol.
  • Stack-Based Protocol smaller context-switch overhead
    • 2 context switches since once execution starts, job cannot be blocked (may be preempted)
    • 4 context switches for PCP since a job may be blocked at most once
srp edf
SRP + EDF

(From “Resource sharing in EDF-scheduled systems: a closer look,” by SanjoyK. Baruah, RTSS’06)

Let 1, 2, . . . , ndenote the tasks, and R1,R2, . . . , Rmdenote the non-preemptable resources.

  • Each resource Rjis statically assigned a ceiling (Rj), which is set equal to the minimum relative deadline parameter of any task that may access it:

(Rj) = min{Di | iaccesses Rj}

  • A system ceiling is computed each instant during runtime. This is set equal to the minimum ceiling of any resource that is currently being held by some job.
  • At any instant in time, a job generated by imay begin execution only if it is the earliest-deadline active job, and Diis strictly less than the system ceiling.
ceiling priority protocol
Ceiling-Priority Protocol
  • Re-formulation of stack-based priority ceiling protocol for multiple stacks (no stack-sharing)
  • Update Current Ceiling in the usual manner
  • Scheduling Rule:
    • No resources held by Ji, i(t) = i
    • Resource held by Ji,i(t) = max((Rx)) for all resource Rxheld by Ji
    • FIFO scheduling among jobs with equal priority
  • Allocation Rule:
    • Allocate when requested
  • Also called: Priority ceiling emulation, highest locker protocol, Immediate priority ceiling protocol (ICPP)
comparison
Comparison
  • Worst case performance of stack-based and basic ceiling protocols are the same
  • Stack-based version
    • supported by the Real-Time systems Annex of Ada95
    • Jobs must not self-suspend
  • When jobs do not self-suspend, stack-based and ceiling-priority protocols yield the same schedules.
  • Stack-based and ceiling-priority have the same worst-case blocking time.
highest locker s priority protocol
Highest Locker’s Priority Protocol

2:{…P(S1)…V(S1)…}

4:{…P(S1)…V(S1)…}

1(H)

ready

B

B

2

ready

3

S1 locked

S1 unlocked

4(L)

run with the priority of 2

summary of synchronization protocols
Summary of Synchronization Protocols

1 Only if tasks do not suspend within critical sections

2 PCP is not affected if tasks suspend within critical sections.

bip and pcp
BIP and PCP

BIP

  • no penalty when the locks are not contended, which covers the vast majority of time-constrained systems.
  • many extra context switches are avoided, and medium priority tasks are not preempted unnecessarily,
  • excellent average performance

CPP (highest locker protocol)

  • change a thread's priority twice regardless of whether there is contention for the lock or not
  • higher overhead and many unnecessary context switches and blocking in unrelated tasks
  • worst-case priority inversion control, it handles nested locks well, and can avoid deadlock in some cases
  • static analysis of the system to find the priority ceiling