Commit c4ce1953 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook Github Bot

Fix io_uring backend tests

Summary: Fix io_uring backend tests

Reviewed By: yfeldblum, danobi

Differential Revision: D19023775

fbshipit-source-id: d696064d26b37f52529c84601f6797ef82b0ddb5
parent 69baad3b
......@@ -124,11 +124,12 @@ int IoUringBackend::cancelOne(IoCb* ioCb) {
return ret;
}
int IoUringBackend::getActiveEvents(bool waitForEvents) {
int IoUringBackend::getActiveEvents(WaitForEventsMode waitForEvents) {
size_t i = 0;
struct io_uring_cqe* cqe = nullptr;
// we can be called from the submitList() method
if (FOLLY_LIKELY(waitForEvents)) {
// or with non blocking flags
if (FOLLY_LIKELY(waitForEvents == WaitForEventsMode::WAIT)) {
::io_uring_wait_cqe(&ioRing_, &cqe);
} else {
::io_uring_peek_cqe(&ioRing_, &cqe);
......@@ -154,7 +155,7 @@ int IoUringBackend::submitBusyCheck() {
int num;
while ((num = ::io_uring_submit(&ioRing_)) == -EBUSY) {
// if we get EBUSY, try to consume some CQ entries
getActiveEvents(false);
getActiveEvents(WaitForEventsMode::DONT_WAIT);
};
return num;
}
......@@ -163,12 +164,14 @@ int IoUringBackend::submitBusyCheckAndWait() {
int num;
while ((num = ::io_uring_submit_and_wait(&ioRing_, 1)) == -EBUSY) {
// if we get EBUSY, try to consume some CQ entries
getActiveEvents(false);
getActiveEvents(WaitForEventsMode::DONT_WAIT);
};
return num;
}
size_t IoUringBackend::submitList(IoCbList& ioCbs) {
size_t IoUringBackend::submitList(
IoCbList& ioCbs,
WaitForEventsMode waitForEvents) {
int i = 0;
size_t ret = 0;
......@@ -182,7 +185,9 @@ size_t IoUringBackend::submitList(IoCbList& ioCbs) {
entry->prepPollAdd(sqe, ev->ev_fd, getPollFlags(ev->ev_events));
i++;
if (ioCbs.empty()) {
int num = submitBusyCheckAndWait();
int num = (waitForEvents == WaitForEventsMode::WAIT)
? submitBusyCheckAndWait()
: submitBusyCheck();
CHECK_EQ(num, i);
ret += i;
} else {
......
......@@ -46,8 +46,8 @@ class IoUringBackend : public PollIoBackend {
protected:
// from PollIoBackend
void* allocSubmissionEntry() override;
int getActiveEvents(bool waitForEvents = true) override;
size_t submitList(IoCbList& ioCbs) override;
int getActiveEvents(WaitForEventsMode waitForEvents) override;
size_t submitList(IoCbList& ioCbs, WaitForEventsMode waitForEvents) override;
int submitOne(IoCb* ioCb) override;
int cancelOne(IoCb* ioCb) override;
......
......@@ -225,7 +225,7 @@ size_t PollIoBackend::processActiveEvents() {
size_t ret = 0;
IoCb* ioCb;
while (!activeEvents_.empty()) {
while (!activeEvents_.empty() && !loopBreak_) {
bool release = true;
ioCb = &activeEvents_.front();
activeEvents_.pop_front();
......@@ -261,15 +261,18 @@ size_t PollIoBackend::processActiveEvents() {
int PollIoBackend::eb_event_base_loop(int flags) {
// schedule the timers
bool done = false;
auto waitForEvents = (flags & EVLOOP_NONBLOCK) ? WaitForEventsMode::DONT_WAIT
: WaitForEventsMode::WAIT;
while (!done) {
scheduleTimeout();
submitList(submitList_);
// check if we need to break here
if (loopBreak_) {
loopBreak_ = false;
break;
}
submitList(submitList_, waitForEvents);
if (!numInsertedEvents_ && timers_.empty()) {
return 1;
}
......@@ -279,7 +282,8 @@ int PollIoBackend::eb_event_base_loop(int flags) {
eb_poll_loop_pre_hook(&call_time);
}
int ret = getActiveEvents();
// do not wait for events if EVLOOP_NONBLOCK is set
int ret = getActiveEvents(waitForEvents);
if (eb_poll_loop_post_hook) {
eb_poll_loop_post_hook(call_time, ret);
......@@ -287,12 +291,12 @@ int PollIoBackend::eb_event_base_loop(int flags) {
size_t numProcessedTimers = 0;
if (processTimers_) {
if (processTimers_ && !loopBreak_) {
numProcessedTimers = processTimers();
processTimers_ = false;
}
if (!activeEvents_.empty()) {
if (!activeEvents_.empty() && !loopBreak_) {
processActiveEvents();
if (flags & EVLOOP_ONCE) {
done = true;
......
......@@ -48,6 +48,8 @@ class PollIoBackend : public EventBaseBackendBase {
int eb_event_del(Event& event) override;
protected:
enum class WaitForEventsMode { WAIT, DONT_WAIT };
struct IoCb
: public boost::intrusive::list_base_hook<
boost::intrusive::link_mode<boost::intrusive::auto_unlink>> {
......@@ -161,8 +163,10 @@ class PollIoBackend : public EventBaseBackendBase {
virtual IoCb* allocNewIoCb() = 0;
virtual void* allocSubmissionEntry() = 0;
virtual int getActiveEvents(bool waitForEvents = true) = 0;
virtual size_t submitList(IoCbList& ioCbs) = 0;
virtual int getActiveEvents(WaitForEventsMode waitForEvents) = 0;
virtual size_t submitList(
IoCbList& ioCbs,
WaitForEventsMode waitForEvents) = 0;
virtual int submitOne(IoCb* ioCb) = 0;
virtual int cancelOne(IoCb* ioCb) = 0;
......
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