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()) {