Skip to content

Commit

Permalink
bp/Config: add option io_uring_sqpoll
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jan 17, 2025
1 parent 7ab5a1a commit 86564cd
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions doc/bp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ The following settings are available:
which can make debugging with ``strace`` easier, because ``strace``
cannot see ``io_uring`` operations.

- ``io_uring_sqpoll``: Enables ``io_uring`` submit-queue polling.
This reduces the number of ``io_uring_enter()`` system calls at the
cost of a kernel thread running at 100% all the time, busy-polling
for new entries.

- ``verbose_response``: Set to ``yes`` to reveal internal error
messages in HTTP responses.

Expand Down
2 changes: 1 addition & 1 deletion libcommon
2 changes: 2 additions & 0 deletions src/bp/Config.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ BpConfig::HandleSet(std::string_view name, const char *value)
use_xattr = ParseBool(value);
} else if (name == "use_io_uring"sv) {
use_io_uring = ParseBool(value);
} else if (name == "io_uring_sqpoll"sv) {
io_uring_sqpoll = ParseBool(value);
} else if (name == "verbose_response"sv) {
verbose_response = ParseBool(value);
} else if (name == "session_cookie"sv) {
Expand Down
2 changes: 2 additions & 0 deletions src/bp/Config.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ struct BpConfig {

bool use_io_uring = true;

bool io_uring_sqpoll = false;

SpawnConfig spawn;

SslClientConfig ssl_client;
Expand Down
6 changes: 5 additions & 1 deletion src/bp/Instance.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ struct BpInstance final : PInstance, BengControl::Handler,
HttpStats http_stats;

[[no_unique_address]]
UringGlue uring{event_loop, config.use_io_uring};
UringGlue uring{
event_loop,
config.use_io_uring,
config.io_uring_sqpoll,
};

const StateDirectories state_directories;

Expand Down
9 changes: 7 additions & 2 deletions src/bp/UringGlue.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@
#include <sys/stat.h>

UringGlue::UringGlue([[maybe_unused]] EventLoop &event_loop,
[[maybe_unused]] bool enable) noexcept
[[maybe_unused]] bool enable,
[[maybe_unused]] bool sqpoll) noexcept
{
#ifdef HAVE_URING
if (!enable)
return;

unsigned flags = 0;
if (sqpoll)
flags |= IORING_SETUP_SQPOLL;

try {
uring.emplace(event_loop, 16384);
uring.emplace(event_loop, 16384, flags);
} catch (...) {
fprintf(stderr, "Failed to initialize io_uring: ");
PrintException(std::current_exception());
Expand Down
3 changes: 2 additions & 1 deletion src/bp/UringGlue.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class UringGlue {
#endif

public:
explicit UringGlue(EventLoop &event_loop, bool enable) noexcept;
explicit UringGlue(EventLoop &event_loop, bool enable,
bool sqpoll) noexcept;

void SetVolatile() noexcept;

Expand Down

0 comments on commit 86564cd

Please sign in to comment.