2025-10-30 19:07:19 -04:00
|
|
|
#ifndef _LIVOX_GEN1_IOURING_ASSEMBLY_ENGINE_H
|
|
|
|
|
#define _LIVOX_GEN1_IOURING_ASSEMBLY_ENGINE_H
|
|
|
|
|
|
2025-11-03 22:18:45 -04:00
|
|
|
#include <boostAsioLinkageFix.h>
|
2025-10-30 19:07:19 -04:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <chrono>
|
|
|
|
|
#include <atomic>
|
2025-11-09 19:34:02 -04:00
|
|
|
#include <random>
|
2025-11-01 21:30:47 -04:00
|
|
|
#include <liburing.h>
|
|
|
|
|
#include <boost/asio/io_service.hpp>
|
|
|
|
|
#include <boost/asio/deadline_timer.hpp>
|
2025-11-05 19:23:30 -04:00
|
|
|
#include <boost/asio/posix/stream_descriptor.hpp>
|
2025-10-30 19:07:19 -04:00
|
|
|
#include <livoxProto1/device.h>
|
2025-11-06 00:00:23 -04:00
|
|
|
#include <asynchronousContinuation.h>
|
|
|
|
|
#include <asynchronousLoop.h>
|
|
|
|
|
#include <callback.h>
|
|
|
|
|
#include <spinLock.h>
|
2025-11-15 20:47:40 -04:00
|
|
|
#include <user/frameAssemblyDesc.h>
|
2025-10-30 19:07:19 -04:00
|
|
|
|
|
|
|
|
namespace smo {
|
|
|
|
|
namespace stim_buff {
|
|
|
|
|
|
2025-11-14 23:50:31 -04:00
|
|
|
class PcloudStimulusProducer;
|
2025-11-01 21:30:47 -04:00
|
|
|
|
2025-10-30 19:07:19 -04:00
|
|
|
class IoUringAssemblyEngine
|
|
|
|
|
{
|
|
|
|
|
public:
|
2025-11-09 00:55:58 -04:00
|
|
|
explicit IoUringAssemblyEngine(
|
2025-11-14 23:50:31 -04:00
|
|
|
PcloudStimulusProducer& parent, size_t nDgramsPerStagingBufferFrame);
|
2025-10-30 21:55:21 -04:00
|
|
|
~IoUringAssemblyEngine() = default;
|
2025-10-30 19:07:19 -04:00
|
|
|
|
2025-11-01 21:30:47 -04:00
|
|
|
bool setup();
|
|
|
|
|
void finalize();
|
2025-11-06 00:00:23 -04:00
|
|
|
|
|
|
|
|
typedef std::function<void(bool, AsynchronousLoop)> assembleFrameReqCbFn;
|
|
|
|
|
void assembleFrameReq(Callback<assembleFrameReqCbFn> cb);
|
2025-11-01 21:30:47 -04:00
|
|
|
|
2025-11-01 20:21:49 -04:00
|
|
|
// Telemetry helpers
|
|
|
|
|
static size_t computePointsPerFrame(int returnMode, size_t nDgramsPerFrame)
|
2025-11-16 12:37:25 -04:00
|
|
|
{ return livoxProto1::Device::getNPointsPerDgram(returnMode) * nDgramsPerFrame; }
|
2025-11-09 19:34:02 -04:00
|
|
|
static bool compactionIsNeeded(uint32_t nSucceeded, uint32_t nTotal)
|
|
|
|
|
{ return nSucceeded != 0 && nTotal != 0 && nSucceeded != nTotal; }
|
2025-10-30 19:07:19 -04:00
|
|
|
|
2025-11-20 03:26:43 -04:00
|
|
|
// Get assembly execution duration in milliseconds
|
|
|
|
|
std::chrono::milliseconds getAssemblyDuration() const;
|
|
|
|
|
|
2025-11-13 20:54:54 -04:00
|
|
|
private:
|
2025-11-15 22:02:30 -04:00
|
|
|
typedef std::function<void(void*, int)> resetAndAssembleFrameCbFn;
|
2025-11-13 20:54:54 -04:00
|
|
|
void resetAndAssembleFrame(resetAndAssembleFrameCbFn onCqeReady);
|
2025-11-13 23:53:31 -04:00
|
|
|
void assemblyCycleComplete();
|
|
|
|
|
bool stop();
|
2025-11-13 20:54:54 -04:00
|
|
|
|
2025-10-30 19:07:19 -04:00
|
|
|
private:
|
2025-11-14 23:50:31 -04:00
|
|
|
PcloudStimulusProducer& parent;
|
2025-11-01 21:30:47 -04:00
|
|
|
|
2025-10-30 19:07:19 -04:00
|
|
|
// Cached descriptor for reuse across iterations
|
2025-11-01 21:30:47 -04:00
|
|
|
std::shared_ptr<FrameAssemblyDesc> frameAssemblyDesc;
|
|
|
|
|
|
|
|
|
|
// io_uring infrastructure
|
|
|
|
|
struct io_uring ring;
|
|
|
|
|
|
2025-11-05 15:34:23 -04:00
|
|
|
// Eventfd for CQE notifications (used with boost's unified loop)
|
|
|
|
|
int eventfdFd;
|
2025-11-05 19:23:30 -04:00
|
|
|
std::unique_ptr<boost::asio::posix::stream_descriptor> eventfdDesc;
|
|
|
|
|
uint64_t eventfd_value; // Buffer for async_read_some
|
2025-11-01 23:01:11 -04:00
|
|
|
// Point cloud data socket descriptor
|
2025-11-01 23:20:31 -04:00
|
|
|
std::shared_ptr<boost::asio::posix::stream_descriptor> pcloudDataFdDesc;
|
2025-11-01 23:01:11 -04:00
|
|
|
|
2025-11-01 21:30:47 -04:00
|
|
|
// Stall detection timer
|
|
|
|
|
boost::asio::deadline_timer stallTimer;
|
2025-11-06 00:00:23 -04:00
|
|
|
// Callback for CQE ntfns (called with user_data+result from each CQE)
|
|
|
|
|
resetAndAssembleFrameCbFn onCqeReadyCallback;
|
2025-11-13 23:53:31 -04:00
|
|
|
/** EXPLANATION:
|
|
|
|
|
* Flag to indicate whether engine should accept new requests.
|
|
|
|
|
* Set by setup(), cleared by stop().
|
|
|
|
|
*/
|
|
|
|
|
SpinLock shouldAcceptRequestsLock;
|
|
|
|
|
bool shouldAcceptRequests;
|
2025-10-30 19:07:19 -04:00
|
|
|
|
2025-11-09 00:55:58 -04:00
|
|
|
size_t nDgramsPerStagingBufferFrame;
|
|
|
|
|
|
|
|
|
|
struct SlotAssemblyDesc
|
|
|
|
|
{
|
|
|
|
|
bool assembled;
|
|
|
|
|
struct msghdr msgHdr;
|
|
|
|
|
struct iovec ioVec;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Track which slots have been successfully assembled and maintain persistent iovecs
|
|
|
|
|
std::vector<SlotAssemblyDesc> assembledSlotsTracker;
|
|
|
|
|
|
2025-11-09 19:34:02 -04:00
|
|
|
// Random number generation for dummy slot creation
|
|
|
|
|
std::random_device randomDevice;
|
|
|
|
|
std::mt19937 randomGenerator;
|
|
|
|
|
|
2025-11-20 03:26:43 -04:00
|
|
|
// Timestamp tracking for assembly execution
|
|
|
|
|
std::chrono::high_resolution_clock::time_point assemblyStartTime;
|
|
|
|
|
std::chrono::high_resolution_clock::time_point assemblyEndTime;
|
|
|
|
|
|
2025-11-09 00:55:58 -04:00
|
|
|
void fillUnAssembledSlotsWithDummyDgrams();
|
2025-11-09 19:34:02 -04:00
|
|
|
void randomDummySlotFiller(AsynchronousLoop& loop);
|
2025-11-05 19:23:30 -04:00
|
|
|
void onEventfdRead(
|
|
|
|
|
const boost::system::error_code& error, std::size_t bytes_transferred);
|
2025-11-06 00:00:23 -04:00
|
|
|
|
|
|
|
|
class AssembleFrameReq;
|
|
|
|
|
friend class AssembleFrameReq;
|
2025-11-09 19:34:02 -04:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void printSlotBytes(size_t slotIndex, size_t nBytes);
|
2025-10-30 19:07:19 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace stim_buff
|
|
|
|
|
} // namespace smo
|
|
|
|
|
|
|
|
|
|
#endif // _LIVOX_GEN1_IOURING_ASSEMBLY_ENGINE_H
|
|
|
|
|
|
|
|
|
|
|