CIRCT 22.0.0git
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
circt::arc::runtime::impl::TraceEncoder Class Referenceabstract

Abstract TraceEncoder managing trace buffers and the encoder thread. More...

#include <TraceEncoder.h>

Inheritance diagram for circt::arc::runtime::impl::TraceEncoder:
Inheritance graph
[legend]
Collaboration diagram for circt::arc::runtime::impl::TraceEncoder:
Collaboration graph
[legend]

Public Member Functions

 TraceEncoder ()=delete
 
 TraceEncoder (const ArcRuntimeModelInfo *modelInfo, ArcState *state, unsigned numBuffers, bool debug)
 Construct a trace encoder for the given model and the given number of buffers.
 
virtual ~TraceEncoder ()=default
 
void run (ArcState *state)
 Begin tracing.
 
uint64_t * dispatch (uint32_t oldBufferSize)
 Dispatch the currently active trace buffer containing oldBufferSize valid entries to the encoder thread and return the storage of the new active buffer.
 
void step (const ArcState *state)
 Signal the start of a new simulation time step.
 
void finish (const ArcState *state)
 Stop tracing.
 

Public Attributes

const unsigned numBuffers
 Number of trace buffers in rotation.
 

Protected Member Functions

virtual bool initialize (const ArcState *state)=0
 Set-up the encoder before starting the worker thread.
 
virtual void startUpWorker ()
 Called by the worker thread before entering the encode loop.
 
virtual void encode (TraceBuffer &work)
 Encode the given trace buffer. Called by the worker thread.
 
virtual void windDownWorker ()
 Called by the worker thread after leaving the encode loop.
 
virtual void finalize (const ArcState *state)
 Finish trace encoding. Called by the simulation thread.
 

Protected Attributes

const ArcRuntimeModelInfo *const modelInfo
 Metadata of the traced model.
 
const bool debug
 Debug mode flag.
 

Private Member Functions

void workLoop ()
 The encoder thread's work loop.
 
void enqueueBuffer (TraceBuffer &&buffer)
 
TraceBuffer getBuffer ()
 

Private Attributes

int64_t timeStep
 Current simulation time step.
 
std::optional< std::thread > worker
 Trace encoder worker thread. If empty, tracing is disabled.
 
std::mutex bufferQueueMutex
 Queue and synchronization primitives for buffers to be processed by the encoder thread.
 
std::condition_variable bufferQueueCv
 
std::queue< TraceBufferbufferQueue
 
std::mutex availableBuffersMutex
 Return stack and synchronization primitives for processed buffers.
 
std::condition_variable availableBuffersCv
 
std::vector< TraceBufferavailableBuffers
 
std::atomic< bool > isFinished
 Flag signaling that no more buffers will be enqueued.
 
TraceBuffer activeBuffer
 Trace buffer currently in use by the hardware model.
 

Detailed Description

Abstract TraceEncoder managing trace buffers and the encoder thread.

Definition at line 93 of file TraceEncoder.h.

Constructor & Destructor Documentation

◆ TraceEncoder() [1/2]

circt::arc::runtime::impl::TraceEncoder::TraceEncoder ( )
delete

◆ TraceEncoder() [2/2]

circt::arc::runtime::impl::TraceEncoder::TraceEncoder ( const ArcRuntimeModelInfo modelInfo,
ArcState state,
unsigned  numBuffers,
bool  debug = false 
)

Construct a trace encoder for the given model and the given number of buffers.

Initializes the state with the first buffer.

Definition at line 23 of file TraceEncoder.cpp.

References activeBuffer, assert(), availableBuffers, circt::arc::runtime::impl::TraceBuffer::getData(), isFinished, modelInfo, numBuffers, ArcModelTraceInfo::numTraceTaps, timeStep, ArcState::traceBuffer, ArcModelTraceInfo::traceBufferCapacity, ArcRuntimeModelInfo::traceInfo, and worker.

◆ ~TraceEncoder()

virtual circt::arc::runtime::impl::TraceEncoder::~TraceEncoder ( )
virtualdefault

Member Function Documentation

◆ dispatch()

uint64_t * circt::arc::runtime::impl::TraceEncoder::dispatch ( uint32_t  oldBufferSize)

Dispatch the currently active trace buffer containing oldBufferSize valid entries to the encoder thread and return the storage of the new active buffer.

Blocks execution until a new buffer is available.

Definition at line 153 of file TraceEncoder.cpp.

References activeBuffer, circt::arc::runtime::impl::TraceBuffer::assertSentinel(), enqueueBuffer(), circt::arc::runtime::impl::fatalError(), circt::arc::runtime::impl::TraceBuffer::firstStep, getBuffer(), circt::arc::runtime::impl::TraceBuffer::getData(), circt::arc::runtime::impl::TraceBuffer::size, timeStep, and worker.

Referenced by finish().

◆ encode()

virtual void circt::arc::runtime::impl::TraceEncoder::encode ( TraceBuffer work)
inlineprotectedvirtual

Encode the given trace buffer. Called by the worker thread.

Reimplemented in circt::arc::runtime::impl::VCDTraceEncoder.

Definition at line 129 of file TraceEncoder.h.

Referenced by workLoop().

◆ enqueueBuffer()

void circt::arc::runtime::impl::TraceEncoder::enqueueBuffer ( TraceBuffer &&  buffer)
private

Definition at line 41 of file TraceEncoder.cpp.

References assert(), bufferQueue, bufferQueueCv, bufferQueueMutex, and worker.

Referenced by dispatch().

◆ finalize()

virtual void circt::arc::runtime::impl::TraceEncoder::finalize ( const ArcState state)
inlineprotectedvirtual

Finish trace encoding. Called by the simulation thread.

Reimplemented in circt::arc::runtime::impl::VCDTraceEncoder.

Definition at line 133 of file TraceEncoder.h.

Referenced by finish().

◆ finish()

void circt::arc::runtime::impl::TraceEncoder::finish ( const ArcState state)

◆ getBuffer()

TraceBuffer circt::arc::runtime::impl::TraceEncoder::getBuffer ( )
private

Definition at line 50 of file TraceEncoder.cpp.

References assert(), availableBuffers, availableBuffersCv, availableBuffersMutex, and worker.

Referenced by dispatch().

◆ initialize()

virtual bool circt::arc::runtime::impl::TraceEncoder::initialize ( const ArcState state)
protectedpure virtual

Set-up the encoder before starting the worker thread.

May return false to indicate failure. In this case, no worker thread will be created. Called by the simulation thread.

Implemented in circt::arc::runtime::impl::DummyTraceEncoder, and circt::arc::runtime::impl::VCDTraceEncoder.

Referenced by run().

◆ run()

void circt::arc::runtime::impl::TraceEncoder::run ( ArcState state)

◆ startUpWorker()

virtual void circt::arc::runtime::impl::TraceEncoder::startUpWorker ( )
inlineprotectedvirtual

Called by the worker thread before entering the encode loop.

Reimplemented in circt::arc::runtime::impl::VCDTraceEncoder.

Definition at line 127 of file TraceEncoder.h.

Referenced by workLoop().

◆ step()

void circt::arc::runtime::impl::TraceEncoder::step ( const ArcState state)

◆ windDownWorker()

virtual void circt::arc::runtime::impl::TraceEncoder::windDownWorker ( )
inlineprotectedvirtual

Called by the worker thread after leaving the encode loop.

Reimplemented in circt::arc::runtime::impl::VCDTraceEncoder.

Definition at line 131 of file TraceEncoder.h.

Referenced by workLoop().

◆ workLoop()

void circt::arc::runtime::impl::TraceEncoder::workLoop ( )
private

Member Data Documentation

◆ activeBuffer

TraceBuffer circt::arc::runtime::impl::TraceEncoder::activeBuffer
private

Trace buffer currently in use by the hardware model.

Definition at line 168 of file TraceEncoder.h.

Referenced by dispatch(), finish(), run(), step(), and TraceEncoder().

◆ availableBuffers

std::vector<TraceBuffer> circt::arc::runtime::impl::TraceEncoder::availableBuffers
private

Definition at line 162 of file TraceEncoder.h.

Referenced by getBuffer(), TraceEncoder(), and workLoop().

◆ availableBuffersCv

std::condition_variable circt::arc::runtime::impl::TraceEncoder::availableBuffersCv
private

Definition at line 161 of file TraceEncoder.h.

Referenced by getBuffer(), and workLoop().

◆ availableBuffersMutex

std::mutex circt::arc::runtime::impl::TraceEncoder::availableBuffersMutex
private

Return stack and synchronization primitives for processed buffers.

Definition at line 160 of file TraceEncoder.h.

Referenced by getBuffer(), and workLoop().

◆ bufferQueue

std::queue<TraceBuffer> circt::arc::runtime::impl::TraceEncoder::bufferQueue
private

Definition at line 157 of file TraceEncoder.h.

Referenced by enqueueBuffer(), run(), and workLoop().

◆ bufferQueueCv

std::condition_variable circt::arc::runtime::impl::TraceEncoder::bufferQueueCv
private

Definition at line 156 of file TraceEncoder.h.

Referenced by enqueueBuffer(), finish(), and workLoop().

◆ bufferQueueMutex

std::mutex circt::arc::runtime::impl::TraceEncoder::bufferQueueMutex
private

Queue and synchronization primitives for buffers to be processed by the encoder thread.

Definition at line 155 of file TraceEncoder.h.

Referenced by enqueueBuffer(), finish(), and workLoop().

◆ debug

const bool circt::arc::runtime::impl::TraceEncoder::debug
protected

◆ isFinished

std::atomic<bool> circt::arc::runtime::impl::TraceEncoder::isFinished
private

Flag signaling that no more buffers will be enqueued.

Definition at line 165 of file TraceEncoder.h.

Referenced by finish(), TraceEncoder(), and workLoop().

◆ modelInfo

const ArcRuntimeModelInfo* const circt::arc::runtime::impl::TraceEncoder::modelInfo
protected

◆ numBuffers

const unsigned circt::arc::runtime::impl::TraceEncoder::numBuffers

Number of trace buffers in rotation.

Definition at line 116 of file TraceEncoder.h.

Referenced by TraceEncoder().

◆ timeStep

int64_t circt::arc::runtime::impl::TraceEncoder::timeStep
private

Current simulation time step.

Definition at line 148 of file TraceEncoder.h.

Referenced by dispatch(), run(), step(), and TraceEncoder().

◆ worker

std::optional<std::thread> circt::arc::runtime::impl::TraceEncoder::worker
private

Trace encoder worker thread. If empty, tracing is disabled.

Definition at line 151 of file TraceEncoder.h.

Referenced by dispatch(), enqueueBuffer(), finish(), getBuffer(), run(), step(), and TraceEncoder().


The documentation for this class was generated from the following files: