The TLM-2.0 Standard
CONTENTS
• Review of SystemC and TLM
• Review of TLM-2.0
• Frequently Asked Questions
Copyright © 2010 by Doulos. All rights reserved.
What is SystemC?
3
• System-level modeling language
• Network of communicating processes (c.f. HDL)
• Modeling hardware and software together
• New: SystemC-AMS (mixed signal)
• C++ class library
• Industry standard IEEE 1666™
• Owned and driven by OSCI (Open SystemC Initiative)
• Open source implementation
• Mature, robust, easy-to-integrate and “free”
Communicating
processes
Copyright © 2010 by Doulos. All rights reserved.
Transaction Level Modeling
4
RTLRTL
Pin AccuratePin Accurate
Simulate every event!
RTLRTL
Behavioral
Model
Behavioral
Model
Behavioral
Model
Behavioral
Model
100-10,000 X faster simulation!
Function CallFunction Call
write(address,data)write(address,data)
Copyright © 2010 by Doulos. All rights reserved.
Reasons for using TLM
5
Software developmentSoftware developmentFirmware /
software
Firmware /
software
Accelerates product release schedule
Test benchTest bench
Hardware verificationHardware verification
RTLRTL
TLM = golden model
Architectural explorationArchitectural explorationTLMTLM
Fast
Ready before RTL
Copyright © 2010 by Doulos. All rights reserved.
TLM is Communication-Oriented
6
Simple functional models, e.g. C programs
Could be synthesized by an ESL synthesis tool ?
Concurrent simulation environment
Transaction
+ timing
Copyright © 2010 by Doulos. All rights reserved.
TLM and Synthesis
7
ESL SynthesisESL Synthesis Pin-level
CompareESL SynthesisESL Synthesis Compare
The TLM-2.0 Standard
CONTENTS
• Review of SystemC and TLM
• Review of TLM-2.0
• Frequently Asked Questions
Copyright © 2010 by Doulos. All rights reserved.
OSCI TLM Timeline
9
Apr 2005
• TLM-1.0
• put, get and transport
• Request-response model
• TLM-1.0
• put, get and transport
• Request-response model
Jun 2008
• TLM-2.0
• Pass-by-reference
• Unified interfaces
• Generic payload
• TLM-2.0
• Pass-by-reference
• Unified interfaces
• Generic payload
July 2009
• TLM-2.0.1
• LRM
• TLM-2.0.1
• LRM
• TLM-2.0 focusses on memory-mapped bus modeling
Copyright © 2010 by Doulos. All rights reserved.
Typical Use Case: Virtual Platform
10
CPU CPU ROMROM DMADMARAMRAM
Interrupt Interrupt TimerTimer BridgeBridge
BridgeBridge
DSP DSP ROMROM RAMRAM
A/DA/DInterrupt Interrupt TimerTimerI/OI/O
Memory
interface
Memory
interfaceI/OI/O DMADMARAMRAM
Custom
peripheral
Custom
peripheral
SoftwareSoftware
D/AD/A
SoftwareSoftware
Multiple software stacksMultiple software stacks
Digital and analog hardware IP blocksDigital and analog hardware IP blocks
Multiple buses and bridgesMultiple buses and bridges
TLM-2.0TLM-2.0
Copyright © 2010 by Doulos. All rights reserved.
Virtual Platform Characteristics
11
Instruction Set
Simulator or software
stubs
Transaction-Level Model RTL
Available early Available early Much later
Fast enough to run
applications
Fast enough to run
applications
Too slow to run
applications
Little or no hardware
detail
Register-accurate Register-accurate and
pin-accurate
No timing information Some timing information Cycle-accurate timing
Copyright © 2010 by Doulos. All rights reserved.
Coding Styles and Mechanisms
12
Blocking
transport
Blocking
transport
Non-blocking
transport
Non-blocking
transportDMIDMI SocketsSocketsQuantum Quantum
Generic
payload
Generic
payload
Mechanisms (definitive API for TLM-2.0 enabling interoperability)
Use cases
Software
development
Software
development
Architectural
analysis
Architectural
analysis
Hardware
verification
Hardware
verification
Software
performance
Software
performance
Loosely-timedLoosely-timed
Approximately-timedApproximately-timed
TLM-2 Coding styles (just guidelines)
PhasesPhases
Copyright © 2010 by Doulos. All rights reserved.
Interoperability Layer
13
TargetInitiator
1. Core interfaces and
sockets
2. Generic payload
Command
Address
Data
Byte enables
Streaming
Response status
Extensions
3. Base protocol
BEGIN_REQ
END_REQ
BEGIN_RESP
END_RESP
Either write bytesEither write bytes
or read bytes
The first function call
Copyright © 2010 by Doulos. All rights reserved.
Utilities
14
• Productivity
• Shortened learning curve
• Consistent coding style
Core interfaces
Sockets
Generic payload
Base protocol
Core interfaces
Sockets
Generic payload
Base protocol
Initiator
Interoperability
layer
Target
Coding Style
Loosely- or Approximately-timed
Utilities
Convenience sockets
Quantum keeper (LT)
Payload event queues (AT)
Instance-specific extensions (GP)
The TLM-2.0 Standard
CONTENTS
• Review of SystemC and TLM
• Review of TLM-2.0
• Frequently Asked Questions
Copyright © 2010 by Doulos. All rights reserved.
Loosely-Timed
17
Resources:
Bus
Memory
Peripherals
Initiator
Initiator
Initiator
Executing software
• Goal: execute software at full speed of host processor
• Target models do not consume any time, initiators run ahead
• Need the initiators to take turns
• Either have explicit synchronization points (can be untimed)
• or initiators must use a time quantum
The End!
Copyright © 2010 by Doulos. All rights reserved.
Loosely-Timed
18
Resources:
Bus
Memory
Peripherals
Initiator
Initiator
Initiator
Executing software
• Goal: execute software at full speed of host processor
• Target models do not consume any time, initiators run ahead
• Need the initiators to take turns
• Either have explicit synchronization points (can be untimed)
• or initiators must use a time quantum
Sync
Copyright © 2010 by Doulos. All rights reserved.
Loosely-Timed
19
Resources:
Bus
Memory
Peripherals
Initiator
Initiator
Initiator
Executing software
• Goal: execute software at full speed of host processor
• Target models do not consume any time, initiators run ahead
• Need the initiators to take turns
• Either have explicit synchronization points (can be untimed)
• or initiators must use a time quantum
Quantum
Copyright © 2010 by Doulos. All rights reserved.
AT and CA
20
BEGIN_REQ
END_REQ
BEGIN_RESP
END_RESP
• No running ahead of simulation time; everything stays in sync
AT CA
Wake up at significant
timing points
Wake up every cycle
Copyright © 2010 by Doulos. All rights reserved.
FAQ #2
21
"How do I model such-and-such a feature using TLM-2?"
"What does it take to make a model TLM-2-compliant?"
"How much of this 194-page LRM do I really need to understand?"
"How can TLM-2 make models of different protocols interoperable?"
Copyright © 2010 by Doulos. All rights reserved.
Initiator Interconnect Target
First Kind of Interoperability
22
• Use the full interoperability layer
• Use the generic payload + ignorable extensions
• Obey all the rules of the base protocol. The LRM is your rule book
tlm_initiator_socket<32, tlm_base_protocol_types> my_socket;tlm_initiator_socket<32, tlm_base_protocol_types> my_socket;
• Functional incompatibilities are still possible (e.g. writing to a ROM)
Copyright © 2010 by Doulos. All rights reserved.
Second Kind of Interoperability
23
• Create a new protocol traits class
• Create user-defined generic payload extensions and phases as needed
• Make your own rules!
TargetAdapterInitiator
• One rule enforced: cannot bind sockets of differing protocol types
• Recommendation: keep close to the base protocol. The LRM is your guidebook
• The clever stuff in TLM-2.0 makes the adapter fast
tlm_initiator_socket<32, my_protocol> my_socket;tlm_initiator_socket<32, my_protocol> my_socket;
Copyright © 2010 by Doulos. All rights reserved.
FAQ #2
24
Q. "How do I model such-and-such a feature using TLM-2?"
A. Either make do with the generic payload, or create extensions
Q. "What does it take to make a model TLM-2-compliant?"
A. Either obey the base protocol or make your own rules
Q. "How much of this 194-page LRM do I really need to understand?"
A. For the base protocol, everything except Utilities and TLM-1
Q. "How can TLM-2 make models of different protocols interoperable?"
A. Either map onto the base protocol, or write adapters
Copyright © 2010 by Doulos. All rights reserved.
FAQ #3
25
Q. "How do I model my algorithm using TLM-2.0"
A1. Not applicable. TLM is communication-centric
A2. Use the LT/AT coding styles as guidelines
A3. Use the utilities at least as examples
Copyright © 2010 by Doulos. All rights reserved.
FAQ #4
26
Q. "How do I use extensions? It's not really explained anywhere."
Copyright © 2010 by Doulos. All rights reserved.
Create an Extension Class
27
struct my_extension: tlm::tlm_extension<my_extension>
{
my_extension() { m_attribute1 = ...; }
virtual tlm_extension_base* clone() const
{
my_extension* ext = new my_extension;
ext->m_attribute1 = this->m_attribute1;
ext->m_attribute2 = this->m_attribute2;
return ext;
}
virtual void copy_from( tlm_extension_base const& ext )
{
m_attribute1 = static_cast<my_extension const &>(ext).m_attribute1;
m_attribute2 = static_cast<my_extension const &>(ext).m_attribute2;
}
int m_attribute1;
string m_attribute2;
};
struct my_extension: tlm::tlm_extension<my_extension>
{
my_extension() { m_attribute1 = ...; }
virtual tlm_extension_base* clone() const
{
my_extension* ext = new my_extension;
ext->m_attribute1 = this->m_attribute1;
ext->m_attribute2 = this->m_attribute2;
return ext;
}
virtual void copy_from( tlm_extension_base const& ext )
{
m_attribute1 = static_cast<my_extension const &>(ext).m_attribute1;
m_attribute2 = static_cast<my_extension const &>(ext).m_attribute2;
}
int m_attribute1;
string m_attribute2;
};
Any number of attributesAny number of attributes
Standard code to clone/copyStandard code to clone/copy
Copyright © 2010 by Doulos. All rights reserved.
Setting and Getting Extensions
28
tlm_generic_payload* trans;
...
my_extension* ext = new my_extension;
ext->m_attribute1 = 1;
ext->m_attribute2 = "foo";
trans->set_auto_extension( ext );
socket->b_transport( *trans, delay );
tlm_generic_payload* trans;
...
my_extension* ext = new my_extension;
ext->m_attribute1 = 1;
ext->m_attribute2 = "foo";
trans->set_auto_extension( ext );
socket->b_transport( *trans, delay );
virtual void b_transport( ... )
{
my_extension* ext;
trans.get_extension(ext);
if (ext) {
... = ext->m_attribute1;
... = ext->m_attribute2;
...
}
virtual void b_transport( ... )
{
my_extension* ext;
trans.get_extension(ext);
if (ext) {
... = ext->m_attribute1;
... = ext->m_attribute2;
...
}
Initiator Target
Have the initiator add the extensionHave the initiator add the extension Target can test for an extensionTarget can test for an extension
Copyright © 2010 by Doulos. All rights reserved.
FAQ #5
29
Q. "Okay, but you've not shown me how to create ignorable extensions.
How do I do that?"
A. Being ignorable is not an explicit property of an extension,
but about how you use it
Copyright © 2010 by Doulos. All rights reserved.
Ignorable Extensions
30
• Timestamp when the transaction was created
• An initiator ID or transaction ID
An ignorable extension is able to be ignored
Extensions that might not be ignorable
• An extended address (initiator might rely on extended address space)
• A priority (initiator might rely on high priority transaction executing first)
• A flag to lock the interconnect (initiator might rely on have exclusive access)
Copyright © 2010 by Doulos. All rights reserved.
FAQ #6
31
Q. "How do I dispose of the extension object? Can I re-use it?"
A. Use a memory manager
Copyright © 2010 by Doulos. All rights reserved.
Using a Memory Manager
32
TargetInterconnectInitiator
nb_transport_fw
Returnnb_transport_fw
nb_transport_fwCall
Returnnb_transport_fw
Allocate transaction object
nb_transport_bwReturn
Callnb_transport_bw
nb_transport_bwReturn
Callnb_transport_bw
acquire()
acquire()
release()
release()
acquire()
release()
free()
0123
# refs
Copyright © 2010 by Doulos. All rights reserved.
Memory Management Methods
33
class tlm_generic_payload {
public:
tlm_generic_payload () ;
tlm_generic_payload(tlm_mm_interface* mm) ;
virtual ~tlm_generic_payload ();
void set_mm(tlm_mm_interface* mm);
bool has_mm();
void acquire();
void release();
int get_ref_count();
void deep_copy_from( const tlm_generic_payload& ) ;
void update_original_from( const tlm_generic_payload& );
void free_all_extensions();
void reset();
...
};Frees all auto-extensionsFrees all auto-extensions
Copyright © 2010 by Doulos. All rights reserved.
A User-Defined Memory Manager
34
#include "tlm.h"
class gp_mm: public tlm::tlm_mm_interface
{
typedef tlm::tlm_generic_payload gp_t;
public:
gp_mm();
virtual ~gp_mm();
gp_t* allocate() {
...
ptr = new gp_t( this );
...
}
void free(gp_t* trans) {
trans->reset();
...
}
...
#include "tlm.h"
class gp_mm: public tlm::tlm_mm_interface
{
typedef tlm::tlm_generic_payload gp_t;
public:
gp_mm();
virtual ~gp_mm();
gp_t* allocate() {
...
ptr = new gp_t( this );
...
}
void free(gp_t* trans) {
trans->reset();
...
}
...
Pass mm as constructor argPass mm as constructor arg
Free auto-extensionsFree auto-extensions
Called when ref count == 0Called when ref count == 0
Copyright © 2010 by Doulos. All rights reserved.
Typical Coding Idiom
35
tlm_generic_payload* trans;
trans = m_mm.allocate();
trans->acquire();
my_extension* ext = new my_extension;
ext->m_attribute1 = 1;
ext->m_attribute2 = "foo";
trans->set_auto_extension( ext );
socket->b_transport( *trans, delay );
trans->release();
tlm_generic_payload* trans;
trans = m_mm.allocate();
trans->acquire();
my_extension* ext = new my_extension;
ext->m_attribute1 = 1;
ext->m_attribute2 = "foo";
trans->set_auto_extension( ext );
socket->b_transport( *trans, delay );
trans->release();
my_module(sc_module_name _n, gp_mm* mm)
: m_mm(mm) {...}
my_module(sc_module_name _n, gp_mm* mm)
: m_mm(mm) {...} Pass mm as constructor argPass mm as constructor arg
Get transaction object from mmGet transaction object from mm
Increment reference countIncrement reference count
Decrement reference countDecrement reference count
Set for auto-deletionSet for auto-deletion
Allocate extension on heapAllocate extension on heap
Not just for nb_transportNot just for nb_transport
Copyright © 2010 by Doulos. All rights reserved.
FAQ #7
36
Q. "How do I connect multiple components together?"
Q. "How do I model a bus with multiple masters/slaves?"
Q. "How many sockets do I need for two-way communication?"
Q. "How many transactions do I use?"
Copyright © 2010 by Doulos. All rights reserved.
Example Topology
37
Initiator
Initiator
Initiator
Initiator
Thread
Thread
Memory
managerTarget
Controller
Target
Target
Target
Target
Target
Bus Interconnect
Multi-socketsMulti-sockets
Control
Data
Copyright © 2010 by Doulos. All rights reserved.
Bridges
38
TargetBridgeInitiator
tlm_*_socket< 32, protocol_A > tlm_*_socket< 32, protocol_B >
Generic
Payload
Extension
Extension
Generic
Payload
Extension
Extension
deep_copy_from()
Extension
Extension
Generic
Payload
Extension
Extension
Extension
Extension
Generic
Payload
Extension
Extension
update_original_from()
Could pass the same transaction if their lifetimes allowCould pass the same transaction if their lifetimes allow
Copyright © 2010 by Doulos. All rights reserved.
Copying the Data Array
39
• Deep-copy the data array in the bridge
new_trans->set_data_ptr( &data_buffer );
new_trans->deep_copy_from ( original_trans );
new_trans->b_transport(...);
original_trans->update_original_from( new_trans );
new_trans->set_data_ptr( &data_buffer );
new_trans->deep_copy_from ( original_trans );
new_trans->b_transport(...);
original_trans->update_original_from( new_trans );
• Shallow-copy the data array in the bridge
new_trans->set_data_ptr( 0 );
new_trans->deep_copy_from ( original_trans );
new_trans->set_data_ptr( original_trans->get_data_ptr() );
new_trans->b_transport(...);
original_trans->update_original_from( new_trans );
new_trans->set_data_ptr( 0 );
new_trans->deep_copy_from ( original_trans );
new_trans->set_data_ptr( original_trans->get_data_ptr() );
new_trans->b_transport(...);
original_trans->update_original_from( new_trans );
Copies back data array on read
Does not touch data array
Copyright © 2010 by Doulos. All rights reserved.
FAQ #7
40
Q. "How do I connect multiple components together?"
A. By having one or more components act as a hub
Q. "How do I model a bus with multiple masters/slaves?"
A. The "hub" can do arbitration and routing. Use multi-sockets for convenience
Q. "How many sockets do I need for two-way communication?"
A. Each initiator needs an initiator socket, each target a target socket
Q. "How many transactions do I use?"
A. As few as possible
Copyright © 2010 by Doulos. All rights reserved.
FAQ #8
41
Q. "How do I model something like a SPI port?"
A. If you can abstract the functionality, use the base protocol
Q. "How do I model something like a SPI port with accurate timing?"
A. You can model precise timing with the AT coding style, but why not use RTL?
Q. "How do I model something like AMBA, PCI, or USB?"
A. Buy a model (or get one through a university/research program)
Copyright © 2010 by Doulos. All rights reserved.
For More FREE Information
42
standards.ieee.org/getieee/1666/index.html
www.systemc.org
• IEEE 1666
• OSCI SystemC 2.2 and TLM-2.0
www.doulos.com/knowhow/systemc/tlm2
• Tutorial introduction to TLM-2.0 and Free TLM-2.0 Protocol Checker
and examples
and videos
Top Related