From 7d1de2ded7218196df955d63d062262406a03906 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 18 Dec 2020 19:50:35 -0800 Subject: [PATCH] ircd::ios: Torch any possible idiv in core epoll(2) instruction stream. --- include/ircd/ios/epoll.h | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/include/ircd/ios/epoll.h b/include/ircd/ios/epoll.h index e01fd37f0..9f85ae923 100644 --- a/include/ircd/ios/epoll.h +++ b/include/ircd/ios/epoll.h @@ -51,28 +51,36 @@ ircd::ios::epoll_wait(int _epfd, int _timeout) noexcept { - const bool peek - { - _timeout == 0 - }; + // Call elision tick counter. + thread_local uint64_t tick; + // Configured frequency to allow the call. const uint64_t freq { empt::freq }; - const bool skip_tick + const bool skip { - !freq || (uint64_t(empt::peek) % freq) + !freq || (tick < freq) + }; + + const bool peek + { + _timeout == 0 }; // Always allow blocking calls; only allow non-blocking calls which // satisfy our conditions. const bool call { - !peek || !skip_tick + !peek || !skip }; + // Modify tick counter prior to call, while we have the line. + tick -= boolmask(call) & tick; + tick += boolmask(!call) & 0x01; + const int ret { call? @@ -94,8 +102,9 @@ noexcept log::logf { log, ircd::log::DEBUG, - "EPOLL %5d peek:%lu skip:%lu call:%lu none:%lu result:%lu low:%lu med:%lu high:%lu stall:%lu", + "EPOLL %5d tick:%lu peek:%lu skip:%lu call:%lu none:%lu result:%lu low:%lu med:%lu high:%lu stall:%lu", ret, + tick, uint64_t(empt::peek), uint64_t(empt::skip), uint64_t(empt::call),