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

Add non persistent events overflow tests

Summary: Add non persistent events overflow tests

Reviewed By: danobi, kevin-vigor

Differential Revision: D19349804

fbshipit-source-id: 360d1f41d074b3d1af5f163213dadfc35f28c353
parent dec61fcb
...@@ -78,6 +78,13 @@ IoUringBackend::~IoUringBackend() { ...@@ -78,6 +78,13 @@ IoUringBackend::~IoUringBackend() {
void IoUringBackend::cleanup() { void IoUringBackend::cleanup() {
if (ioRing_.ring_fd > 0) { if (ioRing_.ring_fd > 0) {
// release the nonsubmitted items from the submitList
while (!submitList_.empty()) {
auto* ioCb = &submitList_.front();
submitList_.pop_front();
releaseIoCb(ioCb);
}
// release the active events // release the active events
while (!activeEvents_.empty()) { while (!activeEvents_.empty()) {
auto* ioCb = &activeEvents_.front(); auto* ioCb = &activeEvents_.front();
......
...@@ -407,7 +407,6 @@ int PollIoBackend::eb_event_del(Event& event) { ...@@ -407,7 +407,6 @@ int PollIoBackend::eb_event_del(Event& event) {
event_ref_flags(ev) &= ~EVLIST_INSERTED; event_ref_flags(ev) &= ~EVLIST_INSERTED;
// not in use - we can cancel it // not in use - we can cancel it
// TBD- batching
if (!iocb->useCount_ && !wasLinked) { if (!iocb->useCount_ && !wasLinked) {
// io_cancel will attempt to cancel the event. the result is // io_cancel will attempt to cancel the event. the result is
// EINVAL - usually the event has already been delivered // EINVAL - usually the event has already been delivered
...@@ -432,6 +431,11 @@ int PollIoBackend::eb_event_del(Event& event) { ...@@ -432,6 +431,11 @@ int PollIoBackend::eb_event_del(Event& event) {
} }
return 0; return 0;
} else {
// we can have an EVLIST_ACTIVE event
// which does not have the EVLIST_INSERTED flag set
// so we need to release it here
releaseIoCb(iocb);
} }
return -1; return -1;
......
...@@ -48,9 +48,6 @@ class EventFD : public folly::EventHandler { ...@@ -48,9 +48,6 @@ class EventFD : public folly::EventHandler {
if (!persist_) { if (!persist_) {
registerHandler(folly::EventHandler::READ); registerHandler(folly::EventHandler::READ);
} }
size_t data;
if (sizeof(data) == folly::readNoInt(fd_, &data, sizeof(data))) {
CHECK_EQ(data, 1);
++num_; ++num_;
if (total_ > 0) { if (total_ > 0) {
--total_; --total_;
...@@ -59,7 +56,6 @@ class EventFD : public folly::EventHandler { ...@@ -59,7 +56,6 @@ class EventFD : public folly::EventHandler {
} }
} }
} }
}
uint64_t getNum() const { uint64_t getNum() const {
return num_; return num_;
...@@ -93,14 +89,14 @@ class EventFD : public folly::EventHandler { ...@@ -93,14 +89,14 @@ class EventFD : public folly::EventHandler {
folly::EventBase* evb_; folly::EventBase* evb_;
}; };
void testOverflow(bool overflow) { void testOverflow(bool overflow, bool persist) {
static constexpr size_t kBackendCapacity = 64; static constexpr size_t kBackendCapacity = 64;
static constexpr size_t kBackendMaxSubmit = 32; static constexpr size_t kBackendMaxSubmit = 32;
// for overflow == true we use a greater than kBackendCapacity number of // for overflow == true we use a greater than kBackendCapacity number of
// EventFD instances and lower when overflow == false // EventFD instances and lower when overflow == false
size_t kNumEventFds = overflow ? 2048 : 32; size_t kNumEventFds = overflow ? 2048 : 32;
static constexpr size_t kEventFdCount = 16; static constexpr size_t kEventFdCount = 16;
auto total = kNumEventFds * kEventFdCount; auto total = kNumEventFds * kEventFdCount + kEventFdCount / 2;
std::unique_ptr<folly::EventBaseBackendBase> backend; std::unique_ptr<folly::EventBaseBackendBase> backend;
...@@ -118,23 +114,31 @@ void testOverflow(bool overflow) { ...@@ -118,23 +114,31 @@ void testOverflow(bool overflow) {
eventsVec.reserve(kNumEventFds); eventsVec.reserve(kNumEventFds);
for (size_t i = 0; i < kNumEventFds; i++) { for (size_t i = 0; i < kNumEventFds; i++) {
eventsVec.emplace_back( eventsVec.emplace_back(
std::make_unique<EventFD>(kEventFdCount, total, true, &evb)); std::make_unique<EventFD>(kEventFdCount, total, persist, &evb));
} }
evb.loopForever(); evb.loopForever();
for (size_t i = 0; i < kNumEventFds; i++) { for (size_t i = 0; i < kNumEventFds; i++) {
CHECK_EQ(eventsVec[i]->getNum(), kEventFdCount); CHECK_GE(eventsVec[i]->getNum(), kEventFdCount);
} }
} }
} // namespace } // namespace
TEST(IoUringBackend, NoOverflow) { TEST(IoUringBackend, NoOverflowNoPersist) {
testOverflow(false); testOverflow(false, false);
}
TEST(IoUringBackend, OverflowNoPersist) {
testOverflow(true, false);
}
TEST(IoUringBackend, NoOverflowPersist) {
testOverflow(false, true);
} }
TEST(IoUringBackend, Overflow) { TEST(IoUringBackend, OverflowPersist) {
testOverflow(true); testOverflow(true, true);
} }
namespace folly { namespace folly {
......
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