Browse Source

dsp/datafifo & dsp/samplesinkfifo: rework Rate-limit overflow messages

FIFO overflows can occur repeatedly when a consumer cannot keep up with
the incoming data rate. Logging every overflow can flood the application
logs and obscure other messages, while providing little additional
information about the underlying problem.

Rate-limit overflow messages from DataFifo and SampleSinkFifo while
continuing to report every overflow through the SampleSinkFifo signal.
Accumulate the number of dropped samples and overflow events during the
suppression interval and report them as a single aggregate message.

After reporting the aggregate, require a quiet recovery interval before
resuming immediate overflow reporting. This limits log volume while
retaining useful information about the severity and duration of FIFO
overruns.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
chirpmodem-v8.0.0
Robin Getz 3 months ago
parent
commit
2385aa01c4
No known key found for this signature in database
GPG Key ID: 51C7231FFED0E060
  1. 64
      sdrbase/dsp/datafifo.cpp
  2. 1
      sdrbase/dsp/datafifo.h
  3. 74
      sdrbase/dsp/samplesinkfifo.cpp
  4. 1
      sdrbase/dsp/samplesinkfifo.h

64
sdrbase/dsp/datafifo.cpp

@ -35,6 +35,7 @@ void DataFifo::reset() @@ -35,6 +35,7 @@ void DataFifo::reset()
{
QMutexLocker mutexLocker(&m_mutex);
m_suppressed = -1;
m_suppressedSamples = 0;
m_fill = 0;
m_head = 0;
m_tail = 0;
@ -47,6 +48,7 @@ DataFifo::DataFifo(QObject* parent) : @@ -47,6 +48,7 @@ DataFifo::DataFifo(QObject* parent) :
{
setObjectName("DataFifo");
m_suppressed = -1;
m_suppressedSamples = 0;
m_size = 0;
m_fill = 0;
m_head = 0;
@ -60,6 +62,7 @@ DataFifo::DataFifo(int size, QObject* parent) : @@ -60,6 +62,7 @@ DataFifo::DataFifo(int size, QObject* parent) :
{
setObjectName("DataFifo");
m_suppressed = -1;
m_suppressedSamples = 0;
create(size);
}
@ -70,6 +73,7 @@ DataFifo::DataFifo(const DataFifo& other) : @@ -70,6 +73,7 @@ DataFifo::DataFifo(const DataFifo& other) :
{
setObjectName("DataFifo");
m_suppressed = -1;
m_suppressedSamples = 0;
m_size = m_data.size();
m_fill = 0;
m_head = 0;
@ -89,25 +93,63 @@ bool DataFifo::setSize(int size) @@ -89,25 +93,63 @@ bool DataFifo::setSize(int size)
return m_data.size() == size;
}
// Rate-limit overflow messages while continuing to report every overflow.
// After an overflow, messages are suppressed for 2.5 seconds and the
// accumulated loss is reported as a single message. A 2.5 second recovery
// interval without further overflow is then required before immediate
// reporting resumes.
void DataFifo::logOverflow(unsigned int total, unsigned int count)
{
unsigned int samplesDropped = count - total;
const bool hasOverflow = total < count;
const unsigned int dropped = count - total;
// m_suppressed: -1 = immediate reporting, 0+ = suppressed message count,
// -2 = recovery monitoring
if (m_suppressed == -1)
{
m_suppressed = 0;
m_msgRateTimer.start();
qCritical("DataFifo::write: overflow - dropping %u samples (size=%u)", samplesDropped, m_size);
if (hasOverflow)
{
qCritical("DataFifo: overflow - dropped %u samples", dropped);
// The current overflow was already reported, so don't count it again.
m_suppressed = 0;
m_suppressedSamples = 0;
m_msgRateTimer.start();
}
}
else if (m_msgRateTimer.elapsed() > 2500)
else if (m_suppressed == -2)
{
qCritical("DataFifo::write: %u messages dropped", m_suppressed);
qCritical("DataFifo::write: overflow - dropping %u samples (size=%u)", samplesDropped, m_size);
m_suppressed = -1;
if (hasOverflow)
{
// Resume accumulation without restarting the recovery timer.
m_suppressed = 1;
m_suppressedSamples += dropped;
}
else if (m_msgRateTimer.elapsed() > 2500)
{
// No overflow for the recovery interval: resume immediate reporting.
m_suppressed = -1;
}
}
else
else // m_suppressed >= 0
{
m_suppressed++;
if (m_msgRateTimer.elapsed() > 2500)
{
if (m_suppressed)
{
qCritical("DataFifo: overflow - dropped %lld samples (%u event%s)",
m_suppressedSamples, m_suppressed, m_suppressed > 1 ? "s" : "");
}
m_suppressed = -2;
m_suppressedSamples = 0;
m_msgRateTimer.restart();
}
else if (hasOverflow)
{
++m_suppressed;
m_suppressedSamples += dropped;
}
}
}
@ -118,6 +160,7 @@ unsigned int DataFifo::write(const quint8* data, unsigned int count, DataType da @@ -118,6 +160,7 @@ unsigned int DataFifo::write(const quint8* data, unsigned int count, DataType da
if (dataType != m_currentDataType)
{
m_suppressed = -1;
m_suppressedSamples = 0;
m_fill = 0;
m_head = 0;
m_tail = 0;
@ -164,6 +207,7 @@ unsigned int DataFifo::write(QByteArray::const_iterator begin, QByteArray::const @@ -164,6 +207,7 @@ unsigned int DataFifo::write(QByteArray::const_iterator begin, QByteArray::const
if (dataType != m_currentDataType)
{
m_suppressed = -1;
m_suppressedSamples = 0;
m_fill = 0;
m_head = 0;
m_tail = 0;

1
sdrbase/dsp/datafifo.h

@ -64,6 +64,7 @@ signals: @@ -64,6 +64,7 @@ signals:
private:
QElapsedTimer m_msgRateTimer;
int m_suppressed;
qint64 m_suppressedSamples;
QByteArray m_data;
DataType m_currentDataType;
QRecursiveMutex m_mutex;

74
sdrbase/dsp/samplesinkfifo.cpp

@ -37,6 +37,7 @@ void SampleSinkFifo::reset() @@ -37,6 +37,7 @@ void SampleSinkFifo::reset()
{
QMutexLocker mutexLocker(&m_mutex);
m_suppressed = -1;
m_suppressedSamples = 0;
m_fill = 0;
m_head = 0;
m_tail = 0;
@ -50,6 +51,7 @@ SampleSinkFifo::SampleSinkFifo(QObject* parent) : @@ -50,6 +51,7 @@ SampleSinkFifo::SampleSinkFifo(QObject* parent) :
m_writtenSignalRateDivider(1)
{
m_suppressed = -1;
m_suppressedSamples = 0;
m_size = 0;
m_fill = 0;
m_head = 0;
@ -64,6 +66,7 @@ SampleSinkFifo::SampleSinkFifo(int size, QObject* parent) : @@ -64,6 +66,7 @@ SampleSinkFifo::SampleSinkFifo(int size, QObject* parent) :
m_writtenSignalRateDivider(1)
{
m_suppressed = -1;
m_suppressedSamples = 0;
create(size);
}
@ -75,6 +78,7 @@ SampleSinkFifo::SampleSinkFifo(const SampleSinkFifo& other) : @@ -75,6 +78,7 @@ SampleSinkFifo::SampleSinkFifo(const SampleSinkFifo& other) :
m_writtenSignalRateDivider(1)
{
m_suppressed = -1;
m_suppressedSamples = 0;
m_size = m_data.size();
m_fill = 0;
m_head = 0;
@ -100,27 +104,69 @@ void SampleSinkFifo::setWrittenSignalRateDivider(unsigned int divider) @@ -100,27 +104,69 @@ void SampleSinkFifo::setWrittenSignalRateDivider(unsigned int divider)
m_writtenSignalRateDivider = divider;
}
// Rate-limit overflow messages while continuing to report every overflow.
// After an overflow, messages are suppressed for 2.5 seconds and the
// accumulated loss is reported as a single message. A 2.5 second recovery
// interval without further overflow is then required before immediate
// reporting resumes.
void SampleSinkFifo::logOverflow(unsigned int total, unsigned int count)
{
unsigned int samplesDropped = count - total;
const bool hasOverflow = total < count;
const unsigned int dropped = count - total;
if (hasOverflow)
{
emit overflow(dropped);
}
// m_suppressed: -1 = immediate reporting, 0+ = suppressed message count,
// -2 = recovery monitoring
if (m_suppressed == -1)
{
m_suppressed = 0;
m_msgRateTimer.start();
qCritical("SampleSinkFifo::write: (%s) overflow - dropping %u samples", qPrintable(m_label), samplesDropped);
emit overflow(samplesDropped);
if (hasOverflow)
{
qCritical("SampleSinkFifo: (%s) overflow - dropped %u samples",
qPrintable(m_label), dropped);
// The current overflow was already reported, so don't count it again.
m_suppressed = 0;
m_suppressedSamples = 0;
m_msgRateTimer.start();
}
}
else if (m_msgRateTimer.elapsed() > 2500)
else if (m_suppressed == -2)
{
qCritical("SampleSinkFifo::write: (%s) %u messages dropped", qPrintable(m_label), m_suppressed);
qCritical("SampleSinkFifo::write: (%s) overflow - dropping %u samples", qPrintable(m_label), samplesDropped);
emit overflow(samplesDropped);
m_suppressed = -1;
if (hasOverflow)
{
// Resume accumulation without restarting the recovery timer.
m_suppressed = 1;
m_suppressedSamples += dropped;
}
else if (m_msgRateTimer.elapsed() > 2500)
{
// No overflow for the recovery interval: resume immediate reporting.
m_suppressed = -1;
}
}
else
else // m_suppressed >= 0
{
m_suppressed++;
if (m_msgRateTimer.elapsed() > 2500)
{
if (m_suppressed)
{
qCritical("SampleSinkFifo: (%s) overflow - dropped %lld samples (%u event%s)",
qPrintable(m_label), m_suppressedSamples, m_suppressed, m_suppressed > 1 ? "s" : "");
}
m_suppressed = -2;
m_suppressedSamples = 0;
m_msgRateTimer.restart();
}
else if (hasOverflow)
{
++m_suppressed;
m_suppressedSamples += dropped;
}
}
}
@ -140,7 +186,7 @@ unsigned int SampleSinkFifo::write(const quint8* data, unsigned int count) @@ -140,7 +186,7 @@ unsigned int SampleSinkFifo::write(const quint8* data, unsigned int count)
total = std::min(count, m_size - m_fill);
if (total < count)
if (m_suppressed != -1 || total < count)
{
logOverflow(total, count);
}
@ -189,7 +235,7 @@ unsigned int SampleSinkFifo::write(SampleVector::const_iterator begin, SampleVec @@ -189,7 +235,7 @@ unsigned int SampleSinkFifo::write(SampleVector::const_iterator begin, SampleVec
total = std::min(count, m_size - m_fill);
if (total < count)
if (m_suppressed != -1 || total < count)
{
logOverflow(total, count);
}

1
sdrbase/dsp/samplesinkfifo.h

@ -33,6 +33,7 @@ class SDRBASE_API SampleSinkFifo : public QObject { @@ -33,6 +33,7 @@ class SDRBASE_API SampleSinkFifo : public QObject {
private:
QElapsedTimer m_msgRateTimer;
int m_suppressed;
qint64 m_suppressedSamples;
SampleVector m_data;
int m_total;
unsigned int m_writtenSignalCount;

Loading…
Cancel
Save