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

Fix io_uring support detection #1445

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### NEXT

- `Worker`: Fix `io_uring` support detection ([PR #1445](https://github.com/versatica/mediasoup/pull/1445)).

### 3.14.11

- `Worker`: Fix `disableLiburing` option in `WorkerSettings` ([PR #1444](https://github.com/versatica/mediasoup/pull/1444)).
Expand Down
2 changes: 1 addition & 1 deletion worker/include/DepLibUring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DepLibUring

static void ClassInit();
static void ClassDestroy();
static void CheckRuntimeSupport();
static bool CheckRuntimeSupport();
static bool IsEnabled();
static flatbuffers::Offset<FBS::LibUring::Dump> FillBuffer(flatbuffers::FlatBufferBuilder& builder);
static void StartPollingCQEs();
Expand Down
52 changes: 33 additions & 19 deletions worker/src/DepLibUring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,27 +120,34 @@ void DepLibUring::ClassInit()
const auto mayor = io_uring_major_version();
const auto minor = io_uring_minor_version();

MS_DEBUG_TAG(info, "liburing version: \"%i.%i\"", mayor, minor);
MS_DEBUG_TAG(info, "io_uring version: \"%i.%i\"", mayor, minor);

if (Settings::configuration.liburingDisabled)
{
MS_DEBUG_TAG(info, "liburing disabled by user settings");
MS_DEBUG_TAG(info, "io_uring disabled by user settings");

return;
}

// This must be called first.
DepLibUring::CheckRuntimeSupport();

if (DepLibUring::IsEnabled())
if (DepLibUring::CheckRuntimeSupport())
{
DepLibUring::liburing = new LibUring();
try
{
DepLibUring::liburing = new LibUring();

MS_DEBUG_TAG(info, "io_uring enabled");

MS_DEBUG_TAG(info, "liburing enabled");
DepLibUring::enabled = true;
}
catch (const MediaSoupError& error)
{
MS_DEBUG_TAG(info, "io_uring initialization failed, io_uring not enabled");
}
}
else
{
MS_DEBUG_TAG(info, "liburing not enabled");
MS_DEBUG_TAG(info, "io_uring not enabled");
}
}

Expand All @@ -151,7 +158,7 @@ void DepLibUring::ClassDestroy()
delete DepLibUring::liburing;
}

void DepLibUring::CheckRuntimeSupport()
bool DepLibUring::CheckRuntimeSupport()
{
// clang-format off
struct utsname buffer{};
Expand All @@ -171,7 +178,14 @@ void DepLibUring::CheckRuntimeSupport()

// liburing `sento` capabilities are supported for kernel versions greather
// than or equal to 6.
DepLibUring::enabled = kernelMayorLong >= 6;
if (kernelMayorLong < 6)
{
MS_DEBUG_TAG(info, "kernel doesn't support io_uring");

return false;
}

return true;
}

bool DepLibUring::IsEnabled()
Expand All @@ -183,7 +197,7 @@ flatbuffers::Offset<FBS::LibUring::Dump> DepLibUring::FillBuffer(flatbuffers::Fl
{
MS_TRACE();

MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled");
MS_ASSERT(DepLibUring::enabled, "io_uring not enabled");

return DepLibUring::liburing->FillBuffer(builder);
}
Expand All @@ -192,7 +206,7 @@ void DepLibUring::StartPollingCQEs()
{
MS_TRACE();

MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled");
MS_ASSERT(DepLibUring::enabled, "io_uring not enabled");

DepLibUring::liburing->StartPollingCQEs();
}
Expand All @@ -201,7 +215,7 @@ void DepLibUring::StopPollingCQEs()
{
MS_TRACE();

MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled");
MS_ASSERT(DepLibUring::enabled, "io_uring not enabled");

DepLibUring::liburing->StopPollingCQEs();
}
Expand All @@ -210,7 +224,7 @@ uint8_t* DepLibUring::GetSendBuffer()
{
MS_TRACE();

MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled");
MS_ASSERT(DepLibUring::enabled, "io_uring not enabled");

return DepLibUring::liburing->GetSendBuffer();
}
Expand All @@ -220,7 +234,7 @@ bool DepLibUring::PrepareSend(
{
MS_TRACE();

MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled");
MS_ASSERT(DepLibUring::enabled, "io_uring not enabled");

return DepLibUring::liburing->PrepareSend(sockfd, data, len, addr, cb);
}
Expand All @@ -230,7 +244,7 @@ bool DepLibUring::PrepareWrite(
{
MS_TRACE();

MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled");
MS_ASSERT(DepLibUring::enabled, "io_uring not enabled");

return DepLibUring::liburing->PrepareWrite(sockfd, data1, len1, data2, len2, cb);
}
Expand All @@ -239,7 +253,7 @@ void DepLibUring::Submit()
{
MS_TRACE();

MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled");
MS_ASSERT(DepLibUring::enabled, "io_uring not enabled");

DepLibUring::liburing->Submit();
}
Expand All @@ -248,7 +262,7 @@ void DepLibUring::SetActive()
{
MS_TRACE();

MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled");
MS_ASSERT(DepLibUring::enabled, "io_uring not enabled");

DepLibUring::liburing->SetActive();
}
Expand All @@ -257,7 +271,7 @@ bool DepLibUring::IsActive()
{
MS_TRACE();

MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled");
MS_ASSERT(DepLibUring::enabled, "io_uring not enabled");

return DepLibUring::liburing->IsActive();
}
Expand Down
Loading