StagingBuff: support both Mlock & IOUring pin; Use in IoUAssmEngn
We use io_uring_register_buffers() for IoUringAssemblyEngine instead of using mlock(). This __appears__ to have reduced CPU utilization on the Dell laptop. Could also be that we recently upgraded total RAM from 8GiB to 32GiB.
This commit is contained in:
@@ -27,8 +27,6 @@
|
||||
#include "pcloudStimulusProducer.h"
|
||||
#include "livoxGen1.h"
|
||||
|
||||
// #define REGISTER_IOURING_BUFFERS
|
||||
|
||||
namespace smo {
|
||||
namespace stim_buff {
|
||||
|
||||
@@ -116,10 +114,6 @@ bool IoUringAssemblyEngine::setup()
|
||||
assembledSlotsTracker[i].ioVec.iov_len = slot.nBytes;
|
||||
}
|
||||
|
||||
// Declare iovec early to avoid goto crossing initialization
|
||||
#ifdef REGISTER_IOURING_BUFFERS
|
||||
struct iovec iov;
|
||||
#endif
|
||||
int ret;
|
||||
|
||||
/** EXPLANATION:
|
||||
@@ -134,23 +128,27 @@ bool IoUringAssemblyEngine::setup()
|
||||
if (ret < 0)
|
||||
{ goto cleanup; }
|
||||
|
||||
#ifdef REGISTER_IOURING_BUFFERS
|
||||
// Register staging buffer with io_uring for DMA-apt I/O
|
||||
iov = parent.assemblyBuffer.getIoUringRegisterIoVec();
|
||||
ret = io_uring_register_buffers(&ring, &iov, 1);
|
||||
if (ret < 0)
|
||||
{ goto cleanup_ring; }
|
||||
#endif
|
||||
try
|
||||
{
|
||||
if (assemblyBufferIoUringPinner)
|
||||
{
|
||||
throw std::runtime_error(std::string(__func__)
|
||||
+ ": assemblyBufferIoUringPinner already exists");
|
||||
}
|
||||
|
||||
assemblyBufferIoUringPinner =
|
||||
parent.assemblyBuffer.makeIoUringPinner(&ring);
|
||||
}
|
||||
catch (const std::exception&)
|
||||
{
|
||||
goto cleanup_ring;
|
||||
}
|
||||
|
||||
// Create eventfd for CQE notifications (used with boost's unified loop)
|
||||
eventfdFd = eventfd(0, EFD_NONBLOCK);
|
||||
if (eventfdFd < 0)
|
||||
{
|
||||
#ifdef REGISTER_IOURING_BUFFERS
|
||||
goto cleanup_buffers;
|
||||
#else
|
||||
goto cleanup_ring;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Register eventfd with io_uring
|
||||
@@ -164,11 +162,8 @@ bool IoUringAssemblyEngine::setup()
|
||||
cleanup_eventfd:
|
||||
close(eventfdFd);
|
||||
eventfdFd = -1;
|
||||
#ifdef REGISTER_IOURING_BUFFERS
|
||||
cleanup_buffers:
|
||||
io_uring_unregister_buffers(&ring);
|
||||
#endif
|
||||
cleanup_ring:
|
||||
assemblyBufferIoUringPinner.reset();
|
||||
io_uring_queue_exit(&ring);
|
||||
cleanup:
|
||||
return false;
|
||||
@@ -217,9 +212,7 @@ void IoUringAssemblyEngine::finalize()
|
||||
|
||||
if (wasAcceptingRequests)
|
||||
{
|
||||
#ifdef REGISTER_IOURING_BUFFERS
|
||||
io_uring_unregister_buffers(&ring);
|
||||
#endif
|
||||
assemblyBufferIoUringPinner.reset();
|
||||
io_uring_queue_exit(&ring);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <spinscale/callback.h>
|
||||
#include <spinscale/spinLock.h>
|
||||
#include <user/frameAssemblyDesc.h>
|
||||
#include <user/stagingBuffer.h>
|
||||
|
||||
#define IOURINGASSM_ENGN_FRAME_ASSEM_TIMEOUT_MS \
|
||||
(CONFIG_STIMBUFF_FRAME_PERIOD_MS / 2)
|
||||
@@ -73,6 +74,7 @@ private:
|
||||
uint64_t eventfd_value; // Buffer for async_read_some
|
||||
// Point cloud data socket descriptor
|
||||
std::shared_ptr<boost::asio::posix::stream_descriptor> pcloudDataFdDesc;
|
||||
std::unique_ptr<StagingBuffer::IoUringPinner> assemblyBufferIoUringPinner;
|
||||
|
||||
// Stall detection timer
|
||||
boost::asio::deadline_timer stallTimer;
|
||||
@@ -122,4 +124,3 @@ public:
|
||||
|
||||
#endif // _LIVOX_GEN1_IOURING_ASSEMBLY_ENGINE_H
|
||||
|
||||
|
||||
|
||||
@@ -34,15 +34,14 @@ public:
|
||||
|
||||
~MeshStimulusBuffer() = default;
|
||||
|
||||
// Non-copyable, movable
|
||||
// Non-copyable, non-movable: inherited pinner lifetime is instance-bound
|
||||
MeshStimulusBuffer(const MeshStimulusBuffer&) = delete;
|
||||
MeshStimulusBuffer& operator=(const MeshStimulusBuffer&) = delete;
|
||||
MeshStimulusBuffer(MeshStimulusBuffer&&) = default;
|
||||
MeshStimulusBuffer& operator=(MeshStimulusBuffer&&) = default;
|
||||
MeshStimulusBuffer(MeshStimulusBuffer&&) = delete;
|
||||
MeshStimulusBuffer& operator=(MeshStimulusBuffer&&) = delete;
|
||||
};
|
||||
|
||||
} // namespace stim_buff
|
||||
} // namespace smo
|
||||
|
||||
#endif // _LIVOX_GEN1_MESH_STIMULUS_BUFFER_H
|
||||
|
||||
|
||||
@@ -73,11 +73,11 @@ public:
|
||||
|
||||
~PcloudAmbienceStimulusBuffer() = default;
|
||||
|
||||
// Non-copyable, movable
|
||||
// Non-copyable, non-movable: inherited pinner lifetime is instance-bound
|
||||
PcloudAmbienceStimulusBuffer(const PcloudAmbienceStimulusBuffer&) = delete;
|
||||
PcloudAmbienceStimulusBuffer& operator=(const PcloudAmbienceStimulusBuffer&) = delete;
|
||||
PcloudAmbienceStimulusBuffer(PcloudAmbienceStimulusBuffer&&) = default;
|
||||
PcloudAmbienceStimulusBuffer& operator=(PcloudAmbienceStimulusBuffer&&) = default;
|
||||
PcloudAmbienceStimulusBuffer(PcloudAmbienceStimulusBuffer&&) = delete;
|
||||
PcloudAmbienceStimulusBuffer& operator=(PcloudAmbienceStimulusBuffer&&) = delete;
|
||||
|
||||
public:
|
||||
uint32_t postrinInterestPercentage;
|
||||
|
||||
@@ -35,15 +35,15 @@ public:
|
||||
|
||||
~PcloudIntensityStimulusBuffer() = default;
|
||||
|
||||
// Non-copyable, movable
|
||||
// Non-copyable, non-movable: inherited pinner lifetime is instance-bound
|
||||
PcloudIntensityStimulusBuffer(
|
||||
const PcloudIntensityStimulusBuffer&) = delete;
|
||||
PcloudIntensityStimulusBuffer& operator=(
|
||||
const PcloudIntensityStimulusBuffer&) = delete;
|
||||
PcloudIntensityStimulusBuffer(
|
||||
PcloudIntensityStimulusBuffer&&) = default;
|
||||
PcloudIntensityStimulusBuffer&&) = delete;
|
||||
PcloudIntensityStimulusBuffer& operator=(
|
||||
PcloudIntensityStimulusBuffer&&) = default;
|
||||
PcloudIntensityStimulusBuffer&&) = delete;
|
||||
};
|
||||
|
||||
} // namespace stim_buff
|
||||
|
||||
@@ -95,10 +95,13 @@ collationBuffer(
|
||||
StagingBuffer::IOEngineConstraints::openClInputConstraints,
|
||||
StagingBuffer::IOEngineConstraints::openClInputConstraints,
|
||||
nDgramsPerStagingBufferFrame),
|
||||
collationBufferMlockPinner(collationBuffer.makeMlockPinner()),
|
||||
averageIntensityBuffer(
|
||||
openClAverageIntensityConstraints,
|
||||
openClAverageIntensityConstraints,
|
||||
nDgramsPerStagingBufferFrame),
|
||||
averageIntensityBufferMlockPinner(
|
||||
averageIntensityBuffer.makeMlockPinner()),
|
||||
tempStimulusFrameMem(0),
|
||||
tempStimulusFrame(
|
||||
FrameAssemblyDesc::SlotDesc{
|
||||
|
||||
@@ -52,11 +52,11 @@ public:
|
||||
|
||||
~PcloudStimulusProducer() = default;
|
||||
|
||||
// Non-copyable, movable
|
||||
// Non-copyable, non-movable: pinners hold buffer instance references
|
||||
PcloudStimulusProducer(const PcloudStimulusProducer&) = delete;
|
||||
PcloudStimulusProducer& operator=(const PcloudStimulusProducer&) = delete;
|
||||
PcloudStimulusProducer(PcloudStimulusProducer&&) = default;
|
||||
PcloudStimulusProducer& operator=(PcloudStimulusProducer&&) = default;
|
||||
PcloudStimulusProducer(PcloudStimulusProducer&&) = delete;
|
||||
PcloudStimulusProducer& operator=(PcloudStimulusProducer&&) = delete;
|
||||
|
||||
// Control methods
|
||||
void start() override;
|
||||
@@ -94,7 +94,10 @@ public:
|
||||
StagingBuffer assemblyBuffer;
|
||||
IoUringAssemblyEngine ioUringAssemblyEngine;
|
||||
StagingBuffer collationBuffer;
|
||||
std::unique_ptr<StagingBuffer::MlockPinner> collationBufferMlockPinner;
|
||||
StagingBuffer averageIntensityBuffer;
|
||||
std::unique_ptr<StagingBuffer::MlockPinner>
|
||||
averageIntensityBufferMlockPinner;
|
||||
size_t tempStimulusFrameMem;
|
||||
StimulusFrame tempStimulusFrame;
|
||||
std::atomic<std::shared_ptr<MeshStimulusBuffer>> meshStimulusBuffer;
|
||||
|
||||
Reference in New Issue
Block a user