IoUringEngn: add random dummy slot generator for debugging
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/uio.h>
|
||||
@@ -63,7 +64,8 @@ eventfdFd(-1), eventfdDesc(nullptr), eventfd_value(0),
|
||||
stallTimer(parent_.device->componentThread->getIoService()),
|
||||
isAssembling(false),
|
||||
nDgramsPerStagingBufferFrame(nDgramsPerStagingBufferFrame_),
|
||||
assembledSlotsTracker(nDgramsPerStagingBufferFrame_)
|
||||
assembledSlotsTracker(nDgramsPerStagingBufferFrame_),
|
||||
randomDevice(), randomGenerator(randomDevice())
|
||||
{}
|
||||
|
||||
bool IoUringAssemblyEngine::setup()
|
||||
@@ -664,6 +666,73 @@ void IoUringAssemblyEngine::fillUnAssembledSlotsWithDummyDgrams()
|
||||
}
|
||||
}
|
||||
|
||||
void IoUringAssemblyEngine::randomDummySlotFiller(AsynchronousLoop& loop)
|
||||
{
|
||||
if (!frameAssemblyDesc)
|
||||
{ return; }
|
||||
|
||||
// Check if there are already dummies (natural dummy instance)
|
||||
uint32_t nSucceeded = loop.nSucceeded.load();
|
||||
uint32_t nTotal = loop.nTotal;
|
||||
uint32_t nFailed = loop.nFailed.load();
|
||||
|
||||
if (nFailed > 0 || nSucceeded < nTotal)
|
||||
{
|
||||
std::cout << __func__ << ": Natural dummy instance detected (nSucceeded="
|
||||
<< nSucceeded << ", nTotal=" << nTotal << ", nFailed=" << nFailed
|
||||
<< "), skipping artificial dummy creation" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Randomly select a number of slots to make into dummies (less than total)
|
||||
std::uniform_int_distribution<size_t> numDummiesDist(1, nTotal - 1);
|
||||
size_t numDummiesToCreate = numDummiesDist(randomGenerator);
|
||||
|
||||
std::uniform_int_distribution<size_t> slotIndexDist(0, nTotal - 1);
|
||||
size_t dummiesCreated = 0;
|
||||
size_t maxAttempts = nTotal * 10; // Safety limit to prevent infinite loop
|
||||
size_t attempts = 0;
|
||||
|
||||
// Mark random slots as unassembled
|
||||
while (dummiesCreated < numDummiesToCreate && attempts < maxAttempts)
|
||||
{
|
||||
++attempts;
|
||||
size_t randomIndex = slotIndexDist(randomGenerator);
|
||||
|
||||
// Skip if already unassembled, re-roll
|
||||
if (randomIndex >= assembledSlotsTracker.size()
|
||||
|| !assembledSlotsTracker[randomIndex].assembled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Mark as unassembled
|
||||
assembledSlotsTracker[randomIndex].assembled = false;
|
||||
++dummiesCreated;
|
||||
}
|
||||
|
||||
if (dummiesCreated < numDummiesToCreate)
|
||||
{
|
||||
std::cerr << __func__ << ": Warning: Could only create " << dummiesCreated
|
||||
<< " dummy slots out of " << numDummiesToCreate
|
||||
<< " requested (max attempts reached)" << std::endl;
|
||||
numDummiesToCreate = dummiesCreated;
|
||||
}
|
||||
|
||||
// Update the AsynchronousLoop to reflect the new number of dummies
|
||||
// Since we only reach here when nSucceeded == nTotal and nFailed == 0,
|
||||
// we can directly calculate the new values
|
||||
uint32_t newSucceeded = nTotal - static_cast<uint32_t>(numDummiesToCreate);
|
||||
uint32_t newFailed = static_cast<uint32_t>(numDummiesToCreate);
|
||||
|
||||
loop.nSucceeded.store(newSucceeded);
|
||||
loop.nFailed.store(newFailed);
|
||||
|
||||
std::cout << __func__ << ": Artificially created " << numDummiesToCreate
|
||||
<< " dummy slots (nSucceeded: " << nTotal << " -> "
|
||||
<< newSucceeded << ", nFailed: 0 -> " << newFailed << ")" << std::endl;
|
||||
}
|
||||
|
||||
void IoUringAssemblyEngine::printSlotBytes(size_t slotIndex, size_t nBytes)
|
||||
{
|
||||
if (!frameAssemblyDesc)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <atomic>
|
||||
#include <random>
|
||||
#include <liburing.h>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
@@ -46,6 +47,8 @@ public:
|
||||
static size_t computePointsPerDgram(int returnMode);
|
||||
static size_t computePointsPerFrame(int returnMode, size_t nDgramsPerFrame)
|
||||
{ return computePointsPerDgram(returnMode) * nDgramsPerFrame; }
|
||||
static bool compactionIsNeeded(uint32_t nSucceeded, uint32_t nTotal)
|
||||
{ return nSucceeded != 0 && nTotal != 0 && nSucceeded != nTotal; }
|
||||
|
||||
private:
|
||||
PcloudStimulusBuffer& parent;
|
||||
@@ -86,13 +89,20 @@ private:
|
||||
// Track which slots have been successfully assembled and maintain persistent iovecs
|
||||
std::vector<SlotAssemblyDesc> assembledSlotsTracker;
|
||||
|
||||
// Random number generation for dummy slot creation
|
||||
std::random_device randomDevice;
|
||||
std::mt19937 randomGenerator;
|
||||
|
||||
void fillUnAssembledSlotsWithDummyDgrams();
|
||||
void printSlotBytes(size_t slotIndex, size_t nBytes);
|
||||
void randomDummySlotFiller(AsynchronousLoop& loop);
|
||||
void onEventfdRead(
|
||||
const boost::system::error_code& error, std::size_t bytes_transferred);
|
||||
|
||||
class AssembleFrameReq;
|
||||
friend class AssembleFrameReq;
|
||||
|
||||
public:
|
||||
void printSlotBytes(size_t slotIndex, size_t nBytes);
|
||||
};
|
||||
|
||||
} // namespace stim_buff
|
||||
|
||||
Reference in New Issue
Block a user