IoUringAssmEngine: Add skeleton setup/finalize

Also add dependency on liburing.
This patch adds basic io_uring_queue_init and io_uring_exit
support and calls.
This commit is contained in:
2025-11-01 21:30:47 -04:00
parent 797a95e6a1
commit b2c73f6bed
3 changed files with 108 additions and 7 deletions
@@ -1,7 +1,9 @@
#include <cstring>
#include <sys/socket.h>
#include <boost/system/error_code.hpp>
#include <livoxProto1/device.h>
#include "ioUringAssemblyEngine.h"
#include "pcloudStimulusBuffer.h"
namespace smo {
namespace stim_buff {
@@ -22,16 +24,90 @@ struct DummyLivoxEthHeader
uint8_t timestamp[8];
};
IoUringAssemblyEngine::IoUringAssemblyEngine(PcloudStimulusBuffer& parent_)
: parent(parent_),
frameAssemblyDesc(nullptr), ring{},
isSetup(false),
stallTimer(parent_.device->componentThread->getIoService())
{}
bool IoUringAssemblyEngine::setup()
{
if (isSetup)
{ return false; }
// Get FrameAssemblyDesc from staging buffer
frameAssemblyDesc = static_cast<std::shared_ptr<FrameAssemblyDesc>>(
parent.stagingBuffer);
if (!frameAssemblyDesc || frameAssemblyDesc->slots.empty())
{ return false; }
// Get UDP socket file descriptor
int udpFd = parent.device->pcloudDataSocketDesc->native_handle();
if (udpFd < 0)
{ return false; }
/** EXPLANATION:
* Initialize io_uring ring - allocate SQEs and CQEs for one frame assembly
* One SQE per slot (one datagram per slot)
*/
int ret = io_uring_queue_init(
static_cast<unsigned int>(frameAssemblyDesc->numSlots), &ring, 0);
if (ret < 0)
{ return false; }
isSetup = true;
return true;
}
void IoUringAssemblyEngine::finalize()
{
// Call stop() to cancel in-flight operations (stop() already cancels the timer)
stop();
// Clean up io_uring ring if it was initialized
if (isSetup)
{
io_uring_queue_exit(&ring);
isSetup = false;
}
// Reset state to allow setup() to be called again
frameAssemblyDesc = nullptr;
}
void IoUringAssemblyEngine::resetAndAssembleFrame()
{
// Design/stub: This method should:
// 1. Submit frameAssemblyDesc->numSlots RECVMSG SQEs using io_uring_prep_recvmsg()
// - Each SQE receives into frameAssemblyDesc->slots[i].vaddr
// - With size frameAssemblyDesc->slots[i].nBytes
// - Socket FD from parent.device->pcloudDataSocketDesc->native_handle()
// 2. Submit batch via io_uring_submit(&ring)
// 3. Set up stall timer using stallTimer with appropriate timeout
// - SQEs are independent and can arrive out of order
// - Timer detects if SQEs get stalled
}
void IoUringAssemblyEngine::stop()
{
// Design/stub: This method should:
// 1. Cancel all pending SQEs using io_uring cancellation mechanisms
// 2. Cancel in-flight stall timeout timer via stallTimer.cancel()
// 3. Set appropriate state flags
}
void IoUringAssemblyEngine::cancelIncompleteAndFillDummies()
{
if (!desc)
if (!frameAssemblyDesc)
{ return; }
for (size_t i = 0; i < desc->numSlots; ++i)
for (size_t i = 0; i < frameAssemblyDesc->numSlots; ++i)
{
// In the real path, decide from CQE accounting whether slot i completed.
// Here, demonstrate dummy header insertion API.
auto* hdr = reinterpret_cast<DummyLivoxEthHeader*>(desc->slots[i].vaddr);
auto* hdr = reinterpret_cast<DummyLivoxEthHeader*>(frameAssemblyDesc->slots[i].vaddr);
hdr->err_code = DummyLivoxEthHeader::INVALID_ERR_CODE;
hdr->timestamp_type = DummyLivoxEthHeader::INVALID_TIMESTAMP_TYPE;
hdr->data_type = DummyLivoxEthHeader::INVALID_DATA_TYPE;