Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Aug 9, 2024
1 parent 54c80c7 commit ad02c78
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 41 deletions.
5 changes: 3 additions & 2 deletions worker/include/DepLibUring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DepLibUring
static void ClassInit();
static void ClassDestroy();
static void CheckRuntimeSupport();
static bool IsRuntimeSupported();
static bool IsEnabled();
static flatbuffers::Offset<FBS::LibUring::Dump> FillBuffer(flatbuffers::FlatBufferBuilder& builder);
static void StartPollingCQEs();
static void StopPollingCQEs();
Expand All @@ -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.
Expand Down
48 changes: 15 additions & 33 deletions worker/src/DepLibUring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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<FBS::LibUring::Dump> 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);
}
Expand All @@ -187,10 +184,7 @@ void DepLibUring::StartPollingCQEs()
{
MS_TRACE();

if (!DepLibUring::liburing)
{
return;
}
MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported");

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

if (!DepLibUring::liburing)
{
return;
}
MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported");

DepLibUring::liburing->StopPollingCQEs();
}
Expand All @@ -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();
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -240,10 +231,7 @@ void DepLibUring::Submit()
{
MS_TRACE();

if (!DepLibUring::liburing)
{
return;
}
MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported");

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

if (!DepLibUring::liburing)
{
return;
}
MS_ASSERT(DepLibUring::enabled, "DepLibUring::liburing not supported");

DepLibUring::liburing->SetActive();
}
Expand All @@ -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();
}
Expand Down
15 changes: 9 additions & 6 deletions worker/src/DepUsrSCTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,15 @@ void DepUsrSCTP::Checker::OnTimer(TimerHandle* /*timer*/)
const int elapsedMs = this->lastCalledAtMs ? static_cast<int>(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);
Expand Down

0 comments on commit ad02c78

Please sign in to comment.