Skip to content
Snippets Groups Projects
Commit 845111e3 authored by Florian Fischer's avatar Florian Fischer
Browse files

AbstractIoSleepStrategy: remove erroneous assertion

In my master's thesis, I described in listing 4.4 an io_uring-based
suspension and notification algorithm, which is slightly different from
what emper does.

The described algorithm does not reset the sleep state if a worker
skips sleeping because of a global sleeper count of less than 0 (line 21).

Emper does always reset the sleep state to SleeperState::Running if
the sleep method returned early (either the worker was specifically
notified or the global sleep count indicated to skip the sleep attempt).

Both variants are sound, but invariably resetting the sleeper count to
running minimizes the windows of useless specific notifications.

However, the assertion in onNewWorkNotification assumes the sleep state
is always SleeperState::Notified if a specific notification is received
through the worker's io_uring.

Emper, resetting the sleep state, introduces a race between the notifier
observing the state as sleeping, setting it to notified, and posting a
notification to the potential sleeper's io_uring.
But the sleeper skips the sleep attempt because the global sleeper count
righteously resetting its state to running while invalidating the
assertion.

Therefore we remove the assertion because it is not invariant.
parent 8dbcf286
No related branches found
No related tags found
No related merge requests found
Pipeline #88634 passed
......@@ -123,16 +123,13 @@ void AbstractIoSleepStrategy::onNewWorkNotification(IoContext& io,
if (data.isMarked()) {
LOGD("Got specific notification");
ATTR_UNUSED auto oldState =
sleepState.exchange(SleeperState::Running, std::memory_order_release);
assert(oldState == SleeperState::Notified);
} else {
LOGD("Got new work notification");
sleepState.store(SleeperState::Running, std::memory_order_release);
// Reset global flag to indicate that a new sleep cqe must be prepared
readingGlobal = false;
}
sleepState.store(SleeperState::Running, std::memory_order_release);
}
template void AbstractIoSleepStrategy::onNewWorkNotification<CallerEnvironment::OWNER>(
......
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