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 19, 2024
1 parent 5fae10c commit 45da25d
Show file tree
Hide file tree
Showing 18 changed files with 2,476 additions and 419 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ set(VERSION_MAJOR "1")
set(VERSION_MINOR "7")
set(VERSION_PATCH "0")
set(VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})

#
# Avoid source tree pollution
#
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_C_FLAGS_DEBUG "-g -O0 -rdynamic")

If(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not permitted. Make a separate folder for building:\nmkdir build; cd build; cmake ..\nBefore that, remove the files already created:\nrm -rf CMakeCache.txt CMakeFiles")
Expand Down Expand Up @@ -59,11 +59,11 @@ 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
38 changes: 0 additions & 38 deletions cmake/FindLibev.cmake

This file was deleted.

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 .. -DCMAKE_BUILD_TYPE=Debug --trace-expand source_dir
make
#rm ../compile_commands.json
#ln -s $build_dir/compile_commands.json ..
24 changes: 18 additions & 6 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 Expand Up @@ -69,7 +80,6 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
#
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${LIBEV_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIRS}
${CJSON_INCLUDE_DIRS}
)
Expand All @@ -78,7 +88,6 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
# Library directories
#
link_libraries(
${LIBEV_LIBRARIES}
${OPENSSL_LIBRARIES}
${CJSON_LIBRARIES}
)
Expand All @@ -100,7 +109,6 @@ else()
#
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include
${LIBEV_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIRS}
${CJSON_INCLUDE_DIRS}
)
Expand All @@ -109,7 +117,6 @@ else()
# Library directories
#
link_libraries(
${LIBEV_LIBRARIES}
${OPENSSL_LIBRARIES}
${CJSON_LIBRARIES}
)
Expand Down Expand Up @@ -152,6 +159,7 @@ endif()
if (CMAKE_BUILD_TYPE MATCHES Debug)
add_compile_options(-O0)
add_compile_options(-DDEBUG)
add_compile_options(-fno-inline)

check_c_compiler_flag(-Wformat HAS_FORMAT)
if (HAS_FORMAT)
Expand Down Expand Up @@ -210,6 +218,10 @@ if (CMAKE_BUILD_TYPE MATCHES Debug)
if (HAS_NO_OMIT_FRAME_POINTER)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer")
endif()


set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -g")

endif()

if (CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
Expand Down
Loading

1 comment on commit 45da25d

@fluca1978
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, I have so far only a few aesthetics comments.

Please sign in to comment.