Eventfd: Difference between revisions

Created page with "Linux offers the eventfd abstraction for file descriptor-based userspace notification. It is backed by merely a single <tt>uint64_t</tt> in the kernel, unlike a pipe (which is usually backed by a much larger buffer). It is thus the most lightweight method of IPC available to userspace. The maximum value of the eventfd counter is 2^64-2 (0xfffffffffffffffe), and the minimum (and default) value is 0. In the past, a full pipe was often used to interrupt a th..."
 
No edit summary
Tags: Mobile edit Mobile web edit
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Linux_APIs|Linux]] offers the eventfd abstraction for file descriptor-based userspace notification. It is backed by merely a single <tt>uint64_t</tt> in the kernel, unlike a pipe (which is usually backed by a much larger buffer). It is thus the most lightweight method of IPC available to userspace. The maximum value of the eventfd counter is 2^64-2 (0xfffffffffffffffe), and the minimum (and default) value is 0.
[[Linux_APIs|Linux]] offers the eventfd abstraction for file descriptor-based userspace notification. It is backed by a single <tt>uint64_t</tt> in the kernel, unlike a pipe (which is usually backed by a much larger buffer). It is thus the most lightweight method of IPC available to userspace. The maximum value of the eventfd counter is 2^64-2 (0xfffffffffffffffe), and the minimum (and default) value is 0.


In the past, a full pipe was often used to interrupt a thread that was blocking in <tt>poll(2)</tt> (or <tt>select</tt>, or <tt>[[epoll]]</tt>, etc.). An eventfd can serve this same purpose while requiring less kernel memory.
In the past, a full pipe was often used to interrupt a thread that was blocking in <tt>poll(2)</tt> (or <tt>select</tt>, or <tt>[[epoll]]</tt>, etc.). An eventfd can serve this same purpose while requiring less kernel memory.
Line 6: Line 6:


<tt>POLLOUT</tt> is high whenever the value of the eventfd is less than its maximum, i.e. 0xfffffffffffffffd or less. It only guarantees that a value of 1 can be written without blocking.
<tt>POLLOUT</tt> is high whenever the value of the eventfd is less than its maximum, i.e. 0xfffffffffffffffd or less. It only guarantees that a value of 1 can be written without blocking.
==External links==
* [https://man7.org/linux/man-pages/man2/eventfd.2.html eventfd(2)] man page