From 137824eb77e9dc3fccc6841ad4bbdbc43886a397 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 23 Feb 2023 16:24:16 -0800 Subject: [PATCH] construct: Interpose IORING_SETUP_COOP_TASKRUN where supported. --- construct/Makefile.am | 1 + construct/construct.cc | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/construct/Makefile.am b/construct/Makefile.am index 3ca824b4f..60feb0657 100644 --- a/construct/Makefile.am +++ b/construct/Makefile.am @@ -32,6 +32,7 @@ AM_LDFLAGS = \ -Wl,--rosegment \ -Wl,-z,noexecstack \ -Wl,--wrap=epoll_wait \ + -Wl,--wrap=io_uring_queue_init \ -L$(top_srcdir)/ircd \ -L$(top_srcdir)/modules \ $(PLATFORM_LDFLAGS) \ diff --git a/construct/construct.cc b/construct/construct.cc index 43275d081..fa6507e5a 100644 --- a/construct/construct.cc +++ b/construct/construct.cc @@ -50,6 +50,7 @@ const char *bootstrap; const char *diagnostic; bool nobanner; bool silentmode; +bool noiouct; lgetopt opts[] { @@ -87,6 +88,7 @@ lgetopt opts[] { "diagnostic", &diagnostic, lgetopt::STRING, "Specify a diagnostic type in conjunction with other commands" }, { "nobanner", &nobanner, lgetopt::BOOL, "Terminal log enabled only in runlevel RUN" }, { "silent", &silentmode, lgetopt::BOOL, "Like quiet mode without console output either" }, + { "noiouct", &noiouct, lgetopt::BOOL, "Disable experimental IORING_SETUP_COOP_TASKRUN" }, { nullptr, nullptr, lgetopt::STRING, nullptr }, }; @@ -671,3 +673,59 @@ __wrap_epoll_wait(int __epfd, } #endif + +/////////////////////////////////////////////////////////////////////////////// +// +// This is where we interpose additional features for io_uring not yet +// leveraged by ASIO. +// +#if IRCD_USE_ASIO_IO_URING + +extern "C" int +__real_io_uring_queue_init(unsigned, + struct io_uring *, + unsigned flags); + +extern "C" int +__wrap_io_uring_queue_init(unsigned entries, + struct io_uring *ring, + unsigned flags) +{ + namespace info = ircd::info; + + const bool have_coop_taskrun + { + info::kernel_version[0] > 5 || + (info::kernel_version[0] >= 5 && info::kernel_version[1] >= 19) + }; + + #if defined(IORING_SETUP_COOP_TASKRUN) + if(have_coop_taskrun && !noiouct) + flags |= IORING_SETUP_COOP_TASKRUN; + #endif + + struct io_uring_params params + { + .flags = flags, + }; + + int ret; + if constexpr((true)) + ret = ::io_uring_queue_init_params + ( + entries, + ring, + ¶ms + ); + else + ret = __real_io_uring_queue_init + ( + entries, + ring, + flags + ); + + return ret; +} + +#endif