Skip to content
Snippets Groups Projects

[IoContext] wrap CQ locking in if constexpr

Merged Florian Fischer requested to merge aj46ezos/emper:improve-reap-completions into master
2 files
+ 26
19
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 24
19
@@ -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)) {
Loading