Skip to content

Commit

Permalink
Fix cascading engine submit; Support running specified event engine i…
Browse files Browse the repository at this point in the history
…n CI test (#273)
  • Loading branch information
beef9999 committed Nov 24, 2023
1 parent 49bc338 commit 1e28e85
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 84 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.linux.x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ jobs:
run: |
cd build
ulimit -l unlimited
export PHOTON_CI_EV_ENGINE=io_uring
ctest --timeout 3600 -V
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,10 @@ endif ()
if (PHOTON_BUILD_TESTING)
include(CTest)

add_library(ci-tools STATIC test/ci-tools.cpp)

include_directories(photon_static ${GFLAGS_INCLUDE_DIRS} ${GOOGLETEST_INCLUDE_DIRS})
link_libraries(${GFLAGS_LIBRARIES} ${GOOGLETEST_LIBRARIES})
link_libraries(${GFLAGS_LIBRARIES} ${GOOGLETEST_LIBRARIES} ci-tools)

add_subdirectory(examples)
add_subdirectory(common/checksum/test)
Expand Down
1 change: 1 addition & 0 deletions io/fd-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class CascadingEventEngine {

/**
* @brief Wait for events, returns number of the arrived events, and their associated `data`
* @note This call will not return until timeout, if there had been no events.
* @param[out] data
* @return -1 for error, positive integer for the number of events, 0 for no events and should run it again
* @warning Do NOT block vcpu
Expand Down
16 changes: 12 additions & 4 deletions io/iouring-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ class iouringEngine : public MasterEventEngine, public CascadingEventEngine {
}
ret = io_uring_register_files(m_ring, entries, REGISTER_FILES_MAX_NUM);
if (ret != 0) {
LOG_ERROR_RETURN(EPERM, -1, "iouring: unable to register files, ", ERRNO(-ret));
LOG_ERROR_RETURN(-ret, -1, "iouring: unable to register files, ", ERRNO(-ret));
}
}

m_eventfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
m_eventfd = eventfd(0, EFD_CLOEXEC);
if (m_eventfd < 0) {
LOG_ERRNO_RETURN(0, -1, "iouring: failed to create eventfd");
}
Expand All @@ -135,7 +135,7 @@ class iouringEngine : public MasterEventEngine, public CascadingEventEngine {
io_uring_sqe_set_data(sqe, this);
ret = io_uring_submit(m_ring);
if (ret <= 0) {
LOG_ERROR_RETURN(0, -1, "iouring: fail to submit multishot poll, ", ERRNO(-ret));
LOG_ERROR_RETURN(-ret, -1, "iouring: fail to submit multishot poll, ", ERRNO(-ret));
}
} else {
// Register cascading engine to eventfd
Expand Down Expand Up @@ -240,6 +240,10 @@ class iouringEngine : public MasterEventEngine, public CascadingEventEngine {
io_uring_prep_poll_multishot(sqe, fd_interest.fd, fd_interest.interest);
}
io_uring_sqe_set_data(sqe, &pair.first->second.io_ctx);
int ret = io_uring_submit(m_ring);
if (ret < 0) {
LOG_ERROR_RETURN(-ret, -1, "iouring: fail to submit when adding interest, ", ERRNO(-ret));
}
return 0;
}

Expand All @@ -256,6 +260,10 @@ class iouringEngine : public MasterEventEngine, public CascadingEventEngine {

io_uring_prep_poll_remove(sqe, (__u64) &iter->second.io_ctx);
io_uring_sqe_set_data(sqe, nullptr);
int ret = io_uring_submit(m_ring);
if (ret < 0) {
LOG_ERROR_RETURN(-ret, -1, "iouring: fail to submit when removing interest, ", ERRNO(-ret));
}
return 0;
}

Expand Down Expand Up @@ -287,7 +295,7 @@ class iouringEngine : public MasterEventEngine, public CascadingEventEngine {
LOG_ERROR_RETURN(0, -1, "iouring: multi-shot poll got POLLERR");
}
if (!ctx->is_event) {
LOG_ERROR_RETURN(0, -1, "iouring: only cascading engine need to handle event. Must be a bug...")
LOG_ERROR_RETURN(0, -1, "iouring: cascading engine only needs to handle event. Must be a bug...")
}
eventCtx* event_ctx = container_of(ctx, eventCtx, io_ctx);
fdInterest fd_interest{event_ctx->event.fd, (uint32_t)evmap.translate_bitwisely(event_ctx->event.interests)};
Expand Down
2 changes: 1 addition & 1 deletion io/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ target_link_libraries(test-syncio PRIVATE photon_shared)
add_test(NAME test-syncio COMMAND $<TARGET_FILE:test-syncio>)

add_executable(test-iouring test-iouring.cpp)
target_link_libraries(test-iouring PRIVATE photon_shared)
target_link_libraries(test-iouring PRIVATE photon_static)
add_test(NAME test-iouring COMMAND $<TARGET_FILE:test-iouring>)
endif ()
Loading

0 comments on commit 1e28e85

Please sign in to comment.