quasi-static scheduling of embedded software using free...
TRANSCRIPT
1
Quasi-Static Scheduling ofEmbedded Software Using
Free-Choice Petri Nets
Marco Sgroi, Alberto Sangiovanni-Vincentelli
Luciano Lavagno
University of California at Berkeley
Cadence Berkeley Labs
Yosinori WatanabeCadence European Labs EE249 - Fall1999
2
Outline
n Quasi-Static Schedulingn Motivation
n Scheduling Free-Choice Petri Netsn Algorithmn Application example
3
Classes of Scheduling
n Static: schedule completely determined at compiletime
n Dynamic: schedule determined at run-time
n Quasi-Static: most of the schedule computed atcompile time, some scheduling decisions made atrun-time (but only when necessary)
4
Embedded Software Synthesis
n System specification: set of concurrent functional blocks(DF actors, CFSMs, CSP, …)
n Software implementation: set of concurrent software tasksn Two sub-problems:
u Generate code for each task (software synthesis)u Schedule tasks dynamically (scheduling)
n Our goal: minimize real-time scheduling overhead
5
Petri Nets Model
6
Petri Nets Model
Schedule: t12, t13, t16...
a = 5c = a + b
7
Petri Nets Model
Shared Processor+ RTOS
Task 1
Task 2
Task 3
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 (+, -, *...)
9
Data processing
i k2 + o
k1
Static Data Flow network
Example: 2nd order IIR filter o(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
i k2 + o
k1
Static Data Flow network
11
Data processing (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 82
F5
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
13
Boolean Data Flow and Petri Nets
i*2F
T
F
T
*2
/2o
>0
oi o>0
*2
/2
Schedule: i, if (i>0) then{ /2} else{ *2}, o
• PNs:• Most properties are decidable• Abstract Dataflow networks by representing if-then-else structures as non-deterministic choices• Non-deterministic actors (choice and merge) make thenetwork non-determinate
BDF PN
14
Existing approaches
n Lee - Messerschmitt ‘86u Static Data Flow: cannot specify data-dependent control
n Buck - Lee ‘94u Boolean Data Flow: scheduling problem is undecidable
n Thoen - Goossens - De Man ‘96u Event graph: no schedulability check, no minimization of
number of tasksn Lin ‘97
u Safe Petri Net: no schedulability check, no multi-rate
15
Bounded scheduling(Marked Graphs)
n A finite complete cycle is a finite sequence of transitionfirings that returns the net to its initial state
Ð Bounded memoryÐ Infinite execution
n 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 1 0 -2 f(σ) D = 0 has no solution
16
Bounded scheduling(Marked Graphs)
n Existence of a T-invariant is only a necessary conditionn 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
17
Free-Choice Petri Nets (FCPN)
Marked Graph (MG)
Free-Choice Confusion (not-Free-Choice)
n Free-Choice:u choice depends on token value rather than arrival time
u easy to analyze (using structural methods)
18
t1 t2 t3 t5 t6
Bounded scheduling(Free-Choice Petri Nets)
t1 t2t3
t4
t5 t6
t7
t1 t2 t3 t5 t6
n Can the “adversary” ever force token overflow?
19
t1 t2 t4 t7
Bounded scheduling(Free-Choice Petri Nets)
t1 t2t3
t4
t5 t6
t7
t1 t2 t4 t7
n Can the “adversary” ever force token overflow?
20
Bounded scheduling(Free-Choice Petri Nets)
t1 t2t3
t4
t5t7
t6
n Can the “adversary” ever force token overflow?
21
Bounded scheduling(Free-Choice Petri Nets)
t1 t2t3
t4
t5t7
t6
n Can the “adversary” ever force token overflow?
22
Bounded scheduling(Free-Choice Petri Nets)
t1 t2t3
t4
t5t7
t6
n Can the “adversary” ever force token overflow?
23
Schedulability (FCPN)
n 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)}
24
Bounded scheduling(Free-Choice Petri Nets)
n 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)
25
How to check schedulability
n Basic intuition: every resolution of data-dependent choices must be schedulable
n Algorithm:u Decompose (by applying the Reduction Algorithm)
the given Free-Choice Petri Nets into as manyConflict-Free components as the number of possibleresolutions of the non-deterministic choices.
u Check if every component is statically schedulableu Derive a valid schedule, i.e. a set of finite complete
cycles one for each conflict-free component
26
Allocatability(Hack, Teruel)
n An Allocation is a control function that chooses whichtransition fires among several conflicting ones ( A: P T).
n A Reduction is the Conflict Free Net generated from oneAllocation by applying the Reduction Algorithm.
n A FCPN is allocatable if every Reduction generated froman allocation is consistent.
n Theorem: A FCPN is schedulable iffu it is allocatable andu every Reduction is schedulable (following Lee)
27
Reduction Algorithm
t6t1
t5
t4t2
t7
t6
t7
t1
t4t2
t4t2t6t1
t1
t5
t4
t7
t2t6
t6
t7
t1
t4t2
t1
t3 t5
t4t6
t2
t7
T-allocation A1={t1,t2,t4,t5,t6,t7}
28
How to find a valid schedule
t1
t2 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}
29
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
tttttt
tttttt
ttttttt
ttttttt
30
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
31
Application example:ATM Switch
Input cells: accept?
Output cells: emit?
Internal buffer
Clock (periodic)
Incoming cells (non-periodic)
Outgoing cells
n No static schedule due to:u Inputs with independent rates
(need Real-Time dynamic scheduling)u Data-dependent control
(can use Quasi-Static Scheduling)
32
Petri Nets Model
33
Functional decomposition
4 Tasks
Accept/discard cell
Output time selector
Output cell enablerClock divider
34
Decomposition with min # of tasks
2 Tasks
Input cell processing
Output cell processing
35
Real-time scheduling ofindependent tasks
+ RTOS
Shared Processor
Task 1
Task 2
36
ATM: experimental results
Sw Implementation QSS Functional partitioning
Number of tasks 2 5
Lines of C code 1664 2187
Clock cycles 197526 249726
Functional partitioning (4+1 tasks) QSS (2 tasks)
37
Conclusion
n 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
n Future worku Larger PN classes (synchronization-dependent choice)u Code optimizations