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);