From 162980dc251797c7d58c2c7b080d79e83e4e68a5 Mon Sep 17 00:00:00 2001 From: Mateusz Gancarz Date: Wed, 26 Feb 2025 11:55:30 +0100 Subject: [PATCH] [#73220] remove SAIF code related to buffers --- include/verilated_saif_c.cpp | 71 +++--------------------------------- include/verilated_saif_c.h | 28 -------------- 2 files changed, 6 insertions(+), 93 deletions(-) diff --git a/include/verilated_saif_c.cpp b/include/verilated_saif_c.cpp index 3ef5ef06b..3a0e4c717 100644 --- a/include/verilated_saif_c.cpp +++ b/include/verilated_saif_c.cpp @@ -97,10 +97,6 @@ VerilatedSaif::VerilatedSaif(VerilatedSaifFile* filep) { // Not in header to avoid link issue if header is included without this .cpp file m_fileNewed = (filep == nullptr); m_filep = m_fileNewed ? new VerilatedSaifFile : filep; - m_wrChunkSize = 8 * 1024; - m_wrBufp = new char[m_wrChunkSize * 8]; - m_wrFlushp = m_wrBufp + m_wrChunkSize * 6; - m_writep = m_wrBufp; } void VerilatedSaif::open(const char* filename) VL_MT_SAFE_EXCLUDES(m_mutex) { @@ -182,11 +178,10 @@ void VerilatedSaif::openNextImp(bool incFilename) { m_isOpen = true; constDump(true); // First dump must containt the const signals fullDump(true); // First dump must be full - m_wroteBytes = 0; } bool VerilatedSaif::preChangeDump() { - if (VL_UNLIKELY(m_rolloverSize && m_wroteBytes > m_rolloverSize)) openNextImp(true); + if (VL_UNLIKELY(m_rolloverSize)) openNextImp(true); return isOpen(); } @@ -194,12 +189,7 @@ void VerilatedSaif::emitTimeChange(uint64_t timeui) { m_time = timeui; } VerilatedSaif::~VerilatedSaif() { close(); - if (m_wrBufp) VL_DO_CLEAR(delete[] m_wrBufp, m_wrBufp = nullptr); if (m_filep && m_fileNewed) VL_DO_CLEAR(delete m_filep, m_filep = nullptr); - if (parallel()) { - assert(m_numBuffers == m_freeBuffers.size()); - for (auto& pair : m_freeBuffers) VL_DO_CLEAR(delete[] pair.first, pair.first = nullptr); - } } void VerilatedSaif::closePrev() { @@ -207,7 +197,6 @@ void VerilatedSaif::closePrev() { if (!isOpen()) return; Super::flushBase(); - bufferFlush(); m_isOpen = false; m_filep->close(); } @@ -330,64 +319,16 @@ void VerilatedSaif::clearCurrentlyCollectedData() m_time = 0; } -void VerilatedSaif::flush() VL_MT_SAFE_EXCLUDES(m_mutex) { - const VerilatedLockGuard lock{m_mutex}; - Super::flushBase(); - bufferFlush(); -} - void VerilatedSaif::printStr(const char* str) { m_filep->write(str, strlen(str)); } -void VerilatedSaif::bufferResize(size_t minsize) { - // minsize is size of largest write. We buffer at least 8 times as much data, - // writing when we are 3/4 full (with thus 2*minsize remaining free) - if (VL_UNLIKELY(minsize > m_wrChunkSize)) { - const char* oldbufp = m_wrBufp; - m_wrChunkSize = roundUpToMultipleOf<1024>(minsize * 2); - m_wrBufp = new char[m_wrChunkSize * 8]; - std::memcpy(m_wrBufp, oldbufp, m_writep - oldbufp); - m_writep = m_wrBufp + (m_writep - oldbufp); - m_wrFlushp = m_wrBufp + m_wrChunkSize * 6; - VL_DO_CLEAR(delete[] oldbufp, oldbufp = nullptr); - } -} - -void VerilatedSaif::bufferFlush() VL_MT_UNSAFE_ONE { - // This function can be called from the trace offload thread - // This function is on the flush() call path - // We add output data to m_writep. - // When it gets nearly full we dump it using this routine which calls write() - // This is much faster than using buffered I/O - if (VL_UNLIKELY(!m_isOpen)) return; - const char* wp = m_wrBufp; - while (true) { - const ssize_t remaining = (m_writep - wp); - if (remaining == 0) break; - errno = 0; - const ssize_t got = m_filep->write(wp, remaining); - if (got > 0) { - wp += got; - m_wroteBytes += got; - } else if (VL_UNCOVERABLE(got < 0)) { - if (VL_UNCOVERABLE(errno != EAGAIN && errno != EINTR)) { - // LCOV_EXCL_START - // write failed, presume error (perhaps out of disk space) - const std::string msg = "VerilatedSaif::bufferFlush: "s + std::strerror(errno); - VL_FATAL_MT("", 0, "", msg.c_str()); - closeErr(); - break; - // LCOV_EXCL_STOP - } - } - } - - // Reset buffer - m_writep = m_wrBufp; -} - //============================================================================= // Definitions +void VerilatedSaif::flush() VL_MT_SAFE_EXCLUDES(m_mutex) { + const VerilatedLockGuard lock{m_mutex}; + Super::flushBase(); +} + void VerilatedSaif::incrementIndent() { m_indent += 1; diff --git a/include/verilated_saif_c.h b/include/verilated_saif_c.h index 88a015f25..12291fc16 100644 --- a/include/verilated_saif_c.h +++ b/include/verilated_saif_c.h @@ -85,13 +85,6 @@ private: int m_indent = 0; // Indentation depth - char* m_wrBufp; // Output buffer - char* m_wrFlushp; // Output buffer flush trigger location - char* m_writep; // Write pointer into output buffer - size_t m_wrChunkSize; // Output buffer size - size_t m_maxSignalBytes = 0; // Upper bound on number of bytes a single signal can generate - uint64_t m_wroteBytes = 0; // Number of bytes written to this file - void clearCurrentlyCollectedData(); int32_t m_currentScope{-1}; @@ -106,17 +99,6 @@ private: std::vector> m_prefixStack{ {"", VerilatedTracePrefixType::SCOPE_MODULE}}; - // Vector of free trace buffers as (pointer, size) pairs. - std::vector> m_freeBuffers; - size_t m_numBuffers = 0; // Number of trace buffers allocated - - void bufferResize(size_t minsize); - void bufferFlush() VL_MT_UNSAFE_ONE; - void bufferCheck() { - // Flush the write buffer if there's not enough space left for new information - // We only call this once per vector, so we need enough slop for a very wide "b###" line - if (VL_UNLIKELY(m_writep > m_wrFlushp)) bufferFlush(); - } void openNextImp(bool incFilename); void closePrev(); void closeErr(); @@ -231,16 +213,6 @@ class VerilatedSaifBuffer VL_NOT_FINAL { VerilatedSaif& m_owner; // Trace file owning this buffer. Required by subclasses. - // Write pointer into output buffer (in parallel mode, this is set up in 'getTraceBuffer') - char* m_writep = m_owner.parallel() ? nullptr : m_owner.m_writep; - // Output buffer flush trigger location (only used when not parallel) - char* const m_wrFlushp = m_owner.parallel() ? nullptr : m_owner.m_wrFlushp; - - // Additional data for parallel tracing only - char* m_bufp = nullptr; // The beginning of the trace buffer - size_t m_size = 0; // The size of the buffer at m_bufp - char* m_growp = nullptr; // Resize limit pointer - // CONSTRUCTOR explicit VerilatedSaifBuffer(VerilatedSaif& owner) : m_owner{owner} {}