Emitting a poll/select event from a timer handler through a wait queue
Call wake_up_interruptible()
on the polled queue just force the .poll
method to be called again. User space process receive notification only when .poll
method returns mask which have polled bits set.
Check that your .poll
method actually returns non-zero mask.
Reading a device from kernel interrupt
After reading the answer of @VivekS in this post I took a look at Linux Device Drivers, chapter 10, which states:
A handler can't transfer data to or from user space, because it
doesn't execute in the context of a process. Handlers also cannot do
anything that would sleep, such as calling wait_event, allocating
memory with anything other than GFP_ATOMIC, or locking a semaphore.
Finally, handlers cannot call schedule.
Using select()/poll() in device driver
You may want to write your own custom sk_buff
handler, which calls the kernel_select()
that tries to lock the semaphore and does a blocking wait when the socket is open.
Not sure if you have already gone through this link Simulate effect of select()
and poll()
in kernel socket programming
linux device driver select/epoll support
Yes, the kernel will loop through all the file descriptors and call the poll() method. It needs to sample the current state of all the file descriptors in order to report them back to the caller in userspace.
Note, that this is true for select and poll, I'm not familiar with epoll, but if it uses the same file op, then it should apply here as well.
Writing to Linux device driver causes infinite loop
I think the kernel write operation is supposed to return the number of bytes written. You return 0. So the write system call returns to userspace with 0. However, since your userspace code is using stdio, then your userspace code tries the write again, assuming the system call simply didn't write out all the data. If you return the length of the input, then stdio will know all the data was written. Alternatively you can use the write system call directly rather than fputs
. Your kernel code will still be incorrect, but your program will terminate.
You can test this using strace
and see all the system calls.
Related Topics
Difference Between Archiving and Compression
Prevent R from Using Virtual Memory on Unix/Linux
See What Process Last Touched a File
Compare Two Different Urls Using Linux
Docker Can't Write to Directory Mounted Using -V Unless It Has 777 Permissions
Nasm X86_64 Assembly in 32-Bit Mode: Why Does This Instruction Produce Rip-Relative Addressing Code
Linux - Change The Hostname in The Cli
Fedora 28/Glibc 2.27 Libm.So.6 Logf() and Powf() C++
Reset Bash History Search Position
Cmake: Don't Set Rpath for a Single Library Used in Link
Does Gcc Support Command Files
Cmake, Rpath, $Origin and @Loader_Path
Docker Run Groupadd && Useradd Directives Have No Effect
Scheduling in Linux: Run a Task When Computer Is Idle (= No User Input)