0

Well, when we poll on some fds in user space the fds belong to the device node being opened(device file). How does data arrive in that device file and how does the data in kernel space goes to the userspace?

2
  • 1
    Read chapter 6 of LDD3.
    – CL.
    Dec 13, 2014 at 15:05
  • 1
    CL is right. Read LDD3. But in case you don't know what that refers to, it's THE linux device driver book to read. And best of all it's readily available for free: lwn.net/Kernel/LDD3
    – kaylum
    Dec 15, 2014 at 23:05

1 Answer 1

0

When poll() is called for some file descriptor, the corresponding device poll_xyx() method registered with file operation structure is invoked in kernel space. This method then checks if the data is readily available, if this condition is true then the event mask is set and the poll returns to user space. The user space application checks for the event mask and gets to know the data is ready for processing. So the user space application now calls read() on the file descriptor thus invoking the device read_xyz() method registered with the file operation structure in kernel space. This method copies the data in kernel space to the buffer passed by user application using copy_to_user() or put user().

However if poll() is called when the data is not readily available, then the process is put to sleep on a wait queue. When the data arrives the drivers wakes up the process sleeping on the wait queue inside the function poll_schedule_timeout(). After the application is woken up the same process described above continues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.