Skip to content

Commit

Permalink
Async: Add AsyncEventLoop::tryLoadingLibUring
Browse files Browse the repository at this point in the history
  • Loading branch information
Pagghiu committed Feb 17, 2024
1 parent 64d9932 commit 76d8c90
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Libraries/Async/Async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,3 +658,8 @@ SC::Result SC::AsyncEventLoop::associateExternallyCreatedFileDescriptor(FileDesc
}

SC::Result SC::AsyncLoopWakeUp::wakeUp() { return getEventLoop()->wakeUpFromExternalThread(*this); }

#if SC_PLATFORM_LINUX
#else
bool SC::AsyncEventLoop::tryLoadingLiburing() { return false; }
#endif
4 changes: 4 additions & 0 deletions Libraries/Async/Async.h
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,10 @@ struct SC::AsyncEventLoop
/// Get Loop time
[[nodiscard]] Time::HighResolutionCounter getLoopTime() const { return loopTime; }

/// Check if liburing is loadable (only on Linux)
/// @return true if liburing has been loaded, false otherwise (and on any non-Linux os)
[[nodiscard]] static bool tryLoadingLiburing();

private:
int numberOfActiveHandles = 0;
int numberOfExternals = 0;
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Async/Internal/AsyncLinux.inl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ struct SC::AsyncEventLoop::KernelQueue
// TODO: Protect it with a mutex or force passing it during creation
static AsyncLinuxLibURingLoader globalLibURing;

bool SC::AsyncEventLoop::tryLoadingLiburing() { return globalLibURing.init(); }

struct SC::AsyncEventLoop::InternalIoURing
{
static constexpr int QueueDepth = 64;
Expand Down
20 changes: 13 additions & 7 deletions Libraries/Async/Tests/AsyncTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ struct SC::AsyncTest : public SC::TestCase
AsyncEventLoop::Options options;
AsyncTest(SC::TestReport& report) : TestCase(report, "AsyncTest")
{
#if SC_PLATFORM_LINUX
// First run all the tests on IOURing and then on epoll
options.apiType = AsyncEventLoop::Options::ApiType::ForceUseIOURing;
for (int i = 0; i < 2; ++i)
#endif
int numTestsToRun = 1;
if (AsyncEventLoop::tryLoadingLiburing())
{
// Run all tests on epoll backend first, and then re-run them on io_uring
options.apiType = AsyncEventLoop::Options::ApiType::ForceUseEpoll;
numTestsToRun = 2;
}
for (int i = 0; i < numTestsToRun; ++i)
{
loopTimeout();
loopWakeUpFromExternalThread();
Expand All @@ -36,8 +39,11 @@ struct SC::AsyncTest : public SC::TestCase
socketClose();
fileReadWrite();
fileClose();
// Next run will be on epoll, in case of Linux
options.apiType = AsyncEventLoop::Options::ApiType::ForceUseEpoll;
if (numTestsToRun == 2)
{
// If on Linux next run will test io_uring backend (if it's installed)
options.apiType = AsyncEventLoop::Options::ApiType::ForceUseIOURing;
}
}
}

Expand Down

0 comments on commit 76d8c90

Please sign in to comment.