StagingBuffer: Prefer mlock to io_uring_register_buffers
This commit is contained in:
@@ -26,6 +26,8 @@
|
|||||||
#include "pcloudStimulusBuffer.h"
|
#include "pcloudStimulusBuffer.h"
|
||||||
#include "livoxGen1.h"
|
#include "livoxGen1.h"
|
||||||
|
|
||||||
|
// #define REGISTER_IOURING_BUFFERS
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace stim_buff {
|
namespace stim_buff {
|
||||||
|
|
||||||
@@ -107,7 +109,9 @@ bool IoUringAssemblyEngine::setup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Declare iovec early to avoid goto crossing initialization
|
// Declare iovec early to avoid goto crossing initialization
|
||||||
|
#ifdef REGISTER_IOURING_BUFFERS
|
||||||
struct iovec iov;
|
struct iovec iov;
|
||||||
|
#endif
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/** EXPLANATION:
|
/** EXPLANATION:
|
||||||
@@ -122,16 +126,24 @@ bool IoUringAssemblyEngine::setup()
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{ goto cleanup; }
|
{ goto cleanup; }
|
||||||
|
|
||||||
|
#ifdef REGISTER_IOURING_BUFFERS
|
||||||
// Register staging buffer with io_uring for DMA-apt I/O
|
// Register staging buffer with io_uring for DMA-apt I/O
|
||||||
iov = parent.assemblyBuffer.getIoUringRegisterIoVec();
|
iov = parent.assemblyBuffer.getIoUringRegisterIoVec();
|
||||||
ret = io_uring_register_buffers(&ring, &iov, 1);
|
ret = io_uring_register_buffers(&ring, &iov, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{ goto cleanup_ring; }
|
{ goto cleanup_ring; }
|
||||||
|
#endif
|
||||||
|
|
||||||
// Create eventfd for CQE notifications (used with boost's unified loop)
|
// Create eventfd for CQE notifications (used with boost's unified loop)
|
||||||
eventfdFd = eventfd(0, EFD_NONBLOCK);
|
eventfdFd = eventfd(0, EFD_NONBLOCK);
|
||||||
if (eventfdFd < 0)
|
if (eventfdFd < 0)
|
||||||
{ goto cleanup_buffers; }
|
{
|
||||||
|
#ifdef REGISTER_IOURING_BUFFERS
|
||||||
|
goto cleanup_buffers;
|
||||||
|
#else
|
||||||
|
goto cleanup_ring;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Register eventfd with io_uring
|
// Register eventfd with io_uring
|
||||||
ret = io_uring_register_eventfd(&ring, eventfdFd);
|
ret = io_uring_register_eventfd(&ring, eventfdFd);
|
||||||
@@ -144,8 +156,10 @@ bool IoUringAssemblyEngine::setup()
|
|||||||
cleanup_eventfd:
|
cleanup_eventfd:
|
||||||
close(eventfdFd);
|
close(eventfdFd);
|
||||||
eventfdFd = -1;
|
eventfdFd = -1;
|
||||||
|
#ifdef REGISTER_IOURING_BUFFERS
|
||||||
cleanup_buffers:
|
cleanup_buffers:
|
||||||
io_uring_unregister_buffers(&ring);
|
io_uring_unregister_buffers(&ring);
|
||||||
|
#endif
|
||||||
cleanup_ring:
|
cleanup_ring:
|
||||||
io_uring_queue_exit(&ring);
|
io_uring_queue_exit(&ring);
|
||||||
cleanup:
|
cleanup:
|
||||||
@@ -166,7 +180,9 @@ void IoUringAssemblyEngine::finalize()
|
|||||||
|
|
||||||
if (isSetup)
|
if (isSetup)
|
||||||
{
|
{
|
||||||
|
#ifdef REGISTER_IOURING_BUFFERS
|
||||||
io_uring_unregister_buffers(&ring);
|
io_uring_unregister_buffers(&ring);
|
||||||
|
#endif
|
||||||
io_uring_queue_exit(&ring);
|
io_uring_queue_exit(&ring);
|
||||||
isSetup = false;
|
isSetup = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,6 +197,13 @@ assemblingFlag(false)
|
|||||||
static_cast<uint8_t*>(mmapped), MmapDeleter(bufferNBytes));
|
static_cast<uint8_t*>(mmapped), MmapDeleter(bufferNBytes));
|
||||||
currentNBytes.store(0);
|
currentNBytes.store(0);
|
||||||
|
|
||||||
|
// Lock the buffer in memory to prevent swapping
|
||||||
|
if (mlock(buffer.get(), bufferNBytes) != 0)
|
||||||
|
{
|
||||||
|
throw std::runtime_error(std::string(__func__)
|
||||||
|
+ ": StagingBuffer: mlock() failed");
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate offset and validate invariants (helper function in .cpp)
|
// Calculate offset and validate invariants (helper function in .cpp)
|
||||||
firstSlotOffsetNBytes = StagingBuffer::calculateFirstSlotOffsetAndValidate(
|
firstSlotOffsetNBytes = StagingBuffer::calculateFirstSlotOffsetAndValidate(
|
||||||
buffer.get(), bufferNBytes, nDgramsPerFrame,
|
buffer.get(), bufferNBytes, nDgramsPerFrame,
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ private:
|
|||||||
{
|
{
|
||||||
if (ptr != nullptr && size > 0)
|
if (ptr != nullptr && size > 0)
|
||||||
{
|
{
|
||||||
|
munlock(ptr, size);
|
||||||
munmap(ptr, size);
|
munmap(ptr, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user