43
Introduction to SystemC Deian Tabakov Rice University Houston, TX September 10, 2007

Intro SystemC P1

Embed Size (px)

DESCRIPTION

Tutorial básico de manejo, simulación e implementación de arquitecturas sencillas utilizando System C.

Citation preview

Page 1: Intro SystemC P1

Introduction to SystemC

Deian Tabakov

Rice UniversityHouston, TX

September 10, 2007

Page 2: Intro SystemC P1

Introduction

The brave new world

Time-to-market : This year’s gadgets must replace last year’s

Shorter design cyclesFind and fix most bugs earlyEarly prototyping and design explorationDesign software and hardware in parallel

Complexity : Designing in the age of the iPhone

Moore’s LawSoC: Hardware + software on a single dieConcurrent systemsIP development, reuse, exchangeSpecifying systems

Deian Tabakov Introduction to SystemC 2/29

Page 3: Intro SystemC P1

Introduction

Toward a new language: desiderata

Specification and design at various levels of abstraction

Executable specification

Executable platform models

Fast simulation speed

Separating communication from computation

Easy to learn

Object-oriented.

Deian Tabakov Introduction to SystemC 3/29

Page 4: Intro SystemC P1

Introduction

Toward a new language: desiderata

Specification and design at various levels of abstraction

Executable specification

Executable platform models

Fast simulation speed

Separating communication from computation

Easy to learn

Object-oriented.

Deian Tabakov Introduction to SystemC 3/29

Page 5: Intro SystemC P1

Introduction

SystemC in a nutshell

A “system-level” modeling languageSeveral levels of abstraction (from purely functional to cycleaccurate pin-accurate)Special attention to systems with embedded software

Deian Tabakov Introduction to SystemC 4/29

Page 6: Intro SystemC P1

Introduction

SystemC in a nutshell

A “system-level” modeling languageSeveral levels of abstraction (from purely functional to cycleaccurate pin-accurate)Special attention to systems with embedded software

A library of C++ templates and classes for modelingconcurrent systems

Hardware-oriented data typesCommunication mechanismConcurrency model

Deian Tabakov Introduction to SystemC 4/29

Page 7: Intro SystemC P1

Introduction

SystemC in a nutshell

A “system-level” modeling languageSeveral levels of abstraction (from purely functional to cycleaccurate pin-accurate)Special attention to systems with embedded software

A library of C++ templates and classes for modelingconcurrent systems

Hardware-oriented data typesCommunication mechanismConcurrency model

An event-driven simulation kernel for executing models

Available for free (Windows + Linux)

Deian Tabakov Introduction to SystemC 4/29

Page 8: Intro SystemC P1

Modeling an EXOR gate

Figure: NAND gate

Deian Tabakov Introduction to SystemC 5/29

Page 9: Intro SystemC P1

Modeling an EXOR gate

Example (nand.h)

#include "systemc.h"

SC_MODULE(nand) { // declare a NAND sc_module

sc_in<bool> A, B; // input signal ports

sc_out<bool> F; // output signal ports

void do_it() { // a C++ function

F.write( !(A.read() && B.read()) );

}

SC_CTOR(nand) { // constructor for the module

SC_METHOD(do_it); // register do_it() w/ kernel

sensitive << A << B; // sensitivity list

}

};

Deian Tabakov Introduction to SystemC 6/29

Page 10: Intro SystemC P1

Modeling an EXOR gate

Figure: EXOR gate

Deian Tabakov Introduction to SystemC 7/29

Page 11: Intro SystemC P1

Modeling an EXOR gate

Example (exor.h)

#include "nand.h"

SC_MODULE(exor) {

sc_in<bool> A, B;

sc_out<bool> F;

nand n1, n2, n3, n4;

sc_signal<bool> S1, S2, S3;

SC_CTOR(exor) : n1("N1"), n2("N2"), n3("N3"), n4("N4") {

n1.A(A);

n1.B(B);

n1.F(S1);

n2 << A << S1 << S2;

n3(S1);

n3(B);

n3(S3);

n4 << S2 << S3 << F;

}

};

Deian Tabakov Introduction to SystemC 8/29

Page 12: Intro SystemC P1

Modeling an EXOR gate

Figure: Test Bench

Deian Tabakov Introduction to SystemC 9/29

Page 13: Intro SystemC P1

Modeling an EXOR gate

Example (stim.h)

#include "systemc.h"SC_MODULE(stim) {

sc_out<bool> A, B;sc_in<bool> Clk;

void StimGen() {A.write(false);B.write(false);wait(); // wait for the next clock tickA.write(false);B.write(true);wait(); // wait for the next clock tick

...sc_stop(); // notify kernel to stop simulation

}SC_CTOR(stim) {SC_THREAD(StimGen);sensitive << Clk.pos();

}};

Deian Tabakov Introduction to SystemC 10/29

Page 14: Intro SystemC P1

Modeling an EXOR gate

Example (mon.h)

#include "systemc.h"SC_MODULE(mon) {

sc_in<bool> A, B, F;sc_in_clk Clk;

void Monitor() {while(1) {

wait();cout << sc_time_stamp() << "\t" << A.read()

<< " " << B.read() << " " << F.read() << endl;}

}SC_CTOR(mon) {SC_THREAD(Monitor);sensitive << Clk.pos();

cout << "Time\tA B F" << endl;}

};

Deian Tabakov Introduction to SystemC 11/29

Page 15: Intro SystemC P1

Modeling an EXOR gate

Example (Putting it all together)

#include "stim.h"

#include "exor.h"

#include "mon.h"

int sc_main(int argc, char* argv[]) {

sc_signal<bool> ASig, BSig, FSig;

sc_clock TestClk("TestClock", 10, SC_NS, 0.5);

stim Stim1("Stimulus"); mon Monitor1("Monitor");

Stim1.A(ASig); Monitor1.A(ASig);

Stim1.B(BSig); Monitor1.B(BSig);

Stim1.Clk(TestClk); Monitor1.F(FSig);

Monitor1.Clk(TestClk);

exor DUV("exor");

DUV.A(ASig);

DUV.B(BSig);

DUV.F(FSig);

sc_start(); // run forever

return 0;

}

Deian Tabakov Introduction to SystemC 12/29

Page 16: Intro SystemC P1

Modeling an EXOR gate

Example (Putting it all together)

#> ./sandbox

SystemC 2.1.v1 --- Jun 13 2007 04:39:21

Copyright (c) 1996-2005 by all Contributors

ALL RIGHTS RESERVED

Time A B F

0 s 0 0 1

10 ns 0 1 1

20 ns 1 0 1

30 ns 1 1 0

SystemC: simulation stopped by user.

#>

Deian Tabakov Introduction to SystemC 13/29

Page 17: Intro SystemC P1

Fundamentals of SystemC

Modules: the building blocks of SystemC models

Hierarchy

Abstraction

IP reuse

sc_out

sc_out

SC_THREADsc_in

SC_METHODsc_insc_signal

Helper MethodHelper Method

SC_MODULE(Child Module)SC_MODULE

(Child Modules)

sc_inout

module memory(local variables)

Figure: SC MODULE

Deian Tabakov Introduction to SystemC 14/29

Page 18: Intro SystemC P1

Fundamentals of SystemC

Modules: the building blocks of SystemC models

Example (Structure of a module)

SC_MODULE(Module_name) {

// Declare ports, internal data, etc.

// Declare and/or define module functions

SC_CTOR(Module_name) {

// Body of the constructor

// Process declarations and sensitivities

SC_METHOD(function1);

sensitive << input1 << input2;

SC_THREAD(function2);

sensitive << input1 << clk;

}

};

Deian Tabakov Introduction to SystemC 15/29

Page 19: Intro SystemC P1

Fundamentals of SystemC

Processes: basic units of functionality

SC THREADsCan be suspended (wait())Implicitly keep state of execution

SC METHODsExecute their body from beginning to endSimulate fasterDo not keep implicit state of execution

Processes must be contained in a module (but not everymember function is a process!)

Deian Tabakov Introduction to SystemC 16/29

Page 20: Intro SystemC P1

Fundamentals of SystemC

Data types

Four-valued logic types (01XZ)

Arbitrary-precision integers

TimeSC SEC, SC MS, SC US, SC NS, etc.sc time t1(42, SC NS) creates a time object representing42 nanosecondsInteger-valued model of time

Deian Tabakov Introduction to SystemC 17/29

Page 21: Intro SystemC P1

Mechanisms for Abstraction

Interfaces: windows into the communication channels

Signature of an operation: name, params, return value

Ignore implementation details

No local data

Ports: helper objects of communication

Agents for connecting modules with their environment

Forward calls to the channel on behalf of the module

Channels: workhorses for transmitting data

Communication between modules

Provide the functionality defined in the interfaces

Deian Tabakov Introduction to SystemC 18/29

Page 22: Intro SystemC P1

Mechanisms for Abstraction

MODULE 1

MODULE 3

MODULE 2

channels

ports

signals

Figure: Modules, channels, ports, signals

Deian Tabakov Introduction to SystemC 19/29

Page 23: Intro SystemC P1

Interfaces and Ports

Every port expects a particular type of interface

Example (nand.h)

#include "systemc.h"

SC MODULE(nand) { // declare a NAND sc module

sc in<bool> A, B; // input signal ports

sc out<bool> F; // output signal ports

...

Deian Tabakov Introduction to SystemC 20/29

Page 24: Intro SystemC P1

Interfaces and Ports

Every port expects a particular type of interface

Example (nand.h)

#include "systemc.h"

SC MODULE(nand) { // declare a NAND sc module

sc port<sc signal in if<bool>,1> A,B; // input sig.

sc out<bool> F; // output signal ports

...

Deian Tabakov Introduction to SystemC 20/29

Page 25: Intro SystemC P1

Interfaces and Ports

Every port expects a particular type of interface

Example (nand.h)

#include "systemc.h"

SC MODULE(nand) { // declare a NAND sc module

sc port<sc signal in if<bool>,1> A,B; // input sig.

sc port<sc signal out if<bool>,1> F; // output sig.

...

Deian Tabakov Introduction to SystemC 20/29

Page 26: Intro SystemC P1

Interfaces and Ports

Every port expects a particular type of interface

Example (nand.h)

#include "systemc.h"

SC MODULE(nand) { // declare a NAND sc module

sc port<sc signal in if<bool>,1> A,B; // input sig.

sc port<sc signal out if<bool>,1> F; // output sig.

...

Every port can use only the methods defined in the interface

Example (nand.h)...

void do it() { // a C++ function

F.write( !(A.read() && B.read()) );

}...

Deian Tabakov Introduction to SystemC 20/29

Page 27: Intro SystemC P1

Channels

Channels implement interfaces

One channel can implement multiple interfaces

Many channels can implement the same interface

Example (exor.h)

SC MODULE(exor) {sc in<bool> A, B;

sc out<bool> F;

nand n1, n2, n3, n4;

sc signal<bool> S1, S2, S3;

...

For example, sc signal<T> implements two interfaces:sc signal in if<T> and sc signal inout if<T>

Deian Tabakov Introduction to SystemC 21/29

Page 28: Intro SystemC P1

Events

In SystemC events are objects (sc event) that determine whethera process’ execution should be triggered or resumedAn event is notified when a particular condition occurs

Rising edge of a clock

Change of a value of a signal

Explicit call (e.notify())

An empty FIFO channel is written to

Many others

Three types of notification: immediate, delta, and timed.“Event notification causes processes that are sensitive to it to betriggered.”

Deian Tabakov Introduction to SystemC 22/29

Page 29: Intro SystemC P1

Simulation Semantics

Simulating parallel execution sequentially

Simulation Kernel: the heart of SystemC

Controls timing

Controls order of execution of processes

Handles event notification

Updates the channels if so requested

Non-preemptive execution

Deian Tabakov Introduction to SystemC 23/29

Page 30: Intro SystemC P1

Simulation Semantics

Simulating parallel execution sequentially

1 InitializeMark all processes runnable (or pending, or eligible)Each SC METHOD will be executed onceEach SC THREAD will be executed until the first synch point

Deian Tabakov Introduction to SystemC 24/29

Page 31: Intro SystemC P1

Simulation Semantics

Simulating parallel execution sequentially

1 Initialize2 Evaluate

Select an eligible process and run itIf the process uses immediate notification, other processes maybecome eligible too (This is bad practice!)Continue selecting eligible processes until none are left

Deian Tabakov Introduction to SystemC 24/29

Page 32: Intro SystemC P1

Simulation Semantics

Simulating parallel execution sequentially

1 Initialize

2 Evaluate3 Update

One type of channels (primitive channels) are allowed torequest an update phaseHandle pending update requestsMay generate additional delta event notifications, thusrendering more processes eligible

Deian Tabakov Introduction to SystemC 24/29

Page 33: Intro SystemC P1

Simulation Semantics

Simulating parallel execution sequentially

1 Initialize

2 Evaluate

3 Update

4 If there are eligible processes, loop back to the Evaluate phase(step 2)

Deian Tabakov Introduction to SystemC 24/29

Page 34: Intro SystemC P1

Simulation Semantics

Simulating parallel execution sequentially

1 Initialize

2 Evaluate

3 Update

4 If there are eligible processes, loop back to the Evaluate phase(step 2)

5 Advance the timeAt this point there are no eligible processesAdvance the simulation clock to the earliest pending timednotification

Deian Tabakov Introduction to SystemC 24/29

Page 35: Intro SystemC P1

Simulation Semantics

Simulating parallel execution sequentially

1 Initialize

2 Evaluate

3 Update

4 If there are eligible processes, loop back to the Evaluate phase(step 2)

5 Advance the time

6 Determine eligible processes and go to Evaluate phase (step 2)

Deian Tabakov Introduction to SystemC 24/29

Page 36: Intro SystemC P1

Simulation Semantics

Simulating parallel execution sequentially

1 Initialize

2 Evaluate

3 Update

4 If there are eligible processes, loop back to the Evaluate phase(step 2)

5 Advance the time

6 Determine eligible processes and go to Evaluate phase (step 2)

Note: Simulation Kernel = SystemC Scheduler = SimulationScheduler

Deian Tabakov Introduction to SystemC 24/29

Page 37: Intro SystemC P1

Simulation Semantics

Algorithm (Simulation Semantics)

Declare all processes runnable // initializationWhile exists a runnable process do { // simulation loop

While exists a runnable process do { // delta cycle/** Simulation time does not advance **/Run all runnable processes // evaluation phaseRun all pending update requests // update phaseExecute all pending delta notifications // delta phase

}

If exists a pending timed notificationor timeout t then // timed phase

/** Simulation time advances **/Advance time to earliest such t

elseEnd simulation

}

Deian Tabakov Introduction to SystemC 25/29

Page 38: Intro SystemC P1

Modeling an EXOR gate

Example (Putting it all together)

#> ./sandbox

SystemC 2.1.v1 --- Jun 13 2007 04:39:21

Copyright (c) 1996-2005 by all Contributors

ALL RIGHTS RESERVED

Time A B F

0 s 0 0 1

10 ns 0 1 1

20 ns 1 0 1

30 ns 1 1 0

Simulation stopped by user.

#>

Deian Tabakov Introduction to SystemC 26/29

Page 39: Intro SystemC P1

Simulation Semantics

Example (main.cc)

#include "stim.h"

#include "exor.h"

#include "mon.h"

int sc main(int argc, char* argv[]) {sc signal<bool> ASig, BSig, FSig;

sc clock TestClk("TestClock", 10, SC NS, 0.5);

...

Deian Tabakov Introduction to SystemC 27/29

Page 40: Intro SystemC P1

Simulation Semantics

Example (main.cc)

#include "stim.h"

#include "exor.h"

#include "mon.h"

int sc main(int argc, char* argv[]) {sc signal<bool> ASig, BSig, FSig;

sc clock TestClk("TestClock", 10, SC NS, 0.5, 1, SC NS);

...

Deian Tabakov Introduction to SystemC 27/29

Page 41: Intro SystemC P1

Simulation Semantics

Example (main.cc)

#include "stim.h"

#include "exor.h"

#include "mon.h"

int sc main(int argc, char* argv[]) {sc signal<bool> ASig, BSig, FSig;

sc clock TestClk("TestClock", 10, SC NS, 0.5, 1, SC NS);

...

Example (Post-correction output)

Time A B F

1 s 0 0 0

11 ns 0 1 1

21 ns 1 0 1

31 ns 1 1 0

Simulation stopped by user.

#>

Deian Tabakov Introduction to SystemC 27/29

Page 42: Intro SystemC P1

Summary

Core SystemC concepts

Process : functionality

Event : process synchronization

Sensitivity : basis of event-driven simulation

Channel : process communication

Module : encapsulation

Ports : external view of the module

Deian Tabakov Introduction to SystemC 28/29

Page 43: Intro SystemC P1

Buzzwords

EDA Electronic Design Automation

SoC System-on-chip

TLM Transaction-Level Model(ing)

PV Programmer’s View

PVt Programmer’s View with Time

HDL Hardware Description Language

RTL Register Transfer Level

ASIC Application-Specific Integrated Circuit

IP Intellectual Property

DSP Digital Signal Processing

DUV Design Under Verification

Deian Tabakov Introduction to SystemC 29/29