投票即将从驾驶员那里退出 [英] poll exiting immidiately from driver

查看:77
本文介绍了投票即将从驾驶员那里退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在linux内核&中实现驱动程序的第一次经验.面对这个问题.

This is my first experience of implementing a driver in linux kernel & facing this problem.

我正在尝试在字符驱动程序中实现"poll()". 我打电话给poll_wait()&通过了等待队列.

I am trying to implement "poll()" in my character driver. I have called poll_wait() & passed a wait queue.

从用户空间程序&打开该驱动程序的设备文件时,在此设备文件描述符(fd)上称为轮询"系统调用的情况下,即使没有数据要发送到用户空间,轮询系统调用也会立即退出.

When the device file of this driver is opened from the user space program & called "poll" system call on this device file descriptor (fd), poll system call exits immediately even when there is no data to be send to the user space.

它不等待平均超时时间.

It does not wait for even timeout period.

我无法找出导致此问题的原因.

I am unable to figure out what is causing this problem.

有人可以提出任何解决方案吗?

Can anyone suggest any solution ?

推荐答案

当有人在设备文件上调用poll()系统调用时,vfs层将以这种方式进行处理.

When someone calls poll() system call on device file then vfs layer handles it this way.

它调用驱动程序的轮询处理程序(以下称为my_poll).

It calls your driver's poll handler (henceforth referred as my_poll).

  1. 如果您不调用poll_wait,那么上层将仅返回mask而不分析其值.
  2. 如果使用poll_wait()将驱动程序/呼叫过程添加到等待队列中,则呼叫过程将添加到等待队列中.
  1. If you do not call poll_wait then upper layer will just return mask without analyzing its value.
  2. If you add your driver/calling process to a wait queue using poll_wait() then calling process will be added to wait queue.

不要被API的名称poll_wait()所欺骗.它实际上并没有等待或休眠.它只是将您的进程添加到等待事件通知的等待进程列表中.

Do not get deceived by the API's name poll_wait(). It doesn't actually wait or sleeps. It merely adds your process to the list of waiting processes for receiving event notification.

poll_wait()返回之后,整个行为取决于返回的掩码.此掩码的值由VFS层使用.如果返回的掩码为零,它将使调用过程进入睡眠状态.现在,过程正在等待事件发生.

After returning from poll_wait(), the entire behavior depends on the mask returned. Value of this mask is used by VFS layer. If the mask returned is zero, it'll put the calling process to sleep. Now the process is waiting for the event to happen.

当某人唤醒此等待队列时,所有等待过程都会得到通知. VFS层再次调用my_poll()&检查mask的返回值.

When someone awakens this wait queue, all waiting processes gets notification. VFS layer again calls my_poll() & checks returned value of mask.

以上过程将继续进行,直到VFS层收到非零掩码为止. 这意味着my_poll()将被多次调用.因此,想要在其设备驱动程序中实现轮询/读取的任何人,都应在返回就绪掩码之前检查设备是否实际上已准备好进行读取/写入操作. 这里要注意的重要一点是,不要假定poll_wait()会在有人唤醒该队列之前进入睡眠状态.

Above process continues until VFS layer receives a non-zero mask. It means my_poll() will be called multiple times. So anyone who wants to implement poll/read in his device driver, should check whether device is actually ready for read/write operation before returning readiness mask. Important thing to note here is that do not assume that poll_wait() will sleep until someone awakens that queue.

这篇关于投票即将从驾驶员那里退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆