diff --git a/emper/Emper.hpp b/emper/Emper.hpp index bbebc22ac9cc083a14f11d528c273479ab2f3032..8a04980038cc238138f9c85182113a9295605bad 100644 --- a/emper/Emper.hpp +++ b/emper/Emper.hpp @@ -89,4 +89,12 @@ static const bool IO_URING_SQPOLL = false #endif ; + +static const bool IO_URING_SHARED_WQ = +#ifdef EMPER_IO_URING_SHARED_WQ + true +#else + false +#endif + ; } // namespace emper diff --git a/emper/Runtime.hpp b/emper/Runtime.hpp index 05c0ea5119cab09aff3ba8544fda2807232ab1e6..803d935d38fb15e7a8a58ec24b8142985781373e 100644 --- a/emper/Runtime.hpp +++ b/emper/Runtime.hpp @@ -58,7 +58,7 @@ class Runtime : public Logger<LogSubsystem::RUNTI> { ContextManager& contextManager; pthread_t* threads; Worker** workers; - IoContext* globalIo; + IoContext* globalIo = nullptr; IoContext* ioContexts; std::default_random_engine randomEngine; diff --git a/emper/io/IoContext.cpp b/emper/io/IoContext.cpp index b7c1c5994f440ec43e33b3780e79faf0d67d46f0..6768524fc08384646cd69541a84a0cb3aae805ee 100644 --- a/emper/io/IoContext.cpp +++ b/emper/io/IoContext.cpp @@ -351,6 +351,14 @@ IoContext::IoContext(size_t uring_entries) { params.flags |= IORING_SETUP_SQPOLL; } + if constexpr (emper::IO_URING_SHARED_WQ) { + auto *gio = getGlobalIo(); + if (gio) { + params.flags |= IORING_SETUP_ATTACH_WQ; + params.wq_fd = gio->ring.ring_fd; + } + } + auto ret = io_uring_queue_init_params(uring_entries, &ring, ¶ms); if (ret < 0) { DIE_MSG_ERRNO("io_uring_queue_init failed"); diff --git a/meson.build b/meson.build index 00d1255221521dccfdaa1c4d64582bee989891ab..8385425d316dca6f19deee3b3187f5b0c04141df 100644 --- a/meson.build +++ b/meson.build @@ -56,6 +56,7 @@ endif io_bool_options = [ 'uring_sqpoll', + 'uring_shared_wq', ] io_raw_options = [ diff --git a/meson_options.txt b/meson_options.txt index 3fa7046edbbeb637f20992cabfafab10626d40cf..ab067837f023da3b784c9b7b462d4ea884c41dba 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -92,3 +92,9 @@ option( value: false, description: 'Enable io_urings SQPOLL feature (start a separate kernel thread which polls the sq reducing the amount of syscalls to submit new requests. This is a privileged operation.).' ) +option( + 'io_uring_shared_wq', + type: 'boolean', + value: false, + description: 'Share a common async backend between all io_urings' +)