Skip to content

Commit

Permalink
set io_uring eventfd non-blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
beef9999 committed Dec 16, 2023
1 parent 70570ee commit 6e4355a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
7 changes: 3 additions & 4 deletions examples/sync-primitive/sync-primitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct Message {
std::chrono::time_point<std::chrono::steady_clock> start;
};

static const int num_producers = 16, num_consumers = 16;
static const int num_producers = 8, num_consumers = 8;
static LockfreeMPMCRingQueue<Message*, 1024 * 1024> ring;
static std::atomic<uint64_t> qps{0}, latency{0};

Expand Down Expand Up @@ -90,7 +90,7 @@ int main() {
Message message;
ring.push(&message);
{
std::unique_lock l(message.mu);
std::unique_lock<std::mutex> l(message.mu);
message.cv.wait(l, [&] { return message.done; });
}
auto end = std::chrono::steady_clock::now();
Expand All @@ -117,7 +117,7 @@ int main() {
m->sem.signal(1);
#else
{
std::unique_lock l(m->mu);
std::unique_lock<std::mutex> l(m->mu);
m->done = true;
m->cv.notify_one();
}
Expand All @@ -128,7 +128,6 @@ int main() {

// Show QPS and latency
photon::thread_create11([&] {
photon::init(photon::INIT_EVENT_DEFAULT, photon::INIT_IO_NONE);
while (true) {
photon::thread_sleep(1);
auto prev_qps = qps.exchange(0, std::memory_order_seq_cst);
Expand Down
8 changes: 3 additions & 5 deletions io/iouring-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class iouringEngine : public MasterEventEngine, public CascadingEventEngine, pub
}
}

m_eventfd = eventfd(0, EFD_CLOEXEC);
m_eventfd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
if (m_eventfd < 0) {
LOG_ERRNO_RETURN(0, -1, "iouring: failed to create eventfd");
}
Expand Down Expand Up @@ -285,10 +285,8 @@ class iouringEngine : public MasterEventEngine, public CascadingEventEngine, pub
if (ret < 0) {
return errno == ETIMEDOUT ? 0 : -1;
}
uint64_t value = 0;
if (eventfd_read(m_eventfd, &value)) {
LOG_ERROR("iouring: error reading cascading event fd, `", ERRNO());
}
uint64_t value;
eventfd_read(m_eventfd, &value);

// Reap events
size_t num = 0;
Expand Down
2 changes: 1 addition & 1 deletion rpc/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ namespace rpc
const T& operator[](long i) const { return ((T*)_ptr)[i]; }
const T& front() const { return (*this)[0]; }
const T& back() const { return (*this)[(long)size() - 1]; }
bool empty() const { return _len == 0; }
void assign(const T* x, size_t size) { buffer::assign(x, sizeof(*x) * size); }
void assign(const std::vector<T>& vec) { assign(&vec[0], vec.size()); }

Expand Down Expand Up @@ -105,7 +106,6 @@ namespace rpc
const char* c_str() const { return cbegin(); }
std::string_view sv() const { return {c_str(), size() - 1}; }
std::string to_std() { return std::string(sv()); };
bool empty() const { return _len == 0; }
bool operator==(const string& rhs) const { return sv() == rhs.sv(); }
bool operator!=(const string& rhs) const { return !(*this == rhs); }
bool operator<(const string& rhs) const { return sv() < rhs.sv(); }
Expand Down

0 comments on commit 6e4355a

Please sign in to comment.