Skip to content

Commit 60a68b7

Browse files
spikehfacebook-github-bot
authored andcommitted
folly async io_uring: set EVB for IoSqeBase derived classes
Summary: There are two categories of IoSqeBase derived classes: 1. IoSqe in IoUringBackend 2. Various derivatives in AsyncIoUringSocket Call `IoSqeBase::setEventBase()` from all derived classes to set/unset the EVB. It's possible for `AsyncIoUringSocket` to detach and attach to different EVBs. Ensure that `IoSqeBase`s are synced. Reviewed By: yfeldblum Differential Revision: D68540579 fbshipit-source-id: 83ad739aec37378e08e4d7fd4855166af6bef290
1 parent 503646e commit 60a68b7

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

folly/io/async/AsyncIoUringSocket.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ AsyncIoUringSocket::ReadSqe::ReadSqe(AsyncIoUringSocket* parent)
141141
: IoSqeBase(IoSqeBase::Type::Read), parent_(parent) {
142142
supportsMultishotRecv_ = parent->options_.multishotRecv &&
143143
parent->backend_->kernelSupportsRecvmsgMultishot();
144+
setEventBase(parent->evb_);
144145
}
145146

146147
AsyncIoUringSocket::~AsyncIoUringSocket() {
@@ -868,6 +869,8 @@ AsyncIoUringSocket::WriteSqe::WriteSqe(
868869
msg_.msg_control = nullptr;
869870
msg_.msg_controllen = 0;
870871
msg_.msg_flags = 0;
872+
873+
setEventBase(parent->evb_);
871874
}
872875

873876
int AsyncIoUringSocket::WriteSqe::sendMsgFlags() const {
@@ -1019,8 +1022,8 @@ void AsyncIoUringSocket::attachEventBase(EventBase* evb) {
10191022
std::move(*detachedWriteResult_)
10201023
.via(evb)
10211024
.thenValue(
1022-
[w = writeSqeActive_,
1023-
a = std::weak_ptr<folly::Unit>(alive_)](auto&& resFlagsPairs) {
1025+
[w = writeSqeActive_, a = std::weak_ptr<folly::Unit>(alive_), evb](
1026+
auto&& resFlagsPairs) {
10241027
VLOG(5) << "attached write done, " << resFlagsPairs.size();
10251028
if (!a.lock()) {
10261029
return;
@@ -1031,6 +1034,7 @@ void AsyncIoUringSocket::attachEventBase(EventBase* evb) {
10311034
cqe.res = res;
10321035
cqe.flags = flags;
10331036

1037+
evb->bumpHandlingTime();
10341038
if (w->cancelled()) {
10351039
w->callbackCancelled(&cqe);
10361040
} else {
@@ -1138,6 +1142,7 @@ void AsyncIoUringSocket::detachEventBase() {
11381142
}
11391143
readSqe_ = ReadSqe::UniquePtr(new ReadSqe(this));
11401144
readSqe_->setReadCallback(oldReadCallback, false);
1145+
readSqe_->setEventBase(nullptr);
11411146

11421147
unregisterFd();
11431148
if (!drc) {
@@ -1178,6 +1183,7 @@ folly::Optional<folly::SemiFuture<std::unique_ptr<IOBuf>>>
11781183
AsyncIoUringSocket::ReadSqe::detachEventBase() {
11791184
alive_ = nullptr;
11801185
parent_ = nullptr;
1186+
setEventBase(nullptr);
11811187
return std::move(oldEventBaseRead_);
11821188
}
11831189

@@ -1193,6 +1199,7 @@ void AsyncIoUringSocket::ReadSqe::attachEventBase() {
11931199
return;
11941200
}
11951201
auto* evb = parent_->evb_;
1202+
setEventBase(evb);
11961203
alive_ = std::make_shared<folly::Unit>();
11971204
folly::Func deferred =
11981205
[p = parent_, a = std::weak_ptr<folly::Unit>(alive_)]() {
@@ -1219,6 +1226,7 @@ AsyncIoUringSocket::FastOpenSqe::FastOpenSqe(
12191226
parent_(parent),
12201227
initialWrite(std::move(i)) {
12211228
addrLen_ = addr.getAddress(&addrStorage);
1229+
setEventBase(parent->evb_);
12221230
}
12231231

12241232
void AsyncIoUringSocket::FastOpenSqe::cleanupMsg() noexcept {
@@ -1311,6 +1319,7 @@ AsyncIoUringSocket::WriteSqe::detachEventBase() {
13111319
newSqe->refs_ = refs_;
13121320

13131321
parent_ = nullptr;
1322+
setEventBase(nullptr);
13141323
detachedSignal_ =
13151324
[prom = std::move(promise),
13161325
ret = std::vector<std::pair<int, uint32_t>>{},

folly/io/async/AsyncIoUringSocket.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,10 @@ class AsyncIoUringSocket : public AsyncSocketTransport {
351351

352352
struct CloseSqe : IoSqeBase {
353353
explicit CloseSqe(AsyncIoUringSocket* parent)
354-
: IoSqeBase(IoSqeBase::Type::Close), parent_(parent) {}
354+
: IoSqeBase(IoSqeBase::Type::Close), parent_(parent) {
355+
setEventBase(parent->evb_);
356+
}
357+
355358
void processSubmit(struct io_uring_sqe* sqe) noexcept override {
356359
parent_->closeProcessSubmit(sqe);
357360
}
@@ -417,7 +420,10 @@ class AsyncIoUringSocket : public AsyncSocketTransport {
417420
explicit ConnectSqe(AsyncIoUringSocket* parent)
418421
: IoSqeBase(IoSqeBase::Type::Connect),
419422
AsyncTimeout(parent->evb_),
420-
parent_(parent) {}
423+
parent_(parent) {
424+
setEventBase(parent->evb_);
425+
}
426+
421427
void processSubmit(struct io_uring_sqe* sqe) noexcept override {
422428
parent_->processConnectSubmit(sqe, addrStorage);
423429
}

folly/io/async/IoUringBackend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,7 @@ int IoUringBackend::eb_event_add(Event& event, const struct timeval* timeout) {
12581258
auto* ioSqe = allocIoSqe(event.getCallback());
12591259
CHECK(ioSqe);
12601260
ioSqe->event_ = &event;
1261+
ioSqe->setEventBase(event.eb_ev_base());
12611262

12621263
// just append it
12631264
submitList_.push_back(*ioSqe);

folly/io/async/IoUringBackend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ class IoUringBackend : public EventBaseBackendBase {
522522
FOLLY_ALWAYS_INLINE void resetEvent() {
523523
// remove it from the list
524524
unlink();
525+
setEventBase(nullptr);
525526
if (event_) {
526527
event_->setUserData(nullptr);
527528
event_ = nullptr;

0 commit comments

Comments
 (0)