Skip to content
Snippets Groups Projects
Commit 29736cf9 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Merge branch 'improve-reap-completions' into 'master'

[IoContext] wrap CQ locking in if constexpr

See merge request i4/manycore/emper!218
parents 1e495961 1055a7aa
No related branches found
No related tags found
No related merge requests found
Pipeline #66221 passed
......@@ -211,24 +211,26 @@ reap_cqes:
LOGD("Reaping completions for worker " << std::to_string(worker->getWorkerId()));
std::array<struct io_uring_cqe *, CQE_BATCH_COUNT> cqes;
// Someone else is currently reaping completions
if constexpr (callerEnvironment == CallerEnvironment::EMPER) {
if (unlikely(!cq_lock.try_lock())) {
LOGD("worker unsuccessful try_lock");
return 0;
}
} else {
// We can not reap completions of this IoContext to not race
// with the sleeping worker.
if (waitInflight.load(std::memory_order_acquire)) {
LOGD("Not reaping worker " << std::to_string(worker->getWorkerId())
<< " since this worker is already waiting for its CQEs");
return 0;
}
if constexpr (needsCqLock) {
// Someone else is currently reaping completions
if constexpr (callerEnvironment == CallerEnvironment::EMPER) {
if (unlikely(!cq_lock.try_lock())) {
LOGD("worker unsuccessful try_lock");
return 0;
}
} else {
// We can not reap completions of this IoContext to not race
// with the sleeping worker.
if (waitInflight.load(std::memory_order_acquire)) {
LOGD("Not reaping worker " << std::to_string(worker->getWorkerId())
<< " since this worker is already waiting for its CQEs");
return 0;
}
if (!cq_lock.try_lock_or_increment()) {
LOGD("Global completer unsuccessful try_lock_or_increment");
return 0;
if (!cq_lock.try_lock_or_increment()) {
LOGD("Global completer unsuccessful try_lock_or_increment");
return 0;
}
}
}
......@@ -245,7 +247,10 @@ reap_cqes:
io_uring_cq_advance(&ring, count);
uint32_t globalCompleterAttempts = cq_lock.unlock();
uint32_t globalCompleterAttempts;
if constexpr (needsCqLock) {
globalCompleterAttempts = cq_lock.unlock();
}
LOGD("got " << count << " cqes from worker " << worker->getWorkerId() << "'s io_uring");
......@@ -336,7 +341,7 @@ reap_cqes:
}
// check if lost wakeup was possible
if constexpr (callerEnvironment == CallerEnvironment::EMPER) {
if constexpr (needsCqLock && callerEnvironment == CallerEnvironment::EMPER) {
bool reReap = false;
// TODO: How sure are we that this is unlikely?
if (unlikely(globalCompleterAttempts > maxRaceFreeCompleterAttempts)) {
......
......@@ -68,6 +68,8 @@ class IoContext : public Logger<LogSubsystem::IO> {
Runtime &runtime;
static thread_local IoContext *workerIo;
static constexpr bool needsCqLock =
emper::IO_COMPLETER_BEHAVIOR != emper::IoCompleterBehavior::none;
// TryLock protecting the completion queue of ring.
ALIGN_TO_CACHE_LINE CqLock cq_lock;
struct io_uring ring;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment