-
Notifications
You must be signed in to change notification settings - Fork 268
Eventfd with epoll EPOLLET event doesn't match Linux #2673
Copy link
Copy link
Closed
Labels
Type: BugError or flaw producing unexpected resultsError or flaw producing unexpected results
Description
Describe the issue
When using eventfd with epoll with EPOLLET flag set, the result of epoll_wait in the real Linux is different from the one in Shadow
To Reproduce
Run the following code in Linux and in Shadow and see the difference.
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#define handle_error(msg) \
do { perror(msg); exit(EXIT_FAILURE); } while (0)
void *thread_fn(void *ptr);
int timeout1 = 2;
int timeout2 = 4;
int efd, epollfd;
void main() {
pthread_t thread1, thread2;
int iret1, iret2;
#define MAX_EVENTS 10
struct epoll_event ev, events[MAX_EVENTS];
int nfds;
epollfd = epoll_create1(EPOLL_CLOEXEC);
efd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
if (efd == -1)
handle_error("eventfd");
ev.events = EPOLLIN | EPOLLRDHUP | EPOLLET;
ev.data.fd = efd;
if (epoll_ctl(epollfd, EPOLL_CTL_ADD, efd, &ev) == -1)
handle_error("epoll_ctl: efd");
iret1 = pthread_create(&thread1, NULL, thread_fn, (void*) &timeout1);
iret2 = pthread_create(&thread2, NULL, thread_fn, (void*) &timeout2);
for (;;) {
nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);
if (nfds == -1)
handle_error("epoll_wait");
for (int n = 0; n < nfds; ++n) {
if (events[n].data.fd == efd) {
uint64_t u;
printf("event found\n");
}
}
fflush(stdout);
}
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
printf("Thread 1 returns: %d\n",iret1);
printf("Thread 2 returns: %d\n",iret2);
exit(0);
}
void *thread_fn(void *ptr) {
int timeout = *((int *)ptr);
sleep(timeout);
printf("%d\n", timeout);
fflush(stdout);
uint64_t inc = 10;
write(efd, &inc, sizeof(uint64_t));
}In Linux, the output will be
2
event found
4
event found
But in Shadow, the output is
2
event found
4
Operating System (please complete the following information):
- OS and version: Ubuntu 20.04.5 LTS
- Kernel version: Linux thinkpad-t14-g2 5.14.0-1055-oem # 62-Ubuntu SMP Wed Nov 30 04:54:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Shadow (please complete the following information):
- Version: Shadow v2.3.0-0-gb09b00ed 2022-11-29--13:01:25
- Which plug-ins you are using: The one shown above
Additional context
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type: BugError or flaw producing unexpected resultsError or flaw producing unexpected results