Brussels / 3 & 4 February 2024

schedule

libvpoll: create synthetic events for poll, select and friends


Many programs use poll/select system calls to wait for events that are triggered by file descriptor I/O events. For instance, to write a library able to behave like a network stack (e.g. lwip and picoTCP) or a device, it's possible to implement functions like my_socket, my_accept, my_open and my_ioctl, as drop-in replacement of the system call counterparts. Additionally, it's possible to use dynamic library magic to rename/divert the system call requests to use their virtual implementation provided by the library. Unfortunately this approach cannot be applied to poll/select system calls because Linux doesn't have a system call that permits to generate synthetic generic events for a file descriptor, so it is not possible for libraries to provide file descriptors suitable for select/poll system calls.

libvpoll permits to define file descriptors whose I/O events can be generated at user level. This permits to generate synthetic events for poll, select, ppoll, pselect, epoll, etc. The libvpoll library can use two different supports: a module that provides a virtual device and a kernel patch extending the eventfd system call. When neither are availables, a feature-limited emulation is provided as a fallback: based on pipe it manages only POLLIN and POLLOUT. This approach allows mixing real file descriptors with others provided by libraries as parameters of poll/select system calls. For example libvpoll has been used in picoxnet, a user-level network stack implemented as a library for the Internet of Threads. libvpoll, as well as the kernel device module, are already available in Debian.

Speakers

Luca Bassi
Photo of Renzo Davoli Renzo Davoli

Attachments

Links