Skip to content

Commit

Permalink
WIP: Add new custom event loop for Linux I/O layer
Browse files Browse the repository at this point in the history
Introduce ev.h and ev.c, establishing the
foundation for the new custom event loop,
`pgagroal_ev`.

Replace previous dependencies on libev with the
custom event loop.

Implement support for io_uring with a fallback to
epoll if io_uring is unavailable.
  • Loading branch information
decarv committed Aug 18, 2024
1 parent 5fae10c commit 24680d8
Show file tree
Hide file tree
Showing 17 changed files with 2,456 additions and 376 deletions.
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ if(NOT COMPILER_SUPPORTS_C17)
message(FATAL_ERROR "The compiler ${CMAKE_C_COMPILER} has no C17 support. Please use a different C compiler.")
endif()

find_package(Libev 4.11)
if (LIBEV_FOUND)
message(STATUS "libev found")
else ()
message(FATAL_ERROR "libev needed")

option(HAVE_URING "Use either io_uring or epoll as Linux event handling backend" ON)
find_package(Liburing 2.5)
if (NOT LIBURING_FOUND)
option(HAVE_URING OFF)
message(STATUS "liburing found")
endif()

find_package(OpenSSL)
Expand Down
18 changes: 18 additions & 0 deletions cmake/FindLiburing.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# - Try to find liburing
# Once done this will define
# LIBURING_FOUND - System has liburing
# LIBURING_LIBRARY - The library needed to use liburing

FIND_LIBRARY(LIBURING_LIBRARY NAMES liburing liburing.a liburing.so liburing.so.2
HINTS
/usr/lib64
/usr/lib
/lib64
/lib
)

IF (LIBURING_LIBRARY)
SET(LIBURING_FOUND TRUE)
ELSE ()
SET(LIBURING_FOUND FALSE)
ENDIF ()
Empty file added jnl_pgagroal.md
Empty file.
10 changes: 10 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

build_dir=$(pwd)/build
mkdir -p $build_dir
cd $build_dir
rm -rf *
cmake -S .. -G "Unix Makefiles" -B . -DCMAKE_BUILD_TYPE=Debug
make
rm ../compile_commands.json
ln -s $build_dir/compile_commands.json ..
15 changes: 13 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
#
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${LIBEV_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIR}
${SYSTEMD_INCLUDE_DIRS}
${CJSON_INCLUDE_DIRS}
Expand All @@ -29,14 +28,26 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
# Library directories
#
link_libraries(
${LIBEV_LIBRARIES}
${OPENSSL_CRYPTO_LIBRARY}
${OPENSSL_SSL_LIBRARY}
${SYSTEMD_LIBRARIES}
${LIBATOMIC_LIBRARY}
${CJSON_LIBRARIES}
)

#
# Event library backend
#
if (HAVE_URING)
add_compile_options(-DHAVE_URING=1)
include_directories(${LIBURING_INCLUDE_DIRS})
link_libraries(${LIBURING_LIBRARY})
message(STATUS "pgagroal ev handling backend: io_uring")
else ()
add_compile_options(-DHAVE_URING=0)
message(STATUS "pgagroal ev handling backend: epoll")
endif()

set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
find_program(HOMEBREW_EXECUTABLE brew)
Expand Down
Loading

0 comments on commit 24680d8

Please sign in to comment.