Project

General

Profile

Bug #8634

epoll fails to wake on certain edge-triggered conditions

Added by Patrick Mooney over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Category:
kernel
Start date:
2017-09-07
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

This replicates downstream bug OS-5882

There are certain circumstances under which epoll will fail to wake and emit events for descriptors under edge-triggered polling.

This small test program completes successfully on Linux but hangs on SmartOS:

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/eventfd.h>
#include <sys/epoll.h>

int evfd = -1;

void *writer(void *args) {
        uint64_t val = 1;

        usleep(1000);
        write(evfd, &val, sizeof (val));
    return NULL;
}

int main() {
        pthread_t thread_write;
        struct epoll_event epev;
        int epfd;

        evfd = eventfd(0, EFD_CLOEXEC|EFD_NONBLOCK);
        epfd = epoll_create1(0);

        epev.events = EPOLLIN|EPOLLOUT|EPOLLET;
        epev.data.fd = evfd;
        epoll_ctl(epfd, EPOLL_CTL_ADD, evfd, &epev);

        /* The eventfd is writable */
        epoll_wait(epfd, &epev, 1, -1);

        pthread_create(&thread_write, NULL, writer, NULL);

        /* The eventfd should report as readable once the above write succeeds */
        epoll_wait(epfd, &epev, 1, -1);

        pthread_join(thread_write, NULL);
}

One could argue that the same edge-triggered behavior in /dev/poll is also incorrect. Given the lack of proper specification, it's unclear.

Also available in: Atom PDF