Skip to content

Commit

Permalink
folly async io_uring: bump EVB start time on IoSqeBase completion
Browse files Browse the repository at this point in the history
Summary:
`EventHandler::libeventCallback()` calls `EventBase::bumpHandlingTime()` which sets the `startTime_` of an EVB loop iteration if it wasn't already set. If no `EventHandler`s are run, then `startTime_` is bumped just before running loop callbacks.

The io_uring based `IoUringBackend` and `AsyncIoUringSocket` do not use `EventHandler`. Thus the `startTime_` of an EVB loop iteration is not being set correctly upon handling the first piece of I/O work via the various `IoSqeBase` types.

Fix this by adding the EventBase to that an IoSqeBase is tied to, and call `EventBase::bumpHandlingTime()` when completing an IoSqeBase i.e. invoking its callback.

Reviewed By: yfeldblum

Differential Revision: D68537153

fbshipit-source-id: 9e991213d69ffa32778e06a0fb447b0514bebba5
  • Loading branch information
spikeh authored and facebook-github-bot committed Jan 24, 2025
1 parent 82528a9 commit 5f1eba8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions third-party/folly/src/folly/io/async/IoUringBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ void IoSqeBase::internalCallback(const io_uring_cqe* cqe) noexcept {
if (!(cqe->flags & IORING_CQE_F_MORE)) {
inFlight_ = false;
}
if (evb_) {
evb_->bumpHandlingTime();
}
if (cancelled_) {
callbackCancelled(cqe);
} else {
Expand Down
1 change: 1 addition & 0 deletions third-party/folly/src/folly/io/async/IoUringBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <folly/Optional.h>
#include <folly/Range.h>
#include <folly/io/IOBuf.h>
#include <folly/io/async/EventBase.h>
#include <folly/io/async/EventBaseBackendBase.h>
#include <folly/io/async/IoUringBase.h>
#include <folly/io/async/Liburing.h>
Expand Down
3 changes: 3 additions & 0 deletions third-party/folly/src/folly/io/async/IoUringBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct io_uring_cqe;
namespace folly {

class IoUringBackend;
class EventBase;

struct IoSqeBase
: boost::intrusive::list_base_hook<
Expand Down Expand Up @@ -57,6 +58,7 @@ struct IoSqeBase
bool inFlight() const { return inFlight_; }
bool cancelled() const { return cancelled_; }
void markCancelled() { cancelled_ = true; }
void setEventBase(EventBase* evb) { evb_ = evb; }

protected:
// This is used if you want to prepare this sqe for reuse, but will manage the
Expand All @@ -72,6 +74,7 @@ struct IoSqeBase

bool inFlight_ = false;
bool cancelled_ = false;
EventBase* evb_ = nullptr;
Type type_;
};

Expand Down

0 comments on commit 5f1eba8

Please sign in to comment.