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