diff --git a/doc/bp.rst b/doc/bp.rst index e0c66db62..3451e13f2 100644 --- a/doc/bp.rst +++ b/doc/bp.rst @@ -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. diff --git a/libcommon b/libcommon index fec4ac2fb..230789b0f 160000 --- a/libcommon +++ b/libcommon @@ -1 +1 @@ -Subproject commit fec4ac2fb2a4470ed281930ca636363d28934c59 +Subproject commit 230789b0f67db10faa7ecae9dcc868c0466c9b14 diff --git a/src/bp/Config.cxx b/src/bp/Config.cxx index 1f2229a63..0996b465c 100644 --- a/src/bp/Config.cxx +++ b/src/bp/Config.cxx @@ -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) { diff --git a/src/bp/Config.hxx b/src/bp/Config.hxx index 270bf0366..ae9d8eda0 100644 --- a/src/bp/Config.hxx +++ b/src/bp/Config.hxx @@ -95,6 +95,8 @@ struct BpConfig { bool use_io_uring = true; + bool io_uring_sqpoll = false; + SpawnConfig spawn; SslClientConfig ssl_client; diff --git a/src/bp/Instance.hxx b/src/bp/Instance.hxx index a891a4bc5..b278b21b5 100644 --- a/src/bp/Instance.hxx +++ b/src/bp/Instance.hxx @@ -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; diff --git a/src/bp/UringGlue.cxx b/src/bp/UringGlue.cxx index f7aa05995..2a18d2c63 100644 --- a/src/bp/UringGlue.cxx +++ b/src/bp/UringGlue.cxx @@ -22,14 +22,19 @@ #include 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()); diff --git a/src/bp/UringGlue.hxx b/src/bp/UringGlue.hxx index 7950f1ff0..7b0ff4629 100644 --- a/src/bp/UringGlue.hxx +++ b/src/bp/UringGlue.hxx @@ -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;