当应用程序使用 poll() 而不是 linux 中的 epoll() 时,调用将路由到驱动程序
Calls are getting routed to the driver, when application uses poll() and not with epoll() in linux
使用 poll()
而不是 epoll()
时,应用程序调用将路由到驱动程序轮询方法。谁能知道为什么会这样?下面是我的 epoll 应用程序代码。另一个观察是,epoll_ctl()
呼叫被路由到驱动程序而不是 epoll_wait()
。
struct epoll_event ev, events[MAX_EPOLL_EVENTS];
int epfd, nfds;
epfd = epoll_create(MAX_EPOLL_EVENTS);
ev.events = EPOLLIN | EPOLLET;
ev.data.fd = fd; /* fd is an open file descriptor */
if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev) == -1) {
printf("epoll_ctl failed\n");
}
nfds = epoll_wait(epfd, &events, MAX_EPOLL_EVENTS, 10000);
poll 和 epoll 的实现不同。
首先,我们知道 driver 的 poll
总是调用 poll_wait()
。这是这两个系统调用最重要的区别。
poll/select
每次从用户空间调用poll/select时,都会调用driver的poll
。它将当前进程添加到等待队列并将等待队列添加到 poll_table
。
- 用户空间轮询了 2 个不同的文件描述符
- 内核调用了每个文件描述符'
poll
driver.
poll
driver 称为 poll_wait
。它在 poll_table
中添加了当前进程
- 假设他们也没有准备好。所以
poll table
中有 2 个等待队列。
- 当 1 个文件描述符准备就绪时,它唤醒了进程。
- 被唤醒的进程然后再次调用每个文件描述符的
poll
driver 以检查哪个文件描述符已准备就绪。
- 终于回到了用户空间
epoll
driver的poll
只被epoll_ctl
调用。
- 用户空间调用
epoll_ctl
来设置 2 个不同的文件描述符
- 内核调用了每个文件描述符'
poll
driver.
poll
driver 称为 poll_wait
。但是这次poll_wait
和poll/select不一样。它不仅在poll_table
中添加当前进程,而且在进程被唤醒时将回调函数更改为ep_poll_callback
。
- 假设他们也没有准备好。所以现在
poll table
中有 2 个等待队列。
- 当 1 个文件描述符准备就绪时,它唤醒了进程。
- 因此
ep_poll_callback
被调用。它将相应的文件描述符添加到epoll
的就绪队列中
epoll_wait
定期检查就绪队列并找到就绪队列。
- 终于回到了用户空间
使用 poll()
而不是 epoll()
时,应用程序调用将路由到驱动程序轮询方法。谁能知道为什么会这样?下面是我的 epoll 应用程序代码。另一个观察是,epoll_ctl()
呼叫被路由到驱动程序而不是 epoll_wait()
。
struct epoll_event ev, events[MAX_EPOLL_EVENTS];
int epfd, nfds;
epfd = epoll_create(MAX_EPOLL_EVENTS);
ev.events = EPOLLIN | EPOLLET;
ev.data.fd = fd; /* fd is an open file descriptor */
if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev) == -1) {
printf("epoll_ctl failed\n");
}
nfds = epoll_wait(epfd, &events, MAX_EPOLL_EVENTS, 10000);
poll 和 epoll 的实现不同。
首先,我们知道 driver 的 poll
总是调用 poll_wait()
。这是这两个系统调用最重要的区别。
poll/select
每次从用户空间调用poll/select时,都会调用driver的poll
。它将当前进程添加到等待队列并将等待队列添加到 poll_table
。
- 用户空间轮询了 2 个不同的文件描述符
- 内核调用了每个文件描述符'
poll
driver. poll
driver 称为poll_wait
。它在poll_table
中添加了当前进程
- 假设他们也没有准备好。所以
poll table
中有 2 个等待队列。 - 当 1 个文件描述符准备就绪时,它唤醒了进程。
- 被唤醒的进程然后再次调用每个文件描述符的
poll
driver 以检查哪个文件描述符已准备就绪。 - 终于回到了用户空间
epoll
driver的poll
只被epoll_ctl
调用。
- 用户空间调用
epoll_ctl
来设置 2 个不同的文件描述符 - 内核调用了每个文件描述符'
poll
driver. poll
driver 称为poll_wait
。但是这次poll_wait
和poll/select不一样。它不仅在poll_table
中添加当前进程,而且在进程被唤醒时将回调函数更改为ep_poll_callback
。- 假设他们也没有准备好。所以现在
poll table
中有 2 个等待队列。 - 当 1 个文件描述符准备就绪时,它唤醒了进程。
- 因此
ep_poll_callback
被调用。它将相应的文件描述符添加到epoll
的就绪队列中
epoll_wait
定期检查就绪队列并找到就绪队列。- 终于回到了用户空间