Commit b412547b authored by Dan Melnic's avatar Dan Melnic Committed by Facebook GitHub Bot

Remove PollIoBackend inline submit

Summary: Remove PollIoBackend inline submit

Reviewed By: danobi

Differential Revision: D21625033

fbshipit-source-id: 02ee55e64a2538c6a2392ea70912f4ae9b642963
parent 509ab86b
......@@ -92,18 +92,14 @@ bool IoUringBackend::FdRegistry::free(
return false;
}
IoUringBackend::IoUringBackend(
size_t capacity,
size_t maxSubmit,
size_t maxGet,
bool useRegisteredFds)
: PollIoBackend(capacity, maxSubmit, maxGet),
fdRegistry_(ioRing_, useRegisteredFds ? capacity : 0) {
IoUringBackend::IoUringBackend(Options options)
: PollIoBackend(options),
fdRegistry_(ioRing_, options.useRegisteredFds ? options.capacity : 0) {
::memset(&ioRing_, 0, sizeof(ioRing_));
::memset(&params_, 0, sizeof(params_));
params_.flags |= IORING_SETUP_CQSIZE;
params_.cq_entries = capacity;
params_.cq_entries = options.capacity;
// allocate entries both for poll add and cancel
if (::io_uring_queue_init_params(2 * maxSubmit_, &ioRing_, &params_)) {
......@@ -142,7 +138,7 @@ IoUringBackend::IoUringBackend(
// we need to call the init before adding the timer fd
// so we avoid a deadlock - waiting for the queue to be drained
if (useRegisteredFds) {
if (options.useRegisteredFds) {
// now init the file registry
// if this fails, we still continue since we
// can run without registered fds
......@@ -202,7 +198,9 @@ bool IoUringBackend::isAvailable() {
static folly::once_flag initFlag;
folly::call_once(initFlag, [&]() {
try {
IoUringBackend backend(1024, 128);
Options options;
options.setCapacity(1024);
IoUringBackend backend(options);
} catch (const NotAvailable&) {
sAvailable = false;
}
......
......@@ -32,11 +32,7 @@ class IoUringBackend : public PollIoBackend {
using std::runtime_error::runtime_error;
};
explicit IoUringBackend(
size_t capacity,
size_t maxSubmit = 128,
size_t maxGet = static_cast<size_t>(-1),
bool useRegisteredFds = false);
explicit IoUringBackend(Options options);
~IoUringBackend() override;
// returns true if the current Linux kernel version
......@@ -160,6 +156,12 @@ class IoUringBackend : public PollIoBackend {
size_t submit_internal();
// submit
size_t maxSubmit_;
// process
size_t maxGet_;
std::unique_ptr<IoSqe[]> entries_;
// io_uring related
......
......@@ -140,11 +140,8 @@ PollIoBackend::SocketPair::~SocketPair() {
}
}
PollIoBackend::PollIoBackend(size_t capacity, size_t maxSubmit, size_t maxGet)
: capacity_(capacity),
numEntries_(capacity),
maxSubmit_(maxSubmit),
maxGet_(maxGet) {
PollIoBackend::PollIoBackend(Options options)
: options_(options), numEntries_(options.capacity) {
// create the timer fd
timerFd_ = ::timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
if (timerFd_ < 0) {
......@@ -544,38 +541,13 @@ int PollIoBackend::eb_event_add(Event& event, const struct timeval* timeout) {
CHECK(iocb);
iocb->event_ = &event;
if (maxSubmit_) {
// just append it
submitList_.push_back(*iocb);
if (~event_ref_flags(ev) & EVLIST_INTERNAL) {
numInsertedEvents_++;
}
event_ref_flags(ev) |= EVLIST_INSERTED;
event.setUserData(iocb);
return 0;
} else {
auto* entry = allocSubmissionEntry(); // this can be nullptr
iocb->prepPollAdd(
entry,
ev->ev_fd,
getPollFlags(ev->ev_events),
(ev->ev_events & EV_PERSIST) != 0);
int ret = submitOne(iocb);
if (ret == 1) {
if (~event_ref_flags(ev) & EVLIST_INTERNAL) {
numInsertedEvents_++;
}
event_ref_flags(ev) |= EVLIST_INSERTED;
event.setUserData(iocb);
} else {
releaseIoCb(iocb);
}
if (ret != 1) {
throw std::runtime_error("io_submit error");
}
return (ret == 1) ? 0 : -1;
// just append it
submitList_.push_back(*iocb);
if (~event_ref_flags(ev) & EVLIST_INTERNAL) {
numInsertedEvents_++;
}
event_ref_flags(ev) |= EVLIST_INSERTED;
event.setUserData(iocb);
}
return 0;
......
......@@ -35,7 +35,40 @@ namespace folly {
class PollIoBackend : public EventBaseBackendBase {
public:
explicit PollIoBackend(size_t capacity, size_t maxSubmit, size_t maxGet);
struct Options {
Options() = default;
Options& setCapacity(size_t v) {
capacity = v;
return *this;
}
Options& setMaxSubmit(size_t v) {
maxSubmit = v;
return *this;
}
Options& setMaxGet(size_t v) {
maxGet = v;
return *this;
}
Options& setUseRegisteredFds(bool v) {
useRegisteredFds = v;
return *this;
}
size_t capacity{0};
size_t maxSubmit{128};
size_t maxGet{static_cast<size_t>(-1)};
bool useRegisteredFds{false};
};
explicit PollIoBackend(Options options);
~PollIoBackend() override;
// from EventBaseBackendBase
......@@ -327,7 +360,7 @@ class PollIoBackend : public EventBaseBackendBase {
return numIoCbInUse_;
}
size_t capacity_;
Options options_;
size_t numEntries_;
IoCb* timerEntry_{nullptr};
IoCb* signalReadEntry_{nullptr};
......@@ -348,12 +381,8 @@ class PollIoBackend : public EventBaseBackendBase {
std::map<int, std::set<Event*>> signals_;
// submit
size_t maxSubmit_;
IoCbList submitList_;
// process
size_t maxGet_;
// loop related
bool loopBreak_{false};
bool shuttingDown_{false};
......
......@@ -26,8 +26,13 @@ static constexpr size_t kMaxGet = static_cast<size_t>(-1);
struct IoUringBackendProvider {
static std::unique_ptr<folly::EventBaseBackendBase> getBackend() {
try {
return std::make_unique<folly::IoUringBackend>(
kCapacity, kMaxSubmit, kMaxGet, false /* useRegisteredFds */);
folly::PollIoBackend::Options options;
options.setCapacity(kCapacity)
.setMaxSubmit(kMaxSubmit)
.setMaxGet(kMaxGet)
.setUseRegisteredFds(false);
return std::make_unique<folly::IoUringBackend>(options);
} catch (const IoUringBackend::NotAvailable&) {
return nullptr;
}
......
......@@ -177,8 +177,9 @@ void testEventFD(bool overflow, bool persist, bool asyncRead) {
std::unique_ptr<folly::EventBaseBackendBase> backend;
try {
backend = std::make_unique<folly::IoUringBackend>(
kBackendCapacity, kBackendMaxSubmit);
folly::PollIoBackend::Options options;
options.setCapacity(kBackendCapacity).setMaxSubmit(kBackendMaxSubmit);
backend = std::make_unique<folly::IoUringBackend>(options);
} catch (const folly::IoUringBackend::NotAvailable&) {
}
......@@ -215,8 +216,10 @@ void testInvalidFd(size_t numTotal, size_t numValid, size_t numInvalid) {
std::unique_ptr<folly::EventBaseBackendBase> backend;
try {
backend = std::make_unique<folly::IoUringBackend>(
kBackendCapacity, kBackendMaxSubmit);
folly::PollIoBackend::Options options;
options.setCapacity(kBackendCapacity).setMaxSubmit(kBackendMaxSubmit);
backend = std::make_unique<folly::IoUringBackend>(options);
} catch (const folly::IoUringBackend::NotAvailable&) {
}
......@@ -363,8 +366,13 @@ void testAsyncUDPRecvmsg(bool useRegisteredFds) {
std::unique_ptr<folly::EventBaseBackendBase> backend;
try {
backend = std::make_unique<folly::IoUringBackend>(
kBackendCapacity, kBackendMaxSubmit, kBackendMaxGet, useRegisteredFds);
folly::PollIoBackend::Options options;
options.setCapacity(kBackendCapacity)
.setMaxSubmit(kBackendMaxSubmit)
.setMaxGet(kBackendMaxGet)
.setUseRegisteredFds(useRegisteredFds);
backend = std::make_unique<folly::IoUringBackend>(options);
} catch (const folly::IoUringBackend::NotAvailable&) {
}
......@@ -475,17 +483,15 @@ TEST(IoUringBackend, RegisteredFds) {
std::unique_ptr<folly::IoUringBackend> backendNoReg;
try {
backendReg = std::make_unique<folly::IoUringBackend>(
kBackendCapacity,
kBackendMaxSubmit,
kBackendMaxGet,
true /*useRegisteredFds*/);
backendNoReg = std::make_unique<folly::IoUringBackend>(
kBackendCapacity,
kBackendMaxSubmit,
kBackendMaxGet,
false /*useRegisteredFds*/);
folly::PollIoBackend::Options options;
options.setCapacity(kBackendCapacity)
.setMaxSubmit(kBackendMaxSubmit)
.setMaxGet(kBackendMaxGet)
.setUseRegisteredFds(true);
backendReg = std::make_unique<folly::IoUringBackend>(options);
options.setUseRegisteredFds(false);
backendNoReg = std::make_unique<folly::IoUringBackend>(options);
} catch (const folly::IoUringBackend::NotAvailable&) {
}
......@@ -535,8 +541,13 @@ static constexpr size_t kMaxGet = static_cast<size_t>(-1);
struct IoUringBackendProvider {
static std::unique_ptr<folly::EventBaseBackendBase> getBackend() {
try {
return std::make_unique<folly::IoUringBackend>(
kCapacity, kMaxSubmit, kMaxGet, false /* useRegisteredFds */);
folly::PollIoBackend::Options options;
options.setCapacity(kCapacity)
.setMaxSubmit(kMaxSubmit)
.setMaxGet(kMaxGet)
.setUseRegisteredFds(false);
return std::make_unique<folly::IoUringBackend>(options);
} catch (const IoUringBackend::NotAvailable&) {
return nullptr;
}
......@@ -546,8 +557,12 @@ struct IoUringBackendProvider {
struct IoUringRegFdBackendProvider {
static std::unique_ptr<folly::EventBaseBackendBase> getBackend() {
try {
return std::make_unique<folly::IoUringBackend>(
kCapacity, kMaxSubmit, kMaxGet, true /* useRegisteredFds */);
folly::PollIoBackend::Options options;
options.setCapacity(kCapacity)
.setMaxSubmit(kMaxSubmit)
.setMaxGet(kMaxGet)
.setUseRegisteredFds(true);
return std::make_unique<folly::IoUringBackend>(options);
} catch (const IoUringBackend::NotAvailable&) {
return nullptr;
}
......
......@@ -91,8 +91,12 @@ class BackendEventBase : public EventBase {
static std::unique_ptr<folly::EventBaseBackendBase> getBackend(
bool useRegisteredFds,
size_t capacity) {
return std::make_unique<IoUringBackend>(
capacity, 256, 128, useRegisteredFds);
folly::PollIoBackend::Options options;
options.setCapacity(capacity)
.setMaxSubmit(256)
.setMaxGet(128)
.setUseRegisteredFds(useRegisteredFds);
return std::make_unique<IoUringBackend>(options);
}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment