-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable liburing usage for linux (kernel versions >= 6). Use liburing to relay incoming RTP to Consumers. This greately reduces the number of system calls as just a single system call is needed to relay the incoming RTP packet to "every" Consumer, opposite to libuv which requires a system call to relay the RTP packet to "each" Consumer. For efficiency, memory buffers are preallocated holding the data payload being sent. --------- Co-authored-by: Iñaki Baz Castillo <ibc@aliax.net>
- Loading branch information
Showing
23 changed files
with
795 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace FBS.LibUring; | ||
|
||
table Dump { | ||
sqe_process_count: uint64; | ||
sqe_miss_count: uint64; | ||
user_data_miss_count: uint64; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#ifndef MS_DEP_LIBURING_HPP | ||
#define MS_DEP_LIBURING_HPP | ||
|
||
#include "DepLibUV.hpp" | ||
#include "FBS/liburing.h" | ||
#include <functional> | ||
#include <liburing.h> | ||
#include <queue> | ||
|
||
class DepLibUring | ||
{ | ||
public: | ||
using onSendCallback = const std::function<void(bool sent)>; | ||
|
||
/* Struct for the user data field of SQE and CQE. */ | ||
struct UserData | ||
{ | ||
uint8_t store[1500]{}; | ||
onSendCallback* cb{ nullptr }; | ||
size_t idx{ 0 }; | ||
}; | ||
|
||
/* Number of submission queue entries (SQE). */ | ||
static constexpr size_t QueueDepth{ 1024 * 4 }; | ||
|
||
static bool IsRuntimeSupported(); | ||
static void ClassInit(); | ||
static void ClassDestroy(); | ||
static flatbuffers::Offset<FBS::LibUring::Dump> FillBuffer(flatbuffers::FlatBufferBuilder& builder); | ||
static void StartPollingCQEs(); | ||
static void StopPollingCQEs(); | ||
static bool PrepareSend( | ||
int sockfd, const void* data, size_t len, const struct sockaddr* addr, onSendCallback* cb); | ||
static bool PrepareWrite( | ||
int sockfd, const void* data1, size_t len1, const void* data2, size_t len2, onSendCallback* cb); | ||
static void Submit(); | ||
static void SetActive(); | ||
static bool IsActive(); | ||
|
||
class LibUring; | ||
|
||
thread_local static LibUring* liburing; | ||
|
||
public: | ||
class LibUring | ||
{ | ||
public: | ||
LibUring(); | ||
~LibUring(); | ||
flatbuffers::Offset<FBS::LibUring::Dump> FillBuffer(flatbuffers::FlatBufferBuilder& builder) const; | ||
void StartPollingCQEs(); | ||
void StopPollingCQEs(); | ||
bool PrepareSend( | ||
int sockfd, const void* data, size_t len, const struct sockaddr* addr, onSendCallback* cb); | ||
bool PrepareWrite( | ||
int sockfd, const void* data1, size_t len1, const void* data2, size_t len2, onSendCallback* cb); | ||
void Submit(); | ||
void SetActive() | ||
{ | ||
this->active = true; | ||
} | ||
bool IsActive() const | ||
{ | ||
return this->active; | ||
} | ||
io_uring* GetRing() | ||
{ | ||
return std::addressof(this->ring); | ||
} | ||
int GetEventFd() const | ||
{ | ||
return this->efd; | ||
} | ||
void ReleaseUserDataEntry(size_t idx) | ||
{ | ||
this->availableUserDataEntries.push(idx); | ||
} | ||
|
||
private: | ||
UserData* GetUserData(); | ||
|
||
private: | ||
// io_uring instance. | ||
io_uring ring; | ||
// Event file descriptor to watch for completions. | ||
int efd; | ||
// libuv handle used to poll io_uring completions. | ||
uv_poll_t* uvHandle{ nullptr }; | ||
// Whether we are currently sending RTP over io_uring. | ||
bool active{ false }; | ||
// Pre-allocated UserData entries. | ||
UserData userDataBuffer[QueueDepth]{}; | ||
// Indexes of available UserData entries. | ||
std::queue<size_t> availableUserDataEntries; | ||
// Submission queue entry process count. | ||
uint64_t sqeProcessCount{ 0u }; | ||
// Submission queue entry miss count. | ||
uint64_t sqeMissCount{ 0u }; | ||
// User data miss count. | ||
uint64_t userDataMissCount{ 0u }; | ||
}; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.