quasi-static scheduling of embedded software using free ... fileee249: design of embedded system...

21
EE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice Petri Nets Marco Sgroi, Alberto Sangiovanni-Vincentelli Luciano Lavagno University of California at Berkeley Cadence Berkeley Labs Yosinori Watanabe Cadence European Labs EE249 - Fall2000 2 Outline Motivation Scheduling Free-Choice Petri Nets Algorithm

Upload: lequynh

Post on 19-Aug-2019

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

1

1

Quasi-Static Scheduling of Embedded Software Using

Free-Choice Petri NetsMarco Sgroi, Alberto Sangiovanni-Vincentelli

Luciano Lavagno

University of California at Berkeley

Cadence Berkeley Labs

Yosinori WatanabeCadence European Labs EE249 - Fall2000

2

Outline

• Motivation• Scheduling Free-Choice Petri Nets• Algorithm

Page 2: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

2

3

Embedded Software Synthesis

• System specification: set of concurrent functional blocks(DF actors, CFSMs, CSP, … )

• Software implementation: (smaller) set of concurrent software tasks

• Two sub-problems:– Generate code for each task (software synthesis)– Schedule tasks dynamically (dynamic scheduling)

• Goal: minimize real-time scheduling overhead

4

Petri Nets Model

Page 3: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

3

5

Petri Nets Model

Schedule: t12, t13, t16...

a = 5c = a + b

t12 t13t16

6

Petri Nets Model

Shared Processor+ RTOS

Task 1

Task 2

Task 3

Page 4: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

4

7

Classes of Scheduling

• Static: schedule completely determined at compile time

• Dynamic: schedule determined at run-time

• Quasi-Static: most of the schedule computed at compile time, some scheduling decisions made at run-time (but only when necessary)

8

Embedded Systems Specifications

Static

Quasi-Static

Dynamic

Specification Scheduling

Data-dependent Control(if ..then ..else, while ..do)

Real-time Control(preemption, suspension)

Data Processing (+, -, *...)

Page 5: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

5

9

An example

i k2 + o

k1

Static Data Flow network

Example: 2nd order IIR filtero(n) = k2 i(n) + k1 o(n-1)

10

Data Processing

i *k2 + o

*k1

Schedule: i, *k2, *k1, +, o

IIR 2nd order filtero(n)=k1 o(n-1) + k2 i(n)

Schedule: i, *k1, *k2, +, o

Page 6: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

6

11

Data computation (Multirate)

o

Fast Fourier Transform

i FFT o256 256

Schedule: ii… i FFT oo… . o

256 256i

Sample rate conversion

Multirate Data Flow network Petri Net

A B C D E2 7 73 82F

5

Schedule: (147A) (147B) (98C) (28D) (32E) (160F)

12

Data-dependent Control

i o>0

*2

/2

Schedule: i, if (i>0) then{ /2} else{ *2}, o

•Petri Nets provide a unified model for mixed control and data processing specifications

•Free-Choice (Equal Conflict) Nets: the outcome of a choice depends on the value of a token (abstracted non-deterministically)

rather than on its arrival time

Page 7: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

7

13

PNs and BDF

BDF network

F

T

F

T

>0

Petri Net

t1t2

t3

t4

t5

<=0<=0

>0

>0

Switch/Select vs. choice/mergePNs: No correlation between different choices

14

PNs and BDF

BDF network

F

T

F

T

>0

Petri Net

PNs are not-determinate

F

t1t2 t4 t6

t8

t7t5t3

Page 8: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

8

15

PNs and BDF

BDF network

F

T

F

T

>0

Petri Net

PNs are not-determinate

TF

t1t2 t4 t6

t8

t7t5t3

16

PNs and BDF

BDF network

F

T

F

T

>0

Petri Net

PNs are not-determinate

TTF

t1t2 t4 t6

t8

t7t5t3

Page 9: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

9

17

Existing approaches• Lee - Messerschmitt ‘86

– Static Data Flow: cannot specify data-dependent control • Buck - Lee ‘94

– Boolean Data Flow: scheduling problem is undecidable• Thoen - Goossens - De Man ‘96

– Event graph: no schedulability check, no minimization of number of tasks

• Lin ‘97– Safe Petri Net: no schedulability check, no multi-rate

• Thiele - Teich ‘99– Bounded Petri Net: partial schedulability check, complex

(reachability-based) algorithm

18

Scheduling Petri Nets

• Petri Nets provide a unified model for mixed control and dataflow specification

• Most properties are decidable• A lot of theory available• Abstract Dataflow networks by representing if-then-else

structures as non-deterministic choices• Non-deterministic actors (choice and merge) make the

network non-determinate according to Kahn’s definition• Free-Choice: the outcome of a choice depends on the value of

a token (abstracted non-deterministically) rather than on its arrival time

Page 10: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

10

19

Bounded scheduling (Marked Graphs)

• A finite complete cycle is a finite sequence of transition firings that returns the net to its initial state

• Bounded memory• Infinite execution

• To find a finite complete cycle solve f(σ) D = 0

t1 t2 t3

T-invariant f(σ) = (4,2,1)

2 22

t1t2

t3

No schedule

D =1 0-2 10 -2 f(σ) D = 0 has no solution

20

Bounded scheduling (Marked Graphs)

• Existence of a T-invariant is only a necessary condition• Verify that the net does not deadlock by simulating the

minimal T-invariant [Lee87]

t1 t2 t3

T-invariant f(σ) = (4,2,1)

2 2

t1 t22 3

23t3

T-invariant f(σ) = (3,2,1)

Deadlock(0,0) (0,0)t1t1t1t1t2t2t4

σ= t1t1t1t1t2t2t4

Not enough initial tokens

Page 11: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

11

21

Free-Choice Petri Nets (FCPN)

Marked Graph (MG)

Free-Choice Confusion (not-Free-Choice)

Free-Choice: choice depends on token value rather than arrival timeeasy to analyze (using structural methods)

22

t1 t2 t3 t5 t6

Bounded scheduling (Free-Choice Petri Nets)

t1 t2t3

t4

t5 t6

t7

t1 t2 t3 t5 t6

• Can the “adversary” ever force token overflow?

Page 12: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

12

23

t1 t2 t4 t7

Bounded scheduling (Free-Choice Petri Nets)

t1 t2t3

t4

t5 t6

t7

t1 t2 t4 t7

• Can the “adversary” ever force token overflow?

24

Bounded scheduling (Free-Choice Petri Nets)

t1 t2t3

t4

t5t7

t6

• Can the “adversary” ever force token overflow?

Page 13: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

13

25

Bounded scheduling (Free-Choice Petri Nets)

t1 t2t3

t4

t5t7

t6

• Can the “adversary” ever force token overflow?

26

Bounded scheduling (Free-Choice Petri Nets)

t1 t2t3

t4

t5t7

t6

• Can the “adversary” ever force token overflow?

Page 14: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

14

27

Schedulability (FCPN)

• Quasi-Static Scheduling• at compile time find one schedule for every

conditional branch • at run-time choose one of these schedules

according to the actual value of the data.

Σ={(t1 t2 t4),(t1 t3 t5)}

28

Bounded scheduling (Free-Choice Petri Nets)

• Valid schedule Σ• is a set of finite firing sequences that return the net

to its initial state • contains one firing sequence for every combination

of outcomes of the free choices

t3

t2t1

t5

t4

SchedulableΣ={(t1 t2 t4),(t1 t3 t5)}

t3

t2t1

t5

t4(t1 t2 t4)

t3

t2t1

t5

t4

(t1 t3 t5)

Page 15: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

15

29

How to check schedulability

• Basic intuition: every resolution of data-dependent choices must be schedulable

• Algorithm:– Decompose (by applying the Reduction Algorithm) the

given Equal Conflict Net into as many Conflict-Free components as the number of possible resolutions of the non-deterministic choices.

– Check if every component is statically schedulable

– Derive a valid schedule, i.e. a set of finite complete cycles one for each conflict-free component

30

Allocatability(Hack, Teruel)

• An Allocation is a control function that chooses which transition fires among several conflicting ones ( A: P T).

• A Reduction is the Conflict Free Net generated from one Allocation by applying the Reduction Algorithm.

• A ECN is allocatable if every Reduction generated from an allocation is consistent.

• Theorem: A ECN is schedulable iff – it is allocatable and– every Reduction is schedulable (following Lee)

Page 16: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

16

31

Reduction Algorithm t6t1

t5

t4t2

t7

t6

t7

t1t4t2

t4t2t6t1

t1

t5

t4

t7

t2t6

t6

t7

t1t4t2

t1

t3 t5

t4t6

t2

t7

T-allocation A1={t1,t2,t4,t5,t6,t7}

32

How to find a valid schedule

t1t2 t4

t5

t6

t7 t9

t8 t10

t3

Conflict Relation Sets:{t2,t3},{t7,t8}

T-allocations:

A1={t1,t2,t4,t5,t6,t7,t9,t10}

A2={t1,t3,t4,t5,t6,t7,t9,t10}A3={t1,t2,t4,t5,t6,t8,t9,t10}A4={t1,t3,t4,t5,t6,t8,t9,t10}

Page 17: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

17

33

Valid schedulet1 t2 t4

t5

t6

t7t9

t1

t3 t5

t6

t7t9

t1 t2 t4

t6t8 t10

t1

t3t5

t6t8 t10

(t1 t2 t4 t6 t7 t9 t5) (t1 t3 t5 t6 t7 t9 t5)(t1 t2 t4 t6 t8 t10) (t1 t3 t5 t6 t8 t10)

1086531

1086421

5976531

5976421

tttttttttttt

tttttttttttttt

34

C code implementation

Σ={(t1 t2 t1 t2 t4 t6 t7 t5) (t1 t3 t5 t6 t7 t5)}

t1

t3 t5

t4t22

t6 t7

Task 1:{ t1;

if (p1)then{ t2;

count(p2)++;if (count(p2) = 2)

then{ t4;count(p2) = count(p2) - 2;}

else{ t3;t5;}

}}

Task 2:{ t6;

t7;t5;

}

p1

p3

p4

p2

Page 18: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

18

35

Application example:ATM Switch

Input cells: accept?

Output cells: emit?

Internal buffer

Clock (periodic)

Incoming cells(non-periodic)

Outgoing cells

• No static schedule due to:– Inputs with independent rates

(need Real-Time dynamic scheduling) – Data-dependent control

(can use Quasi-Static Scheduling)

36

Petri Nets Model

Page 19: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

19

37

Functional decomposition

4 Tasks

Accept/discard cell

Output time selector

Output cell enablerClock divider

38

Decomposition with min # of tasks

2 Tasks

Input cell processing

Output cell processing

Page 20: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

20

39

Real-time scheduling of independent tasks

+ RTOS

Shared Processor

Task 1

Task 2

40

ATM: experimental results

Sw Implementation QSS Functional partitioningNumber of tasks 2 5 Lines of C code 1664 2187

Clock cycles 197526 249726

Functional partitioning (4+1 tasks) QSS (2 tasks)

Page 21: Quasi-Static Scheduling of Embedded Software Using Free ... fileEE249: Design of Embedded System (corrections) ASV/LL 1 1 Quasi-Static Scheduling of Embedded Software Using Free-Choice

EE249: Design of Embedded System (corrections) ASV/LL

21

41

Conclusion

• Advantages of Quasi-Static Scheduling:QSS minimizes run-time overhead with respect to Dynamic

Scheduling byAutomatic partitioning of the system functions into a

minimum number of concurrent tasksThe underlying model is FCPN: can check schedulability

before code generation

• Future work– Larger PN classes – Code optimizations