Mod-3-Spec N Models Upd4
Mod-3-Spec N Models Upd4
Embedded
Systems
Mod-3: Specifications and Modeling
Motivation for considering
specs & models
Why considering specs and models in detail?
[Jantsch, 2004]
Behavioral hierarchy
Examples: states, processes, procedures
Structural hierarchy
Examples: processors, memories, printed circuit boards
proc
Processors include registers proc
proc
Multiplexers include gates
Requirements for specification &
modeling techniques (2)
• Component-based design
• Systems must be designed from components
• Must be “easy” to derive behavior from
behavior of subsystems
• e.g., add a GPS unit to a car
• Concurrency
• Human beings are not very good at understanding concurrent systems
“The lack of timing in the core abstraction (of computer science) is a flaw,
from the perspective of embedded software” [Lee, 2005]
Requirements for specification &
modeling techniques (4)
4 types of timing specs required
? execute
t
t
Requirements for specification &
modeling techniques (5)
3. Possibility to specify timeouts
Stay in a certain state a maximum time
execute
t
Specification of ES (6): Support for designing
reactive systems
State-oriented behavior
Required for reactive systems;
classical automata insufficient
Event-handling
external or internal events
Exception-oriented behavior
Not acceptable to describe
exceptions for every state
Requirements for specification & modeling
techniques (7)
Presence of programming elements
Executability
Support for the design of large systems (F OO)
Domain-specific support: control, data, centralized, distributed
Readability
Portability and flexibility
Termination
Support for non-standard I/O devices
Non-functional properties: fault-tolerance, extendibility, weight, user friendliness
Support for the design of dependable systems
No obstacles for efficient implementation
Adequate model of computation
Models of Computation (MoCs)
Describe the mechanism assumed for performing computations
MoCs define:
- Components and organization of computations in such components
execution model for computations for each component
e.g. procedures, processes, functions, finite state machines
- Communication protocols describe methods for communication between
components
model for exchange of information between components
e.g. asynchronous message passing, rendezvous based communication
Dependence graph: Definition
Sequence
constraint
Nodes could be programs or simple
operations
• Granularity
Models of communication
Two communication paradigms
Shared memory
Message passing
Shared memory
Comp-1 memory Comp-2
… …
send () receive ()
… …
… …
send () receive ()
… …
a 56
time
5 10 13 15 19
b 7 action
c 8 a:=5 b:=7 c:=8 a:=6 a:=9
¶2x
=b
¶t 2
§ Data flow
(models the flow of data in a distributed system)
§ Petri nets
(models synchronization in a distributed system)
Communication/ Shared Message passing
local computations memory Synchronous | Asynchronous
Undefined Plain text, use cases
components | (Message) sequence charts
Communicating finite StateCharts SDL
state machines
Data flow Scoreboarding +
Tomasulo Algorithm
Kahn networks,
(F Comp.Archict.) SDF
Petri nets C/E nets, P/T nets, …
Discrete event (DE) VHDL*, Only experimental systems, e.g.
model Verilog*, distributed DE in Ptolemy
SystemC*, …
Von Neumann C, C++, C, C++, Java with libraries
model Java CSP, ADA |
* Classification based on implementation with centralized data structures
Different MoCs have advantages in certain application areas
Mixed MoCs can help
Translate from on MoC to another
Non-von-Neumann models to von-Neumann models
Model-based design
Start with non-von-Neumann models
Why not just use von-Neumann computing (C,
Java, …) ?
Problems with von-Neumann Computing
Thread-based multiprocessing may access global variables
We know from the theory of operating systems that
access to global variables might lead to race conditions
to avoid these, we need to use mutual exclusion
mutual exclusion may lead to deadlocks
avoiding deadlocks is possible only if we accept performance penalties
Other problems …
Capturing the requirements as text
In the very early phases of some design project, only
descriptions of the system under design (SUD) in a
natural language such as English or Japanese exist.
Expectations for tools:
Machine-readable
Version management
Dependence analysis
Use cases
Use cases describe possible applications of
the SUD
Included in UML (Unified Modeling Language)
Example: Answering machine
Life-line
Asynchronous
message
Time/distance diagrams (TDDs)
• Variant of MSC
Distance
Time
Levi-TDD
Communicating FSMs
Describe state-oriented behavior at a more detailed level
Deterministic FSM
Only one state is active at a time
Synchronous FSM
Implicitly clocked
Other variants
Timed automata
StateCharts
Synchronous languages
SDL (specification and description language)
Timed automata
Timed automata = automata + models of time
The variables model the logical clocks in the system, that are initialized with zero
when the system is started, and then increase synchronously with the same rate
Clock constraints i.e. guards on edges are used to restrict the behavior of the
automaton
A transition represented by an edge can be taken when the clocks values satisfy
the guard labeled on the edge.
Clocks may be reset to zero when a transition is taken
Example: Answering machine
Ensures that transition takes
place
superstate
substates
Default state mechanism
Try to hide internal
structure from outside
world!
F Default state
Filled circle
indicates sub-state
entered whenever
super-state is entered.
Not a state by itself!
History mechanism
same meaning
For instance, the following shows possible uses of the led state machine type:
var machine : led
operation myOp(param : led)
in/out event : led
Line-monitoring and key-monitoring are entered and left, when service switch is
operated
Types of states
In StateCharts, states are either
basic states, or
AND-super-states, or
OR-super-states
.
General form of edge labels
event [condition] / reaction
Events:
Exist only until the next evaluation of the model
Can be either internally or externally generated
Conditions:
Refer to values of variables that keep their value until they are
reassigned
Reactions:
Can either be assignments for variables
or creation of events
Example:
on--key / on:=1
[on=1]
service-off [not in Lproc] / service:=0
Evaluation of StateCharts (1)
Pros (C):
Hierarchy allows arbitrary nesting of AND- and OR-super states
Large number of commercial simulation tools available
(StateMate, StateFlow, BetterState, ...)
Capable of translating into equivalent descritions in C or VHDL by
synthesis tools
Available “back-ends“ translate StateCharts into SW or HW
languages, thus enabling software or hardware implementations
Evaluation of StateCharts (2)
Cons (D):
Not useful for distributed applications
no description of non-functional behavior
no object-orientation
no description of structural hierarchy
generated programs may be inefficient
Data flow modeling
Definition: Data flow modeling is … “the process
of identifying, modeling and documenting how data move around an
information system.
Data flow modeling examines
processes (activities that transform data from one form to
another),
data stores (the holding areas for data),
external entities (what sends data into a system or receives data
from a system, and
data flows (routes by which data can flow)”.
1
1
2
3
2
3
2
3
2
3
2
3
2
3
Decidable:
§ buffer memory requirements
§ deadlock
Schedulable statically
Parallel Scheduling of SDF Models
SDF is suitable for Many scheduling
automated mapping onto A optimization
parallel processors and problems can be
synthesis of parallel C formulated
circuits. B
Sequential Parallel
The expressiveness/analyzability conflict
“Preconditions“
Playing the “token game“
Playing the “token game“
Conflict for resource “track“
Condition/event nets
Def.: N=(C,E,F) is called a net, iff the following holds
1. C and E are disjoint sets
2. F Í (C ´ E) È (E ´ C); is binary relation,
(“flow relation“)
Pre- and post-sets
Def.: Let N be a net and let x Î (C È E).
•x := {y | y F x} is called the pre-set of x,
(or preconditions if x Î E)
x• := {y | x F y} is called the set of post-set of x,
(or postconditions if x Î E)
Example:
•x x x•
Loops and pure nets
Def.: Let (c,e) Î C ´ E. (c, e) is called a loop iff cFe Ù eFc.
f1
f2
f3
Predicate/transition model of the
dining philosophers problem (2)
p2
p1 p3
f1
f2
f3
Bottom up process
Possible branches
Visibility of memory locations and addresses
Example languages
Machine languages (binary)
Assembly languages (mnemonics)
Imperative languages providing limited abstraction of
machine languages (C, C++, Java, ….)
Synchronous message passing: CSP
CSP (communicating sequential processes)[Hoare, 1985]
One of the first languages comprising mechanisms for inter-
process communications
Rendez-vous-based communication:
Example:
process A process B
.. ..
var a ... var b ...
a:=3; ...
c!a; -- output c?b; -- input
end end
Communication/synchronization
Communication libraries can add blocking or
non-blocking communication to von-Neumann languages
like C, C++, Java, …
Java
Potential benefits:
§ Clean and safe language
§ Supports multi-threading (no OS required?)
§ Platform independence (relevant for telecommunications)
Problems:
§ Size of Java run-time libraries? Memory requirements
§ Access to special hardware features
§ Garbage collection time
§ Non-deterministic dispatcher
§ Performance problems
§ Checking of real-time constraints
Modeling levels
Start at different levels of abstraction
System level
Algorithmic level: just the algorithm
Processor/memory/switch (PMS) level
Instruction set architecture (ISA) level: function only
Transaction level modeling (TML): memory reads & writes
are just “transactions“ (not cycle accurate)
Register-transfer level: registers, muxes, adders, …
(cycle accurate, bit accurate)
Gate-level: gates
Layout level
Tradeoff between accuracy and simulation speed
Example: System level
Term not clearly defined
Here: denotes the entire cyber-physical/embedded system,
system into which information processing is embedded, and possibly
also the environment
Models may include mechanics + information processing.
May be difficult to find appropriate simulators.
Solutions: VHDL-AMS, SystemC or MATLAB
MATLAB+VHDL-AMS support partial differential equations
Challenge to model information processing parts of the system such
that the simulation model can be used for the synthesis of the
embedded system
Instruction set architecture (ISA)
Algorithms already compiled for the ISA
Model allows counting the executed # of instructions
Assembler (MIPS) Simulated semantics
and $1,$2,$3 Reg[1]:=Reg[2] Ù Reg[3]
or $1,$2,$3 Reg[1]:=Reg[2] Ú Reg[3]
Not Turing
complete
How to cope with MoC and language problems
in practice?
Transformations between models
Transformations between models are possible, e.g.
Frequent transformation into sequential code
Transformations between restricted Petri nets and SDF
Transformations between VHDL and C
Best to specify in the most convenient model
Transformations should be based on the precise description of the
semantics
Mixing models of computation: UML
(Focus on support of early design phases)