Kernel 函数返回超时值
在LDD3的scull_p_poll函数中,如果我理解正确,如果poll_wait没有被唤醒并且发生超时,poll返回零Kernel 函数返回超时值,kernel,driver,Kernel,Driver,在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;
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如何工作的正确假设吗?这就是我从中拿走的东西
正如我看到的所有示例一样,如果不存在有效的POLLIN或pollrdorm状态,则返回零,我假设零是正确的超时返回。有人能澄清这一点,或者给我指一下显示这一点的文档吗?我没有读过比poll.h更深入的内容。在给定的示例中,假设您有一个userspace应用程序像下面这样轮询您的驱动程序,以获取阅读案例
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);
......
}
完成数据就绪条件后,您需要在kernelspace设备驱动程序中唤醒waitqueue,如下所示:
wake_up_interruptible(&dev->inq);
您是否未能理解第一个链接问题?poll_wait根本不等待。掩码,返回scull_p_poll,并使用select/poll系统调用中请求的掩码进行编辑,并将生成的掩码与0进行比较。若生成的掩码为非零,则设备被视为就绪,系统调用返回。否则,设备将被视为未就绪,系统调用将在scull_p_poll!之外等待!。与轮询相关的系统调用的实际实现是在fs/select.c.ahh中,感谢您将我指向fs/select.c-我实际上并不理解它,但您重复的轮询等待根本没有等待,这让我印象深刻。我现在明白了