co-modeling seminar

23
3/1 /01 CoModelSeminar.ppt - johnS 1 Mentor Graphics Co-modeling Seminar

Upload: osman

Post on 23-Jan-2016

43 views

Category:

Documents


0 download

DESCRIPTION

Co-modeling Seminar. Co-modeling Seminar: Contents. The Routed Design What the design does System Hierarchy The Hardware The Bridge The DUT and Transactors The ClockAdvancer The Software The System Testbench Top Level, Interconnect of SystemC Models The sc_main() Function - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS1 Mentor Graphics

Co-modeling Seminar

Page 2: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS2 Mentor Graphics

Co-modeling Seminar: Contents

• The Routed Design – What the design does

– System Hierarchy

• The Hardware– The Bridge

– The DUT and Transactors

– The ClockAdvancer

• The Software– The System

• Testbench Top Level, Interconnect of SystemC Models

• The sc_main() Function

– The Testbench• Abstract Ports, Autonomous Threads, Slave Threads

• Master Control Loop

– The Scheduler - Interfacing with message port proxies

– The Calendar – Interfacing with the ClockAdvancer– The SceMiDispatcher – Servicing the SceMi

– Error Handling

Page 3: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS3 Mentor Graphics

What the design does

• Small design that simulates passengers air traveling from Origin’s to Destination’s by traversing various interconnected Pipe’s and Hub’s in a RouteMap.

• The "world" consists of these Origin’s,– Anchorage, Cupertino, Noida, SealBeach, UK, Waltham,

and these Destination's,– Anchorage, Cupertino, Maui, SealBeach, UK.

• Travel from any of the Origin’s to any of the Destination’s is possible by traversing the RouteMap containing the following Pipe interconnected Hub’s,– Chicago, Dallas, Newark, SanFran, Seattle.

• The RouteMap is initialized by injecting TeachRoute transactions for the entire system through the Waltham Origin.

• Each hub is progressively taught its routes so that it may, in turn pass additional TeachRoute tokens to hubs more distant from Waltham.

• This process continues until the entire mesh is initialized, at which point it is ready to accommodate travel.

• After running the route configuration, the testbench then executes the itineraries of 4 passengers over a period of 22 days.

• Each itinerary consists of several legs each with scheduled departure from a specified Origin and each with a specified Destination.

Page 4: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS4 Mentor Graphics

What the design does (cont’d) – The RouteMap

Page 5: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS5 Mentor Graphics

System Hierarchy

• Testbench HierarchySystem Testbench Calendar <--> ClockAdvancer Scheduler <--> OrigDest, Origin, Destination RouteConfig SceMiDispatcher

• VLE HierarchyVle Bridge SceMiClockPort

OrigDest anchorage, cupertino, sealBeach, UK

Origin SceMiMessageInPort, SceMiClockControl Destination SceMiMessageOutPort, SceMiClockControl Origin noida, waltham Destination maui RouteMap Hub chicagoHub, dallasHub, newarkHub, sanFranHub, seattleHub Funnel Nozzle RouteTable Pipe*

ClockAdvancer SceMiMessageInPort, SceMiMessageOutPort, SceMiClockControl

• The OrigDest, Origin, and Destination modules are the transactors.• The RouteMap is the DUT.

Page 6: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS6 Mentor Graphics

The Hardware: The Bridge

Page 7: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS7 Mentor Graphics

The DUT and Transactors - Connections

Page 8: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS8 Mentor Graphics

The DUT and Transactors - Components

Page 9: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS9 Mentor Graphics

The DUT and Transactors – Transactor Interface and Implementation

module Destination ( TokenIn );

input [31:0] TokenIn;

// {

wire [3:0] destID;

reg [31:0] message;

reg transmitReady, readyForCclock;

assign destID = TokenIn[7:4];

SceMiMessageOutPort #32 messageOutPort(

//Input Output

//------------------------- ---------------------------

.TransmitReady(transmitReady), .ReceiveReady(receiveReady),

.Message(message) );

SceMiClockControl clockControl(

//Input Output

//------------------------- ---------------------------

.Uclock(uclock),

.Ureset(ureset),

.ReadyForCclock(readyForCclock), .CclockEnabled(cclockEnabled) )

always@( posedge uclock ) begin // {

if( ureset == 1 ) begin

readyForCclock <= 1;

message <= 0;

transmitReady <= 0;

end

else begin // {

// if( DUT clock has been disabled )

// It means that this destination transactor is waiting to

// unload its pending token and does not want to re-enable the

// DUT until that token has been off-loaded or else it might

// lose arriving tokens in subsequent DUT clocks.

if( readyForCclock == 0 ) begin

// When the MessageOutPort portal finally signals acceptance

// of the token, we can re-enable the DUT clock.

if( receiveReady ) begin

readyForCclock <= 1;

transmitReady <= 0;

end

end

else if( cclockEnabled && destID != 0 ) begin

message <= TokenIn;

transmitReady <= 1; // if( token arrives but portal is not ready )

// Stop the assembly line ! (a.k.a. disable the DUT)

if( receiveReady == 0

readyForCclock <= 0;

end

end // }

end // }

endmodule // }

Page 10: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS10 Mentor Graphics

The ClockAdvancer

• Used for tight control of DUT clock advance.

• Standalone transactor – no interface to DUT.

• Used in Routed design to,

– advance a 1 clock between each TeachRoute message,

– advance 1 or more days at a time (1 day = 24 clocks) during travel simulation.

• Our 1st General purpose, reusable transactor – now distributed with the release.

Page 11: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS11 Mentor Graphics

The System – Testbench Top Level

Page 12: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS12 Mentor Graphics

The System – Testbench Top Level, Interconnect of SystemC Models

#include <systemc.h>

#include <SceMi00.hxx>

 

sc_clock UTick;

 

#include "Routed.hxx"

 

#include "Testbench.hxx"

#include "Calendar.hxx"

#include "Scheduler.hxx"

#include "RouteConfig.hxx"

#include "SceMiDispatcher.hxx"

 

SC_MODULE( System ){

sc_link_mp<unsigned> newDay;

sc_link_mp<const Routed::ArrivalRecord *> announceArrival;

sc_link_mp<unsigned> advanceCalendar;

sc_link_mp<const Routed::Itinerary *> scheduleLeg;

sc_link_mp<> loadRouteMap;

sc_link_mp<> done;

 

sc_link_mp<> advanceClock;

sc_link_mp<Routed::Date> todaysDate;

sc_link_mp<const Routed::Route *> loadRoute;

 

//-------------------------------------------------------

// Module declarations

Testbench *testbench;

Calendar *calendar;

Scheduler *scheduler;

RouteConfig *routeConfig;

SceMiDispatcher *dispatcher;

 

SC_CTOR( System ){ … }

};

SC_CTOR( System ){

testbench = new Testbench( "testbench" );

testbench->NewDay( newDay );

testbench->AnnounceArrival( announceArrival );

testbench->AdvanceCalendar( advanceCalendar );

testbench->ScheduleLeg( scheduleLeg );

testbench->LoadRouteMap( loadRouteMap );

testbench->Done( done );

 

calendar = new Calendar( "calendar" );

calendar->AdvanceCalendar( advanceCalendar );

calendar->AdvanceClock( advanceClock );

calendar->NewDay( newDay );

calendar->TodaysDate( todaysDate );

 

scheduler = new Scheduler( "scheduler" );

scheduler->TodaysDate( todaysDate );

scheduler->ScheduleLeg( scheduleLeg );

scheduler->LoadRoute( loadRoute );

scheduler->AnnounceArrival( announceArrival );

 

routeConfig = new RouteConfig( "routeConfig" );

routeConfig->LoadRouteMap( loadRouteMap );

routeConfig->LoadRoute( loadRoute );

routeConfig->AdvanceClock( advanceClock );

 

dispatcher = new SceMiDispatcher( "dispatcher" );

dispatcher->Done( done );

}

};

Page 13: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS13 Mentor Graphics

The System – The sc_main() Function

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

SceMi00::RegisterErrorHandler( errorHandler, NULL );

SceMi00 *mSceMi = NULL;

 

try {

SceMiInitParms00 parameters( "./params.mSceMi" );

mSceMi = SceMi00::Init( 1, &parameters );

 

//---------------------------------------------------------

// Instantiate the system here. Autonomous threads nested

// inside the DispatcherDriver and the Testbench will advance

// untimed activity. Such threads are senstitive to UTick defined

// at the top of this file.

// -- johnS 8-29-00

System system( "system" );

 

//---------------------------------------------------------

// Establish proper bindings between the SceMi and the modules

// modules that directly interact with it.

system.dispatcher->Bind( mSceMi );

system.calendar-> Bind( mSceMi );

system.scheduler-> Bind( mSceMi );

 

//-------------------------------------------------

// Kick off SystemC kernel ...

cerr << "Let 'er rip !" << endl;

sc_start(-1);

}

catch( string message ) { … return -1; }

catch(...) { … return -1; }

return 0;

}

Page 14: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS14 Mentor Graphics

The Testbench - Abstract Ports, Autonomous Threads, Slave Threads

SC_MODULE( Testbench ){ // Abstract port declarations sc_master<> LoadRouteMap; sc_master<> Done; sc_outmaster<unsigned> AdvanceCalendar; sc_inslave<unsigned> NewDay; sc_outmaster<const Routed::Itinerary *> ScheduleLeg; sc_inslave<const Routed::ArrivalRecord *> AnnounceArrival;  private: // Context declarations unsigned dNumMauiArrivals; unsigned dDayNum; const Routed::Itinerary *dItineraries[Routed::NumPassengers];  private: // Thread declarations void driverThread(); // Autonomous "master" thread. void newDayThread() { dDayNum = NewDay; } void announceArrivalThread();  public: SC_CTOR( Testbench ) : dNumMauiArrivals(0), dDayNum(0) { SC_THREAD( driverThread ); sensitive << UTick;  SC_SLAVE( newDayThread, NewDay ); SC_SLAVE( announceArrivalThread, AnnounceArrival );  // Initialize itinerary pointers. dItineraries[0] = Routed::BugsesTrip; dItineraries[1] = Routed::DaffysTrip; dItineraries[2] = Routed::ElmersTrip; dItineraries[3] = Routed::SylvestersTrip; } };

Page 15: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS15 Mentor Graphics

The Testbench - Master Control Loop

void Testbench::driverThread(){ LoadRouteMap(); unsigned dayNum = dDayNum; AdvanceCalendar = 1; // Advance to day 1.  for(;;){ wait(); // Wait for day to advance (i.e. 'NewDay' arrives. if( dayNum != dDayNum ){ unsigned date, minDate = 1000;  // Check itineraries to see if any passengers are // traveling today. If so, advance calendar to tomorrow // in case next leg of itinerary is tomorrow. for( int i=0; i<Routed::NumPassengers; i++ ){ if( (date=dItineraries[i]->DateOfTravel) ){ if( date == dDayNum ){ cout << "On day " << setw(2) << dDayNum << " at " << setw(2) << dItineraries[i]->TimeOfDeparture << ":00 hrs, " << passengerNames[dItineraries[i]->PassengerID] << " departs " << locationNames[dItineraries[i]->OriginID] << " enroute to " << locationNames[dItineraries[i]->DestinationID] << endl; ScheduleLeg = dItineraries[i]++; minDate = dDayNum+1; } else if( date < minDate ) minDate = date; } } dayNum = dDayNum; AdvanceCalendar = minDate - dDayNum; } }}

Page 16: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS16 Mentor Graphics

The Scheduler – Interfacing with message port proxies – Binding Ports

void Scheduler::Bind( SceMi00 *mSceMi ){

// Establish message input portals.

dOriginAnchorage = mSceMi->BindMessageInputPort( "anchorage", "TokenIn" );

dOriginCupertino = mSceMi->BindMessageInputPort( "cupertino", "TokenIn" );

dOriginNoida = mSceMi->BindMessageInputPort( "noida", "TokenIn" );

dOriginSealBeach = mSceMi->BindMessageInputPort( "sealBeach", "TokenIn" );

dOriginUK = mSceMi->BindMessageInputPort( "uk", "TokenIn" );

dOriginWaltham = mSceMi->BindMessageInputPort( "waltham", "TokenIn" );

// Establish message output portals.

MessageOutputPortBinding binding = { this, replyCallback, NULL };

dDestinationAnchorage = mSceMi->BindMessageOutputPort(

"anchorage", "TokenOut", &binding );

dDestinationCupertino = mSceMi->BindMessageOutputPort(

"cupertino", "TokenOut", &binding );

dDestinationMaui = mSceMi->BindMessageOutputPort(

"maui", "TokenOut", &binding );

dDestinationSealBeach = mSceMi->BindMessageOutputPort(

"sealBeach", "TokenOut", &binding );

dDestinationUK = mSceMi->BindMessageOutputPort(

"uk", "TokenOut", &binding );

}

Page 17: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS17 Mentor Graphics

The Scheduler – Interfacing with message port proxies – Sending Messages

void Scheduler::scheduleLegThread(){ const Routed::Itinerary *leg = ScheduleLeg; // Read inslave port.  // Form a 'Passenger Departure' token based on the contents of the given // 'Itinerary' record. SceMiU32 passengerDepartureToken = leg->PassengerID | (leg->DestinationID << 4) | (leg->OriginID << 12) | (leg->TimeOfDeparture << 16); dSendData.Set( 0, passengerDepartureToken );  switch( leg->OriginID ){ case Routed::Anchorage: dOriginAnchorage->Send( dSendData ); break; case Routed::Cupertino: dOriginCupertino->Send( dSendData ); break; case Routed::Noida: dOriginNoida ->Send( dSendData ); break; case Routed::SealBeach: dOriginSealBeach->Send( dSendData ); break; case Routed::UK: dOriginUK ->Send( dSendData ); break; case Routed::Waltham: dOriginWaltham ->Send( dSendData ); break; default: assert(0); }}void Scheduler::loadRouteThread(){ const Routed::Route *route = LoadRoute;  // Form a 'TeachRoute' token based on the contents of the given // 'Route' record. SceMiU32 addRouteToken = (route->RouterID << 4) | (route->DestinationID << 8) | (route->PortID <<12); dSendData.Set( 0, addRouteToken ); dOriginWaltham->Send( dSendData );}

Page 18: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS18 Mentor Graphics

The Scheduler –Interfacing with message port proxies –Receiving Messages

void Scheduler::replyCallback( void *context, const MessageData &data ){

((Scheduler *)context)->announceArrival( data.CycleStamp(), data.Get(0) ); }

 

void Scheduler::announceArrival( SceMiU64 cycleStamp, SceMiU32 arrivalToken ){

 

Routed::Date todaysDate = dSystem->TodaysDate();

 

dArrivalRecord.DateOfArrival = todaysDate.Day;

dArrivalRecord.TimeOfArrival = cycleStamp - todaysDate.CycleStamp;

 

dArrivalRecord.PassengerID = (Routed::PassengerIDs)( arrivalToken & 0xf );

dArrivalRecord.DestinationID = (Routed::LocationIDs) ( (arrivalToken >> 4) & 0xf );

dArrivalRecord.OriginID = (Routed::LocationIDs) ( (arrivalToken >> 12) & 0xf );

dArrivalRecord.LayoverCount = (arrivalToken >> 8) & 0xf ;

assert( dArrivalRecord.LayoverCount < 5 );

arrivalToken >>= 16;

for( unsigned i=0; i<dArrivalRecord.LayoverCount; i++ ){

dArrivalRecord.LayoverIDs[i] = (Routed::LocationIDs)( arrivalToken & 0xf );

arrivalToken >>= 4;

}

 

AnnounceArrival = &dArrivalRecord;

}

Page 19: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS19 Mentor Graphics

The Calendar – Interfacing with the ClockAdvancer

void Calendar::advanceCalendarThread(){ unsigned numberOfDaysToAdvance = AdvanceCalendar;  // In hardware, 1 clock corresponds to 1 hr of travel. // So, we multiply the number of days to advance by 24.  dSendData.Set( 2, 24 * numberOfDaysToAdvance ); dInputPort->Send( dSendData );  // Pend until the cycle stamp gets updated by the port // proxy reply callback. SceMiU64 currentCycleStamp = dCycleStamp; while( dCycleStamp == currentCycleStamp ) dSceMi->ServiceLoop();  dTodaysDate += numberOfDaysToAdvance; SceMiU64 delta = dCycleStamp - currentCycleStamp;  // After the first update, delta better be an integer multiple of 24 // or something is wrong ! assert( (dTodaysDate > 1) ? (delta/24) * 24 == delta : 1 ); NewDay = dTodaysDate;}void Calendar::advanceClockThread(){ dSendData.Set( 2, 1 ); dInputPort->Send( dSendData );  // Pend until the cycle stamp gets updated by the port // proxy reply callback. SceMiU64 currentCycleStamp = dCycleStamp; while( dCycleStamp == currentCycleStamp ) wait();}void Calendar::replyCallback( void *context, const MessageData &data ){ ((Calendar *)context)->dCycleStamp = data.CycleStamp(); }

Page 20: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS20 Mentor Graphics

The SceMiDispatcher – Servicing the SceMi

SC_MODULE( SceMiDispatcher ){ sc_slave<> Done; void dispatchThread(); // Autonomous SceMi dispatcher thread void doneThread(); private: SceMi00 *dSceMi;  public: void Bind( SceMi00 *mSceMi ){ dSceMi = mSceMi; };  SC_CTOR( SceMiDispatcher ){ //-------------------------------------- // Thread bindings SC_THREAD( dispatchThread ); sensitive << UTick;  SC_SLAVE( doneThread, Done ); } }; void SceMiDispatcher::dispatchThread() { // This is all the dispatcher does !! Deceptively simple, eh ? // It just calls the SceMi dispatcher poll function and returns. for(;;){ wait(); dSceMi->ServiceLoop(); }}void SceMiDispatcher::doneThread() { delete dSceMi; exit(0);}

Page 21: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS21 Mentor Graphics

Error Handling

• SceMi error handling is designed to be simple and flexible, set up to minimize the menial details of error status checking and message processing.

• “Conventional” error handling can be done by creating an SceMiEC object, passing it to each call, then checking its status on function return.

• Alternatively, in the interest of code cleanliness, an error handler can be defined that gets called by by the erroneous SceMi function when an error occurs. To use it in this mode this case, no SceMiEC argument needs to be passed to each function call (defaults to NULL).

• When an error occurs in a function that is passed no SceMiEC, if a user defined error handler exists, it is called, otherwise a default error handler is called.

• The SceMiEC struct contains an error type, a detailed UMS compliant message, and an additional string called the ‘culprit’ which identifies the erroneous function by name.

• The application can use all this information to process the message it its own way.• Distinct error types are kept to a minimum – only major categories. All detailed

info is built into the message itself which is UMS compliant.• C++ exceptions are not deployed inside the SceMi code, however, the nice thing

about the way error handlers can be defined is that exceptions can be thrown from the handler. This is what is done in the Routed design.

Page 22: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS22 Mentor Graphics

Error Handling – In Routed Design

int sc_main( int argc, char *argv[] ){  SceMi00::RegisterErrorHandler( errorHandler, NULL ); SceMi00 *mSceMi = NULL;  try { … } catch( string message ) { cerr << message << endl; cerr << "Fatal Error: Program aborting." << endl; if( mSceMi ) delete mSceMi; return -1; } catch(...) { cerr << "Error: Unclassified exception." << endl; cerr << "Fatal Error: Program aborting." << endl; if( mSceMi ) delete mSceMi; return -1; } return 0;} static void errorHandler( void */*context*/, SceMiEC *ec ) { char buf[32];  sprintf( buf, "%d", (int)ec->Type ); string messageText( "SceMi Error[" ); messageText += buf; messageText += "]: Function: "; messageText += ec->Culprit; messageText += "\n"; messageText += ec->Message; throw messageText;}

Page 23: Co-modeling Seminar

3/1/01

CoModelSeminar.ppt - johnS23 Mentor Graphics

Contents of SCE-MI Example

SceMi/

README

VERSION

include/

SceMi.hxx - Main SceMi include file.

SceMiParameters.hxx - SceMi initialization parameters object.

SceMiMessagePortProxy.hxx - MessagePortProxy interfaces.

SceMiMessageData.hxx - MessageData header

SceMiTypes.hxx - Misc SceMi support types, error handling types.  src/

params.SceMi - Sample template file for user specified parameters file that

is used to construct SceMiParameters object.

ChannelParameters.v - Sample template file used to specify channel dimensions.

This file must be provided by the user as it is included by the

Bridge netlists.

lib/solaris_gnu/

libSceMi.a - SceMi main library.

hdl/ClockAdvancer.v - Reusable ClockAdvancer transactor implementation.

Buffer.v - Reusable buffer component for insertion between message

ports and transactors.