From da55b185da17bcc94811200b51a50fd178ecf239 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 4 Sep 2022 11:08:05 -0700 Subject: [PATCH] Enable io_uring on supporting platforms. (#37) docker: Add liburing to base packages. (#37) --- configure.ac | 88 ++++++++++++++++++++++++----- construct/Makefile.am | 3 + docker/alpine/3.16/base/Dockerfile | 2 + docker/ubuntu/22.04/base/Dockerfile | 2 + include/ircd/asio.h | 17 +++++- ircd/Makefile.am | 2 + 6 files changed, 96 insertions(+), 18 deletions(-) diff --git a/configure.ac b/configure.ac index d7a4d7b78..52093b345 100644 --- a/configure.ac +++ b/configure.ac @@ -1474,15 +1474,16 @@ AM_COND_IF(LINUX, ], [ aio=yes ]) -], []) +]) -if test "$aio" = "yes"; then - IRCD_DEFINE(USE_AIO, [1], [Linux AIO is supported and will be used]) -else - IRCD_DEFINE(USE_AIO, [0], [Linux AIO is not supported and won't be used]) -fi +AM_CONDITIONAL([AIO], [test "x$aio" = "xyes" ]) -AM_CONDITIONAL([AIO], [[[[ $aio = yes ]]]]) +AM_COND_IF([AIO], +[ + IRCD_DEFINE(USE_AIO, [1], [Linux AIO is enabled and may be used]) +], [ + IRCD_DEFINE(USE_AIO, [0], [Linux AIO is disabled and will not be used]) +]) dnl dnl Linux io_uring support @@ -1490,21 +1491,21 @@ dnl AM_COND_IF(LINUX, [ - AC_ARG_ENABLE(io_uring, RB_HELP_STRING([--disable-io_uring], [Disable kernel io_uring support]), + AC_ARG_ENABLE(iou, RB_HELP_STRING([--disable-iou], [Disable kernel io_uring support]), [ - io_uring=$enableval + iou=$enableval ], [ - io_uring="$ac_cv_header_linux_io_uring_h" + iou=yes ]) ]) -AM_CONDITIONAL([IOU], [[[[ $io_uring = yes ]]]]) +AM_CONDITIONAL([IOU], [test "x$iou" = "xyes" ]) AM_COND_IF([IOU], [ - IRCD_DEFINE(USE_IOU, [1], [Linux io_uring is supported and may be used]) + IRCD_DEFINE(USE_IOU, [1], [Linux io_uring is enabled for use if available]) ], [ - IRCD_DEFINE(USE_IOU, [0], [Linux io_uring is not available]) + IRCD_DEFINE(USE_IOU, [0], [Linux io_uring is disabled and will not be used]) ]) @@ -2623,6 +2624,63 @@ AM_COND_IF([ARMNN], IRCD_DEFINE(USE_ARMNN, [0], [Arm NN support is not available]) ]) +dnl +dnl +dnl liburing +dnl +dnl + +AC_SUBST(URING_CPPFLAGS, []) +AC_SUBST(URING_LDFLAGS, []) +AC_SUBST(URING_LIBS, []) + +AC_ARG_WITH(uring-includes, +RB_HELP_STRING([--with-uring-includes=[[[DIR]]]], [Path to uring include directory]), +[ + RB_VAR_APPEND([URING_CPPFLAGS], ["-isystem $withval"]) +]) + +AC_ARG_WITH(uring-libs, +RB_HELP_STRING([--with-uring-libs=[[[DIR]]]], [Path to uring libraries directory]), +[ + RB_VAR_APPEND([URING_LDFLAGS], ["-L$withval"]) +]) + +dnl push +restore_cppflags=$CPPFLAGS +restore_ldflags=$LDFLAGS +RB_VAR_PREPEND([CPPFLAGS], [$URING_CPPFLAGS]) +RB_VAR_PREPEND([LDFLAGS], [$URING_LDFLAGS]) + +RB_CHK_SYSHEADER(liburing.h, [LIBURING_H]) + +have_uring="no" +PKG_CHECK_MODULES(uring, [uring], +[ + have_uring="$iou" +], [ + AC_CHECK_LIB([uring], [io_uring_queue_init], + [ + have_uring="$iou" + ], [ + have_uring="no" + ]) +]) + +dnl pop +CPPFLAGS=$restore_cppflags +LDFLAGS=$restore_ldflags + +AM_CONDITIONAL([URING], [test "x$have_uring" = "xyes"]) + +AM_COND_IF([URING], +[ + RB_VAR_APPEND([LIBS], ["-luring"]) + IRCD_DEFINE(USE_URING, [1], [liburing's availability for use.]) +], [ + IRCD_DEFINE(USE_URING, [0], [liburing's availability for use.]) +]) + dnl dnl dnl boost support @@ -2738,6 +2796,7 @@ AC_SUBST(ASIO_UNIT_CPPFLAGS) RB_VAR_APPEND([ASIO_UNIT_CPPFLAGS], ["$BOOST_CPPFLAGS"]) RB_VAR_APPEND([ASIO_UNIT_CPPFLAGS], ["$SSL_CPPFLAGS"]) RB_VAR_APPEND([ASIO_UNIT_CPPFLAGS], ["$CRYPTO_CPPFLAGS"]) +RB_VAR_APPEND([ASIO_UNIT_CPPFLAGS], ["$URING_CPPFLAGS"]) dnl Units defining spirit grammars may benefit from special compiler flags due dnl to their various complexities. The ./configure may have generated flags @@ -3064,8 +3123,7 @@ echo "LLVM library support .............. $have_libllvm" echo "DRM support ....................... $have_drm" echo "ARM NN support .................... $have_armnn" echo "OpenCL support .................... $have_opencl" -echo "Linux AIO support ................. $aio" -echo "Linux io_uring support ............ $io_uring" +echo "Liburing support .................. $have_uring" echo "Memory allocator .................. $alloc_lib" echo echo "Using bundled Boost ............... $with_included_boost" diff --git a/construct/Makefile.am b/construct/Makefile.am index e4aef8407..0a6130ee0 100644 --- a/construct/Makefile.am +++ b/construct/Makefile.am @@ -15,6 +15,7 @@ AM_CPPFLAGS = \ @BOOST_CPPFLAGS@ \ @SSL_CPPFLAGS@ \ @CRYPTO_CPPFLAGS@ \ + @URING_CPPFLAGS@ \ $(EXTRA_CPPFLAGS) \ ### @@ -50,6 +51,7 @@ construct_LDFLAGS = \ @BOOST_LDFLAGS@ \ @SSL_LDFLAGS@ \ @CRYPTO_LDFLAGS@ \ + @URING_LDFLAGS@ \ ### construct_LDADD = \ @@ -57,6 +59,7 @@ construct_LDADD = \ @BOOST_LIBS@ \ @SSL_LIBS@ \ @CRYPTO_LIBS@ \ + @URING_LIBS@ \ $(EXTRA_LIBS) \ ### diff --git a/docker/alpine/3.16/base/Dockerfile b/docker/alpine/3.16/base/Dockerfile index 796c918ae..1b9c21b29 100644 --- a/docker/alpine/3.16/base/Dockerfile +++ b/docker/alpine/3.16/base/Dockerfile @@ -12,6 +12,7 @@ libatomic \ libmagic \ libsodium \ libstdc++ \ +liburing \ lz4 \ openssl \ rocksdb \ @@ -23,6 +24,7 @@ boost-dev \ file-dev \ icu-dev \ libsodium-dev \ +liburing-dev \ lz4-dev \ openssl-dev \ rocksdb-dev \ diff --git a/docker/ubuntu/22.04/base/Dockerfile b/docker/ubuntu/22.04/base/Dockerfile index fcb643325..dc0c1285f 100644 --- a/docker/ubuntu/22.04/base/Dockerfile +++ b/docker/ubuntu/22.04/base/Dockerfile @@ -22,6 +22,7 @@ libsodium23 \ libssl3 \ liblz4-1 \ libmagic1 \ +liburing2 \ libzstd1 \ " @@ -47,6 +48,7 @@ libicu-dev \ libmagic-dev \ libsodium-dev \ libssl-dev \ +liburing-dev \ " ENV rocksdb_cmake="\ diff --git a/include/ircd/asio.h b/include/ircd/asio.h index 70ae7ed36..1f66ae567 100644 --- a/include/ircd/asio.h +++ b/include/ircd/asio.h @@ -44,6 +44,7 @@ namespace boost #include @@ -51,22 +52,32 @@ namespace boost #include #include + +#if defined(HAVE_LIBURING_H) \ +&& IRCD_USE_URING == 1 \ +&& BOOST_VERSION >= 107800 +#define BOOST_ASIO_HAS_IO_URING +#define BOOST_ASIO_DISABLE_EPOLL +#endif + #include #include #include #include -#if defined(BOOST_ASIO_HAS_EPOLL) || defined(BOOST_ASIO_HAS_KQUEUE) +#if defined(BOOST_ASIO_HAS_EPOLL) \ +|| defined(BOOST_ASIO_HAS_KQUEUE) \ +|| defined(BOOST_ASIO_HAS_IO_URING) #pragma GCC visibility push(protected) +#else +#pragma GCC visibility push(default) #endif #include #include #include #include #include -#if defined(BOOST_ASIO_HAS_EPOLL) || defined(BOOST_ASIO_HAS_KQUEUE) #pragma GCC visibility pop -#endif // Template-specializations for some functions we may redefine (interpose). // Declarations are needed for template instantiation in PCH and with LTO. diff --git a/ircd/Makefile.am b/ircd/Makefile.am index ca9b5e65d..a38780643 100644 --- a/ircd/Makefile.am +++ b/ircd/Makefile.am @@ -115,6 +115,7 @@ libircd_la_LDFLAGS += @SNAPPY_LDFLAGS@ libircd_la_LDFLAGS += @LZ4_LDFLAGS@ libircd_la_LDFLAGS += @Z_LDFLAGS@ libircd_la_LDFLAGS += @MALLOC_LDFLAGS@ +libircd_la_LDFLAGS += @URING_LDFLAGS@ libircd_la_LIBADD =# libircd_la_LIBADD += @ROCKSDB_LIBS@ @@ -132,6 +133,7 @@ libircd_la_LIBADD += @ZSTD_LIBS@ libircd_la_LIBADD += @SNAPPY_LIBS@ libircd_la_LIBADD += @LZ4_LIBS@ libircd_la_LIBADD += @Z_LIBS@ +libircd_la_LIBADD += @URING_LIBS@ libircd_la_LIBADD += $(EXTRA_LIBS) if PROFILE