Skip to content

Commit

Permalink
feat(io_context): do not require requests_to_reap
Browse files Browse the repository at this point in the history
  • Loading branch information
Codesire-Deng committed Sep 23, 2023
1 parent 2d1aa60 commit 5c8f587
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
5 changes: 4 additions & 1 deletion include/co_context/io_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include <co_context/config.hpp>
#include <co_context/detail/attributes.hpp>
#include <co_context/detail/io_context_meta.hpp>
#include <co_context/detail/task_info.hpp>
#include <co_context/detail/thread_meta.hpp>
Expand All @@ -28,7 +29,6 @@
#include <co_context/task.hpp>
#include <uring/uring.hpp>

#include <cstdint>
#include <sys/types.h>
#include <thread>

Expand Down Expand Up @@ -93,6 +93,9 @@ class [[nodiscard]] io_context final {

void do_completion_part() noexcept;

[[CO_CONTEXT_NOINLINE]]
void do_completion_part_bad_path() noexcept;

void do_worker_part();

public:
Expand Down
37 changes: 21 additions & 16 deletions lib/co_context/io_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,37 @@ void io_context::do_submission_part() noexcept {
worker.poll_submission();
}

void io_context::do_completion_part_bad_path() noexcept {
log::v("do_completion_part_bad_path(): bad path\n");
const auto &meta = detail::io_context_meta;
if (!worker.peek_uring()
&& (worker.requests_to_reap > 0 || meta.ready_count > 1)) {
log::v("do_completion_part_bad_path(): block on worker.wait_uring()\n");
worker.wait_uring();
}
const uint32_t handled_num = worker.poll_completion();

bool is_not_over =
handled_num | (meta.ready_count > 1) | worker.requests_to_reap;

if (!is_not_over) [[unlikely]] {
will_stop = true;
}
}

void io_context::do_completion_part() noexcept {
// NOTE in the future: if an IO generates multiple requests_to_reap,
// it must be counted carefully

auto &meta = detail::io_context_meta;

uint32_t handled_num = worker.peek_uring() ? worker.poll_completion() : 0;
const uint32_t handled_num =
worker.peek_uring() ? worker.poll_completion() : 0;
bool is_fast_path =
worker.requests_to_submit | worker.has_task_ready() | handled_num;
if (is_fast_path) [[likely]] {
return;
} else {
log::v("do_completion_part(): bad path\n");
if (!worker.peek_uring() && worker.requests_to_reap > 0) {
log::v("do_completion_part(): wait_uring()\n");
worker.wait_uring();
}
handled_num = worker.poll_completion();
}

bool is_not_over =
handled_num | (meta.ready_count > 1) | worker.requests_to_reap;

if (!is_not_over) [[unlikely]] {
will_stop = true;
}
do_completion_part_bad_path();
}

void io_context::run() {
Expand Down

0 comments on commit 5c8f587

Please sign in to comment.