Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

liburing #1218

Merged
merged 53 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
79c0b3d
liburing
jmillan Nov 8, 2023
b819171
Update CHANGELOG.md
jmillan Nov 14, 2023
60acaab
add missing MS_LIBURING_ENABLED flag
jmillan Nov 14, 2023
e011fd4
Update CHANGELOG.md
jmillan Nov 14, 2023
1000439
feedback
jmillan Nov 14, 2023
16acc51
feedback
jmillan Nov 14, 2023
f17b15c
feedback, cont
jmillan Nov 14, 2023
e6ac1dc
feedback, cont
jmillan Nov 14, 2023
610797a
Add comments
jmillan Nov 14, 2023
b146937
use std::addressoff() rather than &
jmillan Nov 14, 2023
edbf854
fix typo
jmillan Nov 14, 2023
d53fc7a
add comments
jmillan Nov 14, 2023
8870b70
fix liburing Rust linkage
jmillan Nov 15, 2023
f6e25f8
close the uv_poll_t handle
jmillan Nov 15, 2023
fa2707e
properly clean uv_poll_t handle
jmillan Nov 15, 2023
61e7320
use 'err' rather than 'error' for consistency
jmillan Nov 15, 2023
0ef4ea6
enable liburing in runtime for kernel version >=6
jmillan Nov 15, 2023
a6c3151
comment typo
jmillan Nov 15, 2023
e6d85ce
disable clang-format for variable
jmillan Nov 15, 2023
e8f59f4
new class LibUring
jmillan Nov 15, 2023
808c2c1
Do not create a LibUring instance if not supported by kernel
jmillan Nov 15, 2023
55979f9
New line
jmillan Nov 15, 2023
c9d0f25
meson: remove extra tabs
jmillan Nov 15, 2023
4f01a2f
Merge remote-tracking branch 'origin/v3' into liburing
jmillan Nov 15, 2023
c69486d
handle feedback
jmillan Nov 17, 2023
ab9ce28
IsSupported() is boolean
jmillan Nov 17, 2023
2c261bf
handle feedback
jmillan Nov 20, 2023
6f7bedc
feedback: Rename MS_LIBURING_ENABLED for MS_LIBURING_SUPPORTED
jmillan Nov 20, 2023
dd322f0
Merge branch 'v3' into liburing
ibc Nov 20, 2023
097287e
Merge branch 'v3' into liburing
ibc Nov 20, 2023
6468706
use MS_LIBURING_SUPPORTED macro everywhere needed
jmillan Nov 20, 2023
05e5039
Perf: add two optiomisation flags
jmillan Nov 20, 2023
69058f6
remove flag
jmillan Nov 20, 2023
19bf1a4
format
jmillan Nov 20, 2023
feb0dc3
add debug logs
jmillan Nov 20, 2023
b353b23
fail if we cannot get the local file descriptor
jmillan Nov 20, 2023
b99c4ca
fix comment
jmillan Nov 20, 2023
f06d95f
feedback: use MS_LIBURING_SUPPORTED around
jmillan Nov 20, 2023
402bc5d
add comments
jmillan Nov 20, 2023
61f28d9
use liburing to send Nacked RTP
jmillan Nov 21, 2023
fb9c872
use liburing to send RTCP compound packets
jmillan Nov 21, 2023
05c58d8
rename DepLibUring::IsSupported by IsRuntimeSupported
jmillan Nov 21, 2023
198551f
Liburing::Dump()
jmillan Nov 21, 2023
7e0682c
Merge branch 'v3' into liburing
ibc Nov 21, 2023
0c4b797
consistency in numerical initializations
jmillan Nov 21, 2023
d4c8e4e
fix Dump()
jmillan Nov 21, 2023
4adf1b2
FBS: LibUring::Dump
jmillan Nov 22, 2023
f6286c9
Add missing liburing.fbs
jmillan Nov 22, 2023
403172e
format
jmillan Nov 22, 2023
e6e198e
Node: lint
jmillan Nov 22, 2023
781f8f4
Node: adapt tests for 'worker.dump()'
jmillan Nov 22, 2023
af995a8
Update CHANGELOG.md
jmillan Nov 23, 2023
cfc953a
Update CHANGELOG.md
jmillan Nov 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog


### NEXT

* Enable liburing usage for linux (kernel versions >= 6) ([PR #1218](https://github.com/versatica/mediasoup/pull/1218)).


### 3.13.1

* Node: Extract version from `package.json` using `require()` ([PR #1217](https://github.com/versatica/mediasoup/pull/1217) by @arcinston).
Expand Down
80 changes: 80 additions & 0 deletions worker/include/DepLibUring.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ifndef MS_DEP_LIBURING_HPP
#define MS_DEP_LIBURING_HPP

#ifdef MS_LIBURING_ENABLED

#include "DepLibUV.hpp"
#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 void ClassInit();
static void ClassDestroy();

thread_local static DepLibUring* liburing;

public:
DepLibUring();
~DepLibUring();
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 &this->ring;
jmillan marked this conversation as resolved.
Show resolved Hide resolved
}
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 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;
};

#endif
#endif
1 change: 1 addition & 0 deletions worker/include/handles/TcpConnectionHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class TcpConnectionHandle
uv_tcp_t* uvHandle{ nullptr };
// Others.
struct sockaddr_storage* localAddr{ nullptr };
uv_os_fd_t fd{ 0u };
bool closed{ false };
size_t recvBytes{ 0u };
size_t sentBytes{ 0u };
Expand Down
1 change: 1 addition & 0 deletions worker/include/handles/UdpSocketHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class UdpSocketHandle
// Allocated by this (may be passed by argument).
uv_udp_t* uvHandle{ nullptr };
// Others.
uv_os_fd_t fd{ 0u };
bool closed{ false };
size_t recvBytes{ 0u };
size_t sentBytes{ 0u };
Expand Down
20 changes: 20 additions & 0 deletions worker/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,26 @@ if host_machine.system() == 'windows'
]
endif

if host_machine.system() == 'linux'
kernel_version = run_command('uname', '-r').stdout().strip()

# Enable liburing for kernel versions greather than or equal to 6.
if kernel_version[0].to_int() >= 6
liburing_proj = subproject('liburing', default_options: ['default_library=static'], required: true)
liburing = liburing_proj.get_variable('uring')

dependencies += [liburing]

common_sources += [
'src/DepLibUring.cpp',
]

cpp_args += [
'-DMS_LIBURING_ENABLED',
jmillan marked this conversation as resolved.
Show resolved Hide resolved
]
endif
endif

libmediasoup_worker = library(
'libmediasoup-worker',
name_prefix: '',
Expand Down