|
CIRCT 22.0.0git
|
Abstract TraceEncoder managing trace buffers and the encoder thread. More...
#include <TraceEncoder.h>


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< TraceBuffer > | bufferQueue |
| std::mutex | availableBuffersMutex |
| Return stack and synchronization primitives for processed buffers. | |
| std::condition_variable | availableBuffersCv |
| std::vector< TraceBuffer > | availableBuffers |
| std::atomic< bool > | isFinished |
| Flag signaling that no more buffers will be enqueued. | |
| TraceBuffer | activeBuffer |
| Trace buffer currently in use by the hardware model. | |
Abstract TraceEncoder managing trace buffers and the encoder thread.
Definition at line 93 of file TraceEncoder.h.
|
delete |
| 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.
|
virtualdefault |
| 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().
|
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().
|
private |
Definition at line 41 of file TraceEncoder.cpp.
References assert(), bufferQueue, bufferQueueCv, bufferQueueMutex, and worker.
Referenced by dispatch().
|
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().
| void circt::arc::runtime::impl::TraceEncoder::finish | ( | const ArcState * | state | ) |
Stop tracing.
Definition at line 133 of file TraceEncoder.cpp.
References activeBuffer, circt::arc::runtime::impl::TraceBuffer::assertSentinel(), bufferQueueCv, bufferQueueMutex, dispatch(), finalize(), isFinished, ArcState::traceBufferSize, and worker.
|
private |
Definition at line 50 of file TraceEncoder.cpp.
References assert(), availableBuffers, availableBuffersCv, availableBuffersMutex, and worker.
Referenced by dispatch().
|
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().
| void circt::arc::runtime::impl::TraceEncoder::run | ( | ArcState * | state | ) |
Begin tracing.
Definition at line 59 of file TraceEncoder.cpp.
References activeBuffer, assert(), bufferQueue, circt::arc::runtime::impl::TraceBuffer::firstStep, initialize(), circt::arc::runtime::impl::TraceBuffer::stepMarkers, timeStep, ArcState::traceBufferSize, worker, and workLoop().
|
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().
| void circt::arc::runtime::impl::TraceEncoder::step | ( | const ArcState * | state | ) |
Signal the start of a new simulation time step.
Definition at line 110 of file TraceEncoder.cpp.
References activeBuffer, assert(), circt::arc::runtime::impl::TraceBuffer::assertSentinel(), circt::arc::runtime::impl::TraceBuffer::firstStep, circt::arc::runtime::impl::TraceBuffer::getData(), circt::arc::runtime::impl::TraceBuffer::stepMarkers, timeStep, ArcState::traceBuffer, ArcState::traceBufferSize, and worker.
|
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().
|
private |
The encoder thread's work loop.
Definition at line 75 of file TraceEncoder.cpp.
References assert(), availableBuffers, availableBuffersCv, availableBuffersMutex, bufferQueue, bufferQueueCv, bufferQueueMutex, encode(), isFinished, startUpWorker(), and windDownWorker().
Referenced by run().
|
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().
|
private |
Definition at line 162 of file TraceEncoder.h.
Referenced by getBuffer(), TraceEncoder(), and workLoop().
|
private |
Definition at line 161 of file TraceEncoder.h.
Referenced by getBuffer(), and workLoop().
|
private |
Return stack and synchronization primitives for processed buffers.
Definition at line 160 of file TraceEncoder.h.
Referenced by getBuffer(), and workLoop().
|
private |
Definition at line 157 of file TraceEncoder.h.
Referenced by enqueueBuffer(), run(), and workLoop().
|
private |
Definition at line 156 of file TraceEncoder.h.
Referenced by enqueueBuffer(), finish(), and workLoop().
|
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().
|
protected |
Debug mode flag.
Definition at line 138 of file TraceEncoder.h.
Referenced by verilator.Verilator::compile_commands(), questa.Questa::run_command(), and simulator.Simulator::run_proc().
|
private |
Flag signaling that no more buffers will be enqueued.
Definition at line 165 of file TraceEncoder.h.
Referenced by finish(), TraceEncoder(), and workLoop().
|
protected |
Metadata of the traced model.
Definition at line 136 of file TraceEncoder.h.
Referenced by circt::arc::runtime::impl::VCDTraceEncoder::createHierarchy(), circt::arc::runtime::impl::VCDTraceEncoder::initialize(), circt::arc::runtime::impl::VCDTraceEncoder::initSignalTable(), and TraceEncoder().
| 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().
|
private |
Current simulation time step.
Definition at line 148 of file TraceEncoder.h.
Referenced by dispatch(), run(), step(), and TraceEncoder().
|
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().