From 54c80c739981ed5b327dd4860022b866a07fdf18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 9 Aug 2024 13:14:22 +0200 Subject: [PATCH 01/11] DepLibUring improvements ### Details - Be explicit. Always check if liburing is supported before calling any method in `DepLibUring`. This is cosmetic but helps when reading the whole code. --- worker/include/DepLibUring.hpp | 11 +++++-- worker/src/DepLibUring.cpp | 56 +++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/worker/include/DepLibUring.hpp b/worker/include/DepLibUring.hpp index 973acaff42..7c8f0357c3 100644 --- a/worker/include/DepLibUring.hpp +++ b/worker/include/DepLibUring.hpp @@ -33,9 +33,10 @@ class DepLibUring using SendBuffer = uint8_t[SendBufferSize]; - static bool IsRuntimeSupported(); static void ClassInit(); static void ClassDestroy(); + static void CheckRuntimeSupport(); + static bool IsRuntimeSupported(); static flatbuffers::Offset FillBuffer(flatbuffers::FlatBufferBuilder& builder); static void StartPollingCQEs(); static void StopPollingCQEs(); @@ -51,8 +52,10 @@ class DepLibUring class LibUring; thread_local static LibUring* liburing; + static bool runtimeSupported{ false }; -public: +private: + // Private singleton. class LibUring { public: @@ -98,6 +101,10 @@ class DepLibUring } private: + void SetInactive() + { + this->active = false; + } UserData* GetUserData(); bool IsDataInSendBuffers(const uint8_t* data) const { diff --git a/worker/src/DepLibUring.cpp b/worker/src/DepLibUring.cpp index 95d2b6631e..ee64880c5e 100644 --- a/worker/src/DepLibUring.cpp +++ b/worker/src/DepLibUring.cpp @@ -114,29 +114,6 @@ inline static void onFdEvent(uv_poll_t* handle, int status, int events) /* Static class methods */ -bool DepLibUring::IsRuntimeSupported() -{ - // clang-format off - struct utsname buffer{}; - // clang-format on - - auto err = uname(std::addressof(buffer)); - - if (err != 0) - { - MS_THROW_ERROR("uname() failed: %s", std::strerror(err)); - } - - MS_DEBUG_TAG(info, "kernel version: %s", buffer.version); - - auto* kernelMayorCstr = buffer.release; - auto kernelMayorLong = strtol(kernelMayorCstr, &kernelMayorCstr, 10); - - // liburing `sento` capabilities are supported for kernel versions greather - // than or equal to 6. - return kernelMayorLong >= 6; -} - void DepLibUring::ClassInit() { const auto mayor = io_uring_major_version(); @@ -144,6 +121,9 @@ void DepLibUring::ClassInit() MS_DEBUG_TAG(info, "liburing version: \"%i.%i\"", mayor, minor); + // This must be called first. + DepLibUring::CheckRuntimeSupport(); + if (DepLibUring::IsRuntimeSupported()) { DepLibUring::liburing = new LibUring(); @@ -163,6 +143,34 @@ void DepLibUring::ClassDestroy() delete DepLibUring::liburing; } +void DepLibUring::CheckRuntimeSupport() +{ + // clang-format off + struct utsname buffer{}; + // clang-format on + + auto err = uname(std::addressof(buffer)); + + if (err != 0) + { + MS_THROW_ERROR("uname() failed: %s", std::strerror(err)); + } + + MS_DEBUG_TAG(info, "kernel version: %s", buffer.version); + + auto* kernelMayorCstr = buffer.release; + auto kernelMayorLong = strtol(kernelMayorCstr, &kernelMayorCstr, 10); + + // liburing `sento` capabilities are supported for kernel versions greather + // than or equal to 6. + DepLibUring::runtimeSupported = kernelMayorLong >= 6; +} + +bool DepLibUring::IsRuntimeSupported() +{ + return DepLibUring::runtimeSupported; +} + flatbuffers::Offset DepLibUring::FillBuffer(flatbuffers::FlatBufferBuilder& builder) { MS_TRACE(); @@ -580,7 +588,7 @@ void DepLibUring::LibUring::Submit() MS_TRACE(); // Unset active flag. - this->active = false; + SetInactive(); auto err = io_uring_submit(std::addressof(this->ring)); From ad02c78e9171139314eb962ec9df3a0d297fbada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 9 Aug 2024 13:31:11 +0200 Subject: [PATCH 02/11] more --- worker/include/DepLibUring.hpp | 5 ++-- worker/src/DepLibUring.cpp | 48 +++++++++++----------------------- worker/src/DepUsrSCTP.cpp | 15 ++++++----- 3 files changed, 27 insertions(+), 41 deletions(-) diff --git a/worker/include/DepLibUring.hpp b/worker/include/DepLibUring.hpp index 7c8f0357c3..0aa3cb9e6e 100644 --- a/worker/include/DepLibUring.hpp +++ b/worker/include/DepLibUring.hpp @@ -36,7 +36,7 @@ class DepLibUring static void ClassInit(); static void ClassDestroy(); static void CheckRuntimeSupport(); - static bool IsRuntimeSupported(); + static bool IsEnabled(); static flatbuffers::Offset FillBuffer(flatbuffers::FlatBufferBuilder& builder); static void StartPollingCQEs(); static void StopPollingCQEs(); @@ -52,7 +52,8 @@ class DepLibUring class LibUring; thread_local static LibUring* liburing; - static bool runtimeSupported{ false }; + // Whether liburing is enabled or not after runtime checks. + static bool enabled{ false }; private: // Private singleton. diff --git a/worker/src/DepLibUring.cpp b/worker/src/DepLibUring.cpp index ee64880c5e..4aaca5123c 100644 --- a/worker/src/DepLibUring.cpp +++ b/worker/src/DepLibUring.cpp @@ -124,15 +124,15 @@ void DepLibUring::ClassInit() // This must be called first. DepLibUring::CheckRuntimeSupport(); - if (DepLibUring::IsRuntimeSupported()) + if (DepLibUring::IsEnabled()) { DepLibUring::liburing = new LibUring(); - MS_DEBUG_TAG(info, "liburing supported, enabled"); + MS_DEBUG_TAG(info, "liburing enabled"); } else { - MS_DEBUG_TAG(info, "liburing not supported, not enabled"); + MS_DEBUG_TAG(info, "liburing not enabled"); } } @@ -163,22 +163,19 @@ void DepLibUring::CheckRuntimeSupport() // liburing `sento` capabilities are supported for kernel versions greather // than or equal to 6. - DepLibUring::runtimeSupported = kernelMayorLong >= 6; + DepLibUring::enabled = kernelMayorLong >= 6; } -bool DepLibUring::IsRuntimeSupported() +bool DepLibUring::IsEnabled() { - return DepLibUring::runtimeSupported; + return DepLibUring::enabled; } flatbuffers::Offset DepLibUring::FillBuffer(flatbuffers::FlatBufferBuilder& builder) { MS_TRACE(); - if (!DepLibUring::liburing) - { - return 0; - } + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); return DepLibUring::liburing->FillBuffer(builder); } @@ -187,10 +184,7 @@ void DepLibUring::StartPollingCQEs() { MS_TRACE(); - if (!DepLibUring::liburing) - { - return; - } + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); DepLibUring::liburing->StartPollingCQEs(); } @@ -199,10 +193,7 @@ void DepLibUring::StopPollingCQEs() { MS_TRACE(); - if (!DepLibUring::liburing) - { - return; - } + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); DepLibUring::liburing->StopPollingCQEs(); } @@ -211,7 +202,7 @@ uint8_t* DepLibUring::GetSendBuffer() { MS_TRACE(); - MS_ASSERT(DepLibUring::liburing, "DepLibUring::liburing is not set"); + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); return DepLibUring::liburing->GetSendBuffer(); } @@ -221,7 +212,7 @@ bool DepLibUring::PrepareSend( { MS_TRACE(); - MS_ASSERT(DepLibUring::liburing, "DepLibUring::liburing is not set"); + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); return DepLibUring::liburing->PrepareSend(sockfd, data, len, addr, cb); } @@ -231,7 +222,7 @@ bool DepLibUring::PrepareWrite( { MS_TRACE(); - MS_ASSERT(DepLibUring::liburing, "DepLibUring::liburing is not set"); + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); return DepLibUring::liburing->PrepareWrite(sockfd, data1, len1, data2, len2, cb); } @@ -240,10 +231,7 @@ void DepLibUring::Submit() { MS_TRACE(); - if (!DepLibUring::liburing) - { - return; - } + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); DepLibUring::liburing->Submit(); } @@ -252,10 +240,7 @@ void DepLibUring::SetActive() { MS_TRACE(); - if (!DepLibUring::liburing) - { - return; - } + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); DepLibUring::liburing->SetActive(); } @@ -264,10 +249,7 @@ bool DepLibUring::IsActive() { MS_TRACE(); - if (!DepLibUring::liburing) - { - return false; - } + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); return DepLibUring::liburing->IsActive(); } diff --git a/worker/src/DepUsrSCTP.cpp b/worker/src/DepUsrSCTP.cpp index 700bac3348..a8c179a4c2 100644 --- a/worker/src/DepUsrSCTP.cpp +++ b/worker/src/DepUsrSCTP.cpp @@ -251,12 +251,15 @@ void DepUsrSCTP::Checker::OnTimer(TimerHandle* /*timer*/) const int elapsedMs = this->lastCalledAtMs ? static_cast(nowMs - this->lastCalledAtMs) : 0; #ifdef MS_LIBURING_SUPPORTED - // Activate liburing usage. - // 'usrsctp_handle_timers()' will synchronously call the send/recv - // callbacks for the pending data. If there are multiple messages to be - // sent over the network then we will send those messages within a single - // system call. - DepLibUring::SetActive(); + if (DepLibUring::IsEnabled()) + { + // Activate liburing usage. + // 'usrsctp_handle_timers()' will synchronously call the send/recv + // callbacks for the pending data. If there are multiple messages to be + // sent over the network then we will send those messages within a single + // system call. + DepLibUring::SetActive(); + } #endif usrsctp_handle_timers(elapsedMs); From 7ae231a27102d5ba3ba08cef2f9411b6f58dcf03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 9 Aug 2024 13:46:33 +0200 Subject: [PATCH 03/11] almost done but not yet --- worker/include/DepLibUring.hpp | 4 +-- worker/src/DepLibUring.cpp | 3 +- worker/src/DepUsrSCTP.cpp | 7 +++-- worker/src/RTC/Router.cpp | 32 +++++++++++++++------- worker/src/RTC/RtpStreamSend.cpp | 14 +++++++--- worker/src/RTC/SrtpSession.cpp | 1 + worker/src/RTC/Transport.cpp | 14 +++++++--- worker/src/Worker.cpp | 14 +++++++--- worker/src/handles/TcpConnectionHandle.cpp | 12 +++++--- worker/src/handles/UdpSocketHandle.cpp | 12 +++++--- 10 files changed, 78 insertions(+), 35 deletions(-) diff --git a/worker/include/DepLibUring.hpp b/worker/include/DepLibUring.hpp index 0aa3cb9e6e..cf7b883a52 100644 --- a/worker/include/DepLibUring.hpp +++ b/worker/include/DepLibUring.hpp @@ -51,9 +51,9 @@ class DepLibUring class LibUring; - thread_local static LibUring* liburing; // Whether liburing is enabled or not after runtime checks. - static bool enabled{ false }; + static bool enabled; + thread_local static LibUring* liburing; private: // Private singleton. diff --git a/worker/src/DepLibUring.cpp b/worker/src/DepLibUring.cpp index 4aaca5123c..d2a9ef533d 100644 --- a/worker/src/DepLibUring.cpp +++ b/worker/src/DepLibUring.cpp @@ -10,7 +10,7 @@ #include /* Static variables. */ - +bool DepLibUring::enabled{ false }; /* liburing instance per thread. */ thread_local DepLibUring::LibUring* DepLibUring::liburing{ nullptr }; /* Completion queue entry array used to retrieve processes tasks. */ @@ -186,6 +186,7 @@ void DepLibUring::StartPollingCQEs() MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); + DepLibUring::liburing->StartPollingCQEs(); } diff --git a/worker/src/DepUsrSCTP.cpp b/worker/src/DepUsrSCTP.cpp index a8c179a4c2..a833a5aefb 100644 --- a/worker/src/DepUsrSCTP.cpp +++ b/worker/src/DepUsrSCTP.cpp @@ -265,8 +265,11 @@ void DepUsrSCTP::Checker::OnTimer(TimerHandle* /*timer*/) usrsctp_handle_timers(elapsedMs); #ifdef MS_LIBURING_SUPPORTED - // Submit all prepared submission entries. - DepLibUring::Submit(); + if (DepLibUring::IsEnabled()) + { + // Submit all prepared submission entries. + DepLibUring::Submit(); + } #endif this->lastCalledAtMs = nowMs; diff --git a/worker/src/RTC/Router.cpp b/worker/src/RTC/Router.cpp index fab0173952..b6e8ff513c 100644 --- a/worker/src/RTC/Router.cpp +++ b/worker/src/RTC/Router.cpp @@ -665,8 +665,11 @@ namespace RTC std::shared_ptr sharedPacket; #ifdef MS_LIBURING_SUPPORTED - // Activate liburing usage. - DepLibUring::SetActive(); + if (DepLibUring::IsEnabled()) + { + // Activate liburing usage. + DepLibUring::SetActive(); + } #endif for (auto* consumer : consumers) @@ -683,8 +686,11 @@ namespace RTC } #ifdef MS_LIBURING_SUPPORTED - // Submit all prepared submission entries. - DepLibUring::Submit(); + if (DepLibUring::IsEnabled()) + { + // Submit all prepared submission entries. + DepLibUring::Submit(); + } #endif } @@ -925,10 +931,13 @@ namespace RTC if (!dataConsumers.empty()) { #ifdef MS_LIBURING_SUPPORTED - // Activate liburing usage. - // The effective sending could be synchronous, thus we would send those - // messages within a single system call. - DepLibUring::SetActive(); + if (DepLibUring::IsEnabled()) + { + // Activate liburing usage. + // The effective sending could be synchronous, thus we would send those + // messages within a single system call. + DepLibUring::SetActive(); + } #endif for (auto* dataConsumer : dataConsumers) @@ -937,8 +946,11 @@ namespace RTC } #ifdef MS_LIBURING_SUPPORTED - // Submit all prepared submission entries. - DepLibUring::Submit(); + if (DepLibUring::IsEnabled()) + { + // Submit all prepared submission entries. + DepLibUring::Submit(); + } #endif } } diff --git a/worker/src/RTC/RtpStreamSend.cpp b/worker/src/RTC/RtpStreamSend.cpp index c0c6f6ce2a..d508bce83e 100644 --- a/worker/src/RTC/RtpStreamSend.cpp +++ b/worker/src/RTC/RtpStreamSend.cpp @@ -128,8 +128,11 @@ namespace RTC this->nackCount++; #ifdef MS_LIBURING_SUPPORTED - // Activate liburing usage. - DepLibUring::SetActive(); + if (DepLibUring::IsEnabled()) + { + // Activate liburing usage. + DepLibUring::SetActive(); + } #endif for (auto it = nackPacket->Begin(); it != nackPacket->End(); ++it) @@ -173,8 +176,11 @@ namespace RTC } #ifdef MS_LIBURING_SUPPORTED - // Submit all prepared submission entries. - DepLibUring::Submit(); + if (DepLibUring::IsEnabled()) + { + // Submit all prepared submission entries. + DepLibUring::Submit(); + } #endif } diff --git a/worker/src/RTC/SrtpSession.cpp b/worker/src/RTC/SrtpSession.cpp index 20755dc656..43eb597c15 100644 --- a/worker/src/RTC/SrtpSession.cpp +++ b/worker/src/RTC/SrtpSession.cpp @@ -204,6 +204,7 @@ namespace RTC uint8_t* encryptBuffer = EncryptBuffer; #ifdef MS_LIBURING_SUPPORTED + if (DepLibUring::IsEnabled()) { if (!DepLibUring::IsActive()) { diff --git a/worker/src/RTC/Transport.cpp b/worker/src/RTC/Transport.cpp index 89f5800ea3..eb469e70fb 100644 --- a/worker/src/RTC/Transport.cpp +++ b/worker/src/RTC/Transport.cpp @@ -2158,8 +2158,11 @@ namespace RTC std::unique_ptr packet{ new RTC::RTCP::CompoundPacket() }; #ifdef MS_LIBURING_SUPPORTED - // Activate liburing usage. - DepLibUring::SetActive(); + if (DepLibUring::IsEnabled()) + { + // Activate liburing usage. + DepLibUring::SetActive(); + } #endif for (auto& kv : this->mapConsumers) @@ -2207,8 +2210,11 @@ namespace RTC } #ifdef MS_LIBURING_SUPPORTED - // Submit all prepared submission entries. - DepLibUring::Submit(); + if (DepLibUring::IsEnabled()) + { + // Submit all prepared submission entries. + DepLibUring::Submit(); + } #endif } diff --git a/worker/src/Worker.cpp b/worker/src/Worker.cpp index 5a3e7f4670..a3372dfdfd 100644 --- a/worker/src/Worker.cpp +++ b/worker/src/Worker.cpp @@ -44,8 +44,11 @@ Worker::Worker(::Channel::ChannelSocket* channel) : channel(channel) DepUsrSCTP::CreateChecker(); #ifdef MS_LIBURING_SUPPORTED - // Start polling CQEs, which will create a uv_pool_t handle. - DepLibUring::StartPollingCQEs(); + if (DepLibUring::IsEnabled()) + { + // Start polling CQEs, which will create a uv_pool_t handle. + DepLibUring::StartPollingCQEs(); + } #endif // Tell the Node process that we are running. @@ -106,8 +109,11 @@ void Worker::Close() DepUsrSCTP::CloseChecker(); #ifdef MS_LIBURING_SUPPORTED - // Stop polling CQEs, which will close the uv_pool_t handle. - DepLibUring::StopPollingCQEs(); + if (DepLibUring::IsEnabled()) + { + // Stop polling CQEs, which will close the uv_pool_t handle. + DepLibUring::StopPollingCQEs(); + } #endif // Close the Channel. diff --git a/worker/src/handles/TcpConnectionHandle.cpp b/worker/src/handles/TcpConnectionHandle.cpp index 475a078ad0..ea53cb8ff9 100644 --- a/worker/src/handles/TcpConnectionHandle.cpp +++ b/worker/src/handles/TcpConnectionHandle.cpp @@ -168,11 +168,14 @@ void TcpConnectionHandle::Start() } #ifdef MS_LIBURING_SUPPORTED - err = uv_fileno(reinterpret_cast(this->uvHandle), std::addressof(this->fd)); - - if (err != 0) + if (DepLibUring::IsEnabled()) { - MS_THROW_ERROR("uv_fileno() failed: %s", uv_strerror(err)); + err = uv_fileno(reinterpret_cast(this->uvHandle), std::addressof(this->fd)); + + if (err != 0) + { + MS_THROW_ERROR("uv_fileno() failed: %s", uv_strerror(err)); + } } #endif } @@ -209,6 +212,7 @@ void TcpConnectionHandle::Write( } #ifdef MS_LIBURING_SUPPORTED + if (DepLibUring::IsEnabled()) { if (!DepLibUring::IsActive()) { diff --git a/worker/src/handles/UdpSocketHandle.cpp b/worker/src/handles/UdpSocketHandle.cpp index 2cb42e40c5..82da018c73 100644 --- a/worker/src/handles/UdpSocketHandle.cpp +++ b/worker/src/handles/UdpSocketHandle.cpp @@ -88,11 +88,14 @@ UdpSocketHandle::UdpSocketHandle(uv_udp_t* uvHandle) : uvHandle(uvHandle) } #ifdef MS_LIBURING_SUPPORTED - err = uv_fileno(reinterpret_cast(this->uvHandle), std::addressof(this->fd)); - - if (err != 0) + if (DepLibUring::IsEnabled()) { - MS_THROW_ERROR("uv_fileno() failed: %s", uv_strerror(err)); + err = uv_fileno(reinterpret_cast(this->uvHandle), std::addressof(this->fd)); + + if (err != 0) + { + MS_THROW_ERROR("uv_fileno() failed: %s", uv_strerror(err)); + } } #endif } @@ -144,6 +147,7 @@ void UdpSocketHandle::Send( } #ifdef MS_LIBURING_SUPPORTED + if (DepLibUring::IsEnabled()) { if (!DepLibUring::IsActive()) { From c7716157f0d823a9daf6f1447e37488676c24f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 9 Aug 2024 13:48:02 +0200 Subject: [PATCH 04/11] maybe done --- worker/src/DepLibUring.cpp | 1 - worker/src/Worker.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/worker/src/DepLibUring.cpp b/worker/src/DepLibUring.cpp index d2a9ef533d..808391d83e 100644 --- a/worker/src/DepLibUring.cpp +++ b/worker/src/DepLibUring.cpp @@ -186,7 +186,6 @@ void DepLibUring::StartPollingCQEs() MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); - DepLibUring::liburing->StartPollingCQEs(); } diff --git a/worker/src/Worker.cpp b/worker/src/Worker.cpp index a3372dfdfd..01c4d90429 100644 --- a/worker/src/Worker.cpp +++ b/worker/src/Worker.cpp @@ -156,7 +156,7 @@ flatbuffers::Offset Worker::FillBuffer( channelMessageHandlers #ifdef MS_LIBURING_SUPPORTED , - DepLibUring::FillBuffer(builder) + DepLibUring::IsEnabled() ? DepLibUring::FillBuffer(builder) : nullptr #endif ); } From a3bff47695a882011d9133abca9bfdd61599b47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 9 Aug 2024 13:52:06 +0200 Subject: [PATCH 05/11] try --- worker/include/DepLibUring.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/worker/include/DepLibUring.hpp b/worker/include/DepLibUring.hpp index cf7b883a52..aa7fe30f88 100644 --- a/worker/include/DepLibUring.hpp +++ b/worker/include/DepLibUring.hpp @@ -49,7 +49,8 @@ class DepLibUring static void SetActive(); static bool IsActive(); - class LibUring; + private: + class LibUring; // Whether liburing is enabled or not after runtime checks. static bool enabled; From d6178abe5eabf100566a7f49fc5f495030c7113a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 9 Aug 2024 14:05:04 +0200 Subject: [PATCH 06/11] ok... --- worker/include/DepLibUring.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/worker/include/DepLibUring.hpp b/worker/include/DepLibUring.hpp index aa7fe30f88..a0b041c899 100644 --- a/worker/include/DepLibUring.hpp +++ b/worker/include/DepLibUring.hpp @@ -49,15 +49,14 @@ class DepLibUring static void SetActive(); static bool IsActive(); - private: - class LibUring; + class LibUring; // Whether liburing is enabled or not after runtime checks. static bool enabled; thread_local static LibUring* liburing; -private: - // Private singleton. +public: + // Singleton. class LibUring { public: From 776a05250519a38e1aee555074dc3c59bef6bdbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 9 Aug 2024 14:11:08 +0200 Subject: [PATCH 07/11] ok I give up... --- worker/src/Worker.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/worker/src/Worker.cpp b/worker/src/Worker.cpp index 01c4d90429..e8eaed06d7 100644 --- a/worker/src/Worker.cpp +++ b/worker/src/Worker.cpp @@ -148,17 +148,26 @@ flatbuffers::Offset Worker::FillBuffer( // Add channelMessageHandlers. auto channelMessageHandlers = this->shared->channelMessageRegistrator->FillBuffer(builder); - return FBS::Worker::CreateDumpResponseDirect( - builder, - Logger::Pid, - &webRtcServerIds, - &routerIds, - channelMessageHandlers #ifdef MS_LIBURING_SUPPORTED - , - DepLibUring::IsEnabled() ? DepLibUring::FillBuffer(builder) : nullptr + if (DepLibUring::IsEnabled()) + { + return FBS::Worker::CreateDumpResponseDirect( + builder, + Logger::Pid, + &webRtcServerIds, + &routerIds, + channelMessageHandlers, + DepLibUring::FillBuffer(builder)); + } + else + { + return FBS::Worker::CreateDumpResponseDirect( + builder, Logger::Pid, &webRtcServerIds, &routerIds, channelMessageHandlers, ); + } +#else + return FBS::Worker::CreateDumpResponseDirect( + builder, Logger::Pid, &webRtcServerIds, &routerIds, channelMessageHandlers, ); #endif - ); } flatbuffers::Offset Worker::FillBufferResourceUsage( From d484996ea6dbe7626d69c1e26601ae6e2ec64aea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 9 Aug 2024 14:19:42 +0200 Subject: [PATCH 08/11] lint --- worker/src/Worker.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worker/src/Worker.cpp b/worker/src/Worker.cpp index e8eaed06d7..2785301357 100644 --- a/worker/src/Worker.cpp +++ b/worker/src/Worker.cpp @@ -162,11 +162,11 @@ flatbuffers::Offset Worker::FillBuffer( else { return FBS::Worker::CreateDumpResponseDirect( - builder, Logger::Pid, &webRtcServerIds, &routerIds, channelMessageHandlers, ); + builder, Logger::Pid, &webRtcServerIds, &routerIds, channelMessageHandlers); } #else return FBS::Worker::CreateDumpResponseDirect( - builder, Logger::Pid, &webRtcServerIds, &routerIds, channelMessageHandlers, ); + builder, Logger::Pid, &webRtcServerIds, &routerIds, channelMessageHandlers); #endif } From 989d9dc3e238f8590569ad8b6051ae948fdd6c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 9 Aug 2024 14:21:48 +0200 Subject: [PATCH 09/11] cosmetic --- worker/src/DepLibUring.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/worker/src/DepLibUring.cpp b/worker/src/DepLibUring.cpp index 808391d83e..c5e8aed778 100644 --- a/worker/src/DepLibUring.cpp +++ b/worker/src/DepLibUring.cpp @@ -175,7 +175,7 @@ flatbuffers::Offset DepLibUring::FillBuffer(flatbuffers::Fl { MS_TRACE(); - MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled"); return DepLibUring::liburing->FillBuffer(builder); } @@ -184,7 +184,7 @@ void DepLibUring::StartPollingCQEs() { MS_TRACE(); - MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled"); DepLibUring::liburing->StartPollingCQEs(); } @@ -193,7 +193,7 @@ void DepLibUring::StopPollingCQEs() { MS_TRACE(); - MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled"); DepLibUring::liburing->StopPollingCQEs(); } @@ -202,7 +202,7 @@ uint8_t* DepLibUring::GetSendBuffer() { MS_TRACE(); - MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled"); return DepLibUring::liburing->GetSendBuffer(); } @@ -212,7 +212,7 @@ bool DepLibUring::PrepareSend( { MS_TRACE(); - MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled"); return DepLibUring::liburing->PrepareSend(sockfd, data, len, addr, cb); } @@ -222,7 +222,7 @@ bool DepLibUring::PrepareWrite( { MS_TRACE(); - MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled"); return DepLibUring::liburing->PrepareWrite(sockfd, data1, len1, data2, len2, cb); } @@ -231,7 +231,7 @@ void DepLibUring::Submit() { MS_TRACE(); - MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled"); DepLibUring::liburing->Submit(); } @@ -240,7 +240,7 @@ void DepLibUring::SetActive() { MS_TRACE(); - MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled"); DepLibUring::liburing->SetActive(); } @@ -249,7 +249,7 @@ bool DepLibUring::IsActive() { MS_TRACE(); - MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported"); + MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not enabled"); return DepLibUring::liburing->IsActive(); } From 600ff0467f768ecbc6e6beb4546001ea3c64ff85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 9 Aug 2024 14:56:01 +0200 Subject: [PATCH 10/11] Add ubuntu-24.04 to CI actions --- .github/workflows/mediasoup-rust.yaml | 1 + .github/workflows/mediasoup-worker-fuzzer.yaml | 2 +- .github/workflows/mediasoup-worker.yaml | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/mediasoup-rust.yaml b/.github/workflows/mediasoup-rust.yaml index 9b76ffcb22..812cbae213 100644 --- a/.github/workflows/mediasoup-rust.yaml +++ b/.github/workflows/mediasoup-rust.yaml @@ -18,6 +18,7 @@ jobs: ci: - os: ubuntu-20.04 - os: ubuntu-22.04 + - os: ubuntu-24.04 - os: macos-12 - os: macos-14 - os: windows-2022 diff --git a/.github/workflows/mediasoup-worker-fuzzer.yaml b/.github/workflows/mediasoup-worker-fuzzer.yaml index 8f47946802..fae1d7479e 100644 --- a/.github/workflows/mediasoup-worker-fuzzer.yaml +++ b/.github/workflows/mediasoup-worker-fuzzer.yaml @@ -13,7 +13,7 @@ jobs: strategy: matrix: build: - - os: ubuntu-22.04 + - os: ubuntu-24.04 cc: clang cxx: clang++ build-type: diff --git a/.github/workflows/mediasoup-worker.yaml b/.github/workflows/mediasoup-worker.yaml index b9522d2215..a97c6ccdf7 100644 --- a/.github/workflows/mediasoup-worker.yaml +++ b/.github/workflows/mediasoup-worker.yaml @@ -31,6 +31,12 @@ jobs: - os: ubuntu-22.04 cc: clang cxx: clang++ + - os: ubuntu-24.04 + cc: gcc + cxx: g++ + - os: ubuntu-24.04 + cc: clang + cxx: clang++ - os: macos-12 cc: gcc cxx: g++ From 8ab79df604df6d1ef2fe275c67b95ddea383cc7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 9 Aug 2024 16:56:24 +0200 Subject: [PATCH 11/11] fix pip usage --- .github/workflows/mediasoup-worker-fuzzer.yaml | 7 ++++--- .github/workflows/mediasoup-worker-prebuild.yaml | 2 ++ .github/workflows/mediasoup-worker.yaml | 10 +++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/mediasoup-worker-fuzzer.yaml b/.github/workflows/mediasoup-worker-fuzzer.yaml index fae1d7479e..c748ce6e67 100644 --- a/.github/workflows/mediasoup-worker-fuzzer.yaml +++ b/.github/workflows/mediasoup-worker-fuzzer.yaml @@ -16,6 +16,7 @@ jobs: - os: ubuntu-24.04 cc: clang cxx: clang++ + pip-break-system-packages: true build-type: - Release - Debug @@ -34,12 +35,12 @@ jobs: uses: actions/checkout@v4 # We need to install pip invoke manually. - - if: runner.os != 'macOS' + - if: ${{ !matrix.build.pip-break-system-packages }} name: pip3 install invoke run: pip3 install invoke - # In macOS we need to specify this option. - - if: runner.os == 'macOS' + # In modern OSs we need to run pip with this option. + - if: ${{ matrix.build.pip-break-system-packages }} name: pip3 install --break-system-packages invoke run: pip3 install --break-system-packages invoke diff --git a/.github/workflows/mediasoup-worker-prebuild.yaml b/.github/workflows/mediasoup-worker-prebuild.yaml index e0c458a903..5c51a72be8 100644 --- a/.github/workflows/mediasoup-worker-prebuild.yaml +++ b/.github/workflows/mediasoup-worker-prebuild.yaml @@ -19,6 +19,8 @@ jobs: cc: gcc cxx: g++ # Worker prebuild for Linux with kernel version 6 Ubuntu (22.04). + # Let's not use Ubutu 24.04 to avoid same potential problem as described + # above. - os: ubuntu-22.04 cc: gcc cxx: g++ diff --git a/.github/workflows/mediasoup-worker.yaml b/.github/workflows/mediasoup-worker.yaml index a97c6ccdf7..cfa1498022 100644 --- a/.github/workflows/mediasoup-worker.yaml +++ b/.github/workflows/mediasoup-worker.yaml @@ -34,15 +34,19 @@ jobs: - os: ubuntu-24.04 cc: gcc cxx: g++ + pip-break-system-packages: true - os: ubuntu-24.04 cc: clang cxx: clang++ + pip-break-system-packages: true - os: macos-12 cc: gcc cxx: g++ + pip-break-system-packages: true - os: macos-14 cc: clang cxx: clang++ + pip-break-system-packages: true - os: windows-2022 cc: cl cxx: cl @@ -81,12 +85,12 @@ jobs: ${{ matrix.build.os }}-node-${{matrix.build.cc}}- # We need to install pip invoke manually. - - if: runner.os != 'macOS' + - if: ${{ !matrix.build.pip-break-system-packages }} name: pip3 install invoke run: pip3 install invoke - # In macOS we need to specify this option. - - if: runner.os == 'macOS' + # In modern OSs we need to run pip with this option. + - if: ${{ matrix.build.pip-break-system-packages }} name: pip3 install --break-system-packages invoke run: pip3 install --break-system-packages invoke