QuasiStatic Scheduling of Embedded Software Using FreeChoice Petri
Quasi-Static Scheduling of Embedded Software Using Free-Choice Petri Nets Marco Sgroi, Alberto Sangiovanni-Vincentelli University of California at Berkeley Luciano Lavagno Cadence Berkeley Labs Yosinori Watanabe Cadence European Labs EE 249 - Fall 2001 1
Outline • Motivation • Scheduling Free-Choice Petri Nets • Algorithm 2
Embedded Software Synthesis • System specification: set of concurrent functional blocks (DF actors, CFSMs, PNs, …) • Software implementation: 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 3
Petri Nets Model 4
Petri Nets Model t 12 t 13 t 16 Schedule: t 12, t 13, t 16. . . a=5 c=a+b 5
Petri Nets Model Task 1 Task 2 + RTOS Shared Processor Task 3 6
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) 7
Embedded Systems Specification Scheduling Real-time Control (preemption, suspension) Dynamic Data-dependent Control (if. . then. . else, while. . do) Quasi-Static Data Processing (+, -, *. . . ) Static 8
Data Processing IIR 2 nd order filter o(n)=k 1 o(n-1) + k 2 i(n) i *k 2 + o *k 1 Schedule: i, *k 2, *k 1, +, o Schedule: i, *k 1, *k 2, +, o 9
Data computation (Multirate) Fast Fourier Transform Multirate Data Flow network i 256 FFT Petri Net i 256 o o 256 Schedule: ii…i FFT oo…. o Sample rate conversion A B 2 3 C 2 7 D 8 7 E 5 F Schedule: (147 A) (147 B) (98 C) (28 D) (32 E) (160 F) 10
Data-dependent Control *2 i o >0 /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 11
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 12
PNs and BDF network Petri Net t 2 F F T >0 TFF T t 1 t 4 <=0 >0 t 5 >0 t 3 Switch/Select vs. choice/merge PNs: No correlation between different choices 13
PNs and BDF network >0 F F T T Petri Net t 2 t 4 t 6 t 3 t 5 t 7 t 8 t 1 F PNs are not-determinate 14
PNs and BDF network >0 F F T T Petri Net t 2 t 4 t 6 t 3 t 5 t 7 t 8 t 1 TF PNs are not-determinate 15
PNs and BDF network >0 F F T T Petri Net t 2 t 4 t 6 t 3 t 5 t 7 t 8 t 1 TTF PNs are not-determinate 16
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 17
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 18
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(s) D = 0 t 1 t 2 2 t 3 2 1 0 D = -2 1 0 -2 T-invariant f(s) = (4, 2, 1) t 2 t 1 2 t 3 f(s) D = 0 has no solution No schedule 19
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 [Lee 87] t 1 t 2 2 t 3 3 2 2 3 t 2 2 T-invariant f(s) = (4, 2, 1) T-invariant f(s) = (3, 2, 1) t 1 t 1 t 2 t 2 t 4 (0, 0) Not enough initial tokens s = t 1 t 1 t 2 t 2 t 4 Deadlock 20
Free-Choice Petri Nets (FCPN) Marked Graph (MG) Free-Choice Confusion (not-Free-Choice) Free-Choice: choice depends on token value rather than arrival time easy to analyze (using structural methods) 21
Bounded scheduling (Free-Choice Petri Nets) • Can the “adversary” ever force token overflow? t 1 t 3 t 5 t 6 t 4 t 7 t 2 t 1 t 2 t 3 t 5 t 6 22
Bounded scheduling (Free-Choice Petri Nets) • Can the “adversary” ever force token overflow? t 1 t 3 t 5 t 4 t 7 t 6 t 2 t 1 t 2 t 4 t 7 23
Bounded scheduling (Free-Choice Petri Nets) • Can the “adversary” ever force token overflow? t 3 t 1 t 5 t 2 t 7 t 4 t 6 24
Bounded scheduling (Free-Choice Petri Nets) • Can the “adversary” ever force token overflow? t 3 t 1 t 5 t 2 t 7 t 4 t 6 25
Bounded scheduling (Free-Choice Petri Nets) • Can the “adversary” ever force token overflow? t 3 t 1 t 5 t 2 t 7 t 4 t 6 26
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. S={(t 1 t 2 t 4), (t 1 t 3 t 5)} 27
Bounded scheduling (Free-Choice Petri Nets) • Valid schedule S t 1 • 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 t 2 t 4 t 1 (t 1 t 2 t 4) t 2 t 4 t 3 t 5 S={(t 1 t 2 t 4), (t 1 t 3 t 5)} t 1 t 3 t 2 t 5 t 4 (t 1 t 3 t 5) t 3 t 5 Schedulable 28
How to check schedulability • Basic intuition: every resolution of datadependent 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 29
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) 30
Reduction Algorithm t 2 t 4 t 2 t 6 t 1 t 4 t 6 t 1 t 3 t 7 t 5 t 7 T-allocation A 1={t 1, t 2, t 4, t 5, t 6, t 7} t 2 t 6 t 1 t 2 t 4 t 6 t 1 t 7 t 5 t 1 t 2 t 4 t 6 t 1 t 4 t 6 t 7 31
How to find a valid schedule t 2 t 4 t 1 Conflict Relation Sets: {t 2, t 3}, {t 7, t 8} T-allocations: t 3 t 7 t 5 t 9 A 2={t 1, t 3, t 4, t 5, t 6, t 7, t 9, t 10} A 3={t 1, t 2, t 4, t 5, t 6, t 8, t 9, t 10} A 4={t 1, t 3, t 4, t 5, t 6, t 8, t 9, t 10} t 6 t 8 A 1={t 1, t 2, t 4, t 5, t 6, t 7, t 9, t 10} t 10 32
Valid schedule t 1 t 4 t 2 t 4 t 1 t 9 t 1 t 3 t 5 t 7 t 6 t 1 t 2 t 7 t 6 t 8 t 10 (t 1 t 2 t 4 t 6 t 7 t 9 t 5) (t 1 t 2 t 4 t 6 t 8 t 10) t 6 t 3 t 5 t 9 t 6 t 8 t 5 t 10 (t 1 t 3 t 5 t 6 t 7 t 9 t 5) (t 1 t 3 t 5 t 6 t 8 t 10) 33
C code implementation t 2 t 1 p 2 2 t 4 p 1 p 4 t 3 t 6 p 3 t 5 t 7 S={(t 1 t 2 t 4 t 6 t 7 t 5) (t 1 t 3 t 5 t 6 t 7 t 5)} Task 1: Task 2: { t 1; { t 6; if (p 1) t 7; then{ t 2; t 5; count(p 2)++; } if (count(p 2) = 2) then{ t 4; count(p 2) = count(p 2) - 2; } else{ t 3; t 5; } } } 34
Application example: ATM Switch Incoming cells (non-periodic) Input cells: accept? Internal buffer Output cells: emit? Outgoing cells Clock (periodic) • No static schedule due to: – Inputs with independent rates (need Real-Time dynamic scheduling) – Data-dependent control (can use Quasi-Static Scheduling) 35
Petri Nets Model 36
Decomposition with min # of tasks Input cell processing 2 Tasks Output cell processing 37
Real-time scheduling of independent tasks Task 1 + RTOS Task 2 Shared Processor 38
Functional decomposition Accept/discard cell 4 Tasks Output time selector Clock divider Output cell enabler 39
ATM: experimental results Functional partitioning (4+1 tasks) Sw Implementation Number of tasks Lines of C code Clock cycles QSS (2 tasks) QSS Functional partitioning 2 5 1664 2187 197526 249726 40
Conclusion • Advantages of Quasi-Static Scheduling: QSS minimizes run-time overhead with respect to Dynamic Scheduling by Automatic partitioning of the system functions into a minimum number of concurrent tasks The underlying model is FCPN: can check schedulability before code generation • Future work – Larger PN classes – Code optimizations 41
- Slides: 41