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
13 changes: 7 additions & 6 deletions toolbox/io/Reactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ int Reactor::poll(CyclTime now, Duration timeout)
}
// Update cycle time after epoll() returns.
now = CyclTime::now();
last_time_priority_io_polled_ = now.wall_time();
last_time_priority_io_polled_ = now.mono_time();
last_time_user_hook_polled_ = now.mono_time();

if (ec) {
if (ec.value() != EINTR) {
Expand Down Expand Up @@ -157,12 +158,12 @@ void Reactor::yield() noexcept
return;
}

WallTime now = WallClock::now();
MonoTime now = MonoClock::now();
cycle_work_ += do_io_priority_poll(now);
cycle_work_ += do_user_priority_poll(now);
}

int Reactor::do_io_priority_poll(WallTime now) noexcept
int Reactor::do_io_priority_poll(MonoTime now) noexcept
{
int ret = 0;
try {
Expand All @@ -172,7 +173,7 @@ int Reactor::do_io_priority_poll(WallTime now) noexcept

if (enabled && breached) {
const auto update_poll_time = make_finally([this]() noexcept {
last_time_priority_io_polled_ = WallClock::now();
last_time_priority_io_polled_ = MonoClock::now();
});

error_code ec;
Expand All @@ -195,7 +196,7 @@ int Reactor::do_io_priority_poll(WallTime now) noexcept
return ret;
}

int Reactor::do_user_priority_poll(WallTime now) noexcept
int Reactor::do_user_priority_poll(MonoTime now) noexcept
{
int ret = 0;
try {
Expand All @@ -206,7 +207,7 @@ int Reactor::do_user_priority_poll(WallTime now) noexcept

if (enabled && breached) {
const auto update_poll_time = make_finally([this]() noexcept {
last_time_user_hook_polled_ = WallClock::now();
last_time_user_hook_polled_ = MonoClock::now();
});

currently_handling_priority_events_ = true;
Expand Down
8 changes: 4 additions & 4 deletions toolbox/io/Reactor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ class TOOLBOX_API Reactor : public Waker {
void set_events(int fd, int sid, unsigned events);
void unsubscribe(int fd, int sid) noexcept;
void set_io_priority(int fd, int sid, Priority priority) noexcept;
int do_io_priority_poll(WallTime now) noexcept;
int do_user_priority_poll(WallTime now) noexcept;
int do_io_priority_poll(MonoTime now) noexcept;
int do_user_priority_poll(MonoTime now) noexcept;

struct Data {
int sid{};
Expand All @@ -215,8 +215,8 @@ class TOOLBOX_API Reactor : public Waker {
HookList end_of_cycle_no_wait_hooks, end_of_event_dispatch_hooks_;
Micros priority_io_poll_threshold_ = Micros::max();
Micros user_hook_poll_threshold_ = Micros::max();
WallTime last_time_priority_io_polled_{};
WallTime last_time_user_hook_polled_{};
MonoTime last_time_priority_io_polled_{};
MonoTime last_time_user_hook_polled_{};
PollSlot priority_poll_user_hook_;
int cycle_work_{0};
bool currently_handling_priority_events_{false};
Expand Down
18 changes: 9 additions & 9 deletions toolbox/io/Reactor.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,16 @@ BOOST_AUTO_TEST_CASE(ReactorHighPriorityHook)

auto [s1, s2] = socketpair(UnixStreamProtocol{});

// This is handler for data on s1. It is an expensive function taking ~100ms
// This is handler for data on s1. It is an expensive function taking ~250ms
std::size_t yield_count = 0;
auto on_data_received = [&](CyclTime, int, unsigned) {
WallTime now = WallClock::now();
WallTime end = now + 500ms;
MonoTime now = MonoClock::now();
MonoTime end = now + 250ms;
while (now < end) {
// wait for 100us, then yield
auto next_stop = now + 1ms;
// wait for 1ms, then yield
auto next_stop = MonoClock::now() + 1ms;
while (now < next_stop) {
now = WallClock::now();
now = MonoClock::now();
}
r.yield();
yield_count++;
Expand Down Expand Up @@ -211,13 +211,13 @@ BOOST_AUTO_TEST_CASE(ReactorHighPriorityYield)

// each invocation will take ~100ms
auto spin_and_yield_periodically = [&r]() {
WallTime now = WallClock::now();
WallTime end = now + 100ms;
MonoTime now = MonoClock::now();
MonoTime end = now + 100ms;
while (now < end) {
// wait for 10us, then yield
auto next_stop = now + 10us;
while (now < next_stop) {
now = WallClock::now();
now = MonoClock::now();
}
r.yield();
};
Expand Down