Top Banner
6 - 1 Swiss Federal Institute of Technology Computer Engineering and Networks Laboratory 6. System Simulation Lothar Thiele Hardware-Software Codesign
50

Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

Jul 19, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 1Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

6. System Simulation

Lothar Thiele

Hardware-Software Codesign

Page 2: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 2Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

SW-compilation HW-synthesis

System Design

specification

system synthesis

machine code net lists

estimation

instruction set

intellectualprop. block

intellectualprop. code

system simulation(this lecture)

(worst-case) perf. analysis

(lectures 10-11)

Page 3: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 3Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Outline

System classification

Discrete event simulation

Illustration: SystemC simulation

Simulation at high abstraction levels

Page 4: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 4Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

System and Model

A system is a combination of components that act together to perform a function not possible with any of the individual parts [IEEE Standard Dictionary of Electrical and Electronic Terms]

A model is a formal description of the system (or subsystem) which covers selected information

inputs outputs

Page 5: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 5Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

System and Model - Example

system

Load

Network Processor Example

model

Page 6: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 6Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

StateThe state of a system model at time t0 contains all informationnecessary to determine the output at all t≥t0, from thisinformation and from the input for all t≥t0The set X of possible states of a system is called its state space

Example: state space modeling of continuous time driven systems

Page 7: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 7Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Discrete State/Continuous StateIn discrete state models, the state space X is isomorphic to the set of integers, i.e., it is countable

…while other models are termed continuous state models

x1

x4 x2

x3

Page 8: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 8Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

TimeIn a continuous time model, the set T of admissible time values is isomorphic to the set of real numbers, i.e., T→R

In a discrete time model, the set T of admissible time values is isomorphic to the set of integer numbers, i.e., T→Z

Page 9: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 9Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Discrete/Continuous State/Time SystemsSome examples

Continuous state systems: physical processes (usually), electrical networks, mechanical systemsDiscrete state systems: finite state machines, queuing systems, computer systemsContinuous time systems: physical processes (usually), electrical circuits, asynchronous systemsDiscrete time systems: digital clocked system, equidistant sampling (z-transform), synchronous system models

time

continuous state space (in continuous time)

discrete state space (in discrete time)

time 123

1 2 3 4

Page 10: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 10Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

EventsAn event e =(v,t) is a tuple of a value v and a tag t

(tags are usually totally ordered)

If the tag denotes time, then the event is a timed event If the tag denotes (only) a sequence number, the event is an

untimed event

events A A B

C D

A A B

C D

Page 11: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 11Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Discrete Event Systems (DES)A DES is an event-driven systemi.e., its state evolution depends entirely on occurrence of discrete events over time (or the tag system, in general), and not by the evolution of timeAs in time-driven systems, a DES model can be defined in continuous or discrete time, depending on whether the admissible time instances are taken from a continuous or discrete setThe state space of a DES model can be either discrete or continuous, depending on X

Page 12: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 12Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Discrete Event Systems (DES) (contn.)

The modeling objects of a DES:

Signals or streams consist of ordered and/or timed events. They can be represented as ordered sequences of events.

Processes can be represented as functions that act on signals or streams.

Page 13: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 13Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Example: Queuing System

x(t):

input token output token

stored token

System

input token

queue

server output token

x(t)

tt2t1 t3 t5t4 t6 t7

Model

State trajectory

Page 14: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 14Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Time-Driven vs. Event-Driven SimulationDiscrete-time, time-driven simulation

The simulated time is partitioned into (equidistant) timeintervalsThe lengths of time intervals are determined by the simulatedsystem (e.g., clock period), by the intended precision(discretization loss), or by the simulation effortA simulation step is performed even if nothing happens

x(t)

t

Page 15: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 15Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Time-Driven vs. Event-Driven SimulationEvent-driven simulation Evaluation and state changes only at occurrence of events Analysis and simulation are possible in discrete or continuous

time

x(t)

t

x(t)

tt2

t1t3

t5t4 t6 t7

Continuoustime

Discretetime

events

in in out in in inout

in in out in in inout

Page 16: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 16Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Outline

System classification

Discrete event simulation

Illustration: SystemC simulation

Simulation at high abstraction levels

Page 17: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 17Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Discrete-Event Modeling and SimulationConcurrent processes are usually modeled using the concept of modules The behavior is described using logic and/or algebraic expressions The state is described using persistent variables inside these modules The communication between modules is done through ports, via signals The synchronization between modules is done through events and/or

signalsModules can be hierarchical, i.e., there can be modules inside of modulesThe system behavior is governed by events event-driven simulation

Page 18: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 18Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Components of Discrete-Event Simulation Event list

Events in the event list are processed in order by the simulation engine. The event list is typically organized as a priority queue. Events in the event list may include the time when the event will happen

(in this case, lists are sorted by event times).

Simulation time The simulation time represents the current value of the time in the modules. During a timed discrete-event simulation, the clock advances to the next

event time by processing the next event in the event list.

System modules System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant to

the respective module is scheduled. System modules process events, manipulate the event queue (add or

remove events), and manipulate the system state.

Page 19: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 19Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Discrete-Event Simulation EngineInitialization routine Initialize the simulation model: set initial

states of subsystem modules, fill the event queue with initial events

Timing routine Determine the next event from the

event queue Advance the simulation time clk to the

time when the event is to occur

Event routine Update the system state when a

particular type of event occurs

initialize

while(!StopCriterion)

set clk to next event time

update simulation output

generate simulation report

- process next event by calling subsystem module(s)- remove event from event queue si

mul

atio

n cy

cle

Page 20: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 20Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Discrete-Event Simulation

simulation cycle

In a simulation cycle The events with the next time in the event queue are processed. All modules sensitive to these events are executed this may

“produce” new events.Problem: Within the same simulation cycle (same simulation clock),

“cause” and “effect” events may share the same time of occurrence!

Page 21: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 21Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Discrete-Event Simulation

t + δ t + 2δ t + nδ

simulation cycle

Solution: The simulator uses a zero duration virtual time interval, called delta-cycle

(δ). Processing of an event that takes 0 time according to the original system model now takes δ time.

The role of a delta-cycle is to order “simultaneous” events within a simulation cycle, i.e., identifying which event caused another. “causes” and “effects” are separated by delta-cycles.Simulation cycles may be composed of several delta-cycles (δ)

Page 22: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 22Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Outline

System classification

Discrete event simulation

Illustration: SystemC simulation

Simulation at high abstraction levels

Page 23: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 23Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

SystemC in a NutshellSystem-level modeling language Several levels of abstraction: from purely functional (only

ordering of events) to cycle-accurate timed simulation. Specially suited for systems that contain embedded software.

Library of C++ templates and classes for modeling concurrent systems. Examples are hardware-oriented data types communication mechanisms concurrency modeling

SystemC is essentially an event-driven simulation kernel for executing discrete-event models

… and available for free (Windows & Linux)

Page 24: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 24Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Executable specification

SystemC

UserModule#1User

module #1

.....events & signals

Events

SystemC Principle

Simulation kernel(Event scheduler)

User module

#2

User module

#N

C++ class libraryC++ class library

Page 25: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 25Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Standard channelsfor various MoC’s

Kahn process networks,static dataflow, etc.

Methodology specific

channelsmaster/slave lib, etc.

Elementary channelssignal, timer, mutex, semaphore, FIFO, etc.

Core languagemodules

portsprocessesinterfaceschannelsevents

Data typeslogic type (0’XZ)

logic vectorsbits and bit vectorsfixed point numbersC++ built-in types

(int, char, double, etc.)C++ user-defined types

C++ language standard

SystemC Language ArchitectureSystemC core language minimal set of modeling constructs for

structural description, concurrency, communication, and synchronization

Data types

On top of core language and data types:Communication mechanisms, e.g., signals, FIFOs. Models of computation (MoCs)

SystemC builds on C++Upper layers built on top of lower layers the lower layers within the diagram can

also be used without passing throught the upper layersSystemC language

Page 26: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 26Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Example NAND nand

Page 27: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 27Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Example EXORn1

n2

n3

n4

A

B

F

alternatives to define connectionsbetween modules

exor

Page 28: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 28Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

ModulesModules are the building blocks of SystemC models.

processesSC_MODULE

ports

Page 29: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 29Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

ProcessesProcesses are the basic units of functionality.

SC_THREADs Typically called once, run forever in a while(true)loop Can be suspended by calling the wait() function which waits for an

event in the associated sensitivity list Keep the state of execution implicitly

SC_METHODs Execute repeatedly from the beginning to end and cannot be suspended. Execution starts again based on the associated sensitivity (occurrence of

an event). Methods do not keep the state of execution implicitly

Processes must be contained in a module

Page 30: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 30Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Wait and Notifywait: halt process execution until an event is raised wait() without arguments dynamic sensitivity

•wait(sc_event)•wait(time)

•wait(time_out, sc_event)

notify: raise an event notify() with arguments delayed notification

•my_event.notify(); //notify immediately

•my_event.notify(SC_ZERO_TIME);

//notify next delta cycle

•my_event.notify(time);//notify after ‘time’

Page 31: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 31Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Module Template

Page 32: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 32Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Inter-Process CommunicationProcesses can communicate directly through signals

Process 1

Process 2

Internal signals

Input ports

I/O ports

Output portsSensitivity

Module

Page 33: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 33Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Advanced CommunicationEvent Flexible, low-level synchronization primitive

Channel Container for communication and synchronization

e.g. can have state/private data, transport data, transport events Channels implement one or more interfaces

Interface Set of access methods to the channel Interface methods need to be implemented

Other communication & synchronization models can be built based on the above primitives

Page 34: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 34Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Channels and Interfaces

Page 35: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 35Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Ex.1: Simple Producer-Consumer Application‘Producer’ communicates with ‘consumer’ via a FIFO channel

Page 36: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 36Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Ex.1: Simple FIFO – Interface

Page 37: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 37Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Ex.1: Simple FIFO – Implementation

Page 38: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 38Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Ex.1: Simple FIFO – Implementation

Page 39: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 39Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Ex.1: Simple Producer-Consumer

Page 40: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 40Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Ex.1: Simple Producer-Consumer

Page 41: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 41Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Ex. 2: Kahn Process Network - Generator

Page 42: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 42Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Ex.2: Kahn Process Network - Adder

Page 43: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 43Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Ex.2: Kahn Process Network - Forker

Page 44: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 44Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Ex.2: Kahn Process Network - Printer

Page 45: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 45Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Ex.2: Kahn Process Network – Top

Page 46: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 46Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Does it work correctly?

Page 47: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 47Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Ex.2: Kahn Process Network - Forker

KPN will deadlock unlessan initial token is put in the loop:

output1.write(0.0);

Page 48: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 48Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Executable specification

SystemC

UserModule#1User

module #1

.....events & signals

Events

SystemC Principle

Simulation kernel(Event scheduler)

User module

#2

User module

#N

C++ class library

Page 49: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 49Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Outline

System classification

Discrete event simulation

Illustration: SystemC simulation

Simulation at high abstraction levels

Page 50: Hardware-Software Codesign 6. System Simulation · System modules model subsystems of the simulated system. System modules are called by the simulation engine if an event relevant

6 - 50Swiss FederalInstitute of Technology

Computer Engineeringand Networks Laboratory

Multiple Levels of Abstraction(Untimed) functional level Use: model (un-)timed functionality Communication: shared variables, messages Typical languages: C/C++, Matlab

Transaction level Use: MPSoC architecture analysis, early SW

development, timing estimation Communication: method calls to channels Typical languages: SystemC

Register transfer level /pin level Use: HW design and verification Communication: wires and registers Typical languages: Verilog, VHDL

Functional

Transaction-Level

Register Transfer Level