在LDD3的scull_p_poll函数中,如果我理解正确,如果没有唤醒poll_wait并且发生超时,则poll返回零。
static unsigned int scull_p_poll(struct file *filp, poll_table *wait)
{
struct scull_pipe *dev = filp->private_data;
unsigned int mask = 0;
/*
* The buffer is circular; it is considered full
* if "wp" is right behind "rp" and empty if the
* two are equal.
*/
down(&dev->sem);
poll_wait(filp, &dev->inq, wait);
poll_wait(filp, &dev->outq, wait);
if (dev->rp != dev->wp)
mask |= POLLIN | POLLRDNORM; /* readable */
if (spacefree(dev))
mask |= POLLOUT | POLLWRNORM; /* writable */
up(&dev->sem);
return mask;
}
这是关于poll_wait如何工作的正确假设吗?这是我从Why do we need to call poll_wait in poll?和How to add poll function to the kernel module code?
中删除的内容由于我看到的所有示例都返回零,如果不存在有效的POLLIN或POLLRDNORM状态,我假设零是正确的超时返回。任何人都可以澄清这一点或指向我显示这个的文档吗?我没有比poll.h更深入地阅读。
答案 0 :(得分:0)
在给定的示例中,假设您有一个用户空间应用,它会像下面那样轮询驱动程序以获取案例。
struct pollfd pofd;
pofd.fd = open("/dev/scull", O_RDONLY | O_NONBLOCK);
pofd.events = POLLIN | POLLRDNORM;
pofd.revents = 0;
/* Notice no timeout given. */
ret = poll(&pofd, 1, -1);
if (pofd.revents | POLLIN) {
printf("POLLIN done, reading from the device.\n");
ret = read(pofd.fd, receive, BUFFER_LENGTH);
......
}
一旦数据就绪条件完成,就需要在内核空间设备驱动程序中唤醒等待队列,例如:
wake_up_interruptible(&dev->inq);