Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions include/condy/cqe_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,6 @@

namespace condy {

namespace detail {

// Just for debugging, check if the CQE is big as expected
inline bool check_cqe32([[maybe_unused]] io_uring_cqe *cqe) {
auto &ring = detail::Context::current().runtime()->ring_internal();
auto ring_flags = ring.ring()->flags;
if (ring_flags & IORING_SETUP_CQE32) {
return true;
}
#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
if (ring_flags & IORING_SETUP_CQE_MIXED) {
return cqe->flags & IORING_CQE_F_32;
}
#endif
return false;
}

} // namespace detail

/**
* @brief A simple CQE handler that extracts the result from the CQE without any
* additional processing.
Expand Down Expand Up @@ -76,8 +57,10 @@ class SelectBufferCQEHandler {
*/
struct NVMePassthruCQEHandler {
std::pair<int32_t, uint64_t> operator()(io_uring_cqe *cqe) noexcept {
assert(detail::check_cqe32(cqe) &&
"Expected big CQE for NVMe passthrough");
assert(
detail::Context::current().runtime()->ring_internal().check_cqe32(
cqe) &&
"Expected big CQE for NVMe passthrough");
return {cqe->res, cqe->big_cqe[0]};
}
};
Expand Down Expand Up @@ -114,8 +97,10 @@ struct TxTimestampResult {
struct TxTimestampCQEHandler {
std::pair<int32_t, TxTimestampResult>
operator()(io_uring_cqe *cqe) noexcept {
assert(detail::check_cqe32(cqe) &&
"Expected big CQE for TX timestamp operations");
assert(
detail::Context::current().runtime()->ring_internal().check_cqe32(
cqe) &&
"Expected big CQE for TX timestamp operations");
TxTimestampResult result;
result.tstype =
static_cast<int>(cqe->flags >> IORING_TIMESTAMP_TYPE_SHIFT);
Expand Down
13 changes: 13 additions & 0 deletions include/condy/detail/ring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ class Ring {
}
#endif

bool check_cqe32([[maybe_unused]] io_uring_cqe *cqe) const noexcept {
auto ring_flags = ring_.flags;
if (ring_flags & IORING_SETUP_CQE32) {
return true;
}
#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
if (ring_flags & IORING_SETUP_CQE_MIXED) {
return cqe->flags & IORING_CQE_F_32;
}
#endif
return false;
}

private:
template <io_uring_sqe *(*get_sqe)(struct io_uring *)>
io_uring_sqe *get_sqe_() noexcept {
Expand Down
13 changes: 13 additions & 0 deletions include/condy/detail/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,18 @@ inline auto TaskBase<T, Allocator>::operator co_await() noexcept {
Context::current().runtime());
}

struct [[nodiscard]] SwitchAwaiter {
bool await_ready() const noexcept { return false; }

template <typename PromiseType>
void await_suspend(std::coroutine_handle<PromiseType> handle) noexcept {
runtime_->schedule_internal(&handle.promise());
}

void await_resume() const noexcept {}

Runtime *runtime_;
};

} // namespace detail
} // namespace condy
17 changes: 0 additions & 17 deletions include/condy/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,6 @@ inline Task<T, Allocator> co_spawn(Coro<T, Allocator> coro) {
return co_spawn(*runtime, std::move(coro));
}

namespace detail {

struct [[nodiscard]] SwitchAwaiter {
bool await_ready() const noexcept { return false; }

template <typename PromiseType>
void await_suspend(std::coroutine_handle<PromiseType> handle) noexcept {
runtime_->schedule_internal(&handle.promise());
}

void await_resume() const noexcept {}

Runtime *runtime_;
};

} // namespace detail

/**
* @brief Switch current coroutine task to the given runtime.
* @param runtime The runtime to switch to.
Expand Down
3 changes: 3 additions & 0 deletions include/condy/zcrx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "condy/detail/buffers.hpp"
#include "condy/detail/context.hpp"
#include "condy/detail/ring.hpp"
#include "condy/detail/utils.hpp"
#include "condy/runtime.hpp"
#include <bit>
Expand Down Expand Up @@ -190,6 +191,8 @@ class ZeroCopyRxBufferPool {
uint32_t zcrx_id() const noexcept { return zcrx_id_; }

ZeroCopyRxBuffer handle_finish(io_uring_cqe *cqe) noexcept {
assert(ring_->check_cqe32(cqe) && "Expected big CQE for ZeroCopyRx");

if (cqe->res < 0) {
return ZeroCopyRxBuffer();
}
Expand Down
Loading